feat:蓝牙绑定和在线客服

This commit is contained in:
李伊帆
2026-10-13 16:23:43 +08:00
parent d4b02745e1
commit e22ebd6bef
128 changed files with 10429 additions and 385 deletions

View File

@@ -0,0 +1,67 @@
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
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 { verifyNewPhone } from '../change-phone.api'
export function useChangePhoneBind() {
const phone = ref('')
const code = ref('')
const changeToken = ref('')
const loading = ref(false)
const { counting, seconds, sendCode } = useSmsCode(SMS_CODE_SCENE.changePhoneNew)
onLoad((query) => {
const raw = (query?.changeToken as string) || ''
changeToken.value = raw ? decodeURIComponent(raw) : ''
if (!changeToken.value) {
uni.showToast({ title: '请先完成原手机号验证', icon: 'none' })
setTimeout(() => uni.navigateBack(), 1500)
}
})
function onSendCode() {
sendCode(phone.value)
}
async function submit() {
if (!changeToken.value) {
uni.showToast({ title: '换绑令牌无效,请重新验证', icon: 'none' })
return
}
if (!isValidPhone(phone.value)) {
uni.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
if (!isValidSmsCode(code.value)) {
uni.showToast({ title: '请输入验证码', icon: 'none' })
return
}
if (loading.value) return
loading.value = true
try {
await verifyNewPhone(changeToken.value, { phone: phone.value, code: code.value })
uni.showToast({ title: '手机号换绑成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack({ delta: 2 })
}, 1200)
} catch (err) {
uni.showToast({ title: getErrorMessage(err, '换绑失败,请重试'), icon: 'none' })
} finally {
loading.value = false
}
}
return {
phone,
code,
counting,
seconds,
onSendCode,
submit,
}
}