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

This commit is contained in:
luo
2026-07-03 09:07:28 +08:00
parent 6756ad5700
commit a9fbbea1e6
7 changed files with 144 additions and 35 deletions

View File

@@ -17,8 +17,7 @@ server {
add_header Content-Type text/plain; add_header Content-Type text/plain;
} }
# H5 部署到 /h5 location / {
location /h5/ {
alias /usr/share/nginx/html/; alias /usr/share/nginx/html/;
index index.html; index index.html;
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;

View File

@@ -85,7 +85,7 @@
"enable" : true "enable" : true
} }
}, },
"publicPath" : "/h5/", "publicPath" : "./",
"devServer" : { "devServer" : {
"proxy" : { "proxy" : {
"/kyhl-weixin-1.0" : { "/kyhl-weixin-1.0" : {

View File

@@ -14,7 +14,7 @@
<view class="flex-col-g20"> <view class="flex-col-g20">
<view class="iccid">ICCID: {{ item.iccid }}</view> <view class="iccid">ICCID: {{ item.iccid }}</view>
<view class="operator">运营商: {{ getCarrier(item.carrier_type).name }}</view> <view class="operator">运营商: {{ getCarrier(item.carrier_type).name }}</view>
<view class="slot">卡槽位: {{ item.slot_position || '-' }}</view> <view v-if="item.isDevice" class="slot">卡槽位: {{ item.slot_position || '-' }}</view>
</view> </view>
</view> </view>
@@ -81,13 +81,14 @@
iccid: card.iccid, iccid: card.iccid,
carrier_type: card.carrier_type, carrier_type: card.carrier_type,
slot_position: card.slot_position, slot_position: card.slot_position,
isDevice: true,
isRealName: card.real_name_status === 1 isRealName: card.real_name_status === 1
}))); })));
} else if (assetData.identifier) { } else if (assetData.iccid) {
list.splice(0, list.length, { list.splice(0, list.length, {
iccid: assetData.identifier, iccid: assetData.iccid,
carrier_type: assetData.carrier_type, carrier_type: assetData.carrier_type,
slot_position: 1, isDevice: false,
isRealName: assetData.real_name_status === 1 isRealName: assetData.real_name_status === 1
}); });
} else { } else {

View File

@@ -155,7 +155,7 @@
</view> </view>
<view class="payment-methods"> <view class="payment-methods">
<view class="method-item" :class="{ active: rechargePaymentMethod === 'wechat' }" @tap="selectRechargePaymentMethod('wechat')"> <view v-if="isDeviceAsset" class="method-item" :class="{ active: rechargePaymentMethod === 'wechat' }" @tap="selectRechargePaymentMethod('wechat')">
<view class="method-left"> <view class="method-left">
<image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image> <image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image>
<text class="method-name">微信支付</text> <text class="method-name">微信支付</text>
@@ -163,7 +163,7 @@
<view class="method-radio" :class="{ checked: rechargePaymentMethod === 'wechat' }"></view> <view class="method-radio" :class="{ checked: rechargePaymentMethod === 'wechat' }"></view>
</view> </view>
<view class="method-item" :class="{ active: rechargePaymentMethod === 'alipay' }" @tap="selectRechargePaymentMethod('alipay')"> <view v-else class="method-item" :class="{ active: rechargePaymentMethod === 'alipay' }" @tap="selectRechargePaymentMethod('alipay')">
<view class="method-left"> <view class="method-left">
<view class="method-icon method-badge method-badge-alipay"></view> <view class="method-icon method-badge method-badge-alipay"></view>
<text class="method-name">支付宝支付</text> <text class="method-name">支付宝支付</text>
@@ -186,9 +186,9 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from 'vue'; import { ref, reactive, onMounted, computed } from 'vue';
import { onShow } from '@dcloudio/uni-app'; import { onShow } from '@dcloudio/uni-app';
import { walletApi } from '@/api/index.js'; import { assetApi, walletApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js'; import { useUserStore } from '@/store/index.js';
import { import {
consumePendingPaymentRefresh, consumePendingPaymentRefresh,
@@ -229,10 +229,13 @@
const rechargePaymentMethod = ref('wechat'); const rechargePaymentMethod = ref('wechat');
const rechargeSubmitting = ref(false); const rechargeSubmitting = ref(false);
const rechargeOrderSubmittingKey = ref(null); const rechargeOrderSubmittingKey = ref(null);
const paymentMethodOptions = [ const isDeviceAsset = ref(true);
{ label: '微信支付', value: 'wechat' }, let assetTypePromise = null;
{ label: '支付宝支付', value: 'alipay' } const paymentMethodOptions = computed(() => [
]; isDeviceAsset.value
? { label: '微信支付', value: 'wechat' }
: { label: '支付宝支付', value: 'alipay' }
]);
const rechargeAmounts = [ const rechargeAmounts = [
{ value: 1000, label: '10' }, { value: 1000, label: '10' },
{ value: 2000, label: '20' }, { value: 2000, label: '20' },
@@ -305,6 +308,34 @@
return rechargeOrderSubmittingKey.value === getRechargeOrderSubmitKey(rechargeOrder); return rechargeOrderSubmittingKey.value === getRechargeOrderSubmitKey(rechargeOrder);
}; };
const getDefaultRechargePaymentMethod = () => isDeviceAsset.value ? 'wechat' : 'alipay';
const normalizeRechargePaymentMethod = () => {
const defaultMethod = getDefaultRechargePaymentMethod();
if (rechargePaymentMethod.value !== defaultMethod) {
rechargePaymentMethod.value = defaultMethod;
}
};
const loadAssetType = async () => {
if (!userStore.state.identifier) return;
if (assetTypePromise) return assetTypePromise;
assetTypePromise = assetApi.getInfo(userStore.state.identifier)
.then((data) => {
isDeviceAsset.value = data.asset_type === 'device';
normalizeRechargePaymentMethod();
})
.catch((error) => {
console.error('加载资产类型失败', error);
})
.finally(() => {
assetTypePromise = null;
});
return assetTypePromise;
};
const resetRechargeListAndLoad = () => { const resetRechargeListAndLoad = () => {
rechargePage.value = 1; rechargePage.value = 1;
rechargeNoMore.value = false; rechargeNoMore.value = false;
@@ -318,6 +349,7 @@
}; };
const syncWalletStatus = () => { const syncWalletStatus = () => {
loadAssetType();
loadWalletDetail(); loadWalletDetail();
resetRechargeListAndLoad(); resetRechargeListAndLoad();
resetTransactionListAndLoad(); resetTransactionListAndLoad();
@@ -337,8 +369,9 @@
}, 3000); }, 3000);
}; };
const openRechargeModal = () => { const openRechargeModal = async () => {
rechargePaymentMethod.value = 'wechat'; await loadAssetType();
rechargePaymentMethod.value = getDefaultRechargePaymentMethod();
showRechargeModal.value = true; showRechargeModal.value = true;
}; };
@@ -354,6 +387,7 @@
}; };
const selectRechargePaymentMethod = (method) => { const selectRechargePaymentMethod = (method) => {
if (method !== getDefaultRechargePaymentMethod()) return;
rechargePaymentMethod.value = method; rechargePaymentMethod.value = method;
}; };
@@ -602,13 +636,15 @@
} }
}; };
const showRechargePaymentMethods = (rechargeOrder) => { const showRechargePaymentMethods = async (rechargeOrder) => {
if (rechargeOrderSubmittingKey.value !== null) return; if (rechargeOrderSubmittingKey.value !== null) return;
await loadAssetType();
const options = paymentMethodOptions.value;
uni.showActionSheet({ uni.showActionSheet({
itemList: paymentMethodOptions.map((item) => item.label), itemList: options.map((item) => item.label),
success: ({ tapIndex }) => { success: ({ tapIndex }) => {
const selectedMethod = paymentMethodOptions[tapIndex]?.value; const selectedMethod = options[tapIndex]?.value;
if (selectedMethod) { if (selectedMethod) {
handleRechargePayment(rechargeOrder, selectedMethod); handleRechargePayment(rechargeOrder, selectedMethod);
} }

View File

@@ -73,9 +73,9 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from 'vue'; import { ref, reactive, onMounted, computed } from 'vue';
import { onShow } from '@dcloudio/uni-app'; import { onShow } from '@dcloudio/uni-app';
import { orderApi } from '@/api/index.js'; import { assetApi, orderApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js'; import { useUserStore } from '@/store/index.js';
import { import {
consumePendingPaymentRefresh, consumePendingPaymentRefresh,
@@ -97,10 +97,14 @@
const orderPayingId = ref(null); const orderPayingId = ref(null);
const pageSize = 10; const pageSize = 10;
const filterIndex = ref(0); const filterIndex = ref(0);
const paymentMethodOptions = [ const isDeviceAsset = ref(true);
{ label: '微信支付', value: 'wechat' }, let assetTypePromise = null;
{ label: '支付宝支付', value: 'alipay' } const paymentMethodOptions = computed(() => [
]; isDeviceAsset.value
? { label: '微信支付', value: 'wechat' }
: { label: '支付宝支付', value: 'alipay' },
{ label: '钱包支付', value: 'wallet' }
]);
const filterOptions = [ const filterOptions = [
{ label: '全部', value: null }, { label: '全部', value: null },
{ label: '待支付', value: 1 }, { label: '待支付', value: 1 },
@@ -124,6 +128,24 @@
return classMap[status] || ''; return classMap[status] || '';
}; };
const loadAssetType = async () => {
if (!userStore.state.identifier) return;
if (assetTypePromise) return assetTypePromise;
assetTypePromise = assetApi.getInfo(userStore.state.identifier)
.then((data) => {
isDeviceAsset.value = data.asset_type === 'device';
})
.catch((error) => {
console.error('加载资产类型失败', error);
})
.finally(() => {
assetTypePromise = null;
});
return assetTypePromise;
};
const resetOrderListAndLoad = () => { const resetOrderListAndLoad = () => {
page.value = 1; page.value = 1;
noMore.value = false; noMore.value = false;
@@ -203,13 +225,15 @@
const isOrderPaying = (order) => orderPayingId.value === order.order_id; const isOrderPaying = (order) => orderPayingId.value === order.order_id;
const showOrderPaymentMethods = (order) => { const showOrderPaymentMethods = async (order) => {
if (orderPayingId.value !== null || !order?.order_id) return; if (orderPayingId.value !== null || !order?.order_id) return;
await loadAssetType();
const options = paymentMethodOptions.value;
uni.showActionSheet({ uni.showActionSheet({
itemList: paymentMethodOptions.map((item) => item.label), itemList: options.map((item) => item.label),
success: ({ tapIndex }) => { success: ({ tapIndex }) => {
const selectedMethod = paymentMethodOptions[tapIndex]?.value; const selectedMethod = options[tapIndex]?.value;
if (selectedMethod) { if (selectedMethod) {
handleOrderPayment(order, selectedMethod); handleOrderPayment(order, selectedMethod);
} }
@@ -230,6 +254,14 @@
const payData = await orderApi.pay(order.order_id, paymentMethod); const payData = await orderApi.pay(order.order_id, paymentMethod);
uni.hideLoading(); uni.hideLoading();
if (paymentMethod === 'wallet') {
showPaymentToast(true, '支付成功');
setTimeout(() => {
resetOrderListAndLoad();
}, 1500);
return;
}
if (paymentMethod === 'wechat') { if (paymentMethod === 'wechat') {
if (!isValidWechatPayConfig(payData?.pay_config)) { if (!isValidWechatPayConfig(payData?.pay_config)) {
uni.showToast({ uni.showToast({
@@ -281,6 +313,7 @@
}); });
onMounted(() => { onMounted(() => {
loadAssetType();
loadOrderList(); loadOrderList();
}); });
</script> </script>

View File

@@ -59,7 +59,7 @@
</view> </view>
<view class="payment-methods"> <view class="payment-methods">
<view class="method-item" :class="{ active: paymentMethod === 'wechat' }" @tap="selectPaymentMethod('wechat')"> <view v-if="isDeviceAsset" class="method-item" :class="{ active: paymentMethod === 'wechat' }" @tap="selectPaymentMethod('wechat')">
<view class="method-left"> <view class="method-left">
<image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image> <image class="method-icon" src="/static/wechat.png" mode="aspectFit"></image>
<text class="method-name">微信支付</text> <text class="method-name">微信支付</text>
@@ -67,7 +67,7 @@
<view class="method-radio" :class="{ checked: paymentMethod === 'wechat' }"></view> <view class="method-radio" :class="{ checked: paymentMethod === 'wechat' }"></view>
</view> </view>
<view class="method-item" :class="{ active: paymentMethod === 'alipay' }" @tap="selectPaymentMethod('alipay')"> <view v-else class="method-item" :class="{ active: paymentMethod === 'alipay' }" @tap="selectPaymentMethod('alipay')">
<view class="method-left"> <view class="method-left">
<view class="method-icon method-badge method-badge-alipay"></view> <view class="method-icon method-badge method-badge-alipay"></view>
<text class="method-name">支付宝支付</text> <text class="method-name">支付宝支付</text>
@@ -120,6 +120,8 @@
const paymentMethod = ref('wechat'); const paymentMethod = ref('wechat');
const walletBalance = ref(0); const walletBalance = ref(0);
const paySubmitting = ref(false); const paySubmitting = ref(false);
const isDeviceAsset = ref(true);
let assetTypePromise = null;
const formatMoney = (amount) => { const formatMoney = (amount) => {
if (!amount && amount !== 0) return '0.00'; if (!amount && amount !== 0) return '0.00';
@@ -133,6 +135,40 @@
return `${allowance} ${unit}`; return `${allowance} ${unit}`;
}; };
const getDefaultPaymentMethod = () => isDeviceAsset.value ? 'wechat' : 'alipay';
const isPaymentMethodAvailable = (method) => {
if (method === 'wallet') return true;
if (method === 'wechat') return isDeviceAsset.value;
if (method === 'alipay') return !isDeviceAsset.value;
return false;
};
const normalizePaymentMethod = () => {
if (!isPaymentMethodAvailable(paymentMethod.value)) {
paymentMethod.value = getDefaultPaymentMethod();
}
};
const loadAssetType = async () => {
if (!userStore.state.identifier) return;
if (assetTypePromise) return assetTypePromise;
assetTypePromise = assetApi.getInfo(userStore.state.identifier)
.then((data) => {
isDeviceAsset.value = data.asset_type === 'device';
normalizePaymentMethod();
})
.catch((error) => {
console.error('加载资产类型失败', error);
})
.finally(() => {
assetTypePromise = null;
});
return assetTypePromise;
};
const loadPackages = async () => { const loadPackages = async () => {
loading.value = true; loading.value = true;
try { try {
@@ -154,17 +190,20 @@
}; };
const syncPackagePageState = () => { const syncPackagePageState = () => {
loadAssetType();
loadPackages(); loadPackages();
loadWalletBalance(); loadWalletBalance();
}; };
const buyPackage = (item) => { const buyPackage = async (item) => {
await loadAssetType();
currentPackage.value = item; currentPackage.value = item;
paymentMethod.value = 'wechat'; paymentMethod.value = getDefaultPaymentMethod();
showModal.value = true; showModal.value = true;
}; };
const selectPaymentMethod = (method) => { const selectPaymentMethod = (method) => {
if (!isPaymentMethodAvailable(method)) return;
paymentMethod.value = method; paymentMethod.value = method;
}; };
@@ -203,7 +242,9 @@
}; };
const getCreateOrderPaymentMethod = () => { const getCreateOrderPaymentMethod = () => {
return paymentMethod.value === 'alipay' ? 'alipay' : undefined; if (paymentMethod.value === 'alipay') return 'alipay';
if (paymentMethod.value === 'wallet' && !isDeviceAsset.value) return 'alipay';
return undefined;
}; };
const confirmPay = async () => { const confirmPay = async () => {

View File

@@ -33,7 +33,6 @@ function copyMpVerifyFiles() {
} }
export default defineConfig({ export default defineConfig({
base: '/h5/',
plugins: [uni(), copyMpVerifyFiles()], plugins: [uni(), copyMpVerifyFiles()],
root: process.cwd(), root: process.cwd(),
css: { css: {