feat: add registration page for new miniprogram users

- New register page with chooseAvatar, nickname input (random default),
  and required phone number authorization via getPhoneNumber
- Login simplified: removed deprecated wx.getUserProfile, checks
  is_new_user flag to redirect new users to registration
- Server login response now includes is_new_user field
这个提交包含在:
Guoguo
2026-05-06 06:12:34 -07:00
父节点 5cc41f0f10
当前提交 563e515bce
修改 9 个文件,包含 301 行新增92 行删除
+7 -63
查看文件
@@ -1,15 +1,12 @@
var app = getApp()
var http = require('../../utils/request')
Page({
data: {
statusBarHeight: 44,
loading: false,
userProfile: null
loading: false
},
onLoad: function () {
var app = getApp()
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
},
@@ -17,73 +14,20 @@ Page({
var self = this
self.setData({ loading: true })
self.getWechatProfile().then(function (profile) {
self.setData({ userProfile: profile })
return app.doLogin()
}).then(function () {
return self.saveProfile()
}).then(function () {
app.doLogin().then(function (data) {
self.setData({ loading: false })
wx.switchTab({ url: '/pages/index/index' })
if (data && data.is_new_user) {
wx.redirectTo({ url: '/pages/register/register' })
} else {
wx.switchTab({ url: '/pages/index/index' })
}
}).catch(function (err) {
self.setData({ loading: false })
wx.showToast({ title: err.message || '登录失败', icon: 'none' })
})
},
getWechatProfile: function () {
return new Promise(function (resolve) {
if (!wx.getUserProfile) {
resolve(null)
return
}
wx.getUserProfile({
desc: '用于完善会员资料',
success: function (res) {
resolve(res.userInfo || null)
},
fail: function () {
resolve(null)
}
})
})
},
saveProfile: function () {
var profile = this.data.userProfile || {}
if (!profile.nickName && !profile.avatarUrl) return Promise.resolve()
return this.updateProfile({
nickname: profile.nickName || '',
avatar: profile.avatarUrl || '',
gender: profile.gender || 0
})
},
updateProfile: function (payload) {
return http.put('/api/v1/user/profile', payload).then(function () {
return app.loadProfile()
})
},
onAgreement: function () {
wx.showModal({ title: '提示', content: '用户协议和隐私政策内容建设中', showCancel: false })
},
onGetPhoneNumber: function (e) {
var self = this
if (!e.detail || !e.detail.code) {
wx.showToast({ title: '已跳过手机号授权', icon: 'none' })
return
}
self.setData({ loading: true })
app.doLogin().then(function () {
return http.post('/api/v1/user/phone', { code: e.detail.code })
}).then(function () {
self.setData({ loading: false })
wx.switchTab({ url: '/pages/index/index' })
}).catch(function (err) {
self.setData({ loading: false })
wx.showToast({ title: err.message || '手机号授权失败', icon: 'none' })
})
}
})