作者 RuoYi

用户头像http(s)链接支持

@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 // make search results more in line with expectations 22 // make search results more in line with expectations
23 import Fuse from 'fuse.js/dist/fuse.min.js' 23 import Fuse from 'fuse.js/dist/fuse.min.js'
24 import path from 'path' 24 import path from 'path'
  25 +import { isHttp } from '@/utils/validate'
25 26
26 export default { 27 export default {
27 name: 'HeaderSearch', 28 name: 'HeaderSearch',
@@ -72,7 +73,7 @@ export default { @@ -72,7 +73,7 @@ export default {
72 change(val) { 73 change(val) {
73 const path = val.path; 74 const path = val.path;
74 const query = val.query; 75 const query = val.query;
75 - if(this.ishttp(val.path)) { 76 + if(isHttp(val.path)) {
76 // http(s):// 路径新窗口打开 77 // http(s):// 路径新窗口打开
77 const pindex = path.indexOf("http"); 78 const pindex = path.indexOf("http");
78 window.open(path.substr(pindex, path.length), "_blank"); 79 window.open(path.substr(pindex, path.length), "_blank");
@@ -115,7 +116,7 @@ export default { @@ -115,7 +116,7 @@ export default {
115 if (router.hidden) { continue } 116 if (router.hidden) { continue }
116 117
117 const data = { 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 title: [...prefixTitle] 120 title: [...prefixTitle]
120 } 121 }
121 122
@@ -149,9 +150,6 @@ export default { @@ -149,9 +150,6 @@ export default {
149 } else { 150 } else {
150 this.options = [] 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 }
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 33
34 <script> 34 <script>
35 import { constantRoutes } from "@/router"; 35 import { constantRoutes } from "@/router";
  36 +import { isHttp } from "@/utils/validate";
36 37
37 // 隐藏侧边栏路由 38 // 隐藏侧边栏路由
38 const hideList = ['/index', '/user/profile']; 39 const hideList = ['/index', '/user/profile'];
@@ -78,7 +79,7 @@ export default { @@ -78,7 +79,7 @@ export default {
78 if(router.path === "/") { 79 if(router.path === "/") {
79 router.children[item].path = "/" + router.children[item].path; 80 router.children[item].path = "/" + router.children[item].path;
80 } else { 81 } else {
81 - if(!this.ishttp(router.children[item].path)) { 82 + if(!isHttp(router.children[item].path)) {
82 router.children[item].path = router.path + "/" + router.children[item].path; 83 router.children[item].path = router.path + "/" + router.children[item].path;
83 } 84 }
84 } 85 }
@@ -126,7 +127,7 @@ export default { @@ -126,7 +127,7 @@ export default {
126 handleSelect(key, keyPath) { 127 handleSelect(key, keyPath) {
127 this.currentIndex = key; 128 this.currentIndex = key;
128 const route = this.routers.find(item => item.path === key); 129 const route = this.routers.find(item => item.path === key);
129 - if (this.ishttp(key)) { 130 + if (isHttp(key)) {
130 // http(s):// 路径新窗口打开 131 // http(s):// 路径新窗口打开
131 window.open(key, "_blank"); 132 window.open(key, "_blank");
132 } else if (!route || !route.children) { 133 } else if (!route || !route.children) {
@@ -160,9 +161,6 @@ export default { @@ -160,9 +161,6 @@ export default {
160 } else { 161 } else {
161 this.$store.dispatch('app/toggleSideBarHide', true); 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 };
1 import { login, logout, getInfo } from '@/api/login' 1 import { login, logout, getInfo } from '@/api/login'
2 import { getToken, setToken, removeToken } from '@/utils/auth' 2 import { getToken, setToken, removeToken } from '@/utils/auth'
  3 +import { isHttp, isEmpty } from "@/utils/validate"
  4 +import defAva from '@/assets/images/profile.jpg'
3 5
4 const user = { 6 const user = {
5 state: { 7 state: {
@@ -55,7 +57,10 @@ const user = { @@ -55,7 +57,10 @@ const user = {
55 return new Promise((resolve, reject) => { 57 return new Promise((resolve, reject) => {
56 getInfo().then(res => { 58 getInfo().then(res => {
57 const user = res.user 59 const user = res.user
58 - const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar; 60 + let avatar = user.avatar || ""
  61 + if (!isHttp(avatar)) {
  62 + avatar = (isEmpty(avatar)) ? defAva : process.env.VUE_APP_BASE_API + avatar
  63 + }
59 if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 64 if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
60 commit('SET_ROLES', res.roles) 65 commit('SET_ROLES', res.roles)
61 commit('SET_PERMISSIONS', res.permissions) 66 commit('SET_PERMISSIONS', res.permissions)
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 * @param {string} path 24 * @param {string} path
3 * @returns {Boolean} 25 * @returns {Boolean}
4 */ 26 */