From 0db3b22ecfd3c05de19566277bf36cd61ff5f399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=99=93=E8=81=AA?= Date: Wed, 17 Jul 2024 14:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=86=B2=E7=AA=81=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=20(#351)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/services/surveyHistory.service.ts | 2 +- web/src/management/pages/edit/index.vue | 57 +++++++++---------- .../modules/contentModule/PublishPanel.vue | 18 +++--- .../edit/modules/contentModule/SavePanel.vue | 23 ++++---- 4 files changed, 51 insertions(+), 49 deletions(-) diff --git a/server/src/modules/survey/services/surveyHistory.service.ts b/server/src/modules/survey/services/surveyHistory.service.ts index a8a1dadf..47ac13e0 100644 --- a/server/src/modules/survey/services/surveyHistory.service.ts +++ b/server/src/modules/survey/services/surveyHistory.service.ts @@ -70,7 +70,7 @@ export class SurveyHistoryService { 'operator.sessionId': { $ne: sessionId }, }, order: { createDate: 'DESC' }, - take: 100, + take: 1, select: ['createDate', 'operator', 'type', '_id'], }); diff --git a/web/src/management/pages/edit/index.vue b/web/src/management/pages/edit/index.vue index 025a5443..ac4d7767 100644 --- a/web/src/management/pages/edit/index.vue +++ b/web/src/management/pages/edit/index.vue @@ -18,6 +18,7 @@ import { onMounted, ref, onUnmounted } from 'vue' import { useStore } from 'vuex' import { useRouter, useRoute } from 'vue-router' import { ElMessage, ElMessageBox } from 'element-plus' +import type { Action } from 'element-plus' import 'element-plus/theme-chalk/src/message.scss' import LeftMenu from '@/management/components/LeftMenu.vue' @@ -31,44 +32,40 @@ const router = useRouter() const route = useRoute() const authCheckInterval = ref(null) const showConfirmBox = () => { - const token = store.state.user.userInfo.token - ElMessageBox.alert('登录状态已失效,请刷新同步。页面将展示最新保存的内容。', '提示', { + ElMessageBox.alert('登录状态已失效,请重新登陆。', '提示', { confirmButtonText: '确认', - callback: () => { - axios.get('/auth/statuscheck', { - headers: { - 'Authorization': `Bearer ${token}` - } - }) - .then((response) => { - if (response.data.expired) { - store.dispatch('user/logout').then(() => { - router.replace({name: 'login'}); // 仍然失效,登出,跳转到登录界面 + showClose: false, + callback: (action: Action) => { + if (action === 'confirm') { + axios.get('/auth/statuscheck') + .then((response) => { + if (response.data.expired) { + store.dispatch('user/logout').then(() => { + router.replace({name: 'login'}); // 仍然失效,登出,跳转到登录界面 + }) + } else { + location.reload(); // 已登录,刷新页面 + } }) - } else { - location.reload(); // 已登录,刷新页面 + .catch((error) => { + console.log("error: " + error); + store.dispatch('user/logout').then(() => { + router.replace({name: 'login'}); + }) + }); } - }) - .catch((error) => { - console.log("error: " + error); - ElMessage.error(error.message || '请求失败'); - }); } }); } const checkAuth = () => { - const token = store.state.user.userInfo.token - axios.get('/auth/statuscheck', { - headers: { - 'Authorization': `Bearer ${token}` - } - }).then((response) => { + axios.get('/auth/statuscheck').then((response) => { if (response.data.expired) { + clearInterval(authCheckInterval.value); + authCheckInterval.value = null showConfirmBox(); } }).catch((error) => { console.log("erro:" + error) - ElMessage.error(error) }); } onMounted(async () => { @@ -77,6 +74,9 @@ onMounted(async () => { try { await store.dispatch('edit/init') await initShowLogicEngine(store.state.edit.schema.logicConf.showLogicConf || {}) + + // 启动定时器,每30分钟调用一次 + authCheckInterval.value = setInterval(() => checkAuth(), 1000); } catch (err: any) { ElMessage.error(err.message) @@ -84,13 +84,10 @@ onMounted(async () => { router.replace({ name: 'survey' }) }, 1000) } - // 启动定时器,每30分钟调用一次 - authCheckInterval.value = setInterval(() => { - checkAuth() - }, 30 * 60 * 1000); }) onUnmounted(() => { clearInterval(authCheckInterval.value); + authCheckInterval.value = null })