refactor(role-edit): 优化菜单树选择和角色关联逻辑
- 将菜单树的 `checkbox-config` 配置改为严格模式 - 添加 `relationTypes` 变量以明确关联类型 - 在菜单服务中优化 SQL 查询逻辑,根据 `roleId` 动态构建条件
This commit is contained in:
parent
e0781b0f8c
commit
408e02e38d
@ -131,12 +131,24 @@ public class MenuService {
|
|||||||
public Flux<Map<String, Object>> getRelation(String table, Map<String, Object> params, Pageable pageable) {
|
public Flux<Map<String, Object>> getRelation(String table, Map<String, Object> params, Pageable pageable) {
|
||||||
return SecurityUtils.getCurrentUserLogin()
|
return SecurityUtils.getCurrentUserLogin()
|
||||||
.flatMapMany(login -> {
|
.flatMapMany(login -> {
|
||||||
|
// 构建基础SQL查询
|
||||||
|
String conditionSql =
|
||||||
|
"(select GROUP_CONCAT(data_scope, ',') from jhi_relation where jhi_relation.relation_type = 'menu' and jhi_relation.number = jhi_menu.number";
|
||||||
|
|
||||||
|
// 根据roleId[value]是否存在构建不同的条件部分,设置完整的SQL查询
|
||||||
params.put(
|
params.put(
|
||||||
"dataScope[field]",
|
"dataScope[field]",
|
||||||
"(select GROUP_CONCAT(data_scope, ',') from jhi_relation where jhi_relation.relation_type = 'menu' and jhi_relation.number = jhi_menu.number and exists(select 1 from jhi_relation r where r.role_number = jhi_relation.role_number and relation_type = 'user' and number = '" +
|
params.get("roleId[value]") == null
|
||||||
|
? conditionSql +
|
||||||
|
" and exists(select 1 from jhi_relation r where r.role_number = jhi_relation.role_number and relation_type = 'user' and number = '" +
|
||||||
login +
|
login +
|
||||||
"'))"
|
"'))"
|
||||||
|
: conditionSql +
|
||||||
|
" and exists(select 1 from jhi_role where number = jhi_relation.role_number and id = " +
|
||||||
|
params.get("roleId[value]").toString() +
|
||||||
|
"))"
|
||||||
);
|
);
|
||||||
|
|
||||||
return getTree(table, params, pageable);
|
return getTree(table, params, pageable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ export default defineComponent({
|
|||||||
const statusDicts = ref([]);
|
const statusDicts = ref([]);
|
||||||
const menuTreeData = ref([]);
|
const menuTreeData = ref([]);
|
||||||
const checkNodeKeys = ref([]);
|
const checkNodeKeys = ref([]);
|
||||||
|
const relationTypes = ref('menu');
|
||||||
const roleForm = ref<VxeFormInstance>();
|
const roleForm = ref<VxeFormInstance>();
|
||||||
const formRules = {
|
const formRules = {
|
||||||
number: [{ required: true, message: $t('entity.validation.required') }],
|
number: [{ required: true, message: $t('entity.validation.required') }],
|
||||||
@ -59,6 +60,7 @@ export default defineComponent({
|
|||||||
name: { name: 'title' },
|
name: { name: 'title' },
|
||||||
icon: { name: '' },
|
icon: { name: '' },
|
||||||
dataScope: { name: '' },
|
dataScope: { name: '' },
|
||||||
|
roleId: { value: route.params?.id },
|
||||||
parentNumber: { op: 'IFNULL', value: '' },
|
parentNumber: { op: 'IFNULL', value: '' },
|
||||||
status: { op: '=', value: '1' },
|
status: { op: '=', value: '1' },
|
||||||
},
|
},
|
||||||
@ -141,7 +143,7 @@ export default defineComponent({
|
|||||||
// 创建一个包含所有菜单编号的关联对象
|
// 创建一个包含所有菜单编号的关联对象
|
||||||
const relation = {
|
const relation = {
|
||||||
number: checkNodeKeys.value.join(','), // 将所有菜单编号合并为一个逗号分隔的字符串
|
number: checkNodeKeys.value.join(','), // 将所有菜单编号合并为一个逗号分隔的字符串
|
||||||
relationType: 'menu',
|
relationType: relationTypes.value,
|
||||||
roleNumber: role.value.number,
|
roleNumber: role.value.number,
|
||||||
status: '1',
|
status: '1',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -62,7 +62,7 @@
|
|||||||
ref="menuTree"
|
ref="menuTree"
|
||||||
v-model:check-node-keys="checkNodeKeys"
|
v-model:check-node-keys="checkNodeKeys"
|
||||||
:data="menuTreeData"
|
:data="menuTreeData"
|
||||||
:checkbox-config="{ checkStrictly: false }"
|
:checkbox-config="{ checkStrictly: true }"
|
||||||
trigger="node"
|
trigger="node"
|
||||||
key-field="number"
|
key-field="number"
|
||||||
show-overflow
|
show-overflow
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user