浏览代码

支付防重试实现

Zhangbw 2 月之前
父节点
当前提交
aef70b330b
共有 3 个文件被更改,包括 52 次插入9 次删除
  1. 18 0
      src/App.vue
  2. 16 5
      src/pages/pool/pool.vue
  3. 18 4
      src/pages/rank/rank.vue

+ 18 - 0
src/App.vue

@@ -159,12 +159,30 @@ uni-tabbar,
   right: 0 !important;
   z-index: 999 !important;
   transform: translateY(var(--keyboard-offset, 0px)) !important;
+  /* 增加安全区域内边距 */
+  padding-bottom: constant(safe-area-inset-bottom) !important;
+  padding-bottom: env(safe-area-inset-bottom) !important;
+}
+
+/* 页面内容区域增加底部安全距离 */
+page {
+  padding-bottom: calc(50px + constant(safe-area-inset-bottom)) !important;
+  padding-bottom: calc(50px + env(safe-area-inset-bottom)) !important;
 }
 
 body {
   padding-bottom: constant(safe-area-inset-bottom) !important;
   padding-bottom: env(safe-area-inset-bottom) !important;
 }
+
+/* 微信浏览器特殊处理 */
+@supports (-webkit-touch-callout: none) {
+  uni-tabbar,
+  .uni-tabbar {
+    padding-bottom: max(constant(safe-area-inset-bottom), 20px) !important;
+    padding-bottom: max(env(safe-area-inset-bottom), 20px) !important;
+  }
+}
 /* #endif */
 
 

+ 16 - 5
src/pages/pool/pool.vue

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

+ 18 - 4
src/pages/rank/rank.vue

@@ -377,8 +377,8 @@ const clearAllCanvases = () => {
   })
 }
 
-// 绘制单个股票的趋势图
-const drawTrendChart = (stock) => {
+// 绘制单个股票的趋势图(带重试机制)
+const drawTrendChart = (stock, retryCount = 0) => {
   const canvasId = 'chart-' + stock.code
   let trendData = stock.trendData
 
@@ -394,7 +394,14 @@ const drawTrendChart = (stock) => {
     .fields({ node: true, size: true })
     .exec((res) => {
       if (!res || !res[0] || !res[0].node) {
-        console.warn('[趋势图] 获取canvas节点失败:', canvasId)
+        console.warn('[趋势图] 获取canvas节点失败:', canvasId, '重试次数:', retryCount)
+
+        // 增加重试机制,最多重试 3 次
+        if (retryCount < 3) {
+          setTimeout(() => {
+            drawTrendChart(stock, retryCount + 1)
+          }, 200 * (retryCount + 1)) // 递增延迟:200ms, 400ms, 600ms
+        }
         return
       }
 
@@ -426,7 +433,14 @@ const drawTrendChart = (stock) => {
       .boundingClientRect()
       .exec((res) => {
         if (!res || !res[0]) {
-          console.warn('[趋势图] 获取canvas节点失败:', canvasId)
+          console.warn('[趋势图] 获取canvas节点失败:', canvasId, '重试次数:', retryCount)
+
+          // 增加重试机制,最多重试 3 次
+          if (retryCount < 3) {
+            setTimeout(() => {
+              drawTrendChart(stock, retryCount + 1)
+            }, 200 * (retryCount + 1)) // 递增延迟:200ms, 400ms, 600ms
+          }
           return
         }