1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 23:11:24 +08:00

Added regex search in RoleManagement

This commit is contained in:
2023-06-04 03:47:46 +08:00
parent 424a6eb330
commit 20fe3a6fa2
6 changed files with 61 additions and 13 deletions

View File

@@ -44,10 +44,10 @@ public class RoleController {
@Operation(summary = "获取所有角色") @Operation(summary = "获取所有角色")
@GetMapping @GetMapping
@PreAuthorize("hasAuthority('system:role:get')") @PreAuthorize("hasAuthority('system:role:get')")
public ResponseResult<IPage<Role>> getAllRole(Long currentPage, Long pageSize, String searchName, String searchPower, Integer searchEnable) { public ResponseResult<IPage<Role>> getAllRole(Long currentPage, Long pageSize, String searchName, String searchPower, Integer searchEnable, Integer searchRegex) {
List<Long> searchPowerList = WebUtil.convertStringToList(searchPower, Long.class); List<Long> searchPowerList = WebUtil.convertStringToList(searchPower, Long.class);
IPage<Role> roles = roleService.getAllRole(currentPage, pageSize, searchName, searchPowerList, searchEnable); IPage<Role> roles = roleService.getAllRole(currentPage, pageSize, searchName, searchPowerList, searchEnable, searchRegex);
return ResponseResult.databaseSelectSuccess(roles); return ResponseResult.databaseSelectSuccess(roles);
} }

View File

@@ -17,7 +17,7 @@ import java.util.List;
*/ */
@Mapper @Mapper
public interface RoleMapper extends BaseMapper<Role> { public interface RoleMapper extends BaseMapper<Role> {
List<Long> filterRoleByPowerId(@Param("roleList") List<Long> roleList, @Param("powerId") Long powerId, String searchName, Integer searchEnable); List<Long> filterRoleByPowerId(@Param("roleList") List<Long> roleList, @Param("powerId") Long powerId, @Param("searchName") String searchName, @Param("searchEnable") Integer searchEnable, @Param("searchRegex") Integer searchRegex);
List<Role> getAll(@Param("roleList") List<Role> roleList); List<Role> getAll(@Param("roleList") List<Role> roleList);

View File

@@ -15,7 +15,7 @@ import java.util.List;
* @since 2023-04-30 * @since 2023-04-30
*/ */
public interface IRoleService extends IService<Role> { public interface IRoleService extends IService<Role> {
IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable); IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable, Integer searchRegex);
Role getRole(long id); Role getRole(long id);

View File

@@ -44,13 +44,13 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
} }
@Override @Override
public IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable) { public IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable, Integer searchRegex) {
IPage<Role> roleIPage = PageDTO.of(currentPage, pageSize); IPage<Role> roleIPage = PageDTO.of(currentPage, pageSize);
searchName = searchName.trim(); searchName = searchName.trim();
List<Long> roleList = roleMapper.filterRoleByPowerId(null, null, searchName, searchEnable); List<Long> roleList = roleMapper.filterRoleByPowerId(null, null, searchName, searchEnable, searchRegex);
if (roleList.size() > 0) { if (roleList.size() > 0) {
for (Long powerId : searchPower) { for (Long powerId : searchPower) {
roleList = roleMapper.filterRoleByPowerId(roleList, powerId, null, null); roleList = roleMapper.filterRoleByPowerId(roleList, powerId, null, null, null);
if (roleList.size() == 0) { if (roleList.size() == 0) {
break; break;
} }

View File

@@ -16,8 +16,13 @@
#{item} #{item}
</foreach> </foreach>
<if test="searchName != null and searchName != ''"> <if test="searchName != null and searchName != ''">
<if test="searchRegex == 1">
and t_role.name regexp #{searchName}
</if>
<if test="searchRegex != 1">
and instr(t_role.name, #{searchName}) > 0 and instr(t_role.name, #{searchName}) > 0
</if> </if>
</if>
<if test="searchEnable != null and searchEnable != -1"> <if test="searchEnable != null and searchEnable != -1">
and t_role.enable = #{searchEnable} and t_role.enable = #{searchEnable}
</if> </if>

View File

@@ -24,14 +24,29 @@
</el-button> </el-button>
</el-col> </el-col>
<el-col :span="5"> <el-col :span="5">
<el-form-item label="名称" class="fill-with"> <el-form-item
label="名称"
class="fill-with"
:error="isRegexLegal ? '' : '非法正则表达式'"
>
<el-input <el-input
v-model="inputName" v-model="inputName"
maxlength="20" maxlength="20"
show-word-limit show-word-limit
placeholder="请输入内容" placeholder="请输入内容"
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
>
<template #suffix>
<el-tooltip content="正则表达式">
<el-checkbox
v-model="checkedRegex"
label=".*"
:true-label="1"
@change="handleInputChange"
/> />
</el-tooltip>
</template>
</el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="9"> <el-col :span="9">
@@ -161,10 +176,13 @@ export default {
dialogLoading: true, dialogLoading: true,
powerOptions: [], powerOptions: [],
searchName: '', searchName: '',
searchPower: [],
searchEnable: -1,
inputName: '', inputName: '',
searchRegex: 0,
checkedRegex: 0,
isRegexLegal: true,
searchPower: [],
selectedPower: [], selectedPower: [],
searchEnable: -1,
selectedEnable: -1, selectedEnable: -1,
currentPage: 1, currentPage: 1,
pageSize: 50, pageSize: 50,
@@ -204,6 +222,13 @@ export default {
}, },
methods: { methods: {
loadRoleTable() { loadRoleTable() {
if (!this.isRegexLegal) {
ElMessage.error({
dangerouslyUseHTMLString: true,
message: '<strong>非法正则表达式</strong>,请重新输入'
})
return
}
this.tableLoading = true this.tableLoading = true
request request
.get('/role', { .get('/role', {
@@ -211,7 +236,8 @@ export default {
pageSize: this.pageSize, pageSize: this.pageSize,
searchName: this.searchName, searchName: this.searchName,
searchPower: this.searchPower + '', searchPower: this.searchPower + '',
searchEnable: this.searchEnable searchEnable: this.searchEnable,
searchRegex: this.searchRegex ?? 0
}) })
.then((res) => { .then((res) => {
const response = res.data const response = res.data
@@ -430,16 +456,33 @@ export default {
}, },
handleQuery() { handleQuery() {
this.searchName = _.cloneDeep(this.inputName) this.searchName = _.cloneDeep(this.inputName)
this.searchRegex = _.cloneDeep(this.checkedRegex)
this.searchPower = _.cloneDeep(this.selectedPower) this.searchPower = _.cloneDeep(this.selectedPower)
this.searchEnable = _.cloneDeep(this.selectedEnable) this.searchEnable = _.cloneDeep(this.selectedEnable)
this.currentPage = 1 this.currentPage = 1
this.handleInputChange()
this.loadRoleTable() this.loadRoleTable()
}, },
handleClear() { handleClear() {
this.inputName = '' this.inputName = ''
this.checkedRegex = 0
this.selectedPower = [] this.selectedPower = []
this.selectedEnable = -1 this.selectedEnable = -1
this.handleQuery() this.handleQuery()
},
handleInputChange() {
if (this.checkedRegex) {
try {
RegExp(this.inputName)
this.isRegexLegal = !(
this.inputName.includes('{}') || this.inputName.includes('[]')
)
} catch (e) {
this.isRegexLegal = false
}
} else {
this.isRegexLegal = true
}
} }
}, },
mounted() { mounted() {