Skip to content

Commit 27fe0e0

Browse files
committed
feat: 用户头像新增支持http(s)链接
1 parent 591dbe0 commit 27fe0e0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

ruoyi-fastapi-frontend/src/store/modules/user.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { login, logout, getInfo } from '@/api/login'
22
import { getToken, setToken, removeToken } from '@/utils/auth'
3+
import { isHttp, isEmpty } from "@/utils/validate"
34
import defAva from '@/assets/images/profile.jpg'
45

56
const useUserStore = defineStore(
@@ -35,8 +36,10 @@ const useUserStore = defineStore(
3536
return new Promise((resolve, reject) => {
3637
getInfo().then(res => {
3738
const user = res.user
38-
const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar;
39-
39+
let avatar = user.avatar || ""
40+
if (!isHttp(avatar)) {
41+
avatar = (isEmpty(avatar)) ? defAva : import.meta.env.VITE_APP_BASE_API + avatar
42+
}
4043
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
4144
this.roles = res.roles
4245
this.permissions = res.permissions

ruoyi-fastapi-frontend/src/utils/validate.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
/**
2+
* 判断value字符串是否为空
3+
* @param {string} value
4+
* @returns {Boolean}
5+
*/
6+
export function isEmpty(value) {
7+
if (value == null || value == "" || value == undefined || value == "undefined") {
8+
return true
9+
}
10+
return false
11+
}
12+
113
/**
214
* 判断url是否是http或https
3-
* @param {string} path
15+
* @param {string} url
416
* @returns {Boolean}
517
*/
6-
export function isHttp(url) {
18+
export function isHttp(url) {
719
return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
820
}
921

@@ -12,7 +24,7 @@
1224
* @param {string} path
1325
* @returns {Boolean}
1426
*/
15-
export function isExternal(path) {
27+
export function isExternal(path) {
1628
return /^(https?:|mailto:|tel:)/.test(path)
1729
}
1830

0 commit comments

Comments
 (0)