Files
Mycontent/miniprogram/pages/dev-login/dev-login.js
乘风 c78a0d531f feat: enhance login modal and avatar selection process
- Updated the login modal to include a user agreement section with clickable links to the user agreement and privacy policy.
- Improved button styling and layout for better user experience.
- Refactored avatar selection process to utilize local image paths, enhancing compatibility and reliability across different environments.
- Added utility functions for resolving avatar file paths and selecting images from the gallery or camera.

This update aims to streamline user interactions during login and avatar selection, ensuring a smoother experience.
2026-05-06 17:21:10 +08:00

87 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 卡若创业派对 - 开发登录页(仅本地调试)
* 勿写入 app.json pages提审包不得注册本页。
* 需要用时在 app.json 的 pages 数组末尾临时加入 "pages/dev-login/dev-login"。
*/
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
}
const pwd = String(password || '').trim()
if (pwd.length < 6) {
wx.showToast({ title: '密码至少6位', icon: 'none' })
return
}
this.setData({ loading: true })
try {
const res = await app.request('/api/miniprogram/dev/login-by-phone', {
method: 'POST',
data: { phone, password: pwd }
})
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 })
}
}
})