Files
airz-uniapp/packages/account/change-phone/change-phone.uvue
T

39 lines
3.1 KiB
Plaintext
Raw Normal View History

<template>
<view class="page" :style="pageStyle()"><AppHeader title="更换手机号" />
<scroll-view scroll-y :style="contentStyle(96, false)"><view class="account-form-content" :style="bottomStyle(40)">
<text class="form-title">验证并绑定新手机号</text><text class="form-description">请分别验证当前号码和新号码,确保账户由您本人操作。</text>
<view class="form-card"><text class="form-label">当前手机号 {{ maskPhone(phone) }}</text><SecurityCode v-model="currentCode" :disabled="submitting" purpose="phone-current" @error="codeError" @sent="errorMessage = ''" /></view>
<view class="form-card"><text class="form-label">新手机号</text><input v-model="newPhone" class="account-input new-phone" :disabled="submitting" type="number" maxlength="11" placeholder="请输入新的 11 位手机号" /><SecurityCode v-model="newCode" :disabled="submitting || !validPhone(newPhone) || newPhone == phone" purpose="phone-new" :phone="newPhone" @error="codeError" @sent="errorMessage = ''" /></view>
<text class="form-hint">换绑成功后需要使用新手机号登录。若原号码已无法接收短信,请通过官方客服核验身份后处理。</text>
<text v-if="errorMessage.length > 0" class="form-error">{{ errorMessage }}</text>
<button class="primary-button form-submit" :disabled="submitting" @click="submit">{{ submitting ? '提交中…' : '确认更换' }}</button>
</view></scroll-view>
</view>
</template>
<script setup lang="uts">
import AppHeader from '@/components/AppHeader.uvue'
import SecurityCode from '@/packages/account/components/SecurityCode.uvue'
import { usePageLayout } from '@/services/layout.uts'
import { getSession, clearSession } from '@/services/api.uts'
import { getAccountProfile, maskPhone, validPhone, changeAccountPhone } from '@/packages/account/services/account.uts'
const { pageStyle, contentStyle, bottomStyle } = usePageLayout()
const phone = ref(''); const newPhone = ref(''); const currentCode = ref(''); const newCode = ref(''); const submitting = ref(false); const errorMessage = ref('')
onLoad(() => { if (getSession() == null) { uni.redirectTo({ url: '/packages/account/login/login' }); return }; phone.value = getAccountProfile().phone })
const codeError = (message: string) => { errorMessage.value = message }
const submit = async () => {
if (submitting.value) return
submitting.value = true; errorMessage.value = ''
try {
if (getAccountProfile().phone != phone.value) throw new Error('登录状态已变化,请重新进入页面')
await changeAccountPhone(newPhone.value, currentCode.value, newCode.value)
currentCode.value = ''; newCode.value = ''; clearSession(); uni.reLaunch({ url: '/packages/account/login/login' }); uni.showToast({ title: '手机号已更换,请重新登录', icon: 'none' })
} catch (error) { errorMessage.value = error instanceof Error ? error.message : '更换失败,请稍后重试' }
finally { submitting.value = false }
}
onHide(() => { currentCode.value = ''; newCode.value = '' })
onUnload(() => { currentCode.value = ''; newCode.value = '' })
</script>
<style>
@import '../styles/forms.css';
</style>