fix(admin): consume booking link actions when cached pages reactivate
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { Boxes, Check, Eye, FileText, FileUp, Link2, ListChecks, MoreHorizontal, Pencil, Plus, Sparkles } from '@lucide/vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
@@ -686,22 +686,31 @@ watch(linkOpen, (open) => {
|
||||
linkSequence += 1
|
||||
linkLoading.value = false
|
||||
})
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadCustomers(), loadRows()])
|
||||
const linkContainerId = typeof route.query.linkContainerId === 'string' ? route.query.linkContainerId : ''
|
||||
if (!isDomestic.value || !linkContainerId || !canEdit.value) return
|
||||
let routeLinkSequence = 0
|
||||
watch([() => route.name, () => route.query.linkContainerId, isDomestic, canEdit], async ([name, requestedId, domestic, editable]) => {
|
||||
const sequence = ++routeLinkSequence
|
||||
const linkContainerId = typeof requestedId === 'string' ? requestedId : ''
|
||||
if (name !== 'domestic-container-workbench' || !domestic || !linkContainerId || !editable) return
|
||||
try {
|
||||
const target = await getContainer(linkContainerId, 'DOMESTIC')
|
||||
if (sequence !== routeLinkSequence) return
|
||||
if (target.sourceType !== 'SIMULATION' || target.oceanBookingId || !hasAction(target, 'EDIT_CONTAINER')) {
|
||||
ElMessage.warning('当前货柜已关联订舱或所处阶段不允许关联')
|
||||
return
|
||||
}
|
||||
await openLink(target)
|
||||
} catch (error) {
|
||||
ElMessage.error(getApiErrorDetails(error, '关联货柜加载失败').message)
|
||||
if (sequence === routeLinkSequence) ElMessage.error(getApiErrorDetails(error, '关联货柜加载失败').message)
|
||||
} finally {
|
||||
void router.replace({ name: 'domestic-container-workbench' })
|
||||
if (sequence === routeLinkSequence && route.query.linkContainerId === linkContainerId) {
|
||||
const { linkContainerId: consumed, ...query } = route.query
|
||||
void router.replace({ path: route.path, query, hash: route.hash })
|
||||
}
|
||||
}
|
||||
}, { immediate: true })
|
||||
onBeforeUnmount(() => { routeLinkSequence += 1 })
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadCustomers(), loadRows()])
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user