完成设计师端与店务端生产隔离改造
This commit is contained in:
@@ -0,0 +1,835 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>账号设置</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<!-- 账号设置内容 -->
|
||||
<div class="account-settings">
|
||||
<!-- 账号设置选项 -->
|
||||
<a-card :bordered="false" class="settings-card">
|
||||
<a-list :data-source="accountSettings" :split="false">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item class="setting-item" @click="handleSettingClick(item.key)">
|
||||
<template #actions>
|
||||
<RightOutlined />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<div class="setting-icon" :style="{ backgroundColor: item.bgColor }">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
<span>{{ item.title }}</span>
|
||||
</template>
|
||||
<template #description v-if="item.desc">
|
||||
<span>{{ item.desc }}</span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 绑定手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="bindPhoneModalVisible"
|
||||
title="绑定手机号"
|
||||
@ok="handleBindPhoneSubmit"
|
||||
@cancel="handleBindPhoneCancel"
|
||||
:confirmLoading="bindPhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="bindPhoneDraftSavedAt"
|
||||
@save="handleSaveBindPhoneDraft"
|
||||
@clear="handleClearBindPhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.phone"
|
||||
placeholder="请输入手机号"
|
||||
:disabled="!!userInfo.phone"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !bindPhoneForm.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePhoneModalVisible"
|
||||
title="修改手机号"
|
||||
@ok="handleChangePhoneSubmit"
|
||||
@cancel="handleChangePhoneCancel"
|
||||
:confirmLoading="changePhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePhoneDraftSavedAt"
|
||||
@save="handleSaveChangePhoneDraft"
|
||||
@clear="handleClearChangePhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="旧手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="新手机号" name="newPhone">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.newPhone"
|
||||
placeholder="请输入新手机号"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !changePhoneForm.newPhone"
|
||||
@click="handleSendChangePhoneVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePasswordModalVisible"
|
||||
title="修改密码"
|
||||
@ok="handleChangePasswordSubmit"
|
||||
@cancel="handleChangePasswordCancel"
|
||||
:confirmLoading="changePasswordLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePasswordDraftSavedAt"
|
||||
@save="handleSaveChangePasswordDraft"
|
||||
@clear="handleClearChangePasswordDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePasswordForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0"
|
||||
@click="handleSendChangePasswordVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.password"
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<div class="password-tip">
|
||||
密码长度至少8位,包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="确认密码" name="confirmPassword">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.confirmPassword"
|
||||
placeholder="请再次输入新密码"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AccountSettingsView page script.
|
||||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||||
*/
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, RightOutlined, LockOutlined, PhoneOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import type { UserVO } from '@/api/user'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
/**
|
||||
* Purpose: router supports AccountSettingsView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
// 状态标识
|
||||
/** hasPassword is a reactive state variable used by the template and event handlers. */
|
||||
const hasPassword = ref(false)
|
||||
/** hasPhone is a reactive state variable used by the template and event handlers. */
|
||||
const hasPhone = ref(false)
|
||||
|
||||
// 绑定手机号表单
|
||||
/** bindPhoneModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const bindPhoneModalVisible = ref(false)
|
||||
/** bindPhoneLoading is a reactive state variable used by the template and event handlers. */
|
||||
const bindPhoneLoading = ref(false)
|
||||
/**
|
||||
* Purpose: bindPhoneDraftSavedAt supports AccountSettingsView.vue by holding or executing the bind phone draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: bindPhoneForm supports AccountSettingsView.vue by holding or executing the bind phone form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改手机号表单
|
||||
/** changePhoneModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const changePhoneModalVisible = ref(false)
|
||||
/** changePhoneLoading is a reactive state variable used by the template and event handlers. */
|
||||
const changePhoneLoading = ref(false)
|
||||
/**
|
||||
* Purpose: changePhoneDraftSavedAt supports AccountSettingsView.vue by holding or executing the change phone draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: changePhoneForm supports AccountSettingsView.vue by holding or executing the change phone form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneForm = reactive({
|
||||
newPhone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改密码表单
|
||||
/** changePasswordModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const changePasswordModalVisible = ref(false)
|
||||
/** changePasswordLoading is a reactive state variable used by the template and event handlers. */
|
||||
const changePasswordLoading = ref(false)
|
||||
/**
|
||||
* Purpose: changePasswordDraftSavedAt supports AccountSettingsView.vue by holding or executing the change password draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: changePasswordForm supports AccountSettingsView.vue by holding or executing the change password form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordForm = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: restoreSessionDraft supports AccountSettingsView.vue by holding or executing the restore session draft page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const restoreSessionDraft = <T extends Record<string, any>>(key: string, target: T, savedAtRef: typeof bindPhoneDraftSavedAt) => {
|
||||
const draft = loadDraftRecord<T>(key, 'session')
|
||||
if (!draft) {
|
||||
savedAtRef.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(target, draft.payload)
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: saveSessionDraft supports AccountSettingsView.vue by holding or executing the save session draft page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const saveSessionDraft = <T>(key: string, payload: T, savedAtRef: typeof bindPhoneDraftSavedAt, successMessage = '已暂存到当前会话') => {
|
||||
const draft = saveDraftRecord(key, payload, 'session')
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success(successMessage)
|
||||
}
|
||||
|
||||
/** clearSessionDraft is a local helper used by this page script. */
|
||||
const clearSessionDraft = (key: string, savedAtRef: typeof bindPhoneDraftSavedAt, showMessage = true) => {
|
||||
clearDraftRecord(key, 'session')
|
||||
savedAtRef.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: bindPhoneDraftKey supports AccountSettingsView.vue by holding or executing the bind phone draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneDraftKey = buildDraftStorageKey('account-settings', 'bind-phone')
|
||||
/**
|
||||
* Purpose: changePhoneDraftKey supports AccountSettingsView.vue by holding or executing the change phone draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneDraftKey = buildDraftStorageKey('account-settings', 'change-phone')
|
||||
/**
|
||||
* Purpose: changePasswordDraftKey supports AccountSettingsView.vue by holding or executing the change password draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordDraftKey = buildDraftStorageKey('account-settings', 'change-password')
|
||||
|
||||
/** handleSaveBindPhoneDraft is a local helper used by this page script. */
|
||||
const handleSaveBindPhoneDraft = () => {
|
||||
saveSessionDraft(bindPhoneDraftKey, { ...bindPhoneForm }, bindPhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearBindPhoneDraft is a local helper used by this page script. */
|
||||
const handleClearBindPhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(bindPhoneDraftKey, bindPhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
/** handleSaveChangePhoneDraft is a local helper used by this page script. */
|
||||
const handleSaveChangePhoneDraft = () => {
|
||||
saveSessionDraft(changePhoneDraftKey, { ...changePhoneForm }, changePhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearChangePhoneDraft is a local helper used by this page script. */
|
||||
const handleClearChangePhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePhoneDraftKey, changePhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
/** handleSaveChangePasswordDraft is a local helper used by this page script. */
|
||||
const handleSaveChangePasswordDraft = () => {
|
||||
saveSessionDraft(changePasswordDraftKey, { ...changePasswordForm }, changePasswordDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearChangePasswordDraft is a local helper used by this page script. */
|
||||
const handleClearChangePasswordDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePasswordDraftKey, changePasswordDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
/** countdown is a reactive state variable used by the template and event handlers. */
|
||||
const countdown = ref(0)
|
||||
|
||||
// 账号设置选项
|
||||
/** accountSettings is a reactive state variable used by the template and event handlers. */
|
||||
const accountSettings = ref([
|
||||
{
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
{
|
||||
key: 'deactivateAccount',
|
||||
title: '注销账号',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
}
|
||||
])
|
||||
|
||||
// 根据用户状态动态更新账号设置选项
|
||||
/** updateAccountSettings is a local helper used by this page script. */
|
||||
const updateAccountSettings = () => {
|
||||
const settings = []
|
||||
|
||||
// 手机号相关
|
||||
if (!hasPhone.value) {
|
||||
settings.push({
|
||||
key: 'bindPhone',
|
||||
title: '绑定手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
})
|
||||
} else {
|
||||
settings.push({
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
})
|
||||
}
|
||||
|
||||
// 密码相关
|
||||
if (!hasPassword.value) {
|
||||
settings.push({
|
||||
key: 'setPassword',
|
||||
title: '设置密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff7e6'
|
||||
})
|
||||
} else {
|
||||
settings.push({
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
})
|
||||
}
|
||||
|
||||
// 注销账号
|
||||
settings.push({
|
||||
key: 'deactivateAccount',
|
||||
title: '注销账号',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
})
|
||||
|
||||
accountSettings.value = settings
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const response = await userApi.getUserInfo() as any
|
||||
userInfo.value = response
|
||||
// 检查是否绑定手机号
|
||||
hasPhone.value = !!userInfo.value.phone
|
||||
// 检查是否设置密码(通过localStorage中的标识)
|
||||
hasPassword.value = localStorage.getItem('needSetPassword') !== 'true'
|
||||
// 更新账号设置选项
|
||||
updateAccountSettings()
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error('获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理设置项点击
|
||||
/** handleSettingClick is a local helper used by this page script. */
|
||||
const handleSettingClick = (key: string) => {
|
||||
switch (key) {
|
||||
case 'bindPhone':
|
||||
restoreSessionDraft(bindPhoneDraftKey, bindPhoneForm, bindPhoneDraftSavedAt)
|
||||
bindPhoneModalVisible.value = true
|
||||
break
|
||||
case 'changePhone':
|
||||
restoreSessionDraft(changePhoneDraftKey, changePhoneForm, changePhoneDraftSavedAt)
|
||||
changePhoneModalVisible.value = true
|
||||
break
|
||||
case 'setPassword':
|
||||
handleSetPassword()
|
||||
break
|
||||
case 'changePassword':
|
||||
restoreSessionDraft(changePasswordDraftKey, changePasswordForm, changePasswordDraftSavedAt)
|
||||
changePasswordModalVisible.value = true
|
||||
break
|
||||
case 'deactivateAccount':
|
||||
handleDeactivateAccount()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设置密码
|
||||
/** handleSetPassword is a local helper used by this page script. */
|
||||
const handleSetPassword = () => {
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
// 发送绑定手机号验证码
|
||||
/** handleSendVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!bindPhoneForm.phone) {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(bindPhoneForm.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: bindPhoneForm.phone,
|
||||
sceneCode: 'USER_BIND_PHONE_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改手机号验证码
|
||||
/** handleSendChangePhoneVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendChangePhoneVerificationCode = async () => {
|
||||
if (!changePhoneForm.newPhone) {
|
||||
message.error('请输入新手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(changePhoneForm.newPhone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: changePhoneForm.newPhone,
|
||||
sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改密码验证码
|
||||
/** handleSendChangePasswordVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendChangePasswordVerificationCode = async () => {
|
||||
if (!userInfo.value.phone) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phone = userInfo.value.phone
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 开始倒计时
|
||||
/** startCountdown is a local helper used by this page script. */
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
// 处理绑定手机号提交
|
||||
/** handleBindPhoneSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBindPhoneSubmit = async () => {
|
||||
if (!bindPhoneForm.phone || !bindPhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
bindPhoneLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await userApi.bindPhone({
|
||||
phone: bindPhoneForm.phone,
|
||||
verificationCode: bindPhoneForm.verificationCode
|
||||
})
|
||||
await fetchUserInfo()
|
||||
})
|
||||
message.success('手机号绑定成功')
|
||||
handleClearBindPhoneDraft(false)
|
||||
bindPhoneModalVisible.value = false
|
||||
} catch (error: any) {
|
||||
console.error('绑定手机号失败:', error)
|
||||
message.error(error.message || '绑定手机号失败')
|
||||
} finally {
|
||||
bindPhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理绑定手机号取消
|
||||
/** handleBindPhoneCancel is a local helper used by this page script. */
|
||||
const handleBindPhoneCancel = () => {
|
||||
bindPhoneModalVisible.value = false
|
||||
bindPhoneForm.phone = ''
|
||||
bindPhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改手机号提交
|
||||
/** handleChangePhoneSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleChangePhoneSubmit = async () => {
|
||||
if (!changePhoneForm.newPhone || !changePhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
changePhoneLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await userApi.updatePhone({
|
||||
oldPhone: userInfo.value.phone!,
|
||||
newPhone: changePhoneForm.newPhone,
|
||||
verificationCode: changePhoneForm.verificationCode
|
||||
})
|
||||
await fetchUserInfo()
|
||||
})
|
||||
message.success('手机号修改成功')
|
||||
handleClearChangePhoneDraft(false)
|
||||
changePhoneModalVisible.value = false
|
||||
} catch (error: any) {
|
||||
console.error('修改手机号失败:', error)
|
||||
message.error(error.message || '修改手机号失败')
|
||||
} finally {
|
||||
changePhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改手机号取消
|
||||
/** handleChangePhoneCancel is a local helper used by this page script. */
|
||||
const handleChangePhoneCancel = () => {
|
||||
changePhoneModalVisible.value = false
|
||||
changePhoneForm.newPhone = ''
|
||||
changePhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改密码提交
|
||||
/** handleChangePasswordSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleChangePasswordSubmit = async () => {
|
||||
if (!changePasswordForm.verificationCode || !changePasswordForm.password || !changePasswordForm.confirmPassword) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
if (changePasswordForm.password !== changePasswordForm.confirmPassword) {
|
||||
message.error('两次输入的密码不一致')
|
||||
return
|
||||
}
|
||||
|
||||
changePasswordLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.updatePassword({
|
||||
password: changePasswordForm.password,
|
||||
verificationCode: changePasswordForm.verificationCode
|
||||
}))
|
||||
message.success('密码修改成功')
|
||||
handleClearChangePasswordDraft(false)
|
||||
changePasswordModalVisible.value = false
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
hasPassword.value = true
|
||||
updateAccountSettings()
|
||||
} catch (error: any) {
|
||||
console.error('修改密码失败:', error)
|
||||
message.error(error.message || '修改密码失败')
|
||||
} finally {
|
||||
changePasswordLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改密码取消
|
||||
/** handleChangePasswordCancel is a local helper used by this page script. */
|
||||
const handleChangePasswordCancel = () => {
|
||||
changePasswordModalVisible.value = false
|
||||
changePasswordForm.verificationCode = ''
|
||||
changePasswordForm.password = ''
|
||||
changePasswordForm.confirmPassword = ''
|
||||
}
|
||||
|
||||
// 处理注销账号
|
||||
/** handleDeactivateAccount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDeactivateAccount = async () => {
|
||||
Modal.confirm({
|
||||
title: '确认注销账号',
|
||||
content: '注销账号后,您的所有数据将被删除且无法恢复。确定要注销账号吗?',
|
||||
okText: '确认注销',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await userApi.deactivateAccount()
|
||||
message.success('账号注销成功')
|
||||
} catch (error) {
|
||||
console.error('注销账号失败:', error)
|
||||
message.error('注销账号失败')
|
||||
} finally {
|
||||
// 无论成功或失败,都清除本地存储的用户信息
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('needSetPassword')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
// 跳转到登录页
|
||||
router.push('/')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: var(--theme-page-bg);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: var(--theme-card-bg);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.account-settings {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.status-tips {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-title) {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user