作者 RuoYi

优化代码

1 package com.ruoyi.common.core.domain; 1 package com.ruoyi.common.core.domain;
2 2
3 import java.util.HashMap; 3 import java.util.HashMap;
  4 +import java.util.Objects;
4 import com.ruoyi.common.constant.HttpStatus; 5 import com.ruoyi.common.constant.HttpStatus;
5 import com.ruoyi.common.utils.StringUtils; 6 import com.ruoyi.common.utils.StringUtils;
6 7
@@ -170,6 +171,36 @@ public class AjaxResult extends HashMap<String, Object> @@ -170,6 +171,36 @@ public class AjaxResult extends HashMap<String, Object>
170 } 171 }
171 172
172 /** 173 /**
  174 + * 是否为成功消息
  175 + *
  176 + * @return 结果
  177 + */
  178 + public boolean isSuccess()
  179 + {
  180 + return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
  181 + }
  182 +
  183 + /**
  184 + * 是否为警告消息
  185 + *
  186 + * @return 结果
  187 + */
  188 + public boolean isWarn()
  189 + {
  190 + return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
  191 + }
  192 +
  193 + /**
  194 + * 是否为错误消息
  195 + *
  196 + * @return 结果
  197 + */
  198 + public boolean isError()
  199 + {
  200 + return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
  201 + }
  202 +
  203 + /**
173 * 方便链式调用 204 * 方便链式调用
174 * 205 *
175 * @param key 键 206 * @param key 键
@@ -66,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> @@ -66,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
66 } 66 }
67 67
68 /** 68 /**
69 - * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。 69 + * 获取类型 4(伪随机生成的)UUID 的静态工厂。
70 * 70 *
71 * @return 随机生成的 {@code UUID} 71 * @return 随机生成的 {@code UUID}
72 */ 72 */
@@ -5,6 +5,7 @@ import java.util.List; @@ -5,6 +5,7 @@ import java.util.List;
5 import java.util.Set; 5 import java.util.Set;
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
  8 +import org.springframework.util.CollectionUtils;
