优化:基于 ESLint 和阿里编码规约插件对部分代码规范进行优化

This commit is contained in:
Charles7c 2023-02-10 20:45:15 +08:00
parent 5251a484f2
commit ebc7c2b3b0
29 changed files with 417 additions and 224 deletions

View File

@ -34,6 +34,8 @@ public interface BaseEnum<V extends Serializable, D extends Serializable> extend
/**
* 枚举描述
*
* @return 枚举描述
*/
D getDescription();
}

View File

@ -81,6 +81,13 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C ext
return BeanUtil.copyProperties(entity, detailVoClass);
}
/**
* 新增
*
* @param request
* 创建信息
* @return 自增 ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public abstract Long create(C request);

View File

@ -16,9 +16,6 @@
package top.charles7c.cnadmin.common.config;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.models.OpenAPI;
@ -29,6 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
@ -50,7 +48,7 @@ public class SwaggerConfiguration {
* 接口文档配置
*/
@Bean
public OpenAPI openAPI() {
public OpenAPI openApi() {
return new OpenAPI().info(
new Info().title(continewAdminProperties.getName() + " 接口文档").version(continewAdminProperties.getVersion())
.description(continewAdminProperties.getDescription()).termsOfService(continewAdminProperties.getUrl())
@ -66,11 +64,8 @@ public class SwaggerConfiguration {
public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
return openApi -> {
if (openApi.getTags() != null) {
openApi.getTags().forEach(tag -> {
Map<String, Object> map = new HashMap<>();
map.put("x-order", RandomUtil.randomInt(0, 100));
tag.setExtensions(map);
});
openApi.getTags()
.forEach(tag -> tag.setExtensions(MapUtil.of("x-order", RandomUtil.randomInt(0, 100))));
}
};
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.cnadmin.common.consts;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import cn.hutool.core.text.CharPool;
/**
* 字符常量
*
* @author Charles7c
* @since 2023/2/10 20:14
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CharConstants implements CharPool {
/**
* 分号
*/
public static final String SEMICOLON = ";";
}

View File

@ -70,7 +70,7 @@ public class IpUtils {
* @return 归属地信息
*/
public static String getHttpCityInfo(String ip) {
if (isInnerIP(ip)) {
if (isInnerIp(ip)) {
return "内网IP";
}
String api = String.format(IP_URL, ip);
@ -86,7 +86,7 @@ public class IpUtils {
* @return 归属地信息
*/
public static String getLocalCityInfo(String ip) {
if (isInnerIP(ip)) {
if (isInnerIp(ip)) {
return "内网IP";
}
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
@ -104,7 +104,7 @@ public class IpUtils {
* IP 地址
* @return 是否为内网 IP
*/
public static boolean isInnerIP(String ip) {
public static boolean isInnerIp(String ip) {
ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
return NetUtil.isInnerIP(ip);
}

View File

@ -19,6 +19,7 @@ package top.charles7c.cnadmin.common.util;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.mail.MessagingException;
@ -33,10 +34,10 @@ import org.springframework.mail.javamail.MimeMessageHelper;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import top.charles7c.cnadmin.common.consts.CharConstants;
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
/**
@ -186,7 +187,7 @@ public class MailUtils {
*/
public static void send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject,
String content, boolean isHtml, File... files) throws MessagingException {
CheckUtils.throwIf(() -> CollUtil.isEmpty(tos), "请至少指定一名收件人");
CheckUtils.throwIfEmpty(tos, "请至少指定一名收件人");
MimeMessage mimeMessage = MAIL_SENDER.createMimeMessage();
MimeMessageHelper messageHelper =
new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.displayName());
@ -228,14 +229,14 @@ public class MailUtils {
*/
private static List<String> splitAddress(String addresses) {
if (StrUtil.isBlank(addresses)) {
return null;
return Collections.emptyList();
}
List<String> result;
if (StrUtil.contains(addresses, CharUtil.COMMA)) {
result = StrUtil.splitTrim(addresses, CharUtil.COMMA);
} else if (StrUtil.contains(addresses, ';')) {
result = StrUtil.splitTrim(addresses, ';');
if (StrUtil.contains(addresses, CharConstants.COMMA)) {
result = StrUtil.splitTrim(addresses, CharConstants.COMMA);
} else if (StrUtil.contains(addresses, CharConstants.SEMICOLON)) {
result = StrUtil.splitTrim(addresses, CharConstants.SEMICOLON);
} else {
result = CollUtil.newArrayList(addresses);
}

View File

@ -205,7 +205,12 @@ public class RedisUtils {
return String.join(":", subKeys);
}
public static NameMapper getNameMapper() {
/**
* 根据集群或单机配置获取名称映射器
*
* @return 名称映射器
*/
private static NameMapper getNameMapper() {
Config config = REDISSON_CLIENT.getConfig();
if (config.isClusterConfig()) {
return config.useClusterServers().getNameMapper();

View File

@ -35,6 +35,54 @@ public class CheckUtils extends Validator {
private static final Class<ServiceException> EXCEPTION_TYPE = ServiceException.class;
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNull(Object obj, String message) {
throwIfNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotNull(Object obj, String message) {
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfEmpty(Object obj, String message) {
throwIfEmpty(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotEmpty(Object obj, String message) {
throwIfNotEmpty(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
@ -115,30 +163,6 @@ public class CheckUtils extends Validator {
throwIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNull(Object obj, String message) {
throwIfNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotNull(Object obj, String message) {
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果条件成立抛出异常
*

View File

@ -35,6 +35,54 @@ public class ValidationUtils extends Validator {
private static final Class<BadRequestException> EXCEPTION_TYPE = BadRequestException.class;
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNull(Object obj, String message) {
throwIfNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotNull(Object obj, String message) {
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfEmpty(Object obj, String message) {
throwIfEmpty(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotEmpty(Object obj, String message) {
throwIfNotEmpty(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
@ -115,30 +163,6 @@ public class ValidationUtils extends Validator {
throwIfNotEqualIgnoreCase(str1, str2, message, EXCEPTION_TYPE);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNull(Object obj, String message) {
throwIfNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
*/
public static void throwIfNotNull(Object obj, String message) {
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果条件成立抛出异常
*

View File

@ -34,6 +34,62 @@ import cn.hutool.core.util.StrUtil;
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Validator {
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> obj == null, message, exceptionType);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> obj != null, message, exceptionType);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> ObjectUtil.isEmpty(obj), message, exceptionType);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> ObjectUtil.isNotEmpty(obj), message, exceptionType);
}
/**
* 如果为空抛出异常
*
@ -132,34 +188,6 @@ public class Validator {
throwIf(() -> !StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
}
/**
* 如果为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> obj == null, message, exceptionType);
}
/**
* 如果不为空抛出异常
*
* @param obj
* 被检测的对象
* @param message
* 错误信息
* @param exceptionType
* 异常类型
*/
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(() -> obj != null, message, exceptionType);
}
/**
* 如果条件成立抛出异常
*

View File

@ -314,7 +314,7 @@ public class LogInterceptor implements HandlerInterceptor {
}
// 2检查是否需要记录内网 IP 操作
boolean isInnerIp = IpUtils.isInnerIP(ServletUtil.getClientIP(request));
boolean isInnerIp = IpUtils.isInnerIp(ServletUtil.getClientIP(request));
if (isInnerIp && Boolean.FALSE.equals(operationLogProperties.getIncludeInnerIp())) {
return false;
}

View File

@ -52,16 +52,16 @@ public class DeptDO extends BaseDO {
*/
private Long parentId;
/**
* 部门排序
*/
private Integer deptSort;
/**
* 描述
*/
private String description;
/**
* 部门排序
*/
private Integer deptSort;
/**
* 状态1启用 2禁用
*/

View File

@ -58,7 +58,7 @@ public class RoleDO extends BaseDO {
private String roleCode;
/**
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
*/
private DataScopeEnum dataScope;

View File

@ -66,9 +66,9 @@ public class RoleRequest extends BaseRequest {
private String roleCode;
/**
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
*/
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)", type = "Integer",
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)", type = "Integer",
allowableValues = {"1", "2", "3", "4", "5"})
private DataScopeEnum dataScope;

View File

@ -61,12 +61,6 @@ public class DeptDetailVO extends BaseDetailVO {
@Schema(description = "上级部门 ID")
private Long parentId;
/**
* 部门排序
*/
@Schema(description = "部门排序")
private Integer deptSort;
/**
* 描述
*/
@ -74,6 +68,12 @@ public class DeptDetailVO extends BaseDetailVO {
@ExcelProperty(value = "描述")
private String description;
/**
* 部门排序
*/
@Schema(description = "部门排序")
private Integer deptSort;
/**
* 状态1启用 2禁用
*/

View File

@ -57,18 +57,18 @@ public class DeptVO extends BaseVO {
@Schema(description = "上级部门 ID")
private Long parentId;
/**
* 部门排序
*/
@Schema(description = "部门排序")
private Integer deptSort;
/**
* 描述
*/
@Schema(description = "描述")
private String description;
/**
* 部门排序
*/
@Schema(description = "部门排序")
private Integer deptSort;
/**
* 状态1启用 2禁用
*/

View File

@ -65,9 +65,9 @@ public class RoleDetailVO extends BaseDetailVO {
private String roleCode;
/**
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
*/
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)")
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)")
@ExcelProperty(value = "数据权限", converter = ExcelBaseEnumConverter.class)
private DataScopeEnum dataScope;

View File

@ -62,9 +62,9 @@ public class RoleVO extends BaseVO {
private String roleCode;
/**
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
* 数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限
*/
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)")
@Schema(description = "数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)")
private DataScopeEnum dataScope;
/**

View File

@ -54,19 +54,6 @@ public interface DeptService extends BaseService<DeptVO, DeptDetailVO, DeptQuery
*/
List<Tree<Long>> buildTree(List<DeptVO> list);
/**
* 检查部门名称是否存在
*
* @param deptName
* 部门名称
* @param parentId
* 上级部门 ID
* @param deptId
* 部门 ID
* @return 是否存在
*/
boolean checkDeptNameExist(String deptName, Long parentId, Long deptId);
/**
* 导出
*

View File

@ -100,7 +100,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
@Transactional(rollbackFor = Exception.class)
public Long create(DeptRequest request) {
String deptName = request.getDeptName();
boolean isExist = this.checkDeptNameExist(deptName, request.getParentId(), null);
boolean isExist = this.checkNameExist(deptName, request.getParentId(), request.getDeptId());
CheckUtils.throwIf(() -> isExist, String.format("新增失败,'%s'已存在", deptName));
// 保存部门信息
@ -110,6 +110,16 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
return deptDO.getDeptId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DeptRequest request) {
String deptName = request.getDeptName();
boolean isExist = this.checkNameExist(deptName, request.getParentId(), request.getDeptId());
CheckUtils.throwIf(() -> isExist, String.format("新增失败,'%s'已存在", deptName));
super.update(request);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List<Long> ids) {
@ -179,12 +189,6 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
});
}
@Override
public boolean checkDeptNameExist(String deptName, Long parentId, Long deptId) {
return baseMapper.exists(Wrappers.<DeptDO>lambdaQuery().eq(DeptDO::getDeptName, deptName)
.eq(DeptDO::getParentId, parentId).ne(deptId != null, DeptDO::getDeptId, deptId));
}
@Override
public void export(DeptQuery query, HttpServletResponse response) {
List<DeptDO> deptList = this.listDept(query);
@ -193,6 +197,22 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
ExcelUtils.export(list, "部门数据", DeptDetailVO.class, response);
}
/**
* 检查名称是否存在
*
* @param deptName
* 部门名称
* @param parentId
* 上级部门 ID
* @param deptId
* 部门 ID
* @return 是否存在
*/
private boolean checkNameExist(String deptName, Long parentId, Long deptId) {
return baseMapper.exists(Wrappers.<DeptDO>lambdaQuery().eq(DeptDO::getDeptName, deptName)
.eq(DeptDO::getParentId, parentId).ne(deptId != null, DeptDO::getDeptId, deptId));
}
/**
* 填充数据
*

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.charles7c.cnadmin.system.mapper.DeptMapper">
</mapper>

View File

@ -10,4 +10,4 @@ export default function listDeptTree(params: DeptParam) {
return qs.stringify(obj);
},
});
}
}

View File

@ -57,7 +57,7 @@ export function listLoginLog(params: LoginLogParam) {
params,
paramsSerializer: (obj) => {
return qs.stringify(obj);
}
},
});
}
@ -78,7 +78,7 @@ export function listOperationLog(params: OperationLogParam) {
params,
paramsSerializer: (obj) => {
return qs.stringify(obj);
}
},
});
}
@ -98,10 +98,10 @@ export function listSystemLog(params: SystemLogParam) {
params,
paramsSerializer: (obj) => {
return qs.stringify(obj);
}
},
});
}
export function getSystemLog(logId: number) {
return axios.get<SystemLogDetailRecord>(`${BASE_URL}/system/${logId}`);
}
}

View File

@ -29,10 +29,10 @@ export function listOnlineUser(params: OnlineUserParam) {
params,
paramsSerializer: (obj) => {
return qs.stringify(obj);
}
},
});
}
export function kickout(token: string) {
return axios.delete(`${BASE_URL}/${token}`);
}
}

View File

@ -56,4 +56,4 @@ export function exportDept(params: DeptParam) {
},
responseType: 'blob',
});
}
}

View File

@ -42,4 +42,4 @@ export interface UpdateEmailReq {
export function updateEmail(req: UpdateEmailReq) {
return axios.patch(`${BASE_URL}/email`, req);
}
}

View File

@ -5,7 +5,7 @@
<!-- 头部区域 -->
<div class="header">
<!-- 搜索栏 -->
<div class="header-query" v-if="showQuery">
<div v-if="showQuery" class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form-item field="deptName" hide-label>
<a-input
@ -45,19 +45,39 @@
<a-button type="primary" @click="toCreate">
<template #icon><icon-plus /></template>新增
</a-button>
<a-button type="primary" status="success" :disabled="single" :title="single ? '请选择一条要修改的数据' : ''" @click="toUpdate(ids[0])">
<a-button
type="primary"
status="success"
:disabled="single"
:title="single ? '请选择一条要修改的数据' : ''"
@click="toUpdate(ids[0])"
>
<template #icon><icon-edit /></template>修改
</a-button>
<a-button type="primary" status="danger" :disabled="multiple" :title="multiple ? '请选择要删除的数据' : ''" @click="handleBatchDelete">
<a-button
type="primary"
status="danger"
:disabled="multiple"
:title="multiple ? '请选择要删除的数据' : ''"
@click="handleBatchDelete"
>
<template #icon><icon-delete /></template>删除
</a-button>
<a-button :loading="exportLoading" type="primary" status="warning" @click="handleExport">
<a-button
:loading="exportLoading"
type="primary"
status="warning"
@click="handleExport"
>
<template #icon><icon-download /></template>导出
</a-button>
</a-space>
</a-col>
<a-col :span="12">
<right-toolbar v-model:show-query="showQuery" @refresh="getList"></right-toolbar>
<right-toolbar
v-model:show-query="showQuery"
@refresh="getList"
/>
</a-col>
</a-row>
</div>
@ -85,10 +105,16 @@
<template #columns>
<a-table-column title="部门名称" data-index="deptName">
<template #cell="{ record }">
<a-link @click="toDetail(record.deptId)">{{ record.deptName }}</a-link>
<a-link @click="toDetail(record.deptId)">{{
record.deptName
}}</a-link>
</template>
</a-table-column>
<a-table-column title="部门排序" align="center" data-index="deptSort" />
<a-table-column
title="部门排序"
align="center"
data-index="deptSort"
/>
<a-table-column title="状态" align="center" data-index="status">
<template #cell="{ record }">
<a-switch
@ -104,11 +130,26 @@
<a-table-column title="创建时间" data-index="createTime" />
<a-table-column title="操作" align="center">
<template #cell="{ record }">
<a-button v-permission="['admin']" type="text" size="small" title="修改" @click="toUpdate(record.deptId)">
<a-button
v-permission="['admin']"
type="text"
size="small"
title="修改"
@click="toUpdate(record.deptId)"
>
<template #icon><icon-edit /></template>修改
</a-button>
<a-popconfirm content="确定要删除当前选中的数据吗?如果存在下级部门则一并删除,此操作不能撤销!" type="warning" @ok="handleDelete([record.deptId])">
<a-button v-permission="['admin']" type="text" size="small" title="删除">
<a-popconfirm
content="确定要删除当前选中的数据吗?如果存在下级部门则一并删除,此操作不能撤销!"
type="warning"
@ok="handleDelete([record.deptId])"
>
<a-button
v-permission="['admin']"
type="text"
size="small"
title="删除"
>
<template #icon><icon-delete /></template>删除
</a-button>
</a-popconfirm>
@ -142,7 +183,11 @@
/>
</a-form-item>
<a-form-item label="部门名称" field="deptName">
<a-input v-model="form.deptName" placeholder="请输入部门名称" size="large" />
<a-input
v-model="form.deptName"
placeholder="请输入部门名称"
size="large"
/>
</a-form-item>
<a-form-item label="部门排序" field="deptSort">
<a-input-number
@ -159,7 +204,7 @@
:max-length="200"
placeholder="请输入描述"
:auto-size="{
minRows:3,
minRows: 3,
}"
show-word-limit
size="large"
@ -178,12 +223,7 @@
render-to-body
@cancel="handleDetailCancel"
>
<a-descriptions
title="基础信息"
:column="2"
bordered
size="large"
>
<a-descriptions title="基础信息" :column="2" bordered size="large">
<a-descriptions-item label="部门名称">
<a-skeleton v-if="detailLoading" :animation="true">
<a-skeleton-line :rows="1" />
@ -201,8 +241,12 @@
<a-skeleton-line :rows="1" />
</a-skeleton>
<span v-else>
<a-tag v-if="dept.status === 1" color="green"><span class="circle pass"></span>启用</a-tag>
<a-tag v-else color="red"><span class="circle fail"></span>禁用</a-tag>
<a-tag v-if="dept.status === 1" color="green">
<span class="circle pass"></span>启用
</a-tag>
<a-tag v-else color="red">
<span class="circle fail"></span>禁用
</a-tag>
</span>
</a-descriptions-item>
<a-descriptions-item label="部门排序">
@ -315,14 +359,16 @@
*/
const getList = (params: DeptParam = { ...queryParams.value }) => {
loading.value = true;
listDept(params).then((res) => {
deptList.value = res.data;
setTimeout(() => {
proxy.$refs.tableRef.expandAll();
}, 0);
}).finally(() => {
loading.value = false;
});
listDept(params)
.then((res) => {
deptList.value = res.data;
setTimeout(() => {
proxy.$refs.tableRef.expandAll();
}, 0);
})
.finally(() => {
loading.value = false;
});
};
getList();
@ -410,11 +456,13 @@
if (detailLoading.value) return;
detailLoading.value = true;
detailVisible.value = true;
getDept(id).then((res) => {
dept.value = res.data;
}).finally(() => {
detailLoading.value = false;
});
getDept(id)
.then((res) => {
dept.value = res.data;
})
.finally(() => {
detailLoading.value = false;
});
};
/**
@ -434,7 +482,8 @@
proxy.$modal.warning({
title: '警告',
titleAlign: 'start',
content: '确定要删除当前选中的数据吗?如果存在下级部门则一并删除,此操作不能撤销!',
content:
'确定要删除当前选中的数据吗?如果存在下级部门则一并删除,此操作不能撤销!',
hideCancel: false,
onOk: () => {
handleDelete(ids.value);
@ -472,37 +521,43 @@
const handleExport = () => {
if (exportLoading.value) return;
exportLoading.value = true;
exportDept({ ...queryParams.value }).then(async(res) => {
const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'});
const contentDisposition = res.headers['content-disposition']
const pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const result = pattern.exec(contentDisposition) || '';
//
const fileName = window.decodeURI(result[1])
//
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob);
downloadElement.style.display = 'none';
downloadElement.href = href;
//
downloadElement.download = fileName;
document.body.appendChild(downloadElement);
//
downloadElement.click();
//
document.body.removeChild(downloadElement);
// blob
window.URL.revokeObjectURL(href);
}).catch(() => {
proxy.$notification.warning({
title: '警告',
content: "如果您正在访问演示环境,点击导出会报错。这是由于演示环境开启了 Mock.js而 Mock.js 会将 responseType 设置为 '',这不仅会导致关键判断出错,也会导致导出的文件无法打开。",
duration: 10000,
closable: true,
exportDept({ ...queryParams.value })
.then(async (res) => {
const blob = new Blob([res.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
});
const contentDisposition = res.headers['content-disposition'];
const pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
const result = pattern.exec(contentDisposition) || '';
//
const fileName = window.decodeURI(result[1]);
//
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob);
downloadElement.style.display = 'none';
downloadElement.href = href;
//
downloadElement.download = fileName;
document.body.appendChild(downloadElement);
//
downloadElement.click();
//
document.body.removeChild(downloadElement);
// blob
window.URL.revokeObjectURL(href);
})
.catch(() => {
proxy.$notification.warning({
title: '警告',
content:
"如果您正在访问演示环境,点击导出会报错。这是由于演示环境开启了 Mock.js而 Mock.js 会将 responseType 设置为 '',这不仅会导致关键判断出错,也会导致导出的文件无法打开。",
duration: 10000,
closable: true,
});
})
.finally(() => {
exportLoading.value = false;
});
}).finally(() => {
exportLoading.value = false;
});
};
/**
@ -512,11 +567,13 @@
*/
const handleChangeStatus = (record: DeptRecord) => {
const tip = record.status === 1 ? '启用' : '禁用';
updateDept(record).then((res) => {
proxy.$message.success(`${tip}成功`);
}).catch(() => {
record.status = (record.status === 1) ? 2 : 1;
});
updateDept(record)
.then((res) => {
proxy.$message.success(`${tip}成功`);
})
.catch(() => {
record.status = record.status === 1 ? 2 : 1;
});
};
/**
@ -527,7 +584,9 @@
*/
const filterDeptTree = (searchValue: string, nodeData: TreeNodeData) => {
if (nodeData.title) {
return nodeData.title.toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
return (
nodeData.title.toLowerCase().indexOf(searchValue.toLowerCase()) > -1
);
}
return false;
};

View File

@ -115,7 +115,7 @@
<span v-else-if="record.dataScope === 2">本部门及以下数据权限</span>
<span v-else-if="record.dataScope === 3">本部门数据权限</span>
<span v-else-if="record.dataScope === 4">仅本人数据权限</span>
<span v-else>自定数据权限</span>
<span v-else>自定数据权限</span>
</template>
</a-table-column>
<a-table-column
@ -290,7 +290,7 @@
<span v-else-if="role.dataScope === 2">本部门及以下数据权限</span>
<span v-else-if="role.dataScope === 3">本部门数据权限</span>
<span v-else-if="role.dataScope === 4">仅本人数据权限</span>
<span v-else>自定数据权限</span>
<span v-else>自定数据权限</span>
</span>
</a-descriptions-item>
<a-descriptions-item label="创建人">
@ -394,7 +394,7 @@
{ label: '本部门及以下数据权限', value: 2 },
{ label: '本部门数据权限', value: 3 },
{ label: '仅本人数据权限', value: 4 },
{ label: '自定数据权限', value: 5 },
{ label: '自定数据权限', value: 5 },
]);
const treeData = ref<TreeNodeData[]>();

View File

@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `sys_role` (
`role_id` bigint(20) unsigned AUTO_INCREMENT COMMENT '角色ID',
`role_name` varchar(255) NOT NULL COMMENT '角色名称',
`role_code` varchar(255) DEFAULT NULL COMMENT '角色编码',
`data_scope` tinyint(1) DEFAULT 4 COMMENT '数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)',
`data_scope` tinyint(1) DEFAULT 4 COMMENT '数据权限1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)',
`data_scope_dept_ids` json DEFAULT NULL COMMENT '数据权限范围部门ID数组',
`description` varchar(512) DEFAULT NULL COMMENT '描述',
`role_sort` int(11) unsigned DEFAULT 999 COMMENT '角色排序',