From a81b403cce2b9dbee100f6ce9096d613564272b2 Mon Sep 17 00:00:00 2001 From: luo Date: Sun, 20 Sep 2026 16:19:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=8B=E6=9C=BA=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/bind/bind.vue | 3 +++ pages/index/index.vue | 13 ++++++++++--- utils/phone-bind.js | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 utils/phone-bind.js diff --git a/pages/bind/bind.vue b/pages/bind/bind.vue index 09f2294..1ed1b31 100644 --- a/pages/bind/bind.vue +++ b/pages/bind/bind.vue @@ -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(); diff --git a/pages/index/index.vue b/pages/index/index.vue index b89bd84..42a324a 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -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 组件独立获取,这里不再处理 diff --git a/utils/phone-bind.js b/utils/phone-bind.js new file mode 100644 index 0000000..5b7652f --- /dev/null +++ b/utils/phone-bind.js @@ -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); +};