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

This commit is contained in:
luo
2026-10-26 15:00:05 +08:00
parent b5f89b744c
commit e084cdeb90
6 changed files with 318 additions and 140 deletions

View File

@@ -10,7 +10,7 @@
<!-- <VoiceCard v-if="!userInfo.isDevice" :voiceStats="voiceStats" :dateRangeText="dateRangeText"
@openDatePicker="openDateRangePicker" /> -->
<TrafficCard :identifier="userStore.state.identifier" />
<TrafficCard :assetInfo="assetStore.state.assetInfo" />
<!-- <WhitelistCard v-if="!userInfo.isDevice" :whitelistData="whitelistData" @refresh="refreshWhitelist"
@add="showAddWhitelistDialog" @showSms="showSmsCodeDialog" /> -->
@@ -205,6 +205,8 @@
let recoverShow = ref(false);
let logoutShow = ref(false);
let loading = ref(false);
let syncing = ref(false);
let assetRequestId = 0;
let userInfo = reactive({
isDevice: true,
@@ -284,7 +286,6 @@
let showSmsCode = ref(false);
let smsCodePhone = ref('');
let smsCode = ref('');
let indexEntryChecking = ref(false);
let notificationUnreadCount = ref(0);
let notificationPopupShow = ref(false);
let notificationItems = ref([]);
@@ -309,11 +310,12 @@
if (!identifier) return;
if (userStore.state.identifier !== identifier) userStore.setIdentifier(identifier);
const context = getSessionContext();
const requestId = ++assetRequestId;
loading.value = true;
try {
const data = await assetApi.getInfo(identifier);
if (!isCurrentSession(context)) return null;
if (!isCurrentSession(context) || requestId !== assetRequestId) return null;
// 基本信息
userInfo.isDevice = data.asset_type === 'device';
@@ -338,7 +340,7 @@
effectiveRealnamePolicy.value = data.effective_realname_policy || 'none';
userStore.setRealNameStatus(data.real_name_status);
// 流量信息已由 TrafficCard 组件独立获取,这里不再处理
// 流量卡片消费同一次 asset/info 快照,支付和有效期变化后一起更新。
// 当前卡信息
if (data.cards && data.cards.length > 0) {
@@ -397,7 +399,7 @@
console.error('加载资产信息失败', e);
return null;
} finally {
loading.value = false;
if (requestId === assetRequestId) loading.value = false;
}
};
@@ -415,14 +417,7 @@
}
if (userStore.state.identifier !== identifier) userStore.setIdentifier(identifier);
if (indexEntryChecking.value) return;
indexEntryChecking.value = true;
try {
await loadAssetInfo();
} finally {
indexEntryChecking.value = false;
}
await loadAssetInfo();
};
const onRenewalVisibilityChange = (visible) => {
@@ -738,6 +733,7 @@
};
const onSync = async () => {
if (syncing.value) return;
const identifier = userStore.state.identifier;
if (!identifier) {
uni.showToast({
@@ -747,11 +743,13 @@
return;
}
const context = getSessionContext();
uni.showModal({
title: '确认同步',
content: '确定要同步运营商数据吗?',
content: '确定要同步运营商数据吗?受理不代表同步或停复机已执行完成,结果以稍后读取的实际状态为准。',
success: (res) => {
if (!res.confirm) return;
if (!res.confirm || syncing.value || !isCurrentSession(context)) return;
syncing.value = true;
uni.showLoading({
title: '同步中...',
mask: true
@@ -759,17 +757,19 @@
assetApi.refresh(identifier).then((data) => {
uni.hideLoading();
if (!isCurrentSession(context)) return;
if (data.accepted) {
if (data?.accepted === true || data?.accepted === 1) {
const refreshTypeText = data.refresh_type === 'device' ? '设备' : '卡';
uni.showToast({
title: `${refreshTypeText}数据同步成功`,
icon: 'success',
duration: 2000
title: `${refreshTypeText}同步请求已受理,请稍后查看状态`,
icon: 'none',
duration: 3000
});
loadAssetInfo();
setTimeout(() => {
loadAssetInfo();
if (homeActive.value && isCurrentSession(context)) loadAssetInfo();
}, 2000);
} else {
uni.showToast({
@@ -779,6 +779,7 @@
}
}).catch((e) => {
uni.hideLoading();
if (!isCurrentSession(context)) return;
console.error('同步数据失败', e);
if (e.msg && e.msg.includes('冷却')) {
@@ -793,7 +794,7 @@
icon: 'none'
});
}
});
}).finally(() => { syncing.value = false; });
}
});
};
@@ -1018,9 +1019,8 @@
handleIndexEntry();
return;
}
if (consumePendingPaymentRefresh(PAYMENT_REFRESH_TARGETS.HOME)) {
loadAssetInfo();
}
// 每次返回首页都重新读取实际状态,支付返回不再重复发起两次请求。
consumePendingPaymentRefresh(PAYMENT_REFRESH_TARGETS.HOME);
loadNotificationUnreadCount();
runPopupCandidate();
await handleIndexEntry();
@@ -1030,6 +1030,7 @@
});
onHide(() => {
homeEntryId++;
assetRequestId++;
homeActive.value = false;
shownExpiryReminder.value = null;
notificationPopupShow.value = false;

View File

@@ -67,14 +67,14 @@
</view>
<RenewalPaymentPopup ref="renewalPopupRef" :identifier="userStore.state.identifier"
paymentRefreshTarget="order-list" @completed="resetOrderListAndLoad" />
paymentRefreshTarget="order-list" @completed="refreshOrderState" />
</view>
</template>
<script setup>
import { ref, reactive, computed, onMounted } from 'vue';
import { ref, reactive, computed } from 'vue';
import { onReachBottom, onShow } from '@dcloudio/uni-app';
import { orderApi } from '@/api/index.js';
import { assetApi, orderApi } from '@/api/index.js';
import RenewalPaymentPopup from '@/components/RenewalPaymentPopup.vue';
import { useUserStore } from '@/store/index.js';
import {
@@ -121,17 +121,25 @@
loadOrderList();
};
const refreshOrderState = () => {
resetOrderListAndLoad();
// 订单支付、退款及套餐生效后,读取后端实际轮询状态,不推测已恢复。
return assetApi.getInfo(userStore.state.identifier).catch(error => {
console.error('刷新订单关联资产状态失败', error);
});
};
const scheduleOrderStatusRefresh = () => {
uni.showToast({
title: '正在同步支付状态',
icon: 'none'
});
resetOrderListAndLoad();
refreshOrderState();
setTimeout(() => {
resetOrderListAndLoad();
}, 1500);
setTimeout(() => {
resetOrderListAndLoad();
refreshOrderState();
}, 3000);
};
@@ -232,16 +240,13 @@
onShow(() => {
if (!consumePendingPaymentRefresh(PAYMENT_REFRESH_TARGETS.ORDER_LIST)) {
refreshOrderState();
return;
}
scheduleOrderStatusRefresh();
});
onMounted(() => {
loadOrderList();
});
onReachBottom(() => {
loadMore();
});

View File

@@ -102,7 +102,7 @@
</template>
<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { ref, reactive, computed } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { assetApi, isAssetRealNameCompleted, orderApi, walletApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
@@ -121,6 +121,7 @@
import { getPaymentErrorMessage, isUnknownPaymentResult } from '@/utils/payment-attempt.js';
import { formatMoney } from '@/utils/display.js';
import { getDefaultPaymentMethod, getPaymentMethodOptions, normalizePaymentMethods } from '@/utils/payment-methods.js';
import { getSessionContext, isCurrentSession } from '@/utils/session-context.js';
const userStore = useUserStore();
const popupCandidateShow = ref(false);
@@ -147,7 +148,7 @@
{ label: '正式套餐', value: 'formal' },
{ label: '加油包', value: 'addon' }
];
let assetTypePromise = null;
let assetRequestId = 0;
let packageRequestId = 0;
const paymentMethodOptions = computed(() => getPaymentMethodOptions(allowedPaymentMethods.value));
@@ -177,22 +178,19 @@
const loadAssetType = async () => {
if (!userStore.state.identifier) return;
if (assetTypePromise) return assetTypePromise;
assetTypePromise = assetApi.getInfo(userStore.state.identifier)
.then((data) => {
assetInfo.value = data;
allowedPaymentMethods.value = normalizePaymentMethods(data.allowed_payment_methods);
normalizePaymentMethod();
})
.catch((error) => {
console.error('加载资产类型失败', error);
})
.finally(() => {
assetTypePromise = null;
});
return assetTypePromise;
const context = getSessionContext();
const requestId = ++assetRequestId;
try {
const data = await assetApi.getInfo(userStore.state.identifier);
if (!isCurrentSession(context) || requestId !== assetRequestId) return null;
assetInfo.value = data;
allowedPaymentMethods.value = normalizePaymentMethods(data.allowed_payment_methods);
normalizePaymentMethod();
return data;
} catch (error) {
console.error('加载资产类型失败', error);
return null;
}
};
const loadPackages = async (packageType = activePackageType.value) => {
@@ -261,12 +259,21 @@
};
const syncPackagePageState = async () => {
await loadAssetType();
if (!await loadAssetType()) return;
await Promise.all([loadPackages(), loadWalletBalance()]);
};
const refreshAfterPayment = async () => {
const context = getSessionContext();
await syncPackagePageState();
// 充值自动购包可能稍后生效,再确认一次,仍以实际响应为准。
setTimeout(() => {
if (isCurrentSession(context)) syncPackagePageState();
}, 1500);
};
const buyPackage = async (item) => {
await loadAssetType();
if (!await loadAssetType()) return;
if (assetInfo.value.effective_realname_policy === 'before_order' &&
assetInfo.value.realname_required && !isAssetRealNameCompleted(assetInfo.value)) {
uni.showModal({
@@ -309,9 +316,7 @@
} else {
showPaymentToast(true, isForceRecharge ? '充值成功,套餐将自动购买' : '支付成功');
}
setTimeout(() => {
loadWalletBalance();
}, 1500);
await refreshAfterPayment();
} catch (error) {
handlePaymentError(error);
}
@@ -464,9 +469,7 @@
} catch (error) {
showPaymentToast(false, '支付结果确认失败,请稍后查看订单');
}
setTimeout(() => {
loadWalletBalance();
}, 1500);
await refreshAfterPayment();
return;
}
@@ -505,11 +508,12 @@
};
onShow(() => {
// 后台也可能修改套餐有效期,返回页面时始终重读,不只处理支付宝返回。
syncPackagePageState();
if (!consumePendingPaymentRefresh(PAYMENT_REFRESH_TARGETS.PACKAGE_ORDER)) {
return;
}
syncPackagePageState();
uni.showModal({
title: '支付状态确认',
content: '已返回页面,支付结果以订单状态为准。是否前往我的订单查看最新状态?',
@@ -539,9 +543,6 @@
popupCandidateShow.value = true;
});
onMounted(() => {
syncPackagePageState();
});
</script>
<style lang="scss" scoped>