From 27fe0e04f6d2e44f145a02e21976a21db1818803 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Tue, 10 Dec 2024 15:02:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81http(s)=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/store/modules/user.js | 7 +++++-- ruoyi-fastapi-frontend/src/utils/validate.js | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ruoyi-fastapi-frontend/src/store/modules/user.js b/ruoyi-fastapi-frontend/src/store/modules/user.js index d439c44..1e59417 100644 --- a/ruoyi-fastapi-frontend/src/store/modules/user.js +++ b/ruoyi-fastapi-frontend/src/store/modules/user.js @@ -1,5 +1,6 @@ import { login, logout, getInfo } from '@/api/login' import { getToken, setToken, removeToken } from '@/utils/auth' +import { isHttp, isEmpty } from "@/utils/validate" import defAva from '@/assets/images/profile.jpg' const useUserStore = defineStore( @@ -35,8 +36,10 @@ const useUserStore = defineStore( return new Promise((resolve, reject) => { getInfo().then(res => { const user = res.user - const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar; - + let avatar = user.avatar || "" + if (!isHttp(avatar)) { + avatar = (isEmpty(avatar)) ? defAva : import.meta.env.VITE_APP_BASE_API + avatar + } if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 this.roles = res.roles this.permissions = res.permissions diff --git a/ruoyi-fastapi-frontend/src/utils/validate.js b/ruoyi-fastapi-frontend/src/utils/validate.js index 702add4..459d421 100644 --- a/ruoyi-fastapi-frontend/src/utils/validate.js +++ b/ruoyi-fastapi-frontend/src/utils/validate.js @@ -1,9 +1,21 @@ +/** + * 判断value字符串是否为空 + * @param {string} value + * @returns {Boolean} + */ +export function isEmpty(value) { + if (value == null || value == "" || value == undefined || value == "undefined") { + return true + } + return false +} + /** * 判断url是否是http或https - * @param {string} path + * @param {string} url * @returns {Boolean} */ - export function isHttp(url) { +export function isHttp(url) { return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1 } @@ -12,7 +24,7 @@ * @param {string} path * @returns {Boolean} */ - export function isExternal(path) { +export function isExternal(path) { return /^(https?:|mailto:|tel:)/.test(path) }