const app = getApp() const config = require("../../config/config") const Http = require("../../utils/HttpBasics.js") const navigationBarHeight = (getApp().statusBarHeight + 44) + "px" Page({ data: { signal: app.globalData.platform, navigationBarHeight, imgHttps: app.globalData.imgHttps, userData: "", userPhone: "", phoneNum:"", showBindPhone: false,//绑定手机号弹框 Num: 60, NumFlag: false, code: ""//验证码 }, showBox() { this.setData({ showBindPhone: true }) }, hideBox() { this.setData({ showBindPhone: false }) }, setUserPhone(e) { let value = e.detail.value this.setData({ userPhone: value }) }, setCodePhone(e) { let value = e.detail.value this.setData({ code: value }) }, phoneFromCode() {//授权手机号 Http.post({ url: config.api.phoneFromCode, data: { code: this.data.code, phone: this.data.userPhone } }).then(res => { tt.showToast({ title: '授权成功', // 内容 icon: "none" }); this.setData({ showBindPhone: false }) this.getUserData() }).catch(err => { tt.showToast({ title: err.message ? err.message : err.data, icon: "none" }); }) }, getCode() {//获取验证码 console.log(this.data.userPhone); let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/; if (!myreg.test(this.data.userPhone)) { tt.showToast({ title: '请输入正确的手机号', icon: "none" }); return } Http.get({ url: config.api.getCodePhone, data: { phone: this.data.userPhone } }).then(res => { this.setData({ NumFlag: true }) let tiem = setInterval(() => { console.log(this.data.Num) this.setData({ Num: this.data.Num - 1 }) if (this.data.Num <= 1) { clearInterval(tiem) this.setData({ NumFlag: false }) } }, 1000) tt.showToast({ title: '发送成功', icon: "none" }); }).catch(err => { tt.showToast({ title: err.message ? err.message : err.data, icon: "none" }); }) }, getUserData() {//获取用户信息 Http.get({ url: config.api.getUserInfo }).then(res => { console.log(res.data.phone); if (res.data.phone) { this.setData({ phoneNum: res.data.phone }) } }).catch(err => { tt.showToast({ title: err.message ? err.message : err.data, icon: "none" }); }) }, onLoad: function () { console.log(123); this.getUserData() let _this = this tt.login({ success(_res) { let { code } = _res Http.post({ url: config.api.login, data: { code: code, appId: 'tt8183f73e1ebb053701' } }).then(res => { Http.setToken(res.data.token); app.globalData.token = res.data.token tt.getUserInfo({// 获取用户信息 withCredentials: true, // withRealNameAuthenticationInfo: true, success(res) { console.log(res); _this.setData({ userData: res.userInfo }) Http.get({ url: config.api.checkUserInfo }).then(res => { }).catch(err => { console.log("我没提交授权", err.code); if (err.code == 11004) { Http.post({ url: config.api.userInfo, data: { iv: res.iv, encryptedData: res.encryptedData } }).then(res => { console.log(res); }) } }) }, fail(res) { tt.navigateTo({ url: 'pages/index/index' // 指定页面的url }); }, }); }).catch(err => { console.log(err); tt.showModal({ title: '提示', showCancel: false, content: '登录失败,请重新尝试', success: (res) => { if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.reLaunch({ url: '/pages/index/index', }) } } }); }) }, }); } })