fix: some
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 2m59s

This commit is contained in:
luo
2026-10-13 14:53:19 +08:00
parent 77b0e25011
commit da95a914e3
31 changed files with 1702 additions and 116 deletions

View File

@@ -1,6 +1,7 @@
<template>
<view class="container">
<view class="card">
<view class="caption mb-md">仅更换您的客户手机号,资产已绑定的手机号不会改变。</view>
<view class="form-item">
<view class="label">原手机号</view>
<up-input placeholder="请输入原手机号" border="surround" v-model="form.oldPhone" disabled/>
@@ -30,19 +31,20 @@
</view>
<view class="btn-wrapper">
<up-button type="primary" @click="submit">确认更换</up-button>
<up-button type="primary" :loading="submitting" :disabled="submitting" @click="submit">确认更换</up-button>
</view>
</view>
</view>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue';
import { authApi } from '@/api/index.js';
import { reactive, ref, onMounted, onUnmounted } from 'vue';
import { authApi, assetApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import { setPhoneBindStatus } from '@/utils/phone-bind.js';
import { getSessionContext, isCurrentSession } from '@/utils/session-context.js';
const userStore = useUserStore();
const submitting = ref(false);
const form = reactive({
oldPhone: '',
@@ -51,14 +53,18 @@
newCode: ''
});
onMounted(() => {
// 获取 URL 参数中的原手机号
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
if (options.oldPhone) {
form.oldPhone = options.oldPhone;
onMounted(async () => {
form.oldPhone = userStore.state.customerPhone || '';
const context = getSessionContext();
const revision = userStore.state.phoneRevision;
try {
const data = await assetApi.getInfo(context.identifier);
if (isCurrentSession(context)) {
form.oldPhone = revision === userStore.state.phoneRevision
? data.bound_phone || '' : userStore.state.customerPhone || '';
}
} catch (e) {
console.error('加载客户手机号失败');
}
});
@@ -126,6 +132,7 @@
};
const submit = async () => {
if (submitting.value) return;
if (!form.oldPhone || !form.oldCode) {
uni.showToast({ title: '请填写原手机号信息', icon: 'none' });
return;
@@ -134,19 +141,34 @@
uni.showToast({ title: '请填写新手机号信息', icon: 'none' });
return;
}
if (!/^1[3-9]\d{9}$/.test(form.newPhone)) {
uni.showToast({ title: '请输入正确的新手机号', icon: 'none' });
return;
}
const context = getSessionContext();
submitting.value = true;
try {
await authApi.changePhone(form.oldPhone, form.oldCode, form.newPhone, form.newCode);
setPhoneBindStatus(userStore.state.identifier, form.newPhone);
form.oldPhone = form.newPhone;
const data = await authApi.changePhone(form.oldPhone, form.oldCode, form.newPhone, form.newCode);
if (!isCurrentSession(context)) return;
if (typeof data?.phone === 'string') {
userStore.completeCustomerPhoneChange(data.phone);
form.oldPhone = data.phone;
}
uni.showToast({ title: '更换成功', icon: 'success' });
setTimeout(() => {
uni.navigateBack();
if (isCurrentSession(context)) uni.navigateBack();
}, 1500);
} catch (e) {
console.error('更换手机号失败', e);
} finally {
submitting.value = false;
}
};
onUnmounted(() => {
clearInterval(oldTimer);
clearInterval(newTimer);
});
</script>
<style lang="scss" scoped>