From 2f43ddd59b8059063532b6078db82ee0e6ac988f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Tue, 30 May 2023 09:34:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=95=B0=E6=8D=AE=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/utils.ts | 20 ++++++++++++++++++++ src/views/chart/ContentEdit/index.vue | 14 ++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 4a1b19e4..16ba9431 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -330,3 +330,23 @@ export const JSONParse = (data: string) => { export const setTitle = (title?: string) => { title && (document.title = title) } + +/** + * 处理网页关闭事件 + */ +export const addWindowUnload = () => { + // 关闭网页出现离开提示 + window.onbeforeunload = function (e) { + e = e || window.event + // 兼容IE8和Firefox 4之前的版本 + if (e) { + e.returnValue = '您确定要离开当前页面吗?请确认是否保存数据!' + } + // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+ + return '您确定要离开当前页面吗?请确认是否保存数据!' + } + // 返回销毁事件函数 + return () => { + window.onbeforeunload = null + } +} \ No newline at end of file diff --git a/src/views/chart/ContentEdit/index.vue b/src/views/chart/ContentEdit/index.vue index a003398f..60de3a08 100644 --- a/src/views/chart/ContentEdit/index.vue +++ b/src/views/chart/ContentEdit/index.vue @@ -87,7 +87,14 @@ import { onMounted, computed, provide } from 'vue' import { chartColors } from '@/settings/chartThemes/index' import { MenuEnum } from '@/enums/editPageEnum' import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d' -import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle, colorCustomMerge } from '@/utils' +import { + animationsClass, + getFilterStyle, + getTransformStyle, + getBlendModeStyle, + colorCustomMerge, + addWindowUnload +} from '@/utils' import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook' import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' @@ -110,6 +117,9 @@ const chartEditStore = useChartEditStore() const { handleContextMenu } = useContextMenu() const { dataSyncFetch, intervalDataSyncUpdate } = useSync() +// 加入网页关闭提示 +addWindowUnload() + // 编辑时注入scale变量,消除警告 provide(SCALE_KEY, null) @@ -186,7 +196,7 @@ onMounted(() => { // 获取数据 dataSyncFetch() // 定时更新数据 - intervalDataSyncUpdate() + // intervalDataSyncUpdate() })