// index.ts // 获取应用实例 const app = getApp() var mixins = require('../../utils/mixins') Page({ mixins: [mixins], data: { isShowHelp: false, isShowAuth: true, userInfo: {}, hasUserInfo: false, }, // 事件处理函数 toPerson() { this.getUserProfile(() => { wx.navigateTo({ url: '../person/index', }) }) }, tapclose() { this.setData({ isShowHelp: false }) }, tapAuthclose(){ this.setData({ isShowAuth: false }) }, tapHelp() { this.setData({ isShowHelp: true }) }, toActivity() { this.getUserProfile(() => { wx.navigateTo({ url: '../activity_mode/index', }) }) }, toGame() { this.getUserProfile(() => { wx.navigateTo({ url: `../game/index`, }) }) }, getUserProfile(cb = () => { }) { if (this.data.hasUserInfo) { cb() } else { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: res => { console.log(res); let { userInfo } = res // @ts-ignore this.data.fetchutil.post(`/sys/wxUser/save`, { "avatarUrl": userInfo.avatarUrl, "gender": userInfo.gender, "nickName": userInfo.nickName, // @ts-ignore id: app.globalData.userInfo.id }, {}).then((response: any) => { console.log(response); this.setData({ hasUserInfo: true }) cb() }) } }) } }, onLoad(options) { let {noTips} = options if (!noTips) { this.setData({ isShowHelp:true }) } }, onShow(){ // @ts-ignore app.watch('hasAvatar', (v: any) => { if (v) { this.setData({ hasUserInfo: true }) } }) } })