const { loginWithWeChat } = require('../../utils/auth'); Page({ data: { loading: false, error: '' }, async handleLogin() { this.setData({ loading: true, error: '' }); try { await loginWithWeChat(null); wx.reLaunch({ url: '/pages/home/home' }); } catch (err) { this.setData({ error: err.message || '登录失败' }); } finally { this.setData({ loading: false }); } }, async handleLoginWithProfile() { this.setData({ loading: true, error: '' }); wx.getUserProfile({ desc: '用于完善用户资料', success: async (res) => { try { await loginWithWeChat(res.userInfo || null); wx.reLaunch({ url: '/pages/home/home' }); } catch (err) { this.setData({ error: err.message || '登录失败' }); } finally { this.setData({ loading: false }); } }, fail: () => { this.setData({ loading: false, error: '未授权用户信息' }); } }); } });