/** * 卡若创业派对 - 开发登录页 * 临时:账户=手机号,密码可空,用于切换为对方账号调试 */ const app = getApp() const { checkAndExecute } = require('../../utils/ruleEngine.js') Page({ data: { statusBarHeight: 44, account: '', password: '', loading: false }, onLoad() { this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 }) }, onAccountInput(e) { this.setData({ account: (e.detail.value || '').trim() }) }, onPasswordInput(e) { this.setData({ password: e.detail.value || '' }) }, goBack() { app.goBackOrToHome() }, async handleLogin() { const { account, password, loading } = this.data if (!account || loading) return const phone = account.replace(/\s/g, '') if (phone.length < 11) { wx.showToast({ title: '请输入11位手机号', icon: 'none' }) return } this.setData({ loading: true }) try { const res = await app.request('/api/miniprogram/dev/login-by-phone', { method: 'POST', data: { phone, password: password || '' } }) if (res.success && res.data) { const user = res.data.user app.globalData.userInfo = user app.globalData.isLoggedIn = true app.globalData.purchasedSections = user.purchasedSections || [] app.globalData.hasFullBook = user.hasFullBook || false app.globalData.isVip = user.isVip || false app.globalData.vipExpireDate = user.vipExpireDate || '' wx.setStorageSync('userInfo', user) wx.setStorageSync('token', res.data.token) const pendingRef = wx.getStorageSync('pendingReferralCode') || app.globalData.pendingReferralCode if (pendingRef) { app.bindReferralCode(pendingRef) } checkAndExecute('after_login', null) setTimeout(() => app.checkVipContactRequiredAndGuide(), 1200) wx.showToast({ title: '登录成功', icon: 'success' }) setTimeout(() => wx.switchTab({ url: '/pages/index/index' }), 800) } } catch (e) { wx.showToast({ title: e.message || '登录失败', icon: 'none' }) } finally { this.setData({ loading: false }) } } })