import { postRequest, getRequest, putRequest } from '../../utils/js/request' import { queryLogin, queryInfo, signIn } from '../../utils/js/locales' let app = getApp(); Page({ data: { userInfo: {}, logo: '', hasUserInfo: false, canIUseGetUserProfile: false, }, onLoad: function (options) { this.setData({ userInfo: {}, logo: app.globalData.info.logo, hasUserInfo: false, canIUseGetUserProfile: false }) }, onShow: function () { if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 let that = this; wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { putRequest('/v1/p/info', { nick: res.userInfo.nickName, logo: res.userInfo.avatarUrl }).then(res => { }).catch(err => { signIn(err) }) app.globalData.userInfo = res.userInfo wx.setStorageSync('nickName', res.userInfo.nickName); wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl); this.setData({ hasUserInfo: true, logo: res.userInfo.avatarUrl, userInfo: res.userInfo }) } }) }, getUserInfo(e) { // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 app.globalData.userInfo = e.detail.userInfo this.setData({ hasUserInfo: true, userInfo: e.detail.userInfo }) }, // 点击用户登录 decryptPhoneNumber(e) { let that = this; wx.checkSession({ success (item) { if (e.detail.encryptedData) { let data = { encrypt: e.detail.encryptedData, errMsg: e.detail.errMsg, iv: e.detail.iv, name: that.data.userInfo.nickName ? that.data.userInfo.nickName : ('肉仔仔' + e.detail.iv.substring(6,13)) } wx.showLoading({ title: '授权中' }) postRequest('/v1/m/cert/phone/encrypt',data).then(res => { setTimeout(function () { queryLogin(app) }, 3000); setTimeout(function () { queryInfo(app) wx.showToast({ icon: 'none', title: '授权成功!', duration: 2000 }) }, 4000); setTimeout(function () { wx.hideLoading(); wx.reLaunch({ url: '/pages/index/index' }) }, 5000); }).catch(err => { wx.hideLoading(); signIn(err) }) } }, fail () { // session_key 已经失效,需要重新执行登录流程 wx.login({ }) } }) }, // /** 用户点击右上角分享 */ // onShareAppMessage: function () { // return { path: "pages/firstpage/firstpage?from=share" } // } })