feat:客服
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { computed, ref } from 'vue'
|
||||
import { fetchProfile } from '@/api/profile'
|
||||
import { useSmsCode } from '@/hooks/use-sms-code'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
import { getStoredToken } from '@/utils/auth-token'
|
||||
import { isValidPhone, isValidSmsCode } from '@/utils/validate'
|
||||
import { SMS_CODE_SCENE } from '@/types/api'
|
||||
import { verifyForgetPasswordCode } from './forgot-password.api'
|
||||
@@ -9,9 +12,29 @@ export function useForgotPassword() {
|
||||
const phone = ref('')
|
||||
const code = ref('')
|
||||
const loading = ref(false)
|
||||
const fromPrivacy = ref(false)
|
||||
|
||||
const { counting, seconds, sendCode } = useSmsCode(SMS_CODE_SCENE.reset)
|
||||
|
||||
const pageTitle = computed(() => (fromPrivacy.value ? '修改登录密码' : '忘记密码'))
|
||||
|
||||
onLoad((query) => {
|
||||
fromPrivacy.value = query?.from === 'privacy'
|
||||
})
|
||||
|
||||
async function loadBoundPhone() {
|
||||
if (!getStoredToken()) return
|
||||
try {
|
||||
const profile = await fetchProfile()
|
||||
const bound = profile?.phonenumber || profile?.userName || ''
|
||||
if (bound) {
|
||||
phone.value = bound
|
||||
}
|
||||
} catch {
|
||||
// 未登录或加载失败时保持手动输入
|
||||
}
|
||||
}
|
||||
|
||||
function onSendCode() {
|
||||
sendCode(phone.value)
|
||||
}
|
||||
@@ -34,7 +57,7 @@ export function useForgotPassword() {
|
||||
return
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: `/pages/change-password/index?resetToken=${encodeURIComponent(res.resetToken)}`,
|
||||
url: `/pages/change-password/index?resetToken=${encodeURIComponent(res.resetToken)}&from=${fromPrivacy.value ? 'privacy' : 'login'}`,
|
||||
})
|
||||
} catch (err) {
|
||||
uni.showToast({ title: getErrorMessage(err, '验证失败,请重试'), icon: 'none' })
|
||||
@@ -43,5 +66,9 @@ export function useForgotPassword() {
|
||||
}
|
||||
}
|
||||
|
||||
return { phone, code, counting, seconds, onSendCode, nextStep }
|
||||
onShow(() => {
|
||||
void loadBoundPhone()
|
||||
})
|
||||
|
||||
return { phone, code, counting, seconds, pageTitle, onSendCode, nextStep }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user