功能:收口小程序前后台安全与防重复提交

This commit is contained in:
xiaowang
2026-04-20 16:02:57 +08:00
parent eb1c209d79
commit a3df262fae
237 changed files with 14068 additions and 728 deletions
+601 -31
View File
@@ -3,24 +3,74 @@ const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { DEFAULT_AVATAR } = require('../../utils/config')
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
const { runWithLoading } = require('../../utils/loading')
const phoneRegex = /^1[3-9]\d{9}$/
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
const SETTINGS_DRAFT_KEY = 'user-settings'
const placeholderEntries = [
{
key: 'notifications',
title: '消息通知'
},
{
key: 'message-push',
title: '消息推送'
},
{
key: 'theme',
title: '主题设置'
},
{
key: 'privacy',
title: '隐私政策'
},
{
key: 'about',
title: '关于我们'
},
{
key: 'help',
title: '帮助中心'
},
{
key: 'clear-cache',
title: '缓存清理'
}
]
Page({
data: {
isLoggedIn: false,
loading: false,
savingProfile: false,
uploadingAvatar: false,
updatingPhone: false,
updatingPassword: false,
deactivating: false,
countdown: 0,
needSetPassword: false,
activeSecurityPanel: '',
userInfo: null,
defaultAvatar: DEFAULT_AVATAR,
placeholderEntries,
form: {
nickname: '',
signature: ''
},
bindPhoneForm: {
phone: '',
verificationCode: ''
},
changePhoneForm: {
newPhone: '',
verificationCode: ''
},
passwordForm: {
verificationCode: '',
password: ''
password: '',
confirmPassword: ''
}
},
@@ -28,16 +78,107 @@ Page({
this.loadSettings()
},
onHide() {
this.clearCountdown()
clearDraftTimer(this)
},
onUnload() {
this.clearCountdown()
clearDraftTimer(this)
},
clearCountdown() {
if (this.countdownTimer) {
clearInterval(this.countdownTimer)
this.countdownTimer = null
}
},
resetSecurityForms() {
this.setData({
bindPhoneForm: {
phone: '',
verificationCode: ''
},
changePhoneForm: {
newPhone: '',
verificationCode: ''
},
passwordForm: {
verificationCode: '',
password: '',
confirmPassword: ''
}
})
},
restoreDraftValues() {
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
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 : ''
})
},
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
}
}))
},
startCountdown() {
this.clearCountdown()
this.setData({
countdown: 60
})
this.countdownTimer = setInterval(() => {
const next = this.data.countdown - 1
if (next <= 0) {
this.clearCountdown()
this.setData({
countdown: 0
})
return
}
this.setData({
countdown: next
})
}, 1000)
},
async loadSettings() {
this._avatarReloadSource = ''
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
needSetPassword: auth.getNeedSetPassword(),
loading: isLoggedIn
})
if (!isLoggedIn) {
this.clearCountdown()
this.setData({
userInfo: null,
activeSecurityPanel: '',
loading: false
})
return
@@ -49,8 +190,10 @@ Page({
this.setData({
userInfo,
'form.nickname': userInfo.nickname || '',
'form.signature': userInfo.signature || ''
'form.signature': userInfo.signature || '',
needSetPassword: auth.getNeedSetPassword()
})
this.restoreDraftValues()
} catch (error) {
wx.showToast({
title: error.message || '设置页加载失败',
@@ -76,6 +219,27 @@ Page({
this.setData({
[`form.${field}`]: event.detail.value
})
this.scheduleSettingsDraft()
},
handleBindPhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`bindPhoneForm.${field}`]: event.detail.value
})
if (field === 'phone') {
this.scheduleSettingsDraft()
}
},
handleChangePhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`changePhoneForm.${field}`]: event.detail.value
})
if (field === 'newPhone') {
this.scheduleSettingsDraft()
}
},
handlePasswordInput(event) {
@@ -85,6 +249,28 @@ Page({
})
},
handleToggleSecurityPanel(event) {
const panel = event.currentTarget.dataset.panel
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
this.clearCountdown()
this.resetSecurityForms()
this.setData({
activeSecurityPanel: nextPanel,
countdown: 0
})
this.scheduleSettingsDraft()
},
handleCloseSecurityPanel() {
this.resetSecurityForms()
this.clearCountdown()
this.setData({
activeSecurityPanel: '',
countdown: 0
})
this.scheduleSettingsDraft()
},
async handleSaveProfile() {
if (!this.data.form.nickname.trim()) {
wx.showToast({
@@ -107,7 +293,8 @@ Page({
title: '资料已更新',
icon: 'none'
})
this.loadSettings()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '资料更新失败',
@@ -120,20 +307,298 @@ Page({
}
},
startCountdown() {
this.setData({
countdown: 60
handleChooseAvatar() {
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] : ''
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() {
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))
})
})
const timer = setInterval(() => {
const next = this.data.countdown - 1
this.setData({
countdown: next
if (!confirmed) {
return
}
try {
await runWithLoading(() => userApi.updateUserInfo({
avatar: ''
}))
wx.showToast({
title: '头像已删除',
icon: 'none'
})
if (next <= 0) {
clearInterval(timer)
}
}, 1000)
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 : []
if (!shopIds.length) {
wx.showToast({
title: '当前账号还没有可用门店',
icon: 'none'
})
return
}
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)
})
})
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() {
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 {
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
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
}
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() {
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 {
await runWithLoading(() => userApi.sendVerificationCode({ phone: newPhone }))
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()
if (!oldPhone) {
wx.showToast({
title: '请先绑定手机号',
icon: 'none'
})
return
}
if (!phoneRegex.test(newPhone)) {
wx.showToast({
title: '请输入正确的新手机号',
icon: 'none'
})
return
}
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
})
}
},
async handleSendPasswordCode() {
@@ -141,19 +606,18 @@ Page({
return
}
const userInfo = this.data.userInfo
if (!userInfo || !userInfo.phone) {
const userInfo = this.data.userInfo || {}
const phone = String(userInfo.phone || '').trim()
if (!phone) {
wx.showToast({
title: '当前账号未绑定手机号',
title: '请先绑定手机号',
icon: 'none'
})
return
}
try {
await runWithLoading(() => authApi.sendVerificationCode({
phone: userInfo.phone
}))
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -168,16 +632,38 @@ Page({
},
async handleUpdatePassword() {
if (!this.data.passwordForm.verificationCode.trim()) {
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 || {}
if (!userInfo.phone) {
wx.showToast({
title: '请先绑定手机号',
icon: 'none'
})
return
}
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
icon: 'none'
})
return
}
if (!this.data.passwordForm.password || this.data.passwordForm.password.length < 6) {
if (!passwordRegex.test(password)) {
wx.showToast({
title: '新密码至少 6 位',
title: '密码需至少8位且包含字母和数字',
icon: 'none'
})
return
}
if (password !== confirmPassword) {
wx.showToast({
title: '两次输入的密码不一致',
icon: 'none'
})
return
@@ -189,20 +675,17 @@ Page({
try {
await runWithLoading(() => userApi.updatePassword({
password: this.data.passwordForm.password,
verificationCode: this.data.passwordForm.verificationCode.trim()
password,
verificationCode
}))
auth.setNeedSetPassword(false)
wx.showToast({
title: '密码已更新',
icon: 'none'
})
this.setData({
passwordForm: {
verificationCode: '',
password: ''
}
})
this.handleCloseSecurityPanel()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '密码更新失败',
@@ -215,6 +698,58 @@ Page({
}
},
handleComingSoon() {
wx.showToast({
title: '该功能暂未开放',
icon: 'none'
})
},
async handleDeactivateAccount() {
if (this.data.deactivating) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '注销账号',
content: '注销后当前账号将不可继续登录,请确认是否继续。',
confirmColor: '#d5536f',
success: res => resolve(Boolean(res.confirm))
})
})
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
})
}
},
async handleLogout() {
const confirmed = await new Promise(resolve => {
wx.showModal({
@@ -232,6 +767,7 @@ Page({
await runWithLoading(() => authApi.logout())
} catch (error) {}
clearDraft(SETTINGS_DRAFT_KEY)
getApp().clearUserSession()
wx.showToast({
title: '已退出登录',
@@ -240,5 +776,39 @@ Page({
wx.switchTab({
url: '/pages/home/index'
})
},
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
if (!currentAvatar) {
return
}
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this._avatarReloadSource = currentAvatar
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this.setData({
userInfo
})
} catch (error) {
this.setData({
'userInfo.avatar': ''
})
}
}
})
+131 -18
View File
@@ -6,27 +6,37 @@
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后进入设置中心</text>
<text class="empty-desc">这里可以修改昵称、个性签名和登录密码。</text>
<text class="empty-desc">登录后管理资料和安全设置。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{userInfo}}">
<view class="page-hero settings-hero">
<text class="hero-kicker">个人设置</text>
<text class="hero-title">维护你的资料与登录信息</text>
<text class="hero-desc">资料会同步到小程序端展示区域,密码更新后下次登录立即生效。</text>
<text class="hero-kicker">账号设置</text>
<text class="hero-title">资料与安全</text>
<text class="hero-desc">常用设置都在这里</text>
</view>
<view class="page-card settings-card">
<view class="section-title">个人资料</view>
<view class="profile-preview">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill"></image>
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}" binderror="handleAvatarError"></image>
<view class="profile-preview-copy">
<view class="preview-name">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="preview-account">{{userInfo.account}}</view>
<view class="preview-phone">{{userInfo.phone || '未绑定手机号'}}</view>
</view>
</view>
<view class="avatar-actions">
<view class="ghost-btn avatar-action" bindtap="handleChooseAvatar">{{uploadingAvatar ? '头像上传中...' : '更换头像'}}</view>
<view wx:if="{{userInfo.avatar}}" class="text-action" bindtap="handleDeleteAvatar">删除头像</view>
</view>
<view wx:if="{{needSetPassword}}" class="hint-card password-hint">
当前账号未设置登录密码。
</view>
<view class="field-block">
<text class="field-label">昵称</text>
<input class="field-input" placeholder="请输入昵称" placeholder-class="field-placeholder" value="{{form.nickname}}" data-field="nickname" bindinput="handleFormInput"></input>
@@ -34,30 +44,133 @@
<view class="field-block">
<text class="field-label">个性签名</text>
<textarea class="field-textarea" placeholder="写一句想让客人认识你的话" placeholder-class="field-placeholder" value="{{form.signature}}" data-field="signature" bindinput="handleFormInput"></textarea>
<textarea class="field-textarea" placeholder="请输入个性签名" placeholder-class="field-placeholder" value="{{form.signature}}" data-field="signature" bindinput="handleFormInput"></textarea>
</view>
<view class="primary-btn save-btn" bindtap="handleSaveProfile">{{savingProfile ? '保存中...' : '保存资料'}}</view>
</view>
<view class="page-card settings-card password-card">
<view class="section-title">登录密码</view>
<view class="section-subtitle">向已绑定手机号发送验证码后更新登录密码。</view>
<view class="page-card settings-card security-card">
<view class="section-title">账号与安全</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{passwordForm.verificationCode}}" data-field="verificationCode" bindinput="handlePasswordInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
<view class="setting-row" bindtap="handleSwitchShop">
<view class="setting-main">
<view class="setting-name">当前登录门店</view>
<view class="setting-desc">{{userInfo.shopName || '当前暂无可用门店'}}</view>
</view>
<view class="setting-action">{{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}}</view>
</view>
<view wx:if="{{!userInfo.phone}}" class="setting-row" data-panel="bindPhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">绑定手机号</view>
<view class="setting-desc">绑定后可设置密码</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'bindPhone' ? '收起' : '去绑定'}}</view>
</view>
<view wx:if="{{userInfo.phone}}" class="setting-row" data-panel="changePhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">修改手机号</view>
<view class="setting-desc">{{userInfo.phone}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'changePhone' ? '收起' : '修改'}}</view>
</view>
<view class="setting-row" data-panel="password" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">{{needSetPassword ? '设置登录密码' : '修改登录密码'}}</view>
<view class="setting-desc">{{userInfo.phone ? '短信验证后修改' : '请先绑定手机号'}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'password' ? '收起' : (needSetPassword ? '去设置' : '修改')}}</view>
</view>
<view wx:if="{{activeSecurityPanel === 'bindPhone'}}" class="security-panel">
<view class="section-subtitle">输入后完成绑定</view>
<view class="field-block">
<text class="field-label">手机号</text>
<input class="field-input" type="number" placeholder="请输入手机号" placeholder-class="field-placeholder" value="{{bindPhoneForm.phone}}" data-field="phone" bindinput="handleBindPhoneInput"></input>
</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{bindPhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleBindPhoneInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendBindPhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleBindPhoneSubmit">{{updatingPhone ? '绑定中...' : '确认绑定'}}</view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密码</text>
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.password}}" data-field="password" bindinput="handlePasswordInput"></input>
<view wx:if="{{activeSecurityPanel === 'changePhone'}}" class="security-panel">
<view class="section-subtitle">验证后更新手机号</view>
<view class="field-block">
<text class="field-label">当前手机号</text>
<view class="field-static">{{userInfo.phone}}</view>
</view>
<view class="field-block">
<text class="field-label">新手机号</text>
<input class="field-input" type="number" placeholder="请输入新的手机号" placeholder-class="field-placeholder" value="{{changePhoneForm.newPhone}}" data-field="newPhone" bindinput="handleChangePhoneInput"></input>
</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{changePhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleChangePhoneInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendChangePhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleChangePhoneSubmit">{{updatingPhone ? '提交中...' : '确认修改'}}</view>
</view>
</view>
<view class="secondary-btn save-btn" bindtap="handleUpdatePassword">{{updatingPassword ? '更新中...' : '更新密码'}}</view>
<view wx:if="{{activeSecurityPanel === 'password'}}" class="security-panel">
<view wx:if="{{!userInfo.phone}}" class="hint-card password-hint">请先绑定手机号,再通过验证码设置或修改登录密码。</view>
<block wx:else>
<view class="section-subtitle">密码需包含字母和数字</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{passwordForm.verificationCode}}" data-field="verificationCode" bindinput="handlePasswordInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密码</text>
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.password}}" data-field="password" bindinput="handlePasswordInput"></input>
</view>
<view class="field-block">
<text class="field-label">确认密码</text>
<input class="field-input" password placeholder="请再次输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.confirmPassword}}" data-field="confirmPassword" bindinput="handlePasswordInput"></input>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleUpdatePassword">{{updatingPassword ? '提交中...' : '确认保存'}}</view>
</view>
</block>
</view>
<view class="setting-row danger-row" bindtap="handleDeactivateAccount">
<view class="setting-main">
<view class="setting-name">注销账号</view>
<view class="setting-desc">注销后不可继续登录</view>
</view>
<view class="setting-action danger-text">{{deactivating ? '处理中' : '注销'}}</view>
</view>
</view>
<view class="page-card settings-card more-card">
<view class="section-title">更多功能</view>
<view wx:for="{{placeholderEntries}}" wx:key="key" class="setting-row" bindtap="handleComingSoon">
<view class="setting-main">
<view class="setting-name">{{item.title}}</view>
</view>
<view class="placeholder-tag">暂未开放</view>
</view>
</view>
<view class="logout-btn" bindtap="handleLogout">退出登录</view>
+118 -2
View File
@@ -29,7 +29,7 @@
.profile-preview {
display: flex;
align-items: center;
gap: 18rpx;
gap: 20rpx;
margin-top: 22rpx;
}
@@ -42,6 +42,7 @@
.profile-preview-copy {
flex: 1;
min-width: 0;
}
.preview-name {
@@ -50,10 +51,31 @@
color: #2d2430;
}
.preview-account,
.preview-phone {
margin-top: 10rpx;
font-size: 24rpx;
color: #8d7a84;
word-break: break-all;
}
.avatar-actions {
display: flex;
align-items: center;
gap: 18rpx;
margin-top: 22rpx;
}
.avatar-action {
width: auto;
min-width: 220rpx;
padding: 0 28rpx;
}
.text-action {
font-size: 24rpx;
font-weight: 600;
color: #c6597d;
}
.field-block {
@@ -64,10 +86,76 @@
margin-top: 26rpx;
}
.password-card {
.password-hint {
margin-top: 20rpx;
}
.security-card,
.more-card {
margin-top: 20rpx;
}
.setting-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
padding: 24rpx 0;
border-bottom: 1rpx solid rgba(239, 216, 224, 0.92);
}
.setting-row:first-of-type {
margin-top: 8rpx;
}
.setting-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.setting-main {
flex: 1;
min-width: 0;
}
.setting-name {
font-size: 28rpx;
font-weight: 700;
color: #2d2430;
}
.setting-desc {
margin-top: 10rpx;
font-size: 24rpx;
line-height: 1.7;
color: #8d7a84;
}
.setting-action {
flex-shrink: 0;
font-size: 24rpx;
font-weight: 700;
color: #c6597d;
}
.security-panel {
margin-top: 6rpx;
padding: 26rpx 24rpx;
border-radius: 28rpx;
background: #fff7f8;
}
.field-static {
display: flex;
align-items: center;
min-height: 92rpx;
padding: 0 28rpx;
border-radius: 24rpx;
background: #f5edf0;
color: #5d4b55;
font-size: 28rpx;
}
.code-row {
display: flex;
align-items: center;
@@ -97,6 +185,34 @@
color: #a998a0;
}
.panel-actions {
display: flex;
gap: 14rpx;
margin-top: 24rpx;
}
.panel-btn {
flex: 1;
}
.placeholder-tag {
flex-shrink: 0;
padding: 12rpx 18rpx;
border-radius: 999rpx;
background: #fdf0f4;
color: #c6597d;
font-size: 22rpx;
font-weight: 700;
}
.danger-row {
margin-top: 8rpx;
}
.danger-text {
color: #d5536f;
}
.logout-btn {
display: flex;
align-items: center;