From 9e66ada9c154170923dc158b205b58b485e7124a Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期六, 24 六月 2023 10:57:05 +0800
Subject: [PATCH] 优化代码
---
ruoyi-ui/src/utils/generator/js.js | 7 +-
ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java | 2
ruoyi-ui/src/components/DictTag/index.vue | 26 ++++----
ruoyi-ui/src/views/index.vue | 2
ruoyi-ui/vue.config.js | 54 ++++++++---------
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java | 31 ++++++++++
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java | 3
7 files changed, 77 insertions(+), 48 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
index 790753d..42dcbcd 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
@@ -1,6 +1,7 @@
package com.ruoyi.common.core.domain;
import java.util.HashMap;
+import java.util.Objects;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.utils.StringUtils;
@@ -170,6 +171,36 @@
}
/**
+ * 是否为成功消息
+ *
+ * @return 结果
+ */
+ public boolean isSuccess()
+ {
+ return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为警告消息
+ *
+ * @return 结果
+ */
+ public boolean isWarn()
+ {
+ return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为错误消息
+ *
+ * @return 结果
+ */
+ public boolean isError()
+ {
+ return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
+ }
+
+ /**
* 方便链式调用
*
* @param key 键
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java
index c0c18af..97497f2 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java
@@ -66,7 +66,7 @@
}
/**
- * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
+ * 获取类型 4(伪随机生成的)UUID 的静态工厂。
*
* @return 随机生成的 {@code UUID}
*/
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java
index 357e12f..6400750 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java
@@ -5,6 +5,7 @@
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysMenuService;
@@ -62,7 +63,7 @@
else
{
List<SysRole> roles = user.getRoles();
- if (!roles.isEmpty() && roles.size() > 1)
+ if (!CollectionUtils.isEmpty(roles))
{
// 多角色设置permissions属性,以便数据权限匹配权限
for (SysRole role : roles)
diff --git a/ruoyi-ui/src/components/DictTag/index.vue b/ruoyi-ui/src/components/DictTag/index.vue
index 279b613..a0fd66f 100644
--- a/ruoyi-ui/src/components/DictTag/index.vue
+++ b/ruoyi-ui/src/components/DictTag/index.vue
@@ -7,7 +7,7 @@
:key="item.value"
:index="index"
:class="item.raw.cssClass"
- >{{ item.label + ' ' }}</span
+ >{{ item.label + " " }}</span
>
<el-tag
v-else
@@ -17,7 +17,7 @@
:type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
:class="item.raw.cssClass"
>
- {{ item.label + ' ' }}
+ {{ item.label + " " }}
</el-tag>
</template>
</template>
@@ -49,39 +49,39 @@
},
computed: {
values() {
- if (this.value !== null && typeof this.value !== 'undefined') {
+ if (this.value !== null && typeof this.value !== "undefined") {
return Array.isArray(this.value) ? this.value : [String(this.value)];
} else {
return [];
}
},
- unmatch(){
+ unmatch() {
this.unmatchArray = [];
- if (this.value !== null && typeof this.value !== 'undefined') {
+ if (this.value !== null && typeof this.value !== "undefined") {
// 传入值为非数组
- if(!Array.isArray(this.value)){
- if(this.options.some(v=> v.value == this.value )) return false;
+ if (!Array.isArray(this.value)) {
+ if (this.options.some((v) => v.value == this.value)) return false;
this.unmatchArray.push(this.value);
return true;
}
// 传入值为Array
- this.value.forEach(item => {
- if (!this.options.some(v=> v.value == item )) this.unmatchArray.push(item)
+ this.value.forEach((item) => {
+ if (!this.options.some((v) => v.value == item))
+ this.unmatchArray.push(item);
});
return true;
}
// 没有value不显示
return false;
},
-
},
filters: {
handleArray(array) {
- if(array.length===0) return '';
+ if (array.length === 0) return "";
return array.reduce((pre, cur) => {
- return pre + ' ' + cur;
+ return pre + " " + cur;
})
- },
+ }
}
};
</script>
diff --git a/ruoyi-ui/src/utils/generator/js.js b/ruoyi-ui/src/utils/generator/js.js
index 35e3e21..ee8668d 100644
--- a/ruoyi-ui/src/utils/generator/js.js
+++ b/ruoyi-ui/src/utils/generator/js.js
@@ -1,4 +1,3 @@
-import { isArray } from 'util'
import { exportDefault, titleCase } from '@/utils/index'
import { trigger } from './config'
@@ -133,12 +132,12 @@
const rules = []
if (trigger[conf.tag]) {
if (conf.required) {
- const type = isArray(conf.defaultValue) ? 'type: \'array\',' : ''
- let message = isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder
+ const type = Array.isArray(conf.defaultValue) ? 'type: \'array\',' : ''
+ let message = Array.isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder
if (message === undefined) message = `${conf.label}不能为空`
rules.push(`{ required: true, ${type} message: '${message}', trigger: '${trigger[conf.tag]}' }`)
}
- if (conf.regList && isArray(conf.regList)) {
+ if (conf.regList && Array.isArray(conf.regList)) {
conf.regList.forEach(item => {
if (item.pattern) {
rules.push(`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${trigger[conf.tag]}' }`)
diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue
index 3772890..b726f7b 100644
--- a/ruoyi-ui/src/views/index.vue
+++ b/ruoyi-ui/src/views/index.vue
@@ -888,7 +888,7 @@
</div>
<div class="body">
<img
- src="https://oscimg.oschina.net/oscnet/up-d6695f82666e5018f715c41cb7ee60d3b73.png"
+ src="http://ruoyi.vip/images/pay.png"
alt="donate"
width="100%"
/>
diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js
index 2506c93..b0f1d75 100644
--- a/ruoyi-ui/vue.config.js
+++ b/ruoyi-ui/vue.config.js
@@ -90,9 +90,7 @@
})
.end()
- config
- .when(process.env.NODE_ENV !== 'development',
- config => {
+ config.when(process.env.NODE_ENV !== 'development', config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
@@ -101,36 +99,36 @@
inline: /runtime\..*\.js$/
}])
.end()
- config
- .optimization.splitChunks({
- chunks: 'all',
- cacheGroups: {
- libs: {
- name: 'chunk-libs',
- test: /[\\/]node_modules[\\/]/,
- priority: 10,
- chunks: 'initial' // only package third parties that are initially dependent
- },
- elementUI: {
- name: 'chunk-elementUI', // split elementUI into a single package
- priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
- test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
- },
- commons: {
- name: 'chunk-commons',
- test: resolve('src/components'), // can customize your rules
- minChunks: 3, // minimum common number
- priority: 5,
- reuseExistingChunk: true
- }
+
+ config.optimization.splitChunks({
+ chunks: 'all',
+ cacheGroups: {
+ libs: {
+ name: 'chunk-libs',
+ test: /[\\/]node_modules[\\/]/,
+ priority: 10,
+ chunks: 'initial' // only package third parties that are initially dependent
+ },
+ elementUI: {
+ name: 'chunk-elementUI', // split elementUI into a single package
+ test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
+ priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
+ },
+ commons: {
+ name: 'chunk-commons',
+ test: resolve('src/components'), // can customize your rules
+ minChunks: 3, // minimum common number
+ priority: 5,
+ reuseExistingChunk: true
}
- })
+ }
+ })
+
config.optimization.runtimeChunk('single'),
{
from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
to: './' //到根目录下
}
- }
- )
+ })
}
}
--
Gitblit v1.9.2