2026-04-01 15:18:35 +08:00
|
|
|
const authApi = require('../../api/auth')
|
|
|
|
|
const userApi = require('../../api/user')
|
|
|
|
|
const auth = require('../../utils/auth')
|
|
|
|
|
const navigation = require('../../utils/navigation')
|
2026-05-21 18:43:59 +08:00
|
|
|
const theme = require('../../utils/theme')
|
2026-04-01 15:18:35 +08:00
|
|
|
const { DEFAULT_AVATAR } = require('../../utils/config')
|
2026-04-20 16:02:57 +08:00
|
|
|
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
|
2026-04-01 15:18:35 +08:00
|
|
|
const { runWithLoading } = require('../../utils/loading')
|
2026-04-22 16:53:32 +08:00
|
|
|
const {
|
|
|
|
|
createKeyboardSafeData,
|
|
|
|
|
attachKeyboardSafe,
|
|
|
|
|
detachKeyboardSafe,
|
|
|
|
|
handleKeyboardFocus,
|
|
|
|
|
handleKeyboardBlur,
|
|
|
|
|
resetKeyboardSafe
|
|
|
|
|
} = require('../../utils/keyboard-safe')
|
2026-04-01 15:18:35 +08:00
|
|
|
|
2026-04-20 16:02:57 +08:00
|
|
|
const phoneRegex = /^1[3-9]\d{9}$/
|
|
|
|
|
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
|
|
|
|
|
const SETTINGS_DRAFT_KEY = 'user-settings'
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* settings page logic.
|
|
|
|
|
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
Page({
|
2026-05-21 18:43:59 +08:00
|
|
|
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), createKeyboardSafeData({
|
2026-04-22 16:53:32 +08:00
|
|
|
cursorSpacing: 108
|
|
|
|
|
}), {
|
2026-04-01 15:18:35 +08:00
|
|
|
isLoggedIn: false,
|
|
|
|
|
loading: false,
|
|
|
|
|
savingProfile: false,
|
2026-04-20 16:02:57 +08:00
|
|
|
uploadingAvatar: false,
|
|
|
|
|
updatingPhone: false,
|
2026-04-01 15:18:35 +08:00
|
|
|
updatingPassword: false,
|
2026-04-20 16:02:57 +08:00
|
|
|
deactivating: false,
|
2026-04-01 15:18:35 +08:00
|
|
|
countdown: 0,
|
2026-04-20 16:02:57 +08:00
|
|
|
needSetPassword: false,
|
|
|
|
|
activeSecurityPanel: '',
|
2026-04-01 15:18:35 +08:00
|
|
|
userInfo: null,
|
|
|
|
|
defaultAvatar: DEFAULT_AVATAR,
|
|
|
|
|
form: {
|
|
|
|
|
nickname: '',
|
|
|
|
|
signature: ''
|
|
|
|
|
},
|
2026-04-20 16:02:57 +08:00
|
|
|
bindPhoneForm: {
|
|
|
|
|
phone: '',
|
|
|
|
|
verificationCode: ''
|
|
|
|
|
},
|
|
|
|
|
changePhoneForm: {
|
|
|
|
|
newPhone: '',
|
|
|
|
|
verificationCode: ''
|
|
|
|
|
},
|
2026-04-01 15:18:35 +08:00
|
|
|
passwordForm: {
|
|
|
|
|
verificationCode: '',
|
2026-04-20 16:02:57 +08:00
|
|
|
password: '',
|
|
|
|
|
confirmPassword: ''
|
2026-04-01 15:18:35 +08:00
|
|
|
}
|
2026-04-22 16:53:32 +08:00
|
|
|
}),
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-22 16:53:32 +08:00
|
|
|
onLoad() {
|
|
|
|
|
this.ensureKeyboardSafe()
|
2026-04-01 15:18:35 +08:00
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
onShow() {
|
2026-04-22 16:53:32 +08:00
|
|
|
this.ensureKeyboardSafe()
|
2026-04-01 15:18:35 +08:00
|
|
|
this.loadSettings()
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
onHide() {
|
2026-04-22 16:53:32 +08:00
|
|
|
resetKeyboardSafe(this)
|
|
|
|
|
detachKeyboardSafe(this)
|
2026-04-20 16:02:57 +08:00
|
|
|
this.clearCountdown()
|
|
|
|
|
clearDraftTimer(this)
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
onUnload() {
|
2026-04-22 16:53:32 +08:00
|
|
|
resetKeyboardSafe(this)
|
|
|
|
|
detachKeyboardSafe(this)
|
2026-04-20 16:02:57 +08:00
|
|
|
this.clearCountdown()
|
|
|
|
|
clearDraftTimer(this)
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-22 16:53:32 +08:00
|
|
|
ensureKeyboardSafe() {
|
|
|
|
|
attachKeyboardSafe(this, {
|
|
|
|
|
cursorSpacing: 108,
|
|
|
|
|
spacerExtraRpx: 48
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-22 16:53:32 +08:00
|
|
|
handleKeyboardFocus(event) {
|
|
|
|
|
handleKeyboardFocus(this, event)
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-22 16:53:32 +08:00
|
|
|
handleKeyboardBlur() {
|
|
|
|
|
handleKeyboardBlur(this)
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
clearCountdown() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this.countdownTimer) {
|
|
|
|
|
clearInterval(this.countdownTimer)
|
|
|
|
|
this.countdownTimer = null
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
resetSecurityForms() {
|
|
|
|
|
this.setData({
|
|
|
|
|
bindPhoneForm: {
|
|
|
|
|
phone: '',
|
|
|
|
|
verificationCode: ''
|
|
|
|
|
},
|
|
|
|
|
changePhoneForm: {
|
|
|
|
|
newPhone: '',
|
|
|
|
|
verificationCode: ''
|
|
|
|
|
},
|
|
|
|
|
passwordForm: {
|
|
|
|
|
verificationCode: '',
|
|
|
|
|
password: '',
|
|
|
|
|
confirmPassword: ''
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
restoreDraftValues() {
|
|
|
|
|
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!draft || typeof draft !== 'object') {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
activeSecurityPanel: draft.activeSecurityPanel || '',
|
|
|
|
|
'form.nickname': draft.form && draft.form.nickname !== undefined ? draft.form.nickname : this.data.form.nickname,
|
|
|
|
|
'form.signature': draft.form && draft.form.signature !== undefined ? draft.form.signature : this.data.form.signature,
|
|
|
|
|
'bindPhoneForm.phone': draft.bindPhoneForm && draft.bindPhoneForm.phone ? draft.bindPhoneForm.phone : '',
|
|
|
|
|
'changePhoneForm.newPhone': draft.changePhoneForm && draft.changePhoneForm.newPhone ? draft.changePhoneForm.newPhone : ''
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
scheduleSettingsDraft() {
|
|
|
|
|
scheduleDraftSave(this, SETTINGS_DRAFT_KEY, () => ({
|
|
|
|
|
activeSecurityPanel: this.data.activeSecurityPanel,
|
|
|
|
|
form: {
|
|
|
|
|
nickname: this.data.form.nickname,
|
|
|
|
|
signature: this.data.form.signature
|
|
|
|
|
},
|
|
|
|
|
bindPhoneForm: {
|
|
|
|
|
phone: this.data.bindPhoneForm.phone
|
|
|
|
|
},
|
|
|
|
|
changePhoneForm: {
|
|
|
|
|
newPhone: this.data.changePhoneForm.newPhone
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
startCountdown() {
|
|
|
|
|
this.clearCountdown()
|
|
|
|
|
this.setData({
|
|
|
|
|
countdown: 60
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.countdownTimer = setInterval(() => {
|
|
|
|
|
const next = this.data.countdown - 1
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (next <= 0) {
|
|
|
|
|
this.clearCountdown()
|
|
|
|
|
this.setData({
|
|
|
|
|
countdown: 0
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
countdown: next
|
|
|
|
|
})
|
|
|
|
|
}, 1000)
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-01 15:18:35 +08:00
|
|
|
async loadSettings() {
|
2026-04-20 16:02:57 +08:00
|
|
|
this._avatarReloadSource = ''
|
2026-04-01 15:18:35 +08:00
|
|
|
const isLoggedIn = auth.isLoggedIn()
|
|
|
|
|
this.setData({
|
|
|
|
|
isLoggedIn,
|
2026-04-20 16:02:57 +08:00
|
|
|
needSetPassword: auth.getNeedSetPassword(),
|
2026-04-01 15:18:35 +08:00
|
|
|
loading: isLoggedIn
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
if (!isLoggedIn) {
|
2026-04-20 16:02:57 +08:00
|
|
|
this.clearCountdown()
|
2026-04-01 15:18:35 +08:00
|
|
|
this.setData({
|
|
|
|
|
userInfo: null,
|
2026-04-20 16:02:57 +08:00
|
|
|
activeSecurityPanel: '',
|
2026-04-01 15:18:35 +08:00
|
|
|
loading: false
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const userInfo = await userApi.getUserInfo()
|
|
|
|
|
getApp().refreshUserInfo(userInfo)
|
|
|
|
|
this.setData({
|
|
|
|
|
userInfo,
|
|
|
|
|
'form.nickname': userInfo.nickname || '',
|
2026-04-20 16:02:57 +08:00
|
|
|
'form.signature': userInfo.signature || '',
|
|
|
|
|
needSetPassword: auth.getNeedSetPassword()
|
2026-04-01 15:18:35 +08:00
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
this.restoreDraftValues()
|
2026-04-01 15:18:35 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '设置页加载失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
loading: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
handleBack() {
|
|
|
|
|
navigation.goBack('/pages/profile/index')
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
handleOpenAuth() {
|
|
|
|
|
navigation.openAuth('/pages/settings/index')
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
handleFormInput(event) {
|
|
|
|
|
const field = event.currentTarget.dataset.field
|
|
|
|
|
this.setData({
|
|
|
|
|
[`form.${field}`]: event.detail.value
|
|
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
this.scheduleSettingsDraft()
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleBindPhoneInput(event) {
|
|
|
|
|
const field = event.currentTarget.dataset.field
|
|
|
|
|
this.setData({
|
|
|
|
|
[`bindPhoneForm.${field}`]: event.detail.value
|
|
|
|
|
})
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (field === 'phone') {
|
|
|
|
|
this.scheduleSettingsDraft()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleChangePhoneInput(event) {
|
|
|
|
|
const field = event.currentTarget.dataset.field
|
|
|
|
|
this.setData({
|
|
|
|
|
[`changePhoneForm.${field}`]: event.detail.value
|
|
|
|
|
})
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (field === 'newPhone') {
|
|
|
|
|
this.scheduleSettingsDraft()
|
|
|
|
|
}
|
2026-04-01 15:18:35 +08:00
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
handlePasswordInput(event) {
|
|
|
|
|
const field = event.currentTarget.dataset.field
|
|
|
|
|
this.setData({
|
|
|
|
|
[`passwordForm.${field}`]: event.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleToggleSecurityPanel(event) {
|
|
|
|
|
const panel = event.currentTarget.dataset.panel
|
|
|
|
|
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
|
2026-04-22 16:53:32 +08:00
|
|
|
resetKeyboardSafe(this)
|
2026-04-20 16:02:57 +08:00
|
|
|
this.clearCountdown()
|
|
|
|
|
this.resetSecurityForms()
|
|
|
|
|
this.setData({
|
|
|
|
|
activeSecurityPanel: nextPanel,
|
|
|
|
|
countdown: 0
|
|
|
|
|
})
|
|
|
|
|
this.scheduleSettingsDraft()
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleCloseSecurityPanel() {
|
2026-04-22 16:53:32 +08:00
|
|
|
resetKeyboardSafe(this)
|
2026-04-20 16:02:57 +08:00
|
|
|
this.resetSecurityForms()
|
|
|
|
|
this.clearCountdown()
|
|
|
|
|
this.setData({
|
|
|
|
|
activeSecurityPanel: '',
|
|
|
|
|
countdown: 0
|
|
|
|
|
})
|
|
|
|
|
this.scheduleSettingsDraft()
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-01 15:18:35 +08:00
|
|
|
async handleSaveProfile() {
|
|
|
|
|
if (!this.data.form.nickname.trim()) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入昵称',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
savingProfile: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.updateUserInfo({
|
|
|
|
|
nickname: this.data.form.nickname.trim(),
|
|
|
|
|
signature: this.data.form.signature.trim()
|
|
|
|
|
}))
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '资料已更新',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
|
|
|
|
await this.loadSettings()
|
2026-04-01 15:18:35 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '资料更新失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
savingProfile: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleChooseAvatar() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this.data.uploadingAvatar) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wx.chooseImage({
|
|
|
|
|
count: 1,
|
|
|
|
|
sizeType: ['compressed', 'original'],
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
success: async res => {
|
|
|
|
|
const filePath = Array.isArray(res.tempFilePaths) ? res.tempFilePaths[0] : ''
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!filePath) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
uploadingAvatar: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.uploadAvatar(filePath))
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '头像已更新',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
await this.loadSettings()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '头像上传失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
uploadingAvatar: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleDeleteAvatar() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!this.data.userInfo || !this.data.userInfo.avatar) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const confirmed = await new Promise(resolve => {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '删除头像',
|
|
|
|
|
content: '删除后会恢复为默认头像。',
|
|
|
|
|
success: res => resolve(Boolean(res.confirm))
|
|
|
|
|
})
|
2026-04-01 15:18:35 +08:00
|
|
|
})
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!confirmed) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.updateUserInfo({
|
|
|
|
|
avatar: ''
|
|
|
|
|
}))
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '头像已删除',
|
|
|
|
|
icon: 'none'
|
2026-04-01 15:18:35 +08:00
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
await this.loadSettings()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '头像删除失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleSwitchShop() {
|
|
|
|
|
if (!navigation.ensureLogin('查看门店')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userInfo = this.data.userInfo
|
|
|
|
|
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
|
|
|
|
|
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!shopIds.length) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '当前账号还没有可用门店',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (shopIds.length === 1) {
|
|
|
|
|
navigation.navigate('/pages/shop-detail/index', {
|
|
|
|
|
id: shopIds[0],
|
|
|
|
|
returnTo: navigation.getCurrentPageUrl()
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const selection = await new Promise(resolve => {
|
|
|
|
|
wx.showActionSheet({
|
|
|
|
|
itemList: shopNames.map((name, index) => name || `门店 ${shopIds[index]}`),
|
|
|
|
|
success: res => resolve(res.tapIndex),
|
|
|
|
|
fail: () => resolve(-1)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (selection < 0 || selection >= shopIds.length) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const payload = await runWithLoading(() => authApi.switchShop({
|
|
|
|
|
shopId: shopIds[selection]
|
|
|
|
|
}))
|
|
|
|
|
getApp().setUserSession(payload)
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '门店已切换',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
await this.loadSettings()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '门店切换失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleSendBindPhoneCode() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this.data.countdown > 0) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const phone = String(this.data.bindPhoneForm.phone || '').trim()
|
|
|
|
|
if (!phoneRegex.test(phone)) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入正确的手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-18 09:46:11 +08:00
|
|
|
await runWithLoading(() => userApi.sendVerificationCode({
|
|
|
|
|
phone,
|
|
|
|
|
sceneCode: 'USER_BIND_PHONE_SMS_CODE'
|
|
|
|
|
}))
|
2026-04-20 16:02:57 +08:00
|
|
|
wx.showToast({
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.startCountdown()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '验证码发送失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleBindPhoneSubmit() {
|
|
|
|
|
const phone = String(this.data.bindPhoneForm.phone || '').trim()
|
|
|
|
|
const verificationCode = String(this.data.bindPhoneForm.verificationCode || '').trim()
|
|
|
|
|
|
|
|
|
|
if (!phoneRegex.test(phone)) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入正确的手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!verificationCode) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入验证码',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPhone: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.bindPhone({
|
|
|
|
|
phone,
|
|
|
|
|
verificationCode
|
|
|
|
|
}))
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '手机号绑定成功',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.handleCloseSecurityPanel()
|
|
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
|
|
|
|
await this.loadSettings()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '手机号绑定失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPhone: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleSendChangePhoneCode() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this.data.countdown > 0) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
|
|
|
|
|
if (!phoneRegex.test(newPhone)) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入正确的新手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-18 09:46:11 +08:00
|
|
|
await runWithLoading(() => userApi.sendVerificationCode({
|
|
|
|
|
phone: newPhone,
|
|
|
|
|
sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
|
|
|
|
|
}))
|
2026-04-20 16:02:57 +08:00
|
|
|
wx.showToast({
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.startCountdown()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '验证码发送失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleChangePhoneSubmit() {
|
|
|
|
|
const userInfo = this.data.userInfo || {}
|
|
|
|
|
const oldPhone = String(userInfo.phone || '').trim()
|
|
|
|
|
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
|
|
|
|
|
const verificationCode = String(this.data.changePhoneForm.verificationCode || '').trim()
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!oldPhone) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请先绑定手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!phoneRegex.test(newPhone)) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入正确的新手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!verificationCode) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入验证码',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPhone: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.updatePhone({
|
|
|
|
|
oldPhone,
|
|
|
|
|
newPhone,
|
|
|
|
|
verificationCode
|
|
|
|
|
}))
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '手机号修改成功',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.handleCloseSecurityPanel()
|
|
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
|
|
|
|
await this.loadSettings()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '手机号修改失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPhone: false
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-01 15:18:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleSendPasswordCode() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
if (this.data.countdown > 0) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 16:02:57 +08:00
|
|
|
const userInfo = this.data.userInfo || {}
|
|
|
|
|
const phone = String(userInfo.phone || '').trim()
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!phone) {
|
2026-04-01 15:18:35 +08:00
|
|
|
wx.showToast({
|
2026-04-20 16:02:57 +08:00
|
|
|
title: '请先绑定手机号',
|
2026-04-01 15:18:35 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-18 09:46:11 +08:00
|
|
|
await runWithLoading(() => authApi.sendVerificationCode({
|
|
|
|
|
phone,
|
|
|
|
|
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
|
|
|
|
}))
|
2026-04-01 15:18:35 +08:00
|
|
|
wx.showToast({
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.startCountdown()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '验证码发送失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleUpdatePassword() {
|
2026-04-20 16:02:57 +08:00
|
|
|
const verificationCode = String(this.data.passwordForm.verificationCode || '').trim()
|
|
|
|
|
const password = String(this.data.passwordForm.password || '')
|
|
|
|
|
const confirmPassword = String(this.data.passwordForm.confirmPassword || '')
|
|
|
|
|
const userInfo = this.data.userInfo || {}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!userInfo.phone) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请先绑定手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!verificationCode) {
|
2026-04-01 15:18:35 +08:00
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入验证码',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-20 16:02:57 +08:00
|
|
|
|
|
|
|
|
if (!passwordRegex.test(password)) {
|
2026-04-01 15:18:35 +08:00
|
|
|
wx.showToast({
|
2026-04-20 16:02:57 +08:00
|
|
|
title: '密码需至少8位且包含字母和数字',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (password !== confirmPassword) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '两次输入的密码不一致',
|
2026-04-01 15:18:35 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPassword: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.updatePassword({
|
2026-04-20 16:02:57 +08:00
|
|
|
password,
|
|
|
|
|
verificationCode
|
2026-04-01 15:18:35 +08:00
|
|
|
}))
|
|
|
|
|
auth.setNeedSetPassword(false)
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '密码已更新',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
this.handleCloseSecurityPanel()
|
|
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
|
|
|
|
await this.loadSettings()
|
2026-04-01 15:18:35 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '密码更新失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
updatingPassword: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-20 16:02:57 +08:00
|
|
|
async handleDeactivateAccount() {
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this.data.deactivating) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const confirmed = await new Promise(resolve => {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '注销账号',
|
|
|
|
|
content: '注销后当前账号将不可继续登录,请确认是否继续。',
|
|
|
|
|
confirmColor: '#d5536f',
|
|
|
|
|
success: res => resolve(Boolean(res.confirm))
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!confirmed) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
deactivating: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => userApi.deactivateAccount())
|
|
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
|
|
|
|
getApp().clearUserSession()
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '账号已注销',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
wx.switchTab({
|
|
|
|
|
url: '/pages/home/index'
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: error.message || '账号注销失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({
|
|
|
|
|
deactivating: false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-01 15:18:35 +08:00
|
|
|
async handleLogout() {
|
|
|
|
|
const confirmed = await new Promise(resolve => {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '退出登录',
|
|
|
|
|
content: '退出后需要重新登录才能查看订单和继续下单。',
|
|
|
|
|
success: res => resolve(Boolean(res.confirm))
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
if (!confirmed) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithLoading(() => authApi.logout())
|
|
|
|
|
} catch (error) {}
|
|
|
|
|
|
2026-04-20 16:02:57 +08:00
|
|
|
clearDraft(SETTINGS_DRAFT_KEY)
|
2026-04-01 15:18:35 +08:00
|
|
|
getApp().clearUserSession()
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '已退出登录',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
wx.switchTab({
|
|
|
|
|
url: '/pages/home/index'
|
|
|
|
|
})
|
2026-04-20 16:02:57 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleAvatarError() {
|
|
|
|
|
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!currentAvatar) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (this._avatarReloadSource === currentAvatar) {
|
|
|
|
|
this.setData({
|
|
|
|
|
'userInfo.avatar': ''
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._avatarReloadSource = currentAvatar
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const userInfo = await userApi.getUserInfo()
|
|
|
|
|
getApp().refreshUserInfo(userInfo)
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
|
|
|
|
|
this.setData({
|
|
|
|
|
'userInfo.avatar': ''
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
userInfo
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({
|
|
|
|
|
'userInfo.avatar': ''
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-01 15:18:35 +08:00
|
|
|
}
|
|
|
|
|
})
|