功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -91,6 +91,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* PasswordSettingsView 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 { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
@@ -104,7 +108,9 @@ import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** countdown is a reactive state variable used by the template and event handlers. */
|
||||
const countdown = ref(0)
|
||||
const userInfo = ref<{ phone?: string } | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
@@ -118,6 +124,7 @@ const formState = reactive({
|
||||
|
||||
const draftKey = buildDraftStorageKey('password-settings', 'set-password')
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<typeof formState>(draftKey, 'session')
|
||||
if (!draft) {
|
||||
@@ -129,12 +136,14 @@ const restoreDraft = () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(draftKey, { ...formState }, 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(draftKey, 'session')
|
||||
draftSavedAt.value = null
|
||||
@@ -143,8 +152,10 @@ const handleClearDraft = (showMessage = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** userPhone is a reactive state variable used by the template and event handlers. */
|
||||
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||
|
||||
/** validateConfirmPassword is a local helper used by this page script. */
|
||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
if (value !== formState.password) {
|
||||
return Promise.reject(new Error('两次输入的密码不一致'))
|
||||
@@ -168,6 +179,7 @@ const formRules: Record<string, Rule[]> = {
|
||||
]
|
||||
}
|
||||
|
||||
/** startCountdown is a local helper used by this page script. */
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
if (countdownTimer) {
|
||||
@@ -182,6 +194,7 @@ const startCountdown = () => {
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
@@ -192,6 +205,7 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSendVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
@@ -199,7 +213,10 @@ const handleSendVerificationCode = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({ phone: userPhone.value }))
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: userPhone.value,
|
||||
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error: any) {
|
||||
@@ -208,6 +225,7 @@ const handleSendVerificationCode = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
@@ -236,6 +254,7 @@ const handleSubmit = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user