From ce076ef7f821a761a64a81ac2cea2381d4af63c9 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 17 Jan 2024 16:03:16 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E5=A4=B4=E5=83=8F=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 2 +- src/store/modules/user.ts | 32 +++++++++----------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.env.production b/.env.production index c00e9d95..4ef86a1f 100644 --- a/.env.production +++ b/.env.production @@ -11,7 +11,7 @@ VITE_APP_NAME = "Core Network EMS" VITE_APP_CODE = "CN EMS" # 应用版本 -VITE_APP_VERSION = "2.240112.2" +VITE_APP_VERSION = "2.240118.2" # 接口基础URL地址-不带/后缀 VITE_API_BASE_URL = "/omc-api" diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 39978f50..34b1b9f1 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -4,9 +4,8 @@ import { login, logout, getInfo } from '@/api/login'; import { getToken, setToken, removeToken } from '@/plugins/auth-token'; 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'; +import { parseUrlPath } from '@/plugins/file-static-url'; /**用户信息类型 */ type UserInfo = { @@ -32,25 +31,6 @@ type UserInfo = { profile: Record; }; -/** - * 格式解析头像地址 - * @param avatar 头像路径 - * @returns url地址 - */ -function parseAvatar(avatar: string): string { - if (!avatar) { - return defaultAvatar; - } - if (validHttp(avatar)) { - return 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', { state: (): UserInfo => ({ token: getToken(), @@ -71,7 +51,10 @@ const useUserStore = defineStore('user', { * @returns 头像地址url */ getAvatar(state) { - return parseAvatar(state.avatar); + if (!state.avatar) { + return defaultAvatar; + } + return parseUrlPath(state.avatar); }, /** * 获取基础信息属性 @@ -110,7 +93,10 @@ const useUserStore = defineStore('user', { * @param avatar */ fnAvatar(avatar: string) { - return parseAvatar(avatar); + if (!avatar) { + return defaultAvatar; + } + return parseUrlPath(avatar); }, // 登录 async fnLogin(loginBody: Record) {