From 8cb514d70e711a0bbfbc2a3f31be55d66aae89f0 Mon Sep 17 00:00:00 2001 From: Allen Date: Thu, 18 Apr 2024 12:40:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?dashboard=E9=85=8D=E7=BD=AE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BF=9D=E5=AD=98=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 13 +++++++++++++ src/pages/dashboard.vue | 14 ++++++++++++-- src/pages/login.vue | 21 +++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 55cea95f..8311232f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,7 @@ diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 5dadee70..01fe2b71 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -9,6 +9,7 @@ import AnalyticsMemory from '@/views/dashboard/AnalyticsMemory.vue' import MediaServerLatest from '@/views/dashboard/MediaServerLatest.vue' import MediaServerLibrary from '@/views/dashboard/MediaServerLibrary.vue' import MediaServerPlaying from '@/views/dashboard/MediaServerPlaying.vue' +import api from '@/api' // 仪表盘配置 const dashboard_names = { @@ -48,8 +49,17 @@ if (Object.keys(config.value).length === 0) { // 设置项目 function setDashboardConfig() { - localStorage.setItem('MP_DASHBOARD', JSON.stringify(config.value)) - dialog.value = false + const data = JSON.stringify(config.value) + api.post('/user/config/Dashboard', data, { + headers: { + "Content-Type": "text/plain" + } + }).then((response: any) => { + if (response && response.success) { + localStorage.setItem('MP_DASHBOARD', data) + dialog.value = false + } + }) } diff --git a/src/pages/login.vue b/src/pages/login.vue index 766a84a7..6f93f357 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -66,6 +66,24 @@ async function fetchOTP() { }) } +// 加载用户监控面板配置 +async function loadDashboardConfig() { + const response = await api.get('/user/config/Dashboard') + if (response && response.data && response.data.value) { + const data = JSON.stringify(response.data.value) + if (data != localStorage.getItem("MP_DASHBOARD")) { + localStorage.setItem("MP_DASHBOARD", data) + } + } +} + +async function afterLogin() { + // 加载用户监控面板配置 + await loadDashboardConfig() + // 跳转到首页或回原始页面 + router.push(store.state.auth.originalPath ?? '/') +} + // 登录获取token事件 function login() { errorMessage.value = '' @@ -103,8 +121,7 @@ function login() { store.dispatch('auth/updateUserName', username) store.dispatch('auth/updateAvatar', avatar) - // 跳转到首页或回原始页面 - router.push(store.state.auth.originalPath ?? '/') + afterLogin() }) .catch((error: any) => { // 登录失败,显示错误提示 From 3db4d883afd8547561e391fb910da87744e4e9d3 Mon Sep 17 00:00:00 2001 From: Allen Date: Thu, 18 Apr 2024 15:19:24 +0800 Subject: [PATCH 2/3] fixbug --- src/pages/dashboard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 01fe2b71..b1e1ad5d 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -52,7 +52,7 @@ function setDashboardConfig() { const data = JSON.stringify(config.value) api.post('/user/config/Dashboard', data, { headers: { - "Content-Type": "text/plain" + "Content-Type": "application/json" } }).then((response: any) => { if (response && response.success) { From f197ed79727a6939fffae02c056a38bac2ee68bf Mon Sep 17 00:00:00 2001 From: Allen Date: Tue, 23 Apr 2024 09:52:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96dashboard=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 10 +++++++++- src/pages/dashboard.vue | 8 +++----- src/pages/login.vue | 12 ++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8311232f..762f79b6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -53,11 +53,19 @@ async function loadDashboardConfig() { } } +// 尝试加载用户监控面板配置(本地无配置时才加载) +async function tryLoadDashboardConfig() { + if (localStorage.getItem("MP_DASHBOARD")) { + return + } + await loadDashboardConfig() +} + // 页面加载时,加载当前用户数据 onBeforeMount(async () => { setTheme() startSSEMessager() - await loadDashboardConfig() + await tryLoadDashboardConfig() }) diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index b1e1ad5d..fcb3ae98 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -50,15 +50,13 @@ if (Object.keys(config.value).length === 0) { // 设置项目 function setDashboardConfig() { const data = JSON.stringify(config.value) + localStorage.setItem('MP_DASHBOARD', data) + dialog.value = false + // 保存到服务端 api.post('/user/config/Dashboard', data, { headers: { "Content-Type": "application/json" } - }).then((response: any) => { - if (response && response.success) { - localStorage.setItem('MP_DASHBOARD', data) - dialog.value = false - } }) } diff --git a/src/pages/login.vue b/src/pages/login.vue index 6f93f357..aa1f261b 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -77,9 +77,17 @@ async function loadDashboardConfig() { } } -async function afterLogin() { - // 加载用户监控面板配置 +// 尝试加载用户监控面板配置(本地无配置时才加载) +async function tryLoadDashboardConfig() { + if (localStorage.getItem("MP_DASHBOARD")) { + return + } await loadDashboardConfig() +} + +async function afterLogin() { + // 尝试加载用户监控面板配置(本地无配置时才加载) + await tryLoadDashboardConfig() // 跳转到首页或回原始页面 router.push(store.state.auth.originalPath ?? '/') }