From d433c25f7bf5b8f960070e7eab388848933d6471 Mon Sep 17 00:00:00 2001 From: George Date: Sun, 26 Apr 2026 08:58:28 +0800 Subject: [PATCH] =?UTF-8?q?20260426:=E5=A4=A7=E5=B1=8F=E6=8A=80=E6=9C=AF?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../src/main/resources/application-dev.yml | 4 ++ yack-view/src/api/axios.ts | 14 ++--- yack-view/src/router/router-guards.ts | 6 +-- yack-view/src/utils/router.ts | 20 +++---- .../ProjectItemsList/hooks/useData.hook.ts | 54 ++++++++++--------- 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 9562f1b7..12039183 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ own-* !*/build/*.java !*/build/*.html !*/build/*.xml +/yack-view/package-lock.json diff --git a/fastbee-admin/src/main/resources/application-dev.yml b/fastbee-admin/src/main/resources/application-dev.yml index 71cc42f5..5f9807f0 100644 --- a/fastbee-admin/src/main/resources/application-dev.yml +++ b/fastbee-admin/src/main/resources/application-dev.yml @@ -1,3 +1,7 @@ +# 本地开发文件上传路径(Windows 下 /uploadPath 会解析到 Tomcat Temp 目录,必须用绝对路径) +fastbee: + profile: D:/uploadPath + # 数据源配置 spring: datasource: diff --git a/yack-view/src/api/axios.ts b/yack-view/src/api/axios.ts index d59895e0..775094c5 100644 --- a/yack-view/src/api/axios.ts +++ b/yack-view/src/api/axios.ts @@ -1,10 +1,8 @@ import axios, { AxiosResponse, AxiosRequestConfig, Axios, AxiosError, InternalAxiosRequestConfig } from 'axios' -import { RequestHttpHeaderEnum, ResultEnum, ModuleTypeEnum } from '@/enums/httpEnum' +import { ResultEnum } from '@/enums/httpEnum' import { PageEnum, ErrorPageNameMap } from '@/enums/pageEnum' import { StorageEnum } from '@/enums/storageEnum' -import { axiosPre } from '@/settings/httpSetting' -import { SystemStoreEnum, SystemStoreUserInfoEnum } from '@/store/modules/systemStore/systemStore.d' -import { redirectErrorPage, getLocalStorage, routerTurnByName, isPreview, getCookie } from '@/utils' +import { redirectErrorPage, routerTurnByName, isPreview, getCookie, clearCookie, clearLocalStorage } from '@/utils' import { fetchAllowList } from './axios.config' import includes from 'lodash/includes' @@ -34,7 +32,7 @@ axiosInstance.interceptors.request.use( routerTurnByName(PageEnum.BASE_LOGIN_NAME) return config } - config.headers['Authorization'] = 'Bearer ' + getCookie(StorageEnum.ADMIN_TOKEN) + config.headers['Authorization'] = 'Bearer ' + getCookie(StorageEnum.ADMIN_TOKEN) return config }, (err: AxiosError) => { @@ -58,9 +56,11 @@ axiosInstance.interceptors.response.use( return Promise.resolve(res.data) } - // 登录过期 - if (code === ResultEnum.TOKEN_OVERDUE) { + // 登录过期(886)或未认证(401)— 后端 renderString 固定返回 HTTP 200,code 在 body 中 + if (code === ResultEnum.TOKEN_OVERDUE || code === 401) { window['$message'].error(window['$t']('http.token_overdue_message')) + clearCookie(StorageEnum.ADMIN_TOKEN) + clearLocalStorage(StorageEnum.GO_SYSTEM_STORE) routerTurnByName(PageEnum.BASE_LOGIN_NAME) return Promise.resolve(res.data) } diff --git a/yack-view/src/router/router-guards.ts b/yack-view/src/router/router-guards.ts index 5c81c514..6fbb5ae9 100644 --- a/yack-view/src/router/router-guards.ts +++ b/yack-view/src/router/router-guards.ts @@ -28,10 +28,10 @@ export function createRouterGuards(router: Router) { } // @ts-ignore - if (!routerAllowList.includes(to.name) && !loginCheck()) { - next({ name: PageEnum.BASE_LOGIN_NAME }) + if (!routerAllowList.includes(to.name) && await loginCheck()) { + return next({ name: PageEnum.BASE_LOGIN_NAME }) } - next() + return next() }) router.afterEach((to, _, failure) => { diff --git a/yack-view/src/utils/router.ts b/yack-view/src/utils/router.ts index 19749d26..b2d99b66 100644 --- a/yack-view/src/utils/router.ts +++ b/yack-view/src/utils/router.ts @@ -108,7 +108,7 @@ export const reloadRoutePage = () => { export const logout = async () => { try { const res = await logoutApi() - if(res && res.code === ResultEnum.SUCCESS) { + if (res && res.code === ResultEnum.SUCCESS) { window['$message'].success(window['$t']('global.logout_success')) clearCookie(RequestHttpHeaderEnum.COOKIE) clearCookie(StorageEnum.ADMIN_TOKEN) @@ -193,19 +193,19 @@ export const goHome = () => { */ export const loginCheck = async () => { try { - + const token = getCookie(StorageEnum.ADMIN_TOKEN); - if(typeof token === 'undefined' || token == null || token === ''){ + if (typeof token === 'undefined' || token == null || token === '') { return true - }else{ + } else { const info = getLocalStorage(StorageEnum.GO_SYSTEM_STORE) - if (info != null){ + if (info != null) { const userInfo = info[SystemStoreEnum.USER_INFO] - if(userInfo != null){ + if (userInfo != null) { return false - }else{ + } else { const res = await getUserInfoApi() as unknown as LoginInfoResponseType - if(res.code === ResultEnum.SUCCESS) { + if (res.code === ResultEnum.SUCCESS) { const systemStore = useSystemStore() const { nickName, userName, userId, avatar } = res.user // 存储到 pinia @@ -217,7 +217,7 @@ export const loginCheck = async () => { [SystemStoreUserInfoEnum.AVATAR]: avatar, }) return false - }else{ + } else { return true } } @@ -233,7 +233,7 @@ export const loginCheck = async () => { * * 预览地址 * @returns */ - export const previewPath = (id?: string | number) => { +export const previewPath = (id?: string | number) => { const { origin, pathname } = document.location const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href') const previewPath = `${origin}${pathname}${path}/${id || fetchRouteParamsLocation()}` diff --git a/yack-view/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts b/yack-view/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts index 7138663a..3ae473c3 100644 --- a/yack-view/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts +++ b/yack-view/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts @@ -23,32 +23,36 @@ export const useDataListInit = () => { // 数据请求 const fetchList = async () => { loading.value = true - const res = await projectListApi({ - pageNum: paginat.page, - pageSize: paginat.limit - }) as any - if (res.rows) { - const { total } = res - paginat.count = total - - list.value = res.rows.map((e: any) => { - const { id, projectName, state, createTime,updateTime, indexImage, createBy } = e - return { - id: id, - title: projectName, - createId: createBy, - time: createTime, - updateTime: updateTime, - image: `${import.meta.env.VITE_GLOB_API_URL}${indexImage}`, - release: state !== 0 - } - }) - setTimeout(() => { - loading.value = false - }, 500) - return + try { + const res = await projectListApi({ + pageNum: paginat.page, + pageSize: paginat.limit + }) as any + if (res && res.rows) { + const { total } = res + paginat.count = total + list.value = res.rows.map((e: any) => { + const { id, projectName, state, createTime, updateTime, indexImage, createBy } = e + return { + id: id, + title: projectName, + createId: createBy, + time: createTime, + updateTime: updateTime, + // indexImage 为空时传空字符串,触发 n-image 的 fallback-src 显示占位图 + image: indexImage ? `${import.meta.env.VITE_GLOB_API_URL}${indexImage}` : '', + release: state !== 0 + } + }) + return + } + // 401/认证失败由 axios 拦截器统一处理(跳转登录),此处仅处理其他失败 + if (res && res.code !== 401) { + httpErrorHandle() + } + } finally { + loading.value = false } - httpErrorHandle() } // 修改页数