File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
ruoyi-fastapi-frontend/src Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 11import { login , logout , getInfo } from '@/api/login'
22import { getToken , setToken , removeToken } from '@/utils/auth'
3+ import { isHttp , isEmpty } from "@/utils/validate"
34import defAva from '@/assets/images/profile.jpg'
45
56const 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
Original file line number Diff line number Diff line change 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
1224 * @param {string } path
1325 * @returns {Boolean }
1426 */
15- export function isExternal ( path ) {
27+ export function isExternal ( path ) {
1628 return / ^ ( h t t p s ? : | m a i l t o : | t e l : ) / . test ( path )
1729}
1830
You can’t perform that action at this time.
0 commit comments