RuoYi 1 рік тому
батько
коміт
08f4b877ce

+ 3 - 5
ruoyi-ui/src/components/HeaderSearch/index.vue

@@ -22,6 +22,7 @@
22 22
 // make search results more in line with expectations
23 23
 import Fuse from 'fuse.js/dist/fuse.min.js'
24 24
 import path from 'path'
25
+import { isHttp } from '@/utils/validate'
25 26
 
26 27
 export default {
27 28
   name: 'HeaderSearch',
@@ -72,7 +73,7 @@ export default {
72 73
     change(val) {
73 74
       const path = val.path;
74 75
       const query = val.query;
75
-      if(this.ishttp(val.path)) {
76
+      if(isHttp(val.path)) {
76 77
         // http(s):// 路径新窗口打开
77 78
         const pindex = path.indexOf("http");
78 79
         window.open(path.substr(pindex, path.length), "_blank");
@@ -115,7 +116,7 @@ export default {
115 116
         if (router.hidden) { continue }
116 117
 
117 118
         const data = {
118
-          path: !this.ishttp(router.path) ? path.resolve(basePath, router.path) : router.path,
119
+          path: !isHttp(router.path) ? path.resolve(basePath, router.path) : router.path,
119 120
           title: [...prefixTitle]
120 121
         }
121 122
 
@@ -149,9 +150,6 @@ export default {
149 150
       } else {
150 151
         this.options = []
151 152
       }
152
-    },
153
-    ishttp(url) {
154
-      return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
155 153
     }
156 154
   }
157 155
 }

+ 3 - 5
ruoyi-ui/src/components/TopNav/index.vue

@@ -33,6 +33,7 @@
33 33
 
34 34
 <script>
35 35
 import { constantRoutes } from "@/router";
36
+import { isHttp } from "@/utils/validate";
36 37
 
37 38
 // 隐藏侧边栏路由
38 39
 const hideList = ['/index', '/user/profile'];
@@ -78,7 +79,7 @@ export default {
78 79
             if(router.path === "/") {
79 80
               router.children[item].path = "/" + router.children[item].path;
80 81
             } else {
81
-              if(!this.ishttp(router.children[item].path)) {
82
+              if(!isHttp(router.children[item].path)) {
82 83
                 router.children[item].path = router.path + "/" + router.children[item].path;
83 84
               }
84 85
             }
@@ -126,7 +127,7 @@ export default {
126 127
     handleSelect(key, keyPath) {
127 128
       this.currentIndex = key;
128 129
       const route = this.routers.find(item => item.path === key);
129
-      if (this.ishttp(key)) {
130
+      if (isHttp(key)) {
130 131
         // http(s):// 路径新窗口打开
131 132
         window.open(key, "_blank");
132 133
       } else if (!route || !route.children) {
@@ -160,9 +161,6 @@ export default {
160 161
       } else {
161 162
         this.$store.dispatch('app/toggleSideBarHide', true);
162 163
       }
163
-    },
164
-    ishttp(url) {
165
-      return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
166 164
     }
167 165
   },
168 166
 };

+ 3 - 1
ruoyi-ui/src/store/modules/user.js

@@ -1,5 +1,7 @@
1 1
 import { login, logout, getInfo, refreshToken } from '@/api/login'
2 2
 import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth'
3
+import { isEmpty } from "@/utils/validate"
4
+import defAva from '@/assets/images/profile.jpg'
3 5
 
4 6
 const user = {
5 7
   state: {
@@ -61,7 +63,7 @@ const user = {
61 63
       return new Promise((resolve, reject) => {
62 64
         getInfo().then(res => {
63 65
           const user = res.user
64
-          const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : user.avatar;
66
+          const avatar = (isEmpty(user.avatar)) ? defAva : user.avatar
65 67
           if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
66 68
             commit('SET_ROLES', res.roles)
67 69
             commit('SET_PERMISSIONS', res.permissions)

+ 22 - 0
ruoyi-ui/src/utils/validate.js

@@ -1,4 +1,26 @@
1 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
+
13
+/**
14
+ * 判断url是否是http或https 
15
+ * @param {string} url
16
+ * @returns {Boolean}
17
+ */
18
+export function isHttp(url) {
19
+  return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
20
+}
21
+
22
+/**
23
+ * 判断path是否为外链
2 24
  * @param {string} path
3 25
  * @returns {Boolean}
4 26
  */