Kaynağa Gözat

支付防重试实现

Zhangbw 2 ay önce
ebeveyn
işleme
1cb67d4bea
2 değiştirilmiş dosya ile 33 ekleme ve 19 silme
  1. 17 14
      .idea/workspace.xml
  2. 16 5
      src/pages/pool/pool.vue

+ 17 - 14
.idea/workspace.xml

@@ -4,7 +4,9 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="3d5f1a44-bea3-411b-bb68-cefe865cc7c2" name="更改" comment="支付防重试实现" />
+    <list default="true" id="3d5f1a44-bea3-411b-bb68-cefe865cc7c2" name="更改" comment="">
+      <change beforePath="$PROJECT_DIR$/src/pages/pool/pool.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/pool/pool.vue" afterDir="false" />
+    </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -51,20 +53,21 @@
     <option name="flattenModules" value="true" />
     <option name="showLibraryContents" value="true" />
   </component>
-  <component name="PropertiesComponent">{
-  &quot;keyToString&quot;: {
-    &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
-    &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
-    &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
-    &quot;RunOnceActivity.typescript.service.memoryLimit.init&quot;: &quot;true&quot;,
-    &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
-    &quot;last_opened_file_path&quot;: &quot;D:/program/gupiao/gupiao-wx&quot;,
-    &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
-    &quot;settings.editor.selected.configurable&quot;: &quot;reference.projectsettings.compiler.annotationProcessors&quot;,
-    &quot;ts.external.directory.path&quot;: &quot;C:\\Users\\Avak\\AppData\\Roaming\\JetBrains\\IntelliJIdea2025.3\\plugins\\javascript-plugin\\jsLanguageServicesImpl\\external&quot;,
-    &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
+  <component name="PropertiesComponent"><![CDATA[{
+  "keyToString": {
+    "ModuleVcsDetector.initialDetectionPerformed": "true",
+    "RunOnceActivity.ShowReadmeOnStart": "true",
+    "RunOnceActivity.git.unshallow": "true",
+    "RunOnceActivity.typescript.service.memoryLimit.init": "true",
+    "git-widget-placeholder": "小程序",
+    "kotlin-language-version-configured": "true",
+    "last_opened_file_path": "D:/program/gupiao/gupiao-wx",
+    "nodejs_package_manager_path": "npm",
+    "settings.editor.selected.configurable": "reference.projectsettings.compiler.annotationProcessors",
+    "ts.external.directory.path": "C:\\Users\\Avak\\AppData\\Roaming\\JetBrains\\IntelliJIdea2025.3\\plugins\\javascript-plugin\\jsLanguageServicesImpl\\external",
+    "vue.rearranger.settings.migration": "true"
   }
-}</component>
+}]]></component>
   <component name="RunManager">
     <configuration default="true" type="JetRunConfigurationType">
       <module name="gupiao-wx" />

+ 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
   }
 }