From 87a2892fc41dd2e003a9dcdad66c12f32a7adc39 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Tue, 1 Jul 2025 01:45:47 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=A3=80=E6=9F=A5=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=9B=B4=E6=96=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/HttpHeaderConst.java | 38 ++++++++++++++++++ .../controller/UserAggregateController.java | 9 ++++- orion-visor-ui/src/api/user/user-aggregate.ts | 5 ++- .../components/system/message-box/const.ts | 2 +- .../src/store/modules/user/index.ts | 39 ++++++++++++++++++- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 orion-visor-common/src/main/java/org/dromara/visor/common/constant/HttpHeaderConst.java diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/constant/HttpHeaderConst.java b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/HttpHeaderConst.java new file mode 100644 index 00000000..3e87a5ea --- /dev/null +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/HttpHeaderConst.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 - present Dromara, All rights reserved. + * + * https://visor.dromara.org + * https://visor.dromara.org.cn + * https://visor.orionsec.cn + * + * Members: + * Jiahang Li - ljh1553488six@139.com - author + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dromara.visor.common.constant; + +import cn.orionsec.kit.lang.constant.StandardHttpHeader; + +/** + * http 请求头 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/7/1 1:02 + */ +public interface HttpHeaderConst extends StandardHttpHeader { + + String APP_VERSION = "X-App-Version"; + +} diff --git a/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/controller/UserAggregateController.java b/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/controller/UserAggregateController.java index 85c1dc34..74d045e0 100644 --- a/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/controller/UserAggregateController.java +++ b/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/controller/UserAggregateController.java @@ -25,6 +25,8 @@ package org.dromara.visor.module.infra.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; +import org.dromara.visor.common.constant.AppConst; +import org.dromara.visor.common.constant.HttpHeaderConst; import org.dromara.visor.framework.log.core.annotation.IgnoreLog; import org.dromara.visor.framework.log.core.enums.IgnoreLogMode; import org.dromara.visor.framework.web.core.annotation.RestWrapper; @@ -37,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -67,7 +70,11 @@ public class UserAggregateController { @IgnoreLog(IgnoreLogMode.RET) @GetMapping("/user") @Operation(summary = "获取用户权限聚合信息") - public UserAggregateVO getUserAggregateInfo() { + public UserAggregateVO getUserAggregateInfo(HttpServletResponse response) { + // 设置版本号请求头 + response.setHeader(HttpHeaderConst.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaderConst.APP_VERSION); + response.setHeader(HttpHeaderConst.APP_VERSION, AppConst.VERSION); + // 获取用户信息 return userAggregateService.getUserAggregateInfo(); } diff --git a/orion-visor-ui/src/api/user/user-aggregate.ts b/orion-visor-ui/src/api/user/user-aggregate.ts index 3e274670..fa95ac6f 100644 --- a/orion-visor-ui/src/api/user/user-aggregate.ts +++ b/orion-visor-ui/src/api/user/user-aggregate.ts @@ -1,4 +1,5 @@ import type { MenuQueryResponse } from '@/api/system/menu'; +import type { AxiosResponse } from 'axios'; import axios from 'axios'; /** @@ -35,7 +36,9 @@ export interface UserUpdatePasswordResponse { * 获取用户聚合信息 */ export function getUserAggregateInfo() { - return axios.get('/infra/user-aggregate/user'); + return axios.get>('/infra/user-aggregate/user', { + unwrap: true + }); } /** diff --git a/orion-visor-ui/src/components/system/message-box/const.ts b/orion-visor-ui/src/components/system/message-box/const.ts index 86a4d398..4f12ef30 100644 --- a/orion-visor-ui/src/components/system/message-box/const.ts +++ b/orion-visor-ui/src/components/system/message-box/const.ts @@ -4,7 +4,7 @@ export const MessageStatus = { READ: 1, }; -export const MESSAGE_CONFIG_KEY = 'messageConfig'; +export const MESSAGE_CONFIG_KEY = 'message-config'; // 查询数量 export const messageLimit = 15; diff --git a/orion-visor-ui/src/store/modules/user/index.ts b/orion-visor-ui/src/store/modules/user/index.ts index cc75bcff..8db1ebaf 100644 --- a/orion-visor-ui/src/store/modules/user/index.ts +++ b/orion-visor-ui/src/store/modules/user/index.ts @@ -8,6 +8,41 @@ import { removeRouteListener } from '@/utils/route-listener'; import { getUserAggregateInfo } from '@/api/user/user-aggregate'; import { useAppStore, useCacheStore, useMenuStore, useTabBarStore, useTipsStore } from '@/store'; +const CHECK_APP_VERSION_KEY = 'check-app-version'; + +// 检查版本更新 +const checkForVersionUpdate = (serverVersion: string) => { + try { + if (!serverVersion) { + return; + } + const clientVersion = import.meta.env.VITE_APP_VERSION; + // 版本相同 + if (serverVersion === clientVersion) { + localStorage.removeItem(CHECK_APP_VERSION_KEY); + return; + } + // 版本不同 + const lastCheck = localStorage.getItem(CHECK_APP_VERSION_KEY); + const lastCheckData = lastCheck ? JSON.parse(lastCheck) : null; + // 判断是否是同版本 或 距离上次提醒不超过 24 小时 + if (lastCheckData?.version === serverVersion && Date.now() - (lastCheckData?.time || 0) < 24 * 60 * 60 * 1000) { + return; + } + // 提示用户更新 + if (window.confirm('检测到新版本, 是否刷新页面以获取最新内容?')) { + window.location.reload(); + } + // 更新 localStorage 记录 + localStorage.setItem(CHECK_APP_VERSION_KEY, JSON.stringify({ + version: serverVersion, + time: Date.now(), + })); + } catch (error) { + // ignored + } +}; + export default defineStore('user', { state: (): UserState => ({ id: undefined, @@ -32,7 +67,9 @@ export default defineStore('user', { // 获取用户信息 async getUserInfo() { - const { data } = await getUserAggregateInfo(); + const { data: { data }, headers } = await getUserAggregateInfo(); + // 检查版本更新 + checkForVersionUpdate(headers?.['x-app-version']); // 设置用户信息 this.setUserInfo({ id: data.user.id,