价格套餐缓存修改
This commit is contained in:
@@ -104,6 +104,27 @@ const detailVersion = ref(null)
|
||||
const versionExcelDrawerRef = ref()
|
||||
const editVisible = ref(false)
|
||||
const editPsvId = ref(undefined)
|
||||
/** 已加载的套餐ID;页面被 keep-alive 缓存复用时据此判断是否需要重新加载 */
|
||||
const loadedId = ref(null)
|
||||
/** 从详情页跳到新建/编辑套餐版本页后,返回时套餐版本数据可能已变化,需强制刷新 */
|
||||
const pendingRefresh = ref(false)
|
||||
|
||||
/** 切换到另一个套餐时,重置所有临时面板状态,避免残留上一套餐的数据 */
|
||||
function resetTransientState() {
|
||||
set.value = {}
|
||||
currentPsvId.value = undefined
|
||||
detailDrawerVisible.value = false
|
||||
detailVersion.value = null
|
||||
editVisible.value = false
|
||||
editPsvId.value = undefined
|
||||
activateVisible.value = false
|
||||
activateSubmitting.value = false
|
||||
activateMode.value = 'activate'
|
||||
activateForm.psvId = undefined
|
||||
activateForm.versionNo = ''
|
||||
activateForm.effectiveTime = undefined
|
||||
activatePrevEffectiveTime.value = undefined
|
||||
}
|
||||
|
||||
function onOpenVersionDetails(row) {
|
||||
detailVersion.value = row || null
|
||||
@@ -118,6 +139,8 @@ function onViewImportAttach(row) {
|
||||
function load() {
|
||||
const id = route.query.priceSetId
|
||||
if (!id) return
|
||||
// 立即标记,首次挂载后紧随的 activated 不会重复请求
|
||||
loadedId.value = String(id)
|
||||
loading.value = true
|
||||
getPriceSet(id).then(res => {
|
||||
set.value = res.data || {}
|
||||
@@ -129,6 +152,20 @@ function load() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* keep-alive 复用同一组件实例时同步数据:
|
||||
* - priceSetId 变化:加载新套餐
|
||||
* - 从新建/编辑版本页返回(force):即使套餐相同也强制重载,保证版本列表最新
|
||||
*/
|
||||
function syncFromRoute(force) {
|
||||
const id = route.query.priceSetId
|
||||
if (!id) return
|
||||
pendingRefresh.value = false
|
||||
if (!force && String(id) === String(loadedId.value)) return
|
||||
resetTransientState()
|
||||
load()
|
||||
}
|
||||
|
||||
function confirmAction(text, request, successText, done) {
|
||||
proxy.$modal.confirm(text).then(() => request()).then(() => {
|
||||
proxy.$modal.msgSuccess(successText)
|
||||
@@ -416,6 +453,24 @@ onMounted(() => {
|
||||
refData.loadProducts()
|
||||
load()
|
||||
})
|
||||
|
||||
// 从其他页签切回(新建完成跳转、列表点另一条详情)时同步数据;
|
||||
// 从新建/编辑版本页返回时即使套餐ID相同也强制刷新版本列表
|
||||
onActivated(() => {
|
||||
syncFromRoute(pendingRefresh.value)
|
||||
})
|
||||
|
||||
// 组件已处于激活状态时路由 query 变化的兜底
|
||||
watch(() => route.query.priceSetId, () => {
|
||||
syncFromRoute(false)
|
||||
})
|
||||
|
||||
// 离开详情页去新建/编辑套餐版本,返回后需要重新加载
|
||||
onBeforeRouteLeave((to) => {
|
||||
if (to && to.path === '/customer/setCreate') {
|
||||
pendingRefresh.value = true
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user