From de16c3d1f5b2156d184a00be272aa2b7fb15f794 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 6 Nov 2023 10:46:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E6=97=A7=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E5=8F=AF=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/app.ts | 22 ++++++++++++++----- src/store/modules/user.ts | 10 ++++++--- .../setting/components/change-login-bg.vue | 15 ++++++++++--- .../system/setting/components/change-logo.vue | 11 ++++++---- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index 9cf730df..b0b17df0 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -4,6 +4,7 @@ import defaultLOGOBrand from '@/assets/logo_brand.png'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { validHttp } from '@/utils/regular-utils'; import { defineStore } from 'pinia'; +import { sessionGet } from '@/utils/cache-session-utils'; /**应用参数类型 */ type AppStore = { @@ -52,8 +53,11 @@ const useAppStore = defineStore('app', { if (validHttp(path)) { return path; } - const baseApi = import.meta.env.VITE_API_BASE_URL; - return `${baseApi}${path}`; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; + return `${baseUrl}${path}`; }, /** * 获取正确LOGO地址-brand @@ -68,8 +72,11 @@ const useAppStore = defineStore('app', { if (validHttp(path)) { return path; } - const baseApi = import.meta.env.VITE_API_BASE_URL; - return `${baseApi}${path}`; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; + return `${baseUrl}${path}`; }, /** * 获取正确登录背景地址 @@ -84,8 +91,11 @@ const useAppStore = defineStore('app', { if (validHttp(path)) { return path; } - const baseApi = import.meta.env.VITE_API_BASE_URL; - return `${baseApi}${path}`; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; + return `${baseUrl}${path}`; }, }, actions: { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 7233c3ce..39978f50 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -6,6 +6,7 @@ import { defineStore } from 'pinia'; import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants'; import { validHttp } from '@/utils/regular-utils'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; +import { sessionGet } from '@/utils/cache-session-utils'; /**用户信息类型 */ type UserInfo = { @@ -43,8 +44,11 @@ function parseAvatar(avatar: string): string { if (validHttp(avatar)) { return avatar; } - const baseApi = import.meta.env.VITE_API_BASE_URL; - return `${baseApi}${avatar}`; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; + return `${baseUrl}${avatar}`; } const useUserStore = defineStore('user', { @@ -168,7 +172,7 @@ const useUserStore = defineStore('user', { waterMarkContent = `${this.userName} ${this.phonenumber}`; } // useLayoutStore().changeWaterMark(waterMarkContent); - useLayoutStore().changeWaterMark(""); + useLayoutStore().changeWaterMark(''); } // 网络错误时退出登录状态 if (res.code === 0) { diff --git a/src/views/system/setting/components/change-login-bg.vue b/src/views/system/setting/components/change-login-bg.vue index 91e93a15..42e12b46 100644 --- a/src/views/system/setting/components/change-login-bg.vue +++ b/src/views/system/setting/components/change-login-bg.vue @@ -8,6 +8,7 @@ import { changeValue } from '@/api/system/config'; import { uploadFile } from '@/api/tool/file'; import { FileType } from 'ant-design-vue/lib/upload/interface'; import { UploadRequestOption } from 'ant-design-vue/lib/vc-upload/interface'; +import { sessionGet } from '@/utils/cache-session-utils'; const appStore = useAppStore(); const { t } = useI18n(); @@ -62,8 +63,11 @@ function fnUpload(up: UploadRequestOption) { if (res.code === RESULT_CODE_SUCCESS) { message.success('文件上传成功,提交保存生效', 3); state.filePath = res.data.fileName; - const baseApi = import.meta.env.VITE_API_BASE_URL; - state.flag = `${baseApi}${res.data.fileName}`; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; + state.flag = `${baseUrl}${res.data.fileName}`; } else { message.error(res.msg, 3); } @@ -181,7 +185,12 @@ onMounted(() => { diff --git a/src/views/system/setting/components/change-logo.vue b/src/views/system/setting/components/change-logo.vue index c0895172..667f6e68 100644 --- a/src/views/system/setting/components/change-logo.vue +++ b/src/views/system/setting/components/change-logo.vue @@ -9,6 +9,7 @@ import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { uploadFile } from '@/api/tool/file'; import { changeValue } from '@/api/system/config'; import { computed } from 'vue'; +import { sessionGet } from '@/utils/cache-session-utils'; const appStore = useAppStore(); const { t } = useI18n(); @@ -64,13 +65,15 @@ function fnUpload(up: UploadRequestOption) { if (res.code === RESULT_CODE_SUCCESS) { message.success('文件上传成功,提交保存生效', 3); state.filePath = res.data.fileName; - // appStore.setLOGO(state.type, res.data.fileName); - const baseApi = import.meta.env.VITE_API_BASE_URL; + // 兼容旧前端可改配置文件 + const baseUrl = import.meta.env.PROD + ? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL + : import.meta.env.VITE_API_BASE_URL; if (state.type === 'icon') { - state.icon = `${baseApi}${res.data.fileName}`; + state.icon = `${baseUrl}${res.data.fileName}`; } if (state.type === 'brand') { - state.brand = `${baseApi}${res.data.fileName}`; + state.brand = `${baseUrl}${res.data.fileName}`; } } else { message.error(res.msg, 3);