2026-09-21 15:04:59 +08:00
|
|
|
<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>
|
2026-10-07 10:01:05 +08:00
|
|
|
<view class="form-card"><text class="form-label">当前手机号 {{ maskPhone(phone) }}</text><SecurityCode v-model="currentCode" :disabled="submitting" :active="pageVisible" :ownerToken="ownerToken" 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" :active="pageVisible" :ownerToken="ownerToken" purpose="phone-new" :phone="newPhone" @error="codeError" @sent="errorMessage = ''" /></view>
|
2026-09-21 15:04:59 +08:00
|
|
|
<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('')
|
2026-10-07 10:01:05 +08:00
|
|
|
const ownerToken = ref(''); const pageVisible = ref(false)
|
|
|
|
|
let ownerId = ''; let generation = 0; let accountTimer = 0
|
|
|
|
|
const clearSecrets = () => { currentCode.value = ''; newCode.value = ''; newPhone.value = '' }
|
|
|
|
|
const stopAccountTimer = () => { clearInterval(accountTimer); accountTimer = 0 }
|
|
|
|
|
const sameOwner = (): boolean => {
|
|
|
|
|
if (!pageVisible.value) return false
|
|
|
|
|
const session = getSession()
|
|
|
|
|
if (ownerToken.value.length > 0 && session?.getString('token') == ownerToken.value && session?.getString('userId') == ownerId) return true
|
|
|
|
|
generation++; clearSecrets(); phone.value = ''; errorMessage.value = ''; stopAccountTimer()
|
|
|
|
|
uni.redirectTo({ url: session == null ? '/packages/account/login/login' : '/packages/account/security/security' })
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
onLoad(() => { const session = getSession(); ownerToken.value = session?.getString('token') ?? ''; ownerId = session?.getString('userId') ?? ''; phone.value = getAccountProfile().phone })
|
|
|
|
|
onShow(() => { pageVisible.value = true; generation++; stopAccountTimer(); if (sameOwner()) accountTimer = setInterval(() => { sameOwner() }, 1000) })
|
|
|
|
|
const codeError = (message: string) => { if (sameOwner()) errorMessage.value = message }
|
2026-09-21 15:04:59 +08:00
|
|
|
const submit = async () => {
|
2026-10-07 10:01:05 +08:00
|
|
|
if (!sameOwner() || submitting.value) return
|
2026-09-21 15:04:59 +08:00
|
|
|
submitting.value = true; errorMessage.value = ''
|
2026-10-07 10:01:05 +08:00
|
|
|
const view = generation; const token = ownerToken.value; const userId = ownerId
|
2026-09-21 15:04:59 +08:00
|
|
|
try {
|
|
|
|
|
await changeAccountPhone(newPhone.value, currentCode.value, newCode.value)
|
2026-10-07 10:01:05 +08:00
|
|
|
if (getSession()?.getString('token') != token || getSession()?.getString('userId') != userId) return
|
|
|
|
|
clearSecrets(); clearSession()
|
|
|
|
|
if (view == generation && pageVisible.value) { uni.reLaunch({ url: '/packages/account/login/login' }); uni.showToast({ title: '手机号已更换,请重新登录', icon: 'none' }) }
|
|
|
|
|
} catch (error) { if (view == generation && sameOwner()) errorMessage.value = error instanceof Error ? error.message : '更换失败,请稍后重试' }
|
2026-09-21 15:04:59 +08:00
|
|
|
finally { submitting.value = false }
|
|
|
|
|
}
|
2026-10-07 10:01:05 +08:00
|
|
|
onHide(() => { pageVisible.value = false; generation++; stopAccountTimer(); clearSecrets(); errorMessage.value = '' })
|
|
|
|
|
onUnload(() => { pageVisible.value = false; generation++; stopAccountTimer(); clearSecrets(); phone.value = '' })
|
2026-09-21 15:04:59 +08:00
|
|
|
</script>
|
|
|
|
|
<style>
|
|
|
|
|
@import '../styles/forms.css';
|
|
|
|
|
</style>
|