fix(公共): 去掉保存状态

This commit is contained in:
xinxin.wu 2023-08-24 16:58:31 +08:00 committed by 刘瑞斌
parent 45ab964050
commit 32cd28176e
1 changed files with 19 additions and 33 deletions

View File

@ -1,26 +1,17 @@
import { ref, onUnmounted } from 'vue';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
import { onBeforeRouteLeave } from 'vue-router'; import { onBeforeRouteLeave } from 'vue-router';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
// 离开页面确认提示 // 离开页面确认提示
export default function useLeaveUnSaveTip() { export default function useLeaveUnSaveTip() {
const isSave = ref(false);
const { openModal } = useModal(); const { openModal } = useModal();
const { t } = useI18n(); const { t } = useI18n();
const setSaveStatus = (status: boolean) => {
isSave.value = status;
};
onBeforeRouteLeave((to, from, next) => { onBeforeRouteLeave((to, from, next) => {
if (to.path === from.path) { if (to.path === from.path) {
return; return;
} }
// 如果已保存 console.log(from);
if (isSave.value) {
next();
} else {
openModal({ openModal({
type: 'error', type: 'error',
title: t('common.unSaveLeaveTitle'), title: t('common.unSaveLeaveTitle'),
@ -31,18 +22,13 @@ export default function useLeaveUnSaveTip() {
status: 'normal', status: 'normal',
}, },
onBeforeOk: async () => { onBeforeOk: async () => {
setSaveStatus(true);
next(); next();
}, },
onCancel: () => {
console.log('取消取消');
console.log(from);
},
hideCancel: false, hideCancel: false,
}); });
}
}); });
onUnmounted(() => {
isSave.value = false;
});
return {
setSaveStatus,
};
} }