功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+216 -3
View File
@@ -18,6 +18,10 @@ const phoneRegex = /^1[3-9]\d{9}$/
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
const SETTINGS_DRAFT_KEY = 'user-settings'
/**
* settings page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 108
@@ -53,15 +57,27 @@ Page({
}
}),
/**
* `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onLoad() {
this.ensureKeyboardSafe()
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.ensureKeyboardSafe()
this.loadSettings()
},
/**
* `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -69,6 +85,10 @@ Page({
clearDraftTimer(this)
},
/**
* `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -76,6 +96,10 @@ Page({
clearDraftTimer(this)
},
/**
* `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 108,
@@ -83,21 +107,41 @@ Page({
})
},
/**
* `handleKeyboardFocus` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleKeyboardFocus(event) {
handleKeyboardFocus(this, event)
},
/**
* `handleKeyboardBlur` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleKeyboardBlur() {
handleKeyboardBlur(this)
},
/**
* `clearCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
clearCountdown() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.countdownTimer) {
clearInterval(this.countdownTimer)
this.countdownTimer = null
}
},
/**
* `resetSecurityForms` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
resetSecurityForms() {
this.setData({
bindPhoneForm: {
@@ -116,8 +160,16 @@ Page({
})
},
/**
* `restoreDraftValues` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
restoreDraftValues() {
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!draft || typeof draft !== 'object') {
return
}
@@ -131,6 +183,10 @@ Page({
})
},
/**
* `scheduleSettingsDraft` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
scheduleSettingsDraft() {
scheduleDraftSave(this, SETTINGS_DRAFT_KEY, () => ({
activeSecurityPanel: this.data.activeSecurityPanel,
@@ -147,6 +203,10 @@ Page({
}))
},
/**
* `startCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
startCountdown() {
this.clearCountdown()
this.setData({
@@ -155,6 +215,10 @@ Page({
this.countdownTimer = setInterval(() => {
const next = this.data.countdown - 1
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (next <= 0) {
this.clearCountdown()
this.setData({
@@ -177,6 +241,10 @@ Page({
loading: isLoggedIn
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.clearCountdown()
this.setData({
@@ -209,14 +277,26 @@ Page({
}
},
/**
* `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/settings/index')
},
/**
* `handleFormInput` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleFormInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
@@ -225,26 +305,46 @@ Page({
this.scheduleSettingsDraft()
},
/**
* `handleBindPhoneInput` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBindPhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`bindPhoneForm.${field}`]: event.detail.value
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (field === 'phone') {
this.scheduleSettingsDraft()
}
},
/**
* `handleChangePhoneInput` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleChangePhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`changePhoneForm.${field}`]: event.detail.value
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (field === 'newPhone') {
this.scheduleSettingsDraft()
}
},
/**
* `handlePasswordInput` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handlePasswordInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
@@ -252,6 +352,10 @@ Page({
})
},
/**
* `handleToggleSecurityPanel` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleToggleSecurityPanel(event) {
const panel = event.currentTarget.dataset.panel
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
@@ -265,6 +369,10 @@ Page({
this.scheduleSettingsDraft()
},
/**
* `handleCloseSecurityPanel` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleCloseSecurityPanel() {
resetKeyboardSafe(this)
this.resetSecurityForms()
@@ -312,7 +420,15 @@ Page({
}
},
/**
* `handleChooseAvatar` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleChooseAvatar() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.uploadingAvatar) {
return
}
@@ -323,6 +439,10 @@ Page({
sourceType: ['album', 'camera'],
success: async res => {
const filePath = Array.isArray(res.tempFilePaths) ? res.tempFilePaths[0] : ''
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!filePath) {
return
}
@@ -353,6 +473,10 @@ Page({
},
async handleDeleteAvatar() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.userInfo || !this.data.userInfo.avatar) {
return
}
@@ -365,6 +489,10 @@ Page({
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!confirmed) {
return
}
@@ -395,6 +523,10 @@ Page({
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopIds.length) {
wx.showToast({
title: '当前账号还没有可用门店',
@@ -403,6 +535,10 @@ Page({
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (shopIds.length === 1) {
navigation.navigate('/pages/shop-detail/index', {
id: shopIds[0],
@@ -419,6 +555,10 @@ Page({
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (selection < 0 || selection >= shopIds.length) {
return
}
@@ -442,6 +582,10 @@ Page({
},
async handleSendBindPhoneCode() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.countdown > 0) {
return
}
@@ -456,7 +600,10 @@ Page({
}
try {
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
await runWithLoading(() => userApi.sendVerificationCode({
phone,
sceneCode: 'USER_BIND_PHONE_SMS_CODE'
}))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -482,6 +629,10 @@ Page({
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -519,6 +670,10 @@ Page({
},
async handleSendChangePhoneCode() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.countdown > 0) {
return
}
@@ -533,7 +688,10 @@ Page({
}
try {
await runWithLoading(() => userApi.sendVerificationCode({ phone: newPhone }))
await runWithLoading(() => userApi.sendVerificationCode({
phone: newPhone,
sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
}))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -553,6 +711,10 @@ Page({
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
const verificationCode = String(this.data.changePhoneForm.verificationCode || '').trim()
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!oldPhone) {
wx.showToast({
title: '请先绑定手机号',
@@ -569,6 +731,10 @@ Page({
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -607,12 +773,20 @@ Page({
},
async handleSendPasswordCode() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.countdown > 0) {
return
}
const userInfo = this.data.userInfo || {}
const phone = String(userInfo.phone || '').trim()
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!phone) {
wx.showToast({
title: '请先绑定手机号',
@@ -622,7 +796,10 @@ Page({
}
try {
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
await runWithLoading(() => authApi.sendVerificationCode({
phone,
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
}))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -642,6 +819,10 @@ Page({
const confirmPassword = String(this.data.passwordForm.confirmPassword || '')
const userInfo = this.data.userInfo || {}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!userInfo.phone) {
wx.showToast({
title: '请先绑定手机号',
@@ -650,6 +831,10 @@ Page({
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -666,6 +851,10 @@ Page({
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (password !== confirmPassword) {
wx.showToast({
title: '两次输入的密码不一致',
@@ -704,6 +893,10 @@ Page({
},
async handleDeactivateAccount() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.deactivating) {
return
}
@@ -717,6 +910,10 @@ Page({
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!confirmed) {
return
}
@@ -757,6 +954,10 @@ Page({
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!confirmed) {
return
}
@@ -778,10 +979,18 @@ Page({
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!currentAvatar) {
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
@@ -794,6 +1003,10 @@ Page({
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''