fix(miniprogram): guard pound QR popup load against stale races.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
be0764779c
commit
f2dd16d851
1 file changed
+9
-2
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user