Ver código fonte

fix(miniprogram): guard pound QR popup load against stale races.

Co-authored-by: Cursor <cursoragent@cursor.com>
wuzilong 1 mês atrás
pai
commit
f2dd16d851

+ 9 - 2
miniprogram/components/db-ui/db-pound-qrcode-popup.vue

@@ -70,6 +70,7 @@ const emit = defineEmits(['close', 'update:show'])
 const loading = ref(false)
 const row = ref(null)
 const qrPath = ref('')
+let loadSeq = 0
 const canvasSize = 200
 const instance = getCurrentInstance()
 
@@ -85,12 +86,14 @@ function close() {
 }
 
 function reset() {
+  loadSeq += 1
   row.value = null
   qrPath.value = ''
   loading.value = false
 }
 
 async function load() {
+  const seq = ++loadSeq
   const id = String(props.inventoryId || '').trim()
   if (!id) {
     uni.showToast({ title: '缺少单据ID', icon: 'none' })
@@ -107,20 +110,24 @@ async function load() {
       data = res?.data ?? res
     }
     if (!data || !data.id) throw new Error('单据不存在')
+    if (seq !== loadSeq) return
     row.value = data
     await new Promise((r) => setTimeout(r, 50))
     const proxy = instance?.proxy
-    qrPath.value = await makeQrTempFile({
+    const path = await makeQrTempFile({
       text: data.id,
       canvasId: 'poundQrCanvas',
       componentInstance: proxy,
       size: canvasSize
     })
+    if (seq !== loadSeq) return
+    qrPath.value = path
   } catch (e) {
+    if (seq !== loadSeq) return
     uni.showToast({ title: e?.message || '加载二维码失败', icon: 'none' })
     close()
   } finally {
-    loading.value = false
+    if (seq === loadSeq) loading.value = false
   }
 }