const auth = require('../../utils/auth'); function authStatusText(status) { const map = { 0: '未认证', 1: '已认证', 2: '审核中' }; return map[status] || '未认证'; } function maskPhone(phone) { if (!phone || phone.length < 7) return phone || ''; return phone.substring(0, 3) + '****' + phone.substring(7); } Page({ data: { loggedIn: false, profile: {}, maskedPhone: '', authStatusText: '未认证' }, onShow() { const accessToken = wx.getStorageSync('accessToken') || ''; if (!accessToken) { this.setData({ loggedIn: false, profile: {}, maskedPhone: '', authStatusText: '未认证' }); return; } this.setData({ loggedIn: true }); this.loadProfile(); }, onPullDownRefresh() { this.loadProfile().finally(() => wx.stopPullDownRefresh()); }, loadProfile() { return auth .fetchMyProfile() .then((profile) => { const p = profile || {}; const st = typeof p.authStatus === 'number' ? p.authStatus : 0; const phone = p.mobile || p.phone || ''; this.setData({ profile: p, maskedPhone: maskPhone(phone), authStatusText: authStatusText(st) }); }) .catch(() => {}); }, goToLogin() { wx.navigateTo({ url: '/subpackages/mine/login/login' }); }, goToPoints() { wx.navigateTo({ url: '/subpackages/mine/points/points' }); }, goToCert() { wx.navigateTo({ url: '/subpackages/mine/cert/cert' }); }, goToRecords() { wx.navigateTo({ url: '/subpackages/mine/records/records' }); }, goToAuth() { // 跳转到实名认证页面(可按需调整) wx.showToast({ title: '身份认证功能开发中', icon: 'none' }); }, goToOrders() { wx.showToast({ title: '我的订单功能开发中', icon: 'none' }); }, goToTeam() { wx.showToast({ title: '我的团队功能开发中', icon: 'none' }); }, onChooseAvatar() { wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], success: (res) => { const tempFilePath = res.tempFiles[0].tempFilePath; this.setData({ 'profile.avatar': tempFilePath }); // TODO: 上传头像到服务器 } }); } });