|
@@ -100,6 +100,7 @@ const showModal = ref(false)
|
|
|
const isLoggedIn = ref(false)
|
|
const isLoggedIn = ref(false)
|
|
|
const isPageVisible = ref(false) // 页面是否可见
|
|
const isPageVisible = ref(false) // 页面是否可见
|
|
|
const shortPrice = ref(1) // 超短池价格,默认1
|
|
const shortPrice = ref(1) // 超短池价格,默认1
|
|
|
|
|
+const isPaying = ref(false) // 是否正在支付中(防止重复点击)
|
|
|
|
|
|
|
|
const stockList = ref([])
|
|
const stockList = ref([])
|
|
|
let refreshTimer = null
|
|
let refreshTimer = null
|
|
@@ -296,26 +297,33 @@ const pollOrderStatus = async (orderNo, maxRetries = 5, interval = 1000) => {
|
|
|
|
|
|
|
|
// 处理购买(调用后端支付接口)
|
|
// 处理购买(调用后端支付接口)
|
|
|
const handlePurchase = async () => {
|
|
const handlePurchase = async () => {
|
|
|
|
|
+ // 防止重复点击
|
|
|
|
|
+ if (isPaying.value) {
|
|
|
|
|
+ console.log('[支付] 正在支付中,忽略重复点击')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
|
|
+ isPaying.value = true
|
|
|
uni.showLoading({ title: '正在支付...' })
|
|
uni.showLoading({ title: '正在支付...' })
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 1. 创建订单
|
|
// 1. 创建订单
|
|
|
const res = await createOrder({ poolType: 1 }) // 1=超短池
|
|
const res = await createOrder({ poolType: 1 }) // 1=超短池
|
|
|
if (res.code !== 200) {
|
|
if (res.code !== 200) {
|
|
|
throw new Error(res.message || '创建订单失败')
|
|
throw new Error(res.message || '创建订单失败')
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const orderNo = res.data.orderNo
|
|
const orderNo = res.data.orderNo
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 2. 调起微信支付
|
|
// 2. 调起微信支付
|
|
|
await wxPay(res.data)
|
|
await wxPay(res.data)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 3. 轮询确认订单状态
|
|
// 3. 轮询确认订单状态
|
|
|
uni.showLoading({ title: '确认支付结果...' })
|
|
uni.showLoading({ title: '确认支付结果...' })
|
|
|
const confirmed = await pollOrderStatus(orderNo)
|
|
const confirmed = await pollOrderStatus(orderNo)
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (confirmed) {
|
|
if (confirmed) {
|
|
|
isPurchased.value = true
|
|
isPurchased.value = true
|
|
|
closePurchaseModal()
|
|
closePurchaseModal()
|
|
@@ -328,6 +336,9 @@ const handlePurchase = async () => {
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
uni.showToast({ title: e.message || '支付失败', icon: 'none' })
|
|
uni.showToast({ title: e.message || '支付失败', icon: 'none' })
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 无论成功或失败,都重置支付状态
|
|
|
|
|
+ isPaying.value = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|