优化代码

This commit is contained in:
RuoYi 2023-06-24 10:57:05 +08:00
parent a63eec3be4
commit 9e66ada9c1
7 changed files with 77 additions and 48 deletions

View File

@ -1,6 +1,7 @@
package com.ruoyi.common.core.domain; package com.ruoyi.common.core.domain;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
@ -169,6 +170,36 @@ public class AjaxResult extends HashMap<String, Object>
return new AjaxResult(code, msg, null); return new AjaxResult(code, msg, null);
} }
/**
* 是否为成功消息
*
* @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));
}
/** /**
* 方便链式调用 * 方便链式调用
* *

View File

@ -66,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
} }
/** /**
* 获取类型 4伪随机生成的UUID 的静态工厂 使用加密的本地线程伪随机数生成器生成该 UUID * 获取类型 4伪随机生成的UUID 的静态工厂
* *
* @return 随机生成的 {@code UUID} * @return 随机生成的 {@code UUID}
*/ */

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; 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.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysMenuService; import com.ruoyi.system.service.ISysMenuService;
@ -62,7 +63,7 @@ public class SysPermissionService
else else
{ {
List<SysRole> roles = user.getRoles(); List<SysRole> roles = user.getRoles();
if (!roles.isEmpty() && roles.size() > 1) if (!CollectionUtils.isEmpty(roles))
{ {
// 多角色设置permissions属性以便数据权限匹配权限 // 多角色设置permissions属性以便数据权限匹配权限
for (SysRole role : roles) for (SysRole role : roles)

View File

@ -7,7 +7,7 @@
:key="item.value" :key="item.value"
:index="index" :index="index"
:class="item.raw.cssClass" :class="item.raw.cssClass"
>{{ item.label + ' ' }}</span >{{ item.label + " " }}</span
> >
<el-tag <el-tag
v-else v-else
@ -17,7 +17,7 @@
:type="item.raw.listClass == 'primary' ? '' : item.raw.listClass" :type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
:class="item.raw.cssClass" :class="item.raw.cssClass"
> >
{{ item.label + ' ' }} {{ item.label + " " }}
</el-tag> </el-tag>
</template> </template>
</template> </template>
@ -49,39 +49,39 @@ export default {
}, },
computed: { computed: {
values() { 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)]; return Array.isArray(this.value) ? this.value : [String(this.value)];
} else { } else {
return []; return [];
} }
}, },
unmatch(){ unmatch() {
this.unmatchArray = []; this.unmatchArray = [];
if (this.value !== null && typeof this.value !== 'undefined') { if (this.value !== null && typeof this.value !== "undefined") {
// //
if(!Array.isArray(this.value)){ if (!Array.isArray(this.value)) {
if(this.options.some(v=> v.value == this.value )) return false; if (this.options.some((v) => v.value == this.value)) return false;
this.unmatchArray.push(this.value); this.unmatchArray.push(this.value);
return true; return true;
} }
// Array // Array
this.value.forEach(item => { this.value.forEach((item) => {
if (!this.options.some(v=> v.value == item )) this.unmatchArray.push(item) if (!this.options.some((v) => v.value == item))
this.unmatchArray.push(item);
}); });
return true; return true;
} }
// value // value
return false; return false;
}, },
}, },
filters: { filters: {
handleArray(array) { handleArray(array) {
if(array.length===0) return ''; if (array.length === 0) return "";
return array.reduce((pre, cur) => { return array.reduce((pre, cur) => {
return pre + ' ' + cur; return pre + " " + cur;
}) })
}, }
} }
}; };
</script> </script>

View File

@ -1,4 +1,3 @@
import { isArray } from 'util'
import { exportDefault, titleCase } from '@/utils/index' import { exportDefault, titleCase } from '@/utils/index'
import { trigger } from './config' import { trigger } from './config'
@ -133,12 +132,12 @@ function buildRules(conf, ruleList) {
const rules = [] const rules = []
if (trigger[conf.tag]) { if (trigger[conf.tag]) {
if (conf.required) { if (conf.required) {
const type = isArray(conf.defaultValue) ? 'type: \'array\',' : '' const type = Array.isArray(conf.defaultValue) ? 'type: \'array\',' : ''
let message = isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder let message = Array.isArray(conf.defaultValue) ? `请至少选择一个${conf.vModel}` : conf.placeholder
if (message === undefined) message = `${conf.label}不能为空` if (message === undefined) message = `${conf.label}不能为空`
rules.push(`{ required: true, ${type} message: '${message}', trigger: '${trigger[conf.tag]}' }`) 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 => { conf.regList.forEach(item => {
if (item.pattern) { if (item.pattern) {
rules.push(`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${trigger[conf.tag]}' }`) rules.push(`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${trigger[conf.tag]}' }`)

View File

@ -888,7 +888,7 @@
</div> </div>
<div class="body"> <div class="body">
<img <img
src="https://oscimg.oschina.net/oscnet/up-d6695f82666e5018f715c41cb7ee60d3b73.png" src="http://ruoyi.vip/images/pay.png"
alt="donate" alt="donate"
width="100%" width="100%"
/> />

View File

@ -90,9 +90,7 @@ module.exports = {
}) })
.end() .end()
config config.when(process.env.NODE_ENV !== 'development', config => {
.when(process.env.NODE_ENV !== 'development',
config => {
config config
.plugin('ScriptExtHtmlWebpackPlugin') .plugin('ScriptExtHtmlWebpackPlugin')
.after('html') .after('html')
@ -101,36 +99,36 @@ module.exports = {
inline: /runtime\..*\.js$/ inline: /runtime\..*\.js$/
}]) }])
.end() .end()
config
.optimization.splitChunks({ config.optimization.splitChunks({
chunks: 'all', chunks: 'all',
cacheGroups: { cacheGroups: {
libs: { libs: {
name: 'chunk-libs', name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/, test: /[\\/]node_modules[\\/]/,
priority: 10, priority: 10,
chunks: 'initial' // only package third parties that are initially dependent chunks: 'initial' // only package third parties that are initially dependent
}, },
elementUI: { elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package 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
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: { commons: {
name: 'chunk-commons', name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number minChunks: 3, // minimum common number
priority: 5, priority: 5,
reuseExistingChunk: true reuseExistingChunk: true
}
} }
}) }
})
config.optimization.runtimeChunk('single'), config.optimization.runtimeChunk('single'),
{ {
from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件 from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
to: './' //到根目录下 to: './' //到根目录下
} }
} })
)
} }
} }