This commit is contained in:
lcw
2026-04-16 15:44:42 +08:00
parent fbf259663b
commit f09a8a0083
6 changed files with 124 additions and 72 deletions

View File

@ -15,10 +15,9 @@
node-key="id"
show-checkbox
default-expand-all
:check-strictly="true"
@check="checkeTree"
/>
:check-strictly="false"
@check="handleCheck"
/>
</div>
<template #footer>
<div class="dialog-footer">
@ -32,7 +31,7 @@
<script setup>
import { ElMessage } from "element-plus";
import { defineProps, watch, ref, onMounted, nextTick } from "vue";
import { defineProps, watch, ref } from "vue";
import {
saveRoleMenuInfo,
getRoleMenuIds,
@ -48,17 +47,31 @@ const props = defineProps({
required: true
}
});
const form = ref({});
const emits = defineEmits(["update:modelValue", "updateRole"]);
const closed = () => {
emits("update:modelValue", false);
};
// 实时记录选中状态
const currentCheckedKeys = ref([]);
const currentHalfCheckedKeys = ref([]);
// 勾选事件,实时记录完全选中 + 半选父节点
const handleCheck = (data, checkInfo) => {
currentCheckedKeys.value = checkInfo.checkedKeys;
currentHalfCheckedKeys.value = checkInfo.halfCheckedKeys;
};
// 提交时合并完全选中 + 半选父节点
const onComfirm = () => {
const checkedKeys = treeRef.value.getCheckedKeys();
const halfCheckedKeys = treeRef.value.getHalfCheckedKeys();
const submitKeys = [...checkedKeys, ...halfCheckedKeys];
let params = {
roleId: Number(props.roleId),
menuIds: treeRef.value.getCheckedKeys().map((item) => Number(item))
menuIds: submitKeys.map((item) => Number(item))
};
saveRoleMenuInfo(params).then((res) => {
ElMessage.success("操作成功");
@ -69,41 +82,23 @@ const onComfirm = () => {
//所有权限
const allPermission = ref([]);
const getPermissionList = async () => {
const res = await getMenuTree({ssxt:'sgxt'});
const res = await getMenuTree({ ssxt: "sgxt" });
allPermission.value = res;
};
getPermissionList();
const treeRef = ref(null);
//属性结构配置
const defaultProps = {
children: "sysMenuList",
label: "menuName"
};
//当前角色权限
//当前角色权限回显
const getRolePermission = async () => {
const checkedKeys = await getRoleMenuIds(props.roleId);
treeRef.value.setCheckedKeys(checkedKeys);
};
// 选中子节点,默认选中父节点
const checkeTree = (data) => {
let thisNode = treeRef.value.getNode(data.id); // 获取当前节点
const keys = treeRef.value.getCheckedKeys(); // 获取已勾选节点的key值
if (thisNode.checked) {
// 当前节点若被选中
for (let i = thisNode.level; i > 1; i--) {
// 判断是否有父级节点
if (!thisNode.parent.checked) {
// 父级节点未被选中则将父节点替换成当前节点往上继续查询并将此节点key存入keys数组
thisNode = thisNode.parent;
// keys.push(thisNode.data.id);
}
}
}
treeRef.value.setCheckedKeys(keys); // 将所有keys数组的节点全选中
};
watch(
() => props.roleId,
(val) => {

View File

@ -294,7 +294,7 @@ const dialogFormVisible = ref(false);
const formLabelWidth = "140px";
// 获取数据的方法
const getListData = async () => {
const params = listQuery.value;
const params = { ...listQuery.value, ssxt: "sgxt" };
params.current = params.page;
const res = await getRoleList(params);
tableData.value = res?.records;
@ -360,7 +360,8 @@ const onSave = () => {
}
buttonLoading.value = true;
updateSysRole({
...dialogForm.value
...dialogForm.value,
ssxt: "sgxt"
})
.then((res) => {
dialogFormVisible.value = false;
@ -382,7 +383,8 @@ const onAdd = () => {
}
buttonLoading.value = true;
addSysRole({
...dialogForm.value
...dialogForm.value,
ssxt: "sgxt"
})
.then((res) => {
dialogFormVisible.value = false;
@ -424,7 +426,7 @@ const allocationUser = (row) => {
};
// 高度计算
const tabHeightFn = () => {
tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
};
onMounted(() => {
tabHeightFn();

View File

@ -3,19 +3,28 @@
<!-- <el-checkbox-group v-model="userRoleTitleList">
<el-checkbox v-for="item in allRoleList" :key="item.id" :label="item.roleName" />
</el-checkbox-group>-->
<el-table max-height="380px" ref="multipleTableRef" :data="allRoleList" style="width: 100%"
@selection-change="handleSelectionChange">
<el-table
max-height="380px"
ref="multipleTableRef"
:data="allRoleList"
style="width: 100%"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column property="orderNo" label="角色编号" />
<el-table-column property="roleName" label="角色名称" />
<el-table-column prop="xtZhxgsj" label="更新时间">
<template #default="{ row }">{{ $filters.dateFilter(row.xtZhxgsj) }}</template>
<template #default="{ row }">{{
$filters.dateFilter(row.xtZhxgsj)
}}</template>
</el-table-column>
</el-table>
<template #footer>
<div class="dialog-footer">
<el-button @click="closed">取消</el-button>
<el-button type="primary" :loading="buttonLoading" @click="onComfirm">保存</el-button>
<el-button type="primary" :loading="buttonLoading" @click="onComfirm"
>保存</el-button
>
</div>
</template>
</el-dialog>
@ -39,13 +48,13 @@ const props = defineProps({
required: true
}
});
const buttonLoading = ref(false)
const buttonLoading = ref(false);
const emits = defineEmits(["update:modelValue", "updateRole"]);
const closed = () => {
emits("update:modelValue", false);
};
const multipleTableRef = ref(null)
const multipleTableRef = ref(null);
const multipleSelection = ref([]);
const handleSelectionChange = (val) => {
@ -83,30 +92,31 @@ const getUserRoles = async () => {
const res = await getUserRoleList(Number(props.userId));
userRoleTitleList.value = res.map((item) => item.id);
const hx = [];
allRoleList.value.forEach(item => {
allRoleList.value.forEach((item) => {
if (userRoleTitleList.value.includes(item.id)) {
hx.push(item)
hx.push(item);
}
})
toggleSelection(hx)
});
toggleSelection(hx);
};
const toggleSelection = (rows) => {
if (rows) {
rows.forEach((row) => {
multipleTableRef.value.toggleRowSelection(row, true)
})
multipleTableRef.value.toggleRowSelection(row, true);
});
} else {
multipleTableRef.value.clearSelection()
multipleTableRef.value.clearSelection();
}
}
};
//所有角色
const allRoleList = ref([]);
const getAllRoleList = async () => {
const params = {
page: 1,
size: 999
size: 999,
ssxt: "sgxt"
};
const res = await getRoleList(params);
allRoleList.value = res?.records;
@ -123,5 +133,4 @@ watch(
);
</script>
<style>
</style>
<style></style>