fix: 手机绑定状态
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 2m24s

This commit is contained in:
luo
2026-09-20 16:19:48 +08:00
parent c0cc1ae6dd
commit a81b403cce
3 changed files with 38 additions and 3 deletions

View File

@@ -42,6 +42,7 @@
import { ref, reactive, onMounted } from 'vue';
import { authApi, assetApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import { setPhoneBindStatus } from '@/utils/phone-bind.js';
const POST_BIND_RELOGIN_NOTICE_KEY = 'postBindReloginNotice';
@@ -139,6 +140,8 @@
try {
await authApi.bindPhone(bind.phone, bind.code);
const identifier = userStore.state.identifier || uni.getStorageSync('identifier') || '';
setPhoneBindStatus(identifier, bind.phone);
if (fromLogin.value) {
prepareManualRelogin();

View File

@@ -148,6 +148,7 @@
useUserStore
} from '@/store/index.js';
import { consumePendingPaymentRefresh, PAYMENT_REFRESH_TARGETS } from '@/utils/payment.js';
import { getPhoneBindStatus, setPhoneBindStatus } from '@/utils/phone-bind.js';
const userStore = useUserStore();
@@ -258,6 +259,7 @@
const loadAssetInfo = async () => {
const identifier = userStore.state.identifier;
if (!identifier) return;
const localBindStatus = getPhoneBindStatus(identifier);
loading.value = true;
try {
@@ -270,7 +272,9 @@
deviceInfo.status = data.status;
deviceInfo.imei = data.imei || '-';
deviceInfo.asset_type = data.asset_type || 'device';
deviceInfo.bound_phone = data.bound_phone || '';
const apiBoundPhone = data.bound_phone || '';
const effectiveBoundPhone = apiBoundPhone || localBindStatus?.phone || '';
deviceInfo.bound_phone = effectiveBoundPhone;
deviceInfo.packageName = data.current_package || '-';
deviceInfo.currentPackageId = Number(data.current_package_id || 0);
deviceInfo.renewalPrice = data.renewal_price ?? null;
@@ -285,8 +289,11 @@
realNameStatus.value = isRealName.value ? '已实名' : '未实名';
effectiveRealnamePolicy.value = data.effective_realname_policy || 'none';
userStore.setRealNameStatus(data.real_name_status);
boundPhone.value = data.bound_phone || '';
alreadyBindPhone.value = !!data.bound_phone;
boundPhone.value = effectiveBoundPhone;
alreadyBindPhone.value = !!(apiBoundPhone || localBindStatus?.bound);
if (apiBoundPhone) {
setPhoneBindStatus(identifier, apiBoundPhone);
}
// 流量信息已由 TrafficCard 组件独立获取,这里不再处理

25
utils/phone-bind.js Normal file
View File

@@ -0,0 +1,25 @@
const PHONE_BIND_STATUS_KEY = 'phoneBindStatus';
const readStatuses = () => {
const statuses = uni.getStorageSync(PHONE_BIND_STATUS_KEY);
return statuses && typeof statuses === 'object' && !Array.isArray(statuses) ? statuses : {};
};
export const getPhoneBindStatus = (identifier) => {
if (!identifier) return null;
const status = readStatuses()[identifier];
return status && status.bound ? status : null;
};
export const setPhoneBindStatus = (identifier, phone) => {
if (!identifier) return;
const statuses = readStatuses();
statuses[identifier] = {
bound: true,
phone: phone || '',
updatedAt: Date.now()
};
uni.setStorageSync(PHONE_BIND_STATUS_KEY, statuses);
};