// 使用 Vue Router 导航守卫拦截返回
onBeforeRouteLeave((to, from, next) => {
console.log('触发路由离开守卫')
// 检查是否有未保存的修改
const hasUnsavedChanges = JSON.stringify(initialSelectedRegions.value) !== JSON.stringify(selectDistrict.value)
if (!hasUnsavedChanges) {
// 没有未保存的修改,或者已经确认离开,允许导航
next()
} else {
// 有未保存的修改,显示确认对话框
setTimeout(() => {
DialogShow.value = true
}, 500)
// 阻止导航
next(false)
}
})