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

@@ -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>