⚡ 检查页面更新.
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,6 +25,8 @@ package org.dromara.visor.module.infra.controller;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.annotation.IgnoreLog;
|
||||||
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
||||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
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 org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +70,11 @@ public class UserAggregateController {
|
|||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/user")
|
@GetMapping("/user")
|
||||||
@Operation(summary = "获取用户权限聚合信息")
|
@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();
|
return userAggregateService.getUserAggregateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { MenuQueryResponse } from '@/api/system/menu';
|
import type { MenuQueryResponse } from '@/api/system/menu';
|
||||||
|
import type { AxiosResponse } from 'axios';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,9 @@ export interface UserUpdatePasswordResponse {
|
|||||||
* 获取用户聚合信息
|
* 获取用户聚合信息
|
||||||
*/
|
*/
|
||||||
export function getUserAggregateInfo() {
|
export function getUserAggregateInfo() {
|
||||||
return axios.get<UserAggregateResponse>('/infra/user-aggregate/user');
|
return axios.get<AxiosResponse<UserAggregateResponse>>('/infra/user-aggregate/user', {
|
||||||
|
unwrap: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export const MessageStatus = {
|
|||||||
READ: 1,
|
READ: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MESSAGE_CONFIG_KEY = 'messageConfig';
|
export const MESSAGE_CONFIG_KEY = 'message-config';
|
||||||
|
|
||||||
// 查询数量
|
// 查询数量
|
||||||
export const messageLimit = 15;
|
export const messageLimit = 15;
|
||||||
|
|||||||
@@ -8,6 +8,41 @@ import { removeRouteListener } from '@/utils/route-listener';
|
|||||||
import { getUserAggregateInfo } from '@/api/user/user-aggregate';
|
import { getUserAggregateInfo } from '@/api/user/user-aggregate';
|
||||||
import { useAppStore, useCacheStore, useMenuStore, useTabBarStore, useTipsStore } from '@/store';
|
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', {
|
export default defineStore('user', {
|
||||||
state: (): UserState => ({
|
state: (): UserState => ({
|
||||||
id: undefined,
|
id: undefined,
|
||||||
@@ -32,7 +67,9 @@ export default defineStore('user', {
|
|||||||
|
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
async getUserInfo() {
|
async getUserInfo() {
|
||||||
const { data } = await getUserAggregateInfo();
|
const { data: { data }, headers } = await getUserAggregateInfo();
|
||||||
|
// 检查版本更新
|
||||||
|
checkForVersionUpdate(headers?.['x-app-version']);
|
||||||
// 设置用户信息
|
// 设置用户信息
|
||||||
this.setUserInfo({
|
this.setUserInfo({
|
||||||
id: data.user.id,
|
id: data.user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user