作者 RuoYi

优化代码

1 -如果使用的是RuoYi-Vue3前端,那么需要覆盖一下此目录的模板index.vue.vm、index-tree.vue.vm文件到上级vue目录。  
@@ -11,14 +11,14 @@ import ThemePicker from "@/components/ThemePicker"; @@ -11,14 +11,14 @@ import ThemePicker from "@/components/ThemePicker";
11 export default { 11 export default {
12 name: "App", 12 name: "App",
13 components: { ThemePicker }, 13 components: { ThemePicker },
14 - metaInfo() {  
15 - return {  
16 - title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,  
17 - titleTemplate: title => {  
18 - return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE  
19 - }  
20 - } 14 + metaInfo() {
  15 + return {
  16 + title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
  17 + titleTemplate: title => {
  18 + return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
  19 + }
21 } 20 }
  21 + }
22 }; 22 };
23 </script> 23 </script>
24 <style scoped> 24 <style scoped>
@@ -168,7 +168,7 @@ export default { @@ -168,7 +168,7 @@ export default {
168 // 删除图片 168 // 删除图片
169 handleDelete(file) { 169 handleDelete(file) {
170 const findex = this.fileList.map(f => f.name).indexOf(file.name); 170 const findex = this.fileList.map(f => f.name).indexOf(file.name);
171 - if(findex > -1) { 171 + if (findex > -1) {
172 this.fileList.splice(findex, 1); 172 this.fileList.splice(findex, 1);
173 this.$emit("input", this.listToString(this.fileList)); 173 this.$emit("input", this.listToString(this.fileList));
174 } 174 }
@@ -57,9 +57,9 @@ export default { @@ -57,9 +57,9 @@ export default {
57 if (menu.hidden !== true) { 57 if (menu.hidden !== true) {
58 // 兼容顶部栏一级菜单内部跳转 58 // 兼容顶部栏一级菜单内部跳转
59 if (menu.path === "/") { 59 if (menu.path === "/") {
60 - topMenus.push(menu.children[0]); 60 + topMenus.push(menu.children[0]);
61 } else { 61 } else {
62 - topMenus.push(menu); 62 + topMenus.push(menu);
63 } 63 }
64 } 64 }
65 }); 65 });
1 /** 1 /**
2 -* v-dialogDragWidth 可拖动弹窗高度(右下角)  
3 -* Copyright (c) 2019 ruoyi  
4 -*/ 2 + * v-dialogDragWidth 可拖动弹窗高度(右下角)
  3 + * Copyright (c) 2019 ruoyi
  4 + */
5 5
6 export default { 6 export default {
7 - bind(el) {  
8 - const dragDom = el.querySelector('.el-dialog');  
9 - const lineEl = document.createElement('div');  
10 - lineEl.style = 'width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;';  
11 - lineEl.addEventListener('mousedown',  
12 - function(e) {  
13 - // 鼠标按下,计算当前元素距离可视区的距离  
14 - const disX = e.clientX - el.offsetLeft;  
15 - const disY = e.clientY - el.offsetTop;  
16 - // 当前宽度 高度  
17 - const curWidth = dragDom.offsetWidth;  
18 - const curHeight = dragDom.offsetHeight;  
19 - document.onmousemove = function(e) {  
20 - e.preventDefault(); // 移动时禁用默认事件  
21 - // 通过事件委托,计算移动的距离  
22 - const xl = e.clientX - disX;  
23 - const yl = e.clientY - disY  
24 - dragDom.style.width = `${curWidth + xl}px`;  
25 - dragDom.style.height = `${curHeight + yl}px`;  
26 - };  
27 - document.onmouseup = function(e) {  
28 - document.onmousemove = null;  
29 - document.onmouseup = null;  
30 - };  
31 - }, false);  
32 - dragDom.appendChild(lineEl);  
33 - }  
34 -}  
  7 + bind(el) {
  8 + const dragDom = el.querySelector('.el-dialog');
  9 + const lineEl = document.createElement('div');
  10 + lineEl.style = 'width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;';
  11 + lineEl.addEventListener('mousedown',
  12 + function(e) {
  13 + // 鼠标按下,计算当前元素距离可视区的距离
  14 + const disX = e.clientX - el.offsetLeft;
  15 + const disY = e.clientY - el.offsetTop;
  16 + // 当前宽度 高度
  17 + const curWidth = dragDom.offsetWidth;
  18 + const curHeight = dragDom.offsetHeight;
  19 + document.onmousemove = function(e) {
  20 + e.preventDefault(); // 移动时禁用默认事件
  21 + // 通过事件委托,计算移动的距离
  22 + const xl = e.clientX - disX;
  23 + const yl = e.clientY - disY
  24 + dragDom.style.width = `${curWidth + xl}px`;
  25 + dragDom.style.height = `${curHeight + yl}px`;
  26 + };
  27 + document.onmouseup = function(e) {
  28 + document.onmousemove = null;
  29 + document.onmouseup = null;
  30 + };
  31 + }, false);
  32 + dragDom.appendChild(lineEl);
  33 + }
  34 +}
1 /** 1 /**
2 -* v-dialogDragWidth 可拖动弹窗宽度(右侧边)  
3 -* Copyright (c) 2019 ruoyi  
4 -*/ 2 + * v-dialogDragWidth 可拖动弹窗宽度(右侧边)
  3 + * Copyright (c) 2019 ruoyi
  4 + */
5 5
6 export default { 6 export default {
7 - bind(el) {  
8 - const dragDom = el.querySelector('.el-dialog');  
9 - const lineEl = document.createElement('div');  
10 - lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;';  
11 - lineEl.addEventListener('mousedown',  
12 - function (e) {  
13 - // 鼠标按下,计算当前元素距离可视区的距离  
14 - const disX = e.clientX - el.offsetLeft;  
15 - // 当前宽度  
16 - const curWidth = dragDom.offsetWidth;  
17 - document.onmousemove = function (e) {  
18 - e.preventDefault(); // 移动时禁用默认事件  
19 - // 通过事件委托,计算移动的距离  
20 - const l = e.clientX - disX;  
21 - dragDom.style.width = `${curWidth + l}px`;  
22 - };  
23 - document.onmouseup = function (e) {  
24 - document.onmousemove = null;  
25 - document.onmouseup = null;  
26 - };  
27 - }, false);  
28 - dragDom.appendChild(lineEl);  
29 - }  
30 -}  
  7 + bind(el) {
  8 + const dragDom = el.querySelector('.el-dialog');
  9 + const lineEl = document.createElement('div');
  10 + lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;';
  11 + lineEl.addEventListener('mousedown',
  12 + function (e) {
  13 + // 鼠标按下,计算当前元素距离可视区的距离
  14 + const disX = e.clientX - el.offsetLeft;
  15 + // 当前宽度
  16 + const curWidth = dragDom.offsetWidth;
  17 + document.onmousemove = function (e) {
  18 + e.preventDefault(); // 移动时禁用默认事件
  19 + // 通过事件委托,计算移动的距离
  20 + const l = e.clientX - disX;
  21 + dragDom.style.width = `${curWidth + l}px`;
  22 + };
  23 + document.onmouseup = function (e) {
  24 + document.onmousemove = null;
  25 + document.onmouseup = null;
  26 + };
  27 + }, false);
  28 + dragDom.appendChild(lineEl);
  29 + }
  30 +}
@@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
13 <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" /> 13 <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
14 </template> 14 </template>
15 <sidebar-item 15 <sidebar-item
16 - v-for="child in item.children"  
17 - :key="child.path" 16 + v-for="(child, index) in item.children"
  17 + :key="child.path + index"
18 :is-nest="true" 18 :is-nest="true"
19 :item="child" 19 :item="child"
20 :base-path="resolvePath(child.path)" 20 :base-path="resolvePath(child.path)"
@@ -60,7 +60,7 @@ export default { @@ -60,7 +60,7 @@ export default {
60 }, 60 },
61 // 添加tab页签 61 // 添加tab页签
62 openPage(title, url, params) { 62 openPage(title, url, params) {
63 - var obj = { path: url, meta: { title: title } } 63 + const obj = { path: url, meta: { title: title } }
64 store.dispatch('tagsView/addView', obj); 64 store.dispatch('tagsView/addView', obj);
65 return router.push({ path: url, query: params }); 65 return router.push({ path: url, query: params });
66 }, 66 },
@@ -15,10 +15,8 @@ export function checkPermi(value) { @@ -15,10 +15,8 @@ export function checkPermi(value) {
15 return all_permission === permission || permissionDatas.includes(permission) 15 return all_permission === permission || permissionDatas.includes(permission)
16 }) 16 })
17 17
18 - if (!hasPermission) {  
19 - return false  
20 - }  
21 - return true 18 + return hasPermission;
  19 +
22 } else { 20 } else {
23 console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`) 21 console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
24 return false 22 return false
@@ -40,10 +38,8 @@ export function checkRole(value) { @@ -40,10 +38,8 @@ export function checkRole(value) {
40 return super_admin === role || permissionRoles.includes(role) 38 return super_admin === role || permissionRoles.includes(role)
41 }) 39 })
42 40
43 - if (!hasRole) {  
44 - return false  
45 - }  
46 - return true 41 + return hasRole;
  42 +
47 } else { 43 } else {
48 console.error(`need roles! Like checkRole="['admin','editor']"`) 44 console.error(`need roles! Like checkRole="['admin','editor']"`)
49 return false 45 return false
@@ -65,10 +65,7 @@ export function validEmail(email) { @@ -65,10 +65,7 @@ export function validEmail(email) {
65 * @returns {Boolean} 65 * @returns {Boolean}
66 */ 66 */
67 export function isString(str) { 67 export function isString(str) {
68 - if (typeof str === 'string' || str instanceof String) {  
69 - return true  
70 - }  
71 - return false 68 + return typeof str === 'string' || str instanceof String;
72 } 69 }
73 70
74 /** 71 /**