fix(公共): 去掉保存状态
This commit is contained in:
parent
45ab964050
commit
32cd28176e
|
@ -1,26 +1,17 @@
|
|||
import { ref, onUnmounted } from 'vue';
|
||||
import useModal from '@/hooks/useModal';
|
||||
import { onBeforeRouteLeave } from 'vue-router';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
|
||||
// 离开页面确认提示
|
||||
export default function useLeaveUnSaveTip() {
|
||||
const isSave = ref(false);
|
||||
const { openModal } = useModal();
|
||||
const { t } = useI18n();
|
||||
|
||||
const setSaveStatus = (status: boolean) => {
|
||||
isSave.value = status;
|
||||
};
|
||||
|
||||
onBeforeRouteLeave((to, from, next) => {
|
||||
if (to.path === from.path) {
|
||||
return;
|
||||
}
|
||||
// 如果已保存
|
||||
if (isSave.value) {
|
||||
next();
|
||||
} else {
|
||||
console.log(from);
|
||||
openModal({
|
||||
type: 'error',
|
||||
title: t('common.unSaveLeaveTitle'),
|
||||
|
@ -31,18 +22,13 @@ export default function useLeaveUnSaveTip() {
|
|||
status: 'normal',
|
||||
},
|
||||
onBeforeOk: async () => {
|
||||
setSaveStatus(true);
|
||||
next();
|
||||
},
|
||||
onCancel: () => {
|
||||
console.log('取消取消');
|
||||
console.log(from);
|
||||
},
|
||||
hideCancel: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
onUnmounted(() => {
|
||||
isSave.value = false;
|
||||
});
|
||||
|
||||
return {
|
||||
setSaveStatus,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue