import { SuperPage, wxPage } from '@core/setup'; import session from '@src/utils/auth/session'; import model from './model'; @wxPage() export default class Home extends SuperPage { data = { model, avatar: '', nickName: '', hasUserInfo: false, toyModuleList: [ { imgUrl: 'https://img.yzcdn.cn/vant/cat.jpeg', title: '红色宝宝', }, { imgUrl: '', title: '黄色宝宝', }, { imgUrl: '', title: '绿色宝宝', }, { imgUrl: '', title: '超级无敌彩虹宝宝', }, ], }; onLoad() { this.initPage(); } initPage() { if (!this.data.hasUserInfo) return; } async getUserProfile() { if (this.data.hasUserInfo) return; const { encryptedData, iv } = await wx.getUserProfile({ desc: '展示用户信息' }); const res = await session.updateUser({ encryptedData, iv }); this.setData({ avatar: res.userInfo.headPhotoUrl, nickName: res.userInfo.nickName, hasUserInfo: true, }); } async onClickOrderItem(e: WechatMiniprogram.TouchEvent) { const { row } = e.currentTarget.dataset; await this.app.route.go({ url: row.url, query: { type: row.type }, }); } async onClickToyItem() { await this.app.route.go({ name: 'ToyCabinet', }); } }