fix:bug解决

This commit is contained in:
李伊帆
2026-10-28 10:36:39 +08:00
parent c369127166
commit 91bca314ba
57 changed files with 2839 additions and 384 deletions

View File

@@ -1,15 +1,17 @@
import { onLoad } from '@dcloudio/uni-app'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { fetchProfile } from '@/api/profile'
import { useSmsCode } from '@/hooks/use-sms-code'
import { SMS_CODE_SCENE } from '@/types/api'
import { getErrorMessage } from '@/utils/api-error'
import { isValidPhone, isValidSmsCode } from '@/utils/validate'
import { isSamePhone, isValidPhone, isValidSmsCode } from '@/utils/validate'
import { verifyNewPhone } from '../change-phone.api'
export function useChangePhoneBind() {
const phone = ref('')
const code = ref('')
const changeToken = ref('')
const boundPhone = ref('')
const loading = ref(false)
const { counting, seconds, sendCode } = useSmsCode(SMS_CODE_SCENE.changePhoneNew, {
@@ -28,7 +30,30 @@ export function useChangePhoneBind() {
}
})
async function loadBoundPhone() {
try {
const profile = await fetchProfile()
boundPhone.value = profile?.phonenumber || profile?.userName || ''
} catch {
// 新号校验依赖当前绑定号;加载失败时仍走格式校验
}
}
function ensureNewPhoneDiffersFromBound(): boolean {
if (!isValidPhone(phone.value)) {
uni.showToast({ title: '请输入正确手机号', icon: 'none' })
return false
}
const bound = boundPhone.value.trim()
if (bound && isSamePhone(phone.value, bound)) {
uni.showToast({ title: '新手机号不能与当前手机号相同', icon: 'none' })
return false
}
return true
}
function onSendCode() {
if (!ensureNewPhoneDiffersFromBound()) return
sendCode(phone.value)
}
@@ -37,10 +62,7 @@ export function useChangePhoneBind() {
uni.showToast({ title: '换绑令牌无效,请重新验证', icon: 'none' })
return
}
if (!isValidPhone(phone.value)) {
uni.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
if (!ensureNewPhoneDiffersFromBound()) return
if (!isValidSmsCode(code.value)) {
uni.showToast({ title: '请输入验证码', icon: 'none' })
return
@@ -61,6 +83,10 @@ export function useChangePhoneBind() {
}
}
onShow(() => {
void loadBoundPhone()
})
return {
phone,
code,