8 import com.ruoyi.common.core.domain.entity.SysRole; 9 import com.ruoyi.common.core.domain.entity.SysRole;
9 import com.ruoyi.common.core.domain.entity.SysUser; 10 import com.ruoyi.common.core.domain.entity.SysUser;
10 import com.ruoyi.system.service.ISysMenuService; 11 import com.ruoyi.system.service.ISysMenuService;
@@ -62,7 +63,7 @@ public class SysPermissionService @@ -62,7 +63,7 @@ public class SysPermissionService
62 else 63 else
63 { 64 {
64 List<SysRole> roles = user.getRoles(); 65 List<SysRole> roles = user.getRoles();
65 - if (!roles.isEmpty() && roles.size() > 1) 66 + if (!CollectionUtils.isEmpty(roles))
66 { 67 {
67 // 多角色设置permissions属性,以便数据权限匹配权限 68 // 多角色设置permissions属性,以便数据权限匹配权限
68 for (SysRole role : roles) 69 for (SysRole role : roles)
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 :key="item.value" 7 :key="item.value"
8 :index="index" 8 :index="index"
9 :class="item.raw.cssClass" 9 :class="item.raw.cssClass"
10 - >{{ item.label + ' ' }}</span 10 + >{{ item.label + " " }}</span
11 > 11 >
12 <el-tag 12 <el-tag
13 v-else 13 v-else
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 :type="item.raw.listClass == 'primary' ? '' : item.raw.listClass" 17 :type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
18 :class="item.raw.cssClass" 18 :class="item.raw.cssClass"
19 > 19 >
20 - {{ item.label + ' ' }} 20 + {{ item.label + " " }}
21 </el-tag> 21 </el-tag>
22 </template> 22 </template>
23 </template> 23 </template>
@@ -49,39 +49,39 @@ export default { @@ -49,39 +49,39 @@ export default {
49 }, 49 },
50 computed: { 50 computed: {
51 values() { 51 values() {
52 - if (this.value !== null && typeof this.value !== 'undefined') { 52 + if (this.value !== null && typeof this.value !== "undefined") {
53 return Array.isArray(this.value) ? this.value : [String(this.value)]; 53 return Array.isArray(this.value) ? this.value : [String(this.value)];
54 } else { 54 } else {
55 return []; 55 return [];
56 } 56 }
57 }, 57 },
58 - unmatch(){ 58 + unmatch() {
59 this.unmatchArray = []; 59 this.unmatchArray = [];
60 - if (this.value !== null && typeof this.value !== 'undefined') { 60 + if (this.value !== null && typeof this.value !== "undefined") {
61 // 传入值为非数组 61 // 传入值为非数组
62 - if(!Array.isArray(this.value)){  
63 - if(this.options.some(v=> v.value == this.value )) return false; 62 + if (!Array.isArray(this.value)) {
  63 + if (this.options.some((v) => v.value == this.value)) return false;
64 this.unmatchArray.push(this.value); 64 this.unmatchArray.push(this.value);
65 return true; 65 return true;
66 } 66 }
67 // 传入值为Array 67 // 传入值为Array
68 - this.value.forEach(item => {  
69 - if (!this.options.some(v=> v.value == item )) this.unmatchArray.push(item) 68 + this.value.forEach((item) => {
  69 + if (!this.options.some((v) => v.value == item))
  70 + this.unmatchArray.push(item);
70 }); 71 });
71 return true; 72 return true;
72 } 73 }
73 // 没有value不显示 74 // 没有value不显示
74 return false; 75 return false;
75 }, 76 },
76 -  
77 }, 77 },
78 filters: { 78 filters: {
79 handleArray(array) { 79 handleArray(array) {
80 - if(array.length===0) return ''; 80 + if (array.length === 0) return "";
81 return array.reduce((pre, cur) => { 81 return array.reduce((pre, cur) => {
82 - return pre + ' ' + cur; 82 + return pre + " " + cur;
83 }) 83 })
84 - }, 84 + }
85 } 85 }
86 }; 86 };
87 </script> 87 </script>
1 -import { isArray } from 'util'  
2 import { exportDefault, titleCase } from '@/utils/index' 1 import { exportDefault, titleCase } from '@/utils/index'
3 import { trigger } from './config' 2 import { trigger } from './config'
4 3
@@ -133,12 +132,12 @@ function buildRules(conf, ruleList) { @@ -133,12 +132,12 @@ function buildRules(conf, ruleList) {
133 const rules = [] 132 const rules = []
134 if (trigger[conf.tag]) { 133 if (trigger[conf.tag]) {
135 if (conf.required) { 134 if (conf.required) {
136 - const type = isArray(conf.defaultValue) ? 'type: \'array\',' : ''  
137 - let message = isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder 135 + const type = Array.isArray(conf.defaultValue) ? 'type: \'array\',' : ''
  136 + let message = Array.isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder
138 if (message === undefined) message = `${conf.label}不能为空` 137 if (message === undefined) message = `${conf.label}不能为空`
139 rules.push(`{ required: true, ${type} message: '${message}', trigger: '${trigger[conf.tag]}' }`) 138 rules.push(`{ required: true, ${type} message: '${message}', trigger: '${trigger[conf.tag]}' }`)
140 } 139 }
141 - if (conf.regList && isArray(conf.regList)) { 140 + if (conf.regList && Array.isArray(conf.regList)) {
142 conf.regList.forEach(item => { 141 conf.regList.forEach(item => {
143 if (item.pattern) { 142 if (item.pattern) {
144 rules.push(`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${trigger[conf.tag]}' }`) 143 rules.push(`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${trigger[conf.tag]}' }`)
@@ -888,7 +888,7 @@ @@ -888,7 +888,7 @@
888 </div> 888 </div>
889 <div class="body"> 889 <div class="body">
890 <img 890 <img
891 - src="https://oscimg.oschina.net/oscnet/up-d6695f82666e5018f715c41cb7ee60d3b73.png" 891 + src="http://ruoyi.vip/images/pay.png"
892 alt="donate" 892 alt="donate"
893 width="100%" 893 width="100%"
894 /> 894 />
@@ -90,9 +90,7 @@ module.exports = { @@ -90,9 +90,7 @@ module.exports = {
90 }) 90 })
91 .end() 91 .end()
92 92
93 - config  
94 - .when(process.env.NODE_ENV !== 'development',  
95 - config => { 93 + config.when(process.env.NODE_ENV !== 'development', config => {
96 config 94 config
97 .plugin('ScriptExtHtmlWebpackPlugin') 95 .plugin('ScriptExtHtmlWebpackPlugin')
98 .after('html') 96 .after('html')
@@ -101,8 +99,8 @@ module.exports = { @@ -101,8 +99,8 @@ module.exports = {
101 inline: /runtime\..*\.js$/ 99 inline: /runtime\..*\.js$/
102 }]) 100 }])
103 .end() 101 .end()
104 - config  
105 - .optimization.splitChunks({ 102 +
  103 + config.optimization.splitChunks({
106 chunks: 'all', 104 chunks: 'all',
107 cacheGroups: { 105 cacheGroups: {
108 libs: { 106 libs: {
@@ -113,8 +111,8 @@ module.exports = { @@ -113,8 +111,8 @@ module.exports = {
113 }, 111 },
114 elementUI: { 112 elementUI: {
115 name: 'chunk-elementUI', // split elementUI into a single package 113 name: 'chunk-elementUI', // split elementUI into a single package
  114 + test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
116 priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app 115 priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
117 - test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm  
118 }, 116 },
119 commons: { 117 commons: {
120 name: 'chunk-commons', 118 name: 'chunk-commons',
@@ -125,12 +123,12 @@ module.exports = { @@ -125,12 +123,12 @@ module.exports = {
125 } 123 }
126 } 124 }
127 }) 125 })
  126 +
128 config.optimization.runtimeChunk('single'), 127 config.optimization.runtimeChunk('single'),
129 { 128 {
130 from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件 129 from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
131 to: './' //到根目录下 130 to: './' //到根目录下
132 } 131 }
133 - }  
134 - ) 132 + })
135 } 133 }
136 } 134 }