mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
feat: 职位权限分配页改用公司可见树,权限表单加父级/排序字段
- 职位权限分配页:加载 getCompanyVisiblePermissionTreeApi(按公司过滤) - 公司权限分配页:改为加载全量树(不用 visible tree) - TreeNodeContent 组件独立到 components 目录 - PermissionController: /permission/tree/company 去掉 URL 参数,从 currentUserContext 取 companyId - 后端新增 BatchSortPermissionDTO - PermissionMapper 新增 batchUpdateSortOrder
This commit is contained in:
+10
@@ -9,6 +9,7 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.BatchSortPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.UpdatePermissionDTO;
|
||||
@@ -119,4 +120,13 @@ public class PermissionController {
|
||||
List<PermissionVO> tree = permissionService.getSystemPermissionTree();
|
||||
return ApiResponse.success(tree);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量更新权限排序")
|
||||
@PutMapping("/sort")
|
||||
@RequirePermission(value = "system:permission:update", description = "批量更新权限排序", allowSuper = true)
|
||||
public ApiResponse<Void> batchSortPermission(
|
||||
@RequestBody @Valid BatchSortPermissionDTO dto) {
|
||||
permissionService.batchSortPermission(dto);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.sys.permission.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.BatchSortPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.po.PermissionPO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,4 +33,10 @@ public interface PermissionMapper extends BaseMapper<PermissionPO> {
|
||||
* @return 所有祖先ID列表
|
||||
*/
|
||||
List<Long> selectAncestorPermissionIds(@Param("permissionId") Long permissionId);
|
||||
|
||||
/**
|
||||
* 批量更新权限排序
|
||||
* @param sortItems 排序项列表
|
||||
*/
|
||||
void batchUpdateSortOrder(@Param("sortItems") List<BatchSortPermissionDTO.SortItem> sortItems);
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量权限排序DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BatchSortPermissionDTO {
|
||||
|
||||
@NotNull(message = "排序项列表不能为空")
|
||||
private List<SortItem> sortItems;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class SortItem {
|
||||
|
||||
@NotNull(message = "权限ID不能为空")
|
||||
private Long permissionId;
|
||||
|
||||
@NotNull(message = "排序值不能为空")
|
||||
private Integer sortOrder;
|
||||
}
|
||||
}
|
||||
+6
@@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.sys.permission.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.BatchSortPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.UpdatePermissionDTO;
|
||||
@@ -78,4 +79,9 @@ public interface PermissionService {
|
||||
* 获取系统权限树(只返回系统管理模块下的权限,用于平台超管查看)
|
||||
*/
|
||||
List<PermissionVO> getSystemPermissionTree();
|
||||
|
||||
/**
|
||||
* 批量更新权限排序
|
||||
*/
|
||||
void batchSortPermission(BatchSortPermissionDTO dto);
|
||||
}
|
||||
|
||||
+9
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
@@ -12,6 +13,7 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.permission.service.CompanyPermissionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.service.PositionPermissionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.mapper.PermissionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.BatchSortPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.UpdatePermissionDTO;
|
||||
@@ -26,6 +28,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* 权限服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionPO> implements PermissionService {
|
||||
|
||||
@@ -244,6 +247,12 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
return getPermissionTree();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchSortPermission(BatchSortPermissionDTO dto) {
|
||||
log.info("批量权限排序,数量:{}", dto.getSortItems().size());
|
||||
permissionMapper.batchUpdateSortOrder(dto.getSortItems());
|
||||
}
|
||||
|
||||
private PermissionVO convertToVO(PermissionPO po) {
|
||||
PermissionVO vo = new PermissionVO();
|
||||
BeanUtils.copyProperties(po, vo);
|
||||
|
||||
@@ -37,4 +37,19 @@
|
||||
SELECT id FROM ancestor_tree
|
||||
</select>
|
||||
|
||||
<!-- 批量更新权限排序 -->
|
||||
<update id="batchUpdateSortOrder">
|
||||
UPDATE sys_permission
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
sort_order =
|
||||
<foreach collection="sortItems" item="item" separator=" " open="CASE id " close="END">
|
||||
WHEN #{item.permissionId} THEN #{item.sortOrder}
|
||||
</foreach>
|
||||
</trim>
|
||||
WHERE id IN
|
||||
<foreach collection="sortItems" item="item" open="(" separator="," close=")">
|
||||
#{item.permissionId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
+125
-183
@@ -2,14 +2,13 @@
|
||||
import type { PositionVO } from '#/api/organization/position/types';
|
||||
import type { PermissionVO } from '#/api/system/permission/types';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
Flex,
|
||||
Input,
|
||||
message,
|
||||
@@ -17,16 +16,16 @@ import {
|
||||
Select,
|
||||
Spin,
|
||||
Tag,
|
||||
Tree,
|
||||
} from 'ant-design-vue';
|
||||
import { unrefElement } from '@vueuse/core';
|
||||
|
||||
import { getPositionPageApi } from '#/api/organization/position';
|
||||
import {
|
||||
batchUpdatePositionPermissionsApi,
|
||||
getPositionPermissionIdsApi,
|
||||
} from '#/api/organization/position-permission-assign/apis';
|
||||
import { getPermissionTreeApi } from '#/api/system/permission';
|
||||
import { getCompanyVisiblePermissionTreeApi } from '#/api/system/permission';
|
||||
|
||||
import TreeNodeContent from '#/views/system/company-permission-manage/components/TreeNodeContent.vue';
|
||||
|
||||
defineOptions({ name: 'PositionPermissionAssignPage' });
|
||||
|
||||
@@ -45,12 +44,27 @@ const currentPosition = ref<null | PositionVO.PositionInfoVO>(null);
|
||||
const permissionTree = ref<PermissionVO.PermissionInfoVO[]>([]);
|
||||
const permissionLoading = ref(false);
|
||||
|
||||
// 当前岗位已分配的权限ID
|
||||
// 职位原始已分配的权限ID
|
||||
const assignedPermissionIds = ref<number[]>([]);
|
||||
// 用户当前选中的权限ID
|
||||
const selectedPermissionIds = ref<number[]>([]);
|
||||
|
||||
// Ant Design Tree 的选中 key(只存叶子节点)
|
||||
const checkedKeys = ref<number[]>([]);
|
||||
// 展开状态
|
||||
const expandedIds = ref<Set<number>>(new Set());
|
||||
|
||||
// 统计
|
||||
const stats = computed(() => ({
|
||||
total: countLeafPermissions(permissionTree.value),
|
||||
assigned: assignedPermissionIds.value.length,
|
||||
selected: selectedPermissionIds.value.length,
|
||||
changed: !sameArray(selectedPermissionIds.value, assignedPermissionIds.value),
|
||||
}));
|
||||
|
||||
function sameArray(a: number[], b: number[]): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
const sa = new Set(a);
|
||||
return b.every((id) => sa.has(id));
|
||||
}
|
||||
|
||||
// 搜索职位列表
|
||||
async function searchPositions() {
|
||||
@@ -70,23 +84,14 @@ async function searchPositions() {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载权限树
|
||||
async function loadPermissionTree() {
|
||||
permissionLoading.value = true;
|
||||
try {
|
||||
const result = await getPermissionTreeApi();
|
||||
permissionTree.value = result || [];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取权限树失败');
|
||||
} finally {
|
||||
permissionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 选择职位
|
||||
// 选择职位(切换公司时重载权限树,同公司内只更新已选状态)
|
||||
async function selectPosition(position: PositionVO.PositionInfoVO) {
|
||||
const isCompanyChanged = currentPosition.value?.companyId !== position.companyId;
|
||||
currentPosition.value = position;
|
||||
await loadAssignedPermissions();
|
||||
if (isCompanyChanged) {
|
||||
await loadPermissionTree();
|
||||
}
|
||||
}
|
||||
|
||||
// 加载职位已分配的权限ID
|
||||
@@ -97,8 +102,6 @@ async function loadAssignedPermissions() {
|
||||
const result = await getPositionPermissionIdsApi(currentPosition.value.id);
|
||||
assignedPermissionIds.value = result || [];
|
||||
selectedPermissionIds.value = [...assignedPermissionIds.value];
|
||||
// Tree 组件的 checkedKeys 直接用数字
|
||||
checkedKeys.value = [...assignedPermissionIds.value];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取职位权限失败');
|
||||
} finally {
|
||||
@@ -106,80 +109,94 @@ async function loadAssignedPermissions() {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存权限分配
|
||||
// 加载权限树(公司的可见权限树,职位只能分配公司已有的权限)
|
||||
async function loadPermissionTree() {
|
||||
if (!currentPosition.value?.companyId) return;
|
||||
try {
|
||||
const result = await getCompanyVisiblePermissionTreeApi();
|
||||
permissionTree.value = result || [];
|
||||
expandedIds.value = new Set(result?.map((n: PermissionVO.PermissionInfoVO) => n.id) || []);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取权限树失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存权限分配(只保存叶子权限节点,模块节点仅作视觉分组)
|
||||
async function savePermissions() {
|
||||
if (!currentPosition.value?.id) return;
|
||||
// 过滤掉模块节点,只保留叶子权限
|
||||
const leafIds = selectedPermissionIds.value.filter((id) => {
|
||||
const node = findNode(permissionTree.value, id);
|
||||
return node && (!node.children || node.children.length === 0);
|
||||
});
|
||||
try {
|
||||
await batchUpdatePositionPermissionsApi(currentPosition.value.id, selectedPermissionIds.value);
|
||||
await batchUpdatePositionPermissionsApi(currentPosition.value.id, leafIds);
|
||||
message.success('权限分配保存成功');
|
||||
assignedPermissionIds.value = [...selectedPermissionIds.value];
|
||||
assignedPermissionIds.value = [...leafIds];
|
||||
selectedPermissionIds.value = [...leafIds];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 重置搜索
|
||||
function resetSearch() {
|
||||
searchForm.value = { name: '', status: undefined };
|
||||
positionPagination.value.current = 1;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
// 分页变化
|
||||
function handlePageChange(page: number, pageSize: number) {
|
||||
positionPagination.value.current = page;
|
||||
positionPagination.value.pageSize = pageSize;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
// 统计
|
||||
const stats = computed(() => {
|
||||
const totalLeaf = countLeafPermissions(permissionTree.value);
|
||||
const assigned = assignedPermissionIds.value.length;
|
||||
const selected = selectedPermissionIds.value.length;
|
||||
return { total: totalLeaf, assigned, selected, changed: selected !== assigned };
|
||||
});
|
||||
|
||||
// 统计叶子权限数
|
||||
function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
|
||||
let count = 0;
|
||||
for (const node of nodes) {
|
||||
if (node.children && node.children.length > 0) {
|
||||
count += countLeafPermissions(node.children);
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
if (node.children && node.children.length > 0) count += countLeafPermissions(node.children);
|
||||
else count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// 把权限树转成 Ant Design Tree 格式
|
||||
function toAntdTreeData(nodes: PermissionVO.PermissionInfoVO[]): any[] {
|
||||
return nodes.map((node) => ({
|
||||
key: node.id,
|
||||
title: node.name,
|
||||
code: node.code,
|
||||
type: node.type,
|
||||
children: node.children && node.children.length > 0 ? toAntdTreeData(node.children) : undefined,
|
||||
disabled: node.type === 'module',
|
||||
}));
|
||||
}
|
||||
|
||||
// 递归获取某节点下的所有叶子权限ID
|
||||
function getLeafIds(nodes: PermissionVO.PermissionInfoVO[], parentId: number): number[] {
|
||||
// 获取所有叶子权限ID
|
||||
function getAllLeafIds(nodes: PermissionVO.PermissionInfoVO[]): number[] {
|
||||
const result: number[] = [];
|
||||
const children = nodes.find((n) => n.id === parentId)?.children;
|
||||
if (!children) return [];
|
||||
for (const child of children) {
|
||||
if (child.type === 'module' && child.children) {
|
||||
result.push(...getLeafIds(nodes, child.id));
|
||||
} else {
|
||||
result.push(child.id);
|
||||
}
|
||||
for (const node of nodes) {
|
||||
if (!node.children || node.children.length === 0) result.push(node.id);
|
||||
else result.push(...getAllLeafIds(node.children));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 递归获取某节点的父节点链(从根到该节点)
|
||||
// 全选
|
||||
function selectAll() {
|
||||
selectedPermissionIds.value = getAllLeafIds(permissionTree.value);
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function selectNone() {
|
||||
selectedPermissionIds.value = [];
|
||||
}
|
||||
|
||||
// 单个 checkbox 变化
|
||||
function onCheck(permissionId: number, checked: boolean) {
|
||||
if (checked) {
|
||||
const toAdd = new Set<number>([permissionId]);
|
||||
getParentChain(permissionTree.value, permissionId).forEach((id) => toAdd.add(id));
|
||||
getDescendantIds(permissionTree.value, permissionId).forEach((id) => toAdd.add(id));
|
||||
const newSet = new Set(selectedPermissionIds.value);
|
||||
toAdd.forEach((id) => newSet.add(id));
|
||||
selectedPermissionIds.value = Array.from(newSet);
|
||||
} else {
|
||||
const toRemove = new Set<number>([permissionId, ...getDescendantIds(permissionTree.value, permissionId)]);
|
||||
selectedPermissionIds.value = selectedPermissionIds.value.filter((id) => !toRemove.has(id));
|
||||
}
|
||||
}
|
||||
|
||||
// 递归获取父节点链
|
||||
function getParentChain(nodes: PermissionVO.PermissionInfoVO[], targetId: number, path: number[] = []): number[] {
|
||||
for (const node of nodes) {
|
||||
if (node.id === targetId) return [...path, node.id];
|
||||
@@ -191,80 +208,48 @@ function getParentChain(nodes: PermissionVO.PermissionInfoVO[], targetId: number
|
||||
return [];
|
||||
}
|
||||
|
||||
// Tree 勾选变化处理(支持父→子全选/取消,子→父自动勾选父节点)
|
||||
function handleTreeCheck(checked: number[], info: any) {
|
||||
const { node, checked: isChecked } = info;
|
||||
const nodeId = node.key as number;
|
||||
const nodeData = findNodeById(permissionTree.value, nodeId);
|
||||
|
||||
let newSelected = new Set(selectedPermissionIds.value);
|
||||
|
||||
if (isChecked) {
|
||||
// 勾选:加入自己 + 所有子权限
|
||||
newSelected.add(nodeId);
|
||||
if (nodeData?.type !== 'module' && nodeData?.children) {
|
||||
// 如果是子模块,展开时自动勾选所有叶子
|
||||
const leafIds = getAllLeafIds([nodeData]);
|
||||
leafIds.forEach((id) => newSelected.add(id));
|
||||
// 递归获取某节点下所有子孙ID
|
||||
function getDescendantIds(nodes: PermissionVO.PermissionInfoVO[], permissionId: number): number[] {
|
||||
const node = findNode(nodes, permissionId);
|
||||
if (!node || !node.children) return [];
|
||||
const result: number[] = [];
|
||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
||||
if (n.children) {
|
||||
for (const child of n.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
// 自动勾选父节点链
|
||||
const parents = getParentChain(permissionTree.value, nodeId);
|
||||
parents.forEach((pid) => newSelected.add(pid));
|
||||
} else {
|
||||
// 取消勾选:移除自己 + 所有子权限
|
||||
newSelected.delete(nodeId);
|
||||
if (nodeData?.children) {
|
||||
const leafIds = getAllLeafIds([nodeData]);
|
||||
leafIds.forEach((id) => newSelected.delete(id));
|
||||
}
|
||||
// 不自动移除父节点(允许只选子节点)
|
||||
}
|
||||
|
||||
selectedPermissionIds.value = Array.from(newSelected);
|
||||
checkedKeys.value = [...newSelected];
|
||||
for (const child of node.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 递归查找节点
|
||||
function findNodeById(nodes: PermissionVO.PermissionInfoVO[], id: number): PermissionVO.PermissionInfoVO | null {
|
||||
function findNode(nodes: PermissionVO.PermissionInfoVO[], id: number): PermissionVO.PermissionInfoVO | null {
|
||||
for (const node of nodes) {
|
||||
if (node.id === id) return node;
|
||||
if (node.children) {
|
||||
const found = findNodeById(node.children, id);
|
||||
const found = findNode(node.children, id);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取某节点下所有叶子权限ID
|
||||
function getAllLeafIds(nodes: PermissionVO.PermissionInfoVO[]): number[] {
|
||||
const result: number[] = [];
|
||||
for (const node of nodes) {
|
||||
if (node.type !== 'module' && !node.children) {
|
||||
result.push(node.id);
|
||||
} else if (node.children) {
|
||||
result.push(...getAllLeafIds(node.children));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 全选(只选叶子节点)
|
||||
function selectAll() {
|
||||
const allLeafIds = getAllLeafIds(permissionTree.value);
|
||||
selectedPermissionIds.value = allLeafIds;
|
||||
checkedKeys.value = [...allLeafIds];
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function selectNone() {
|
||||
selectedPermissionIds.value = [];
|
||||
checkedKeys.value = [];
|
||||
// 展开/收起
|
||||
function toggleExpand(nodeId: number) {
|
||||
const newSet = new Set(expandedIds.value);
|
||||
if (newSet.has(nodeId)) newSet.delete(nodeId);
|
||||
else newSet.add(nodeId);
|
||||
expandedIds.value = newSet;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
searchPositions();
|
||||
loadPermissionTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -306,7 +291,7 @@ onMounted(() => {
|
||||
hoverable
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="group mb-2 cursor-pointer transition-all duration-200"
|
||||
class="mb-2 cursor-pointer transition-all duration-200"
|
||||
:class="[currentPosition?.id === position.id && 'ring-primary shadow ring-1']"
|
||||
@click="selectPosition(position)"
|
||||
>
|
||||
@@ -322,9 +307,6 @@ onMounted(() => {
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-xs text-[var(--text-secondary)]">编码:{{ position.code }}</div>
|
||||
<div v-if="position.remark" class="truncate text-xs text-[var(--text-secondary)]">
|
||||
{{ position.remark }}
|
||||
</div>
|
||||
</div>
|
||||
<Tag :color="position.status === 1 ? 'green' : 'red'">
|
||||
{{ position.status === 1 ? '启用' : '禁用' }}
|
||||
@@ -341,7 +323,6 @@ onMounted(() => {
|
||||
:total="positionPagination.total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
:show-total="(total: number) => `共 ${total} 条`"
|
||||
@change="handlePageChange"
|
||||
/>
|
||||
</Flex>
|
||||
@@ -355,7 +336,7 @@ onMounted(() => {
|
||||
:body-style="{ height: '100%' }"
|
||||
>
|
||||
<template v-if="currentPosition">
|
||||
<!-- 职位信息 + 操作 -->
|
||||
<!-- 头部 -->
|
||||
<div class="mb-4 rounded bg-gray-50 p-4 dark:bg-neutral-800">
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
@@ -375,66 +356,27 @@ onMounted(() => {
|
||||
<div class="flex items-center gap-6 text-xs text-gray-500">
|
||||
<span>编码:{{ currentPosition.code }}</span>
|
||||
<span>全部叶子权限:<span class="font-semibold">{{ stats.total }}</span></span>
|
||||
<span>
|
||||
已分配:<span class="font-semibold text-[var(--success)]">{{ stats.assigned }}</span>
|
||||
</span>
|
||||
<span>
|
||||
当前选择:<span
|
||||
class="font-semibold"
|
||||
:class="stats.changed ? 'text-[var(--warning)]' : 'text-[var(--success)]'"
|
||||
>
|
||||
{{ stats.selected }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="stats.changed" class="text-[var(--warning)]">(有未保存的更改)</span>
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-gray-400">
|
||||
提示:勾选父节点会自动选中所有子权限;取消父节点会同时取消所有子权限
|
||||
<span>已分配:<span class="font-semibold text-green-600">{{ stats.assigned }}</span></span>
|
||||
<span>当前选择:<span class="font-semibold" :class="stats.changed ? 'text-orange-500' : 'text-green-600'">{{ stats.selected }}</span></span>
|
||||
<span v-if="stats.changed" class="text-orange-500">(有未保存的更改)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 权限树 -->
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<Spin :spinning="permissionLoading">
|
||||
<Tree
|
||||
v-if="permissionTree.length > 0"
|
||||
checkable
|
||||
:tree-data="toAntdTreeData(permissionTree)"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
:expanded-keys="permissionTree.map((n) => n.id)"
|
||||
:auto-expand-parent="true"
|
||||
:selectable="false"
|
||||
class="permission-tree"
|
||||
@check="(checked: number[], info: any) => handleTreeCheck(checked, info)"
|
||||
>
|
||||
<template #title="{ dataRef }">
|
||||
<div class="flex items-center justify-between gap-4 pr-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
:class="
|
||||
dataRef.type === 'module'
|
||||
? 'font-semibold text-[var(--text-primary)]'
|
||||
: 'text-[var(--text-secondary)]'
|
||||
"
|
||||
>
|
||||
{{ dataRef.title }}
|
||||
</span>
|
||||
<span class="text-xs text-gray-400">{{ dataRef.code }}</span>
|
||||
</div>
|
||||
<Tag
|
||||
v-if="dataRef.type !== 'module'"
|
||||
:color="
|
||||
selectedPermissionIds.includes(dataRef.key as number)
|
||||
? 'green'
|
||||
: 'default'
|
||||
"
|
||||
class="text-xs"
|
||||
>
|
||||
{{ selectedPermissionIds.includes(dataRef.key as number) ? '已选' : '未选' }}
|
||||
</Tag>
|
||||
</div>
|
||||
</template>
|
||||
</Tree>
|
||||
<div v-if="permissionTree.length > 0" class="py-2">
|
||||
<TreeNodeContent
|
||||
v-for="node in permissionTree"
|
||||
:key="node.id"
|
||||
:node="node"
|
||||
:level="0"
|
||||
:expanded-ids="expandedIds"
|
||||
:selected-ids="selectedPermissionIds"
|
||||
@toggle="toggleExpand"
|
||||
@check="onCheck"
|
||||
/>
|
||||
</div>
|
||||
<div v-else-if="!permissionLoading" class="py-8 text-center text-gray-500">
|
||||
暂无可分配的权限
|
||||
</div>
|
||||
@@ -442,8 +384,8 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else class="flex h-full flex-1 items-center justify-center">
|
||||
<div class="text-center text-gray-500">
|
||||
<div v-else class="flex h-full flex-1 items-center justify-center text-gray-500">
|
||||
<div class="text-center">
|
||||
<div class="mb-4 text-5xl">👈</div>
|
||||
<div class="text-base">请先选择一个职位</div>
|
||||
</div>
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import type { PermissionVO } from '#/api/system/permission/types';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Checkbox, Tag } from 'ant-design-vue';
|
||||
|
||||
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
|
||||
const ChevronRightIcon = createIconifyIcon('lucide:chevron-right');
|
||||
|
||||
defineOptions({ name: 'PermissionTreeNode' });
|
||||
|
||||
const props = defineProps<{
|
||||
node: PermissionVO.PermissionInfoVO;
|
||||
level: number;
|
||||
expandedIds: Set<number>;
|
||||
selectedIds: number[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
toggle: [id: number];
|
||||
check: [id: number, checked: boolean];
|
||||
}>();
|
||||
|
||||
function isChecked(): boolean {
|
||||
if (!props.node.children || props.node.children.length === 0) {
|
||||
return props.selectedIds.includes(props.node.id);
|
||||
}
|
||||
const allIds = getDescendantIds(props.node);
|
||||
return allIds.length > 0 && allIds.every((id) => props.selectedIds.includes(id));
|
||||
}
|
||||
|
||||
function isIndeterminate(): boolean {
|
||||
if (!props.node.children || props.node.children.length === 0) return false;
|
||||
const allIds = getDescendantIds(props.node);
|
||||
const selectedCount = allIds.filter((id) => props.selectedIds.includes(id)).length;
|
||||
return selectedCount > 0 && selectedCount < allIds.length;
|
||||
}
|
||||
|
||||
function getDescendantIds(node: PermissionVO.PermissionInfoVO): number[] {
|
||||
const result: number[] = [];
|
||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
||||
if (n.children) {
|
||||
for (const child of n.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.children) {
|
||||
for (const child of node.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function onCheckboxChange(e: Event) {
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
emit('check', props.node.id, checked);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="tree-node">
|
||||
<!-- 节点行 -->
|
||||
<div
|
||||
class="flex items-center gap-2 py-1.5 px-2 rounded cursor-pointer hover:bg-gray-50 transition-colors"
|
||||
:style="{ paddingLeft: (level * 20 + 8) + 'px' }"
|
||||
>
|
||||
<!-- 展开/收起图标(antd 默认图标) -->
|
||||
<span
|
||||
v-if="node.children && node.children.length > 0"
|
||||
class="flex items-center justify-center w-4 h-4 cursor-pointer"
|
||||
@click="emit('toggle', node.id)"
|
||||
>
|
||||
<ChevronDownIcon v-if="expandedIds.has(node.id)" class="text-xs text-gray-400" />
|
||||
<ChevronRightIcon v-else class="text-xs text-gray-400" />
|
||||
</span>
|
||||
<span v-else class="w-4"></span>
|
||||
|
||||
<!-- Checkbox -->
|
||||
<Checkbox
|
||||
:checked="isChecked()"
|
||||
:indeterminate="isIndeterminate()"
|
||||
@change="onCheckboxChange"
|
||||
/>
|
||||
|
||||
<!-- 名称 -->
|
||||
<span
|
||||
class="flex-1 text-sm leading-5"
|
||||
:class="node.type === 'module' ? 'font-semibold text-[var(--text-primary)]' : 'text-[var(--text-secondary)]'"
|
||||
>
|
||||
{{ node.name }}
|
||||
</span>
|
||||
|
||||
<!-- Code -->
|
||||
<span class="text-xs text-gray-400 mr-2">{{ node.code }}</span>
|
||||
|
||||
<!-- 类型标签 -->
|
||||
<Tag v-if="node.type === 'module'" color="purple" class="text-xs">模块</Tag>
|
||||
</div>
|
||||
|
||||
<!-- 子节点 -->
|
||||
<template v-if="node.children && node.children.length > 0 && expandedIds.has(node.id)">
|
||||
<TreeNodeContent
|
||||
v-for="child in node.children"
|
||||
:key="child.id"
|
||||
:node="child"
|
||||
:level="level + 1"
|
||||
:expanded-ids="expandedIds"
|
||||
:selected-ids="selectedIds"
|
||||
@toggle="(id) => emit('toggle', id)"
|
||||
@check="(id, checked) => emit('check', id, checked)"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
+110
-99
@@ -6,12 +6,14 @@ import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Button, Card, Flex, Input, message, Pagination, Select, Spin, Tag, Tree } from 'ant-design-vue';
|
||||
import { Button, Card, Checkbox, Flex, Input, message, Pagination, Select, Spin, Tag } from 'ant-design-vue';
|
||||
|
||||
import { batchUpdateCompanyPermissionsApi, getCompanyPermissionIdsApi } from '#/api/organization/company-permission/apis';
|
||||
import { getCompanyPageApi } from '#/api/organization/company';
|
||||
import { getPermissionTreeApi } from '#/api/system/permission';
|
||||
|
||||
import TreeNodeContent from './components/TreeNodeContent.vue';
|
||||
|
||||
defineOptions({ name: 'CompanyPermissionManagePage' });
|
||||
|
||||
// 搜索表单
|
||||
@@ -29,20 +31,29 @@ const currentCompany = ref<null | CompanyVO.CompanyInfoVO>(null);
|
||||
const permissionTree = ref<PermissionVO.PermissionInfoVO[]>([]);
|
||||
const permissionLoading = ref(false);
|
||||
|
||||
// 当前公司的权限ID
|
||||
// 公司原始已分配权限ID
|
||||
const companyPermissionIds = ref<number[]>([]);
|
||||
// 用户当前选中的权限ID(唯一真实数据源)
|
||||
const selectedPermissionIds = ref<number[]>([]);
|
||||
const checkedKeys = ref<number[]>([]);
|
||||
|
||||
// 展开状态
|
||||
const expandedIds = ref<Set<number>>(new Set());
|
||||
|
||||
// 统计
|
||||
const stats = computed(() => ({
|
||||
total: countLeafPermissions(permissionTree.value),
|
||||
company: companyPermissionIds.value.length,
|
||||
selected: selectedPermissionIds.value.length,
|
||||
changed: selectedPermissionIds.value.length !== companyPermissionIds.value.length,
|
||||
changed: !sameArray(selectedPermissionIds.value, companyPermissionIds.value),
|
||||
}));
|
||||
|
||||
// 搜索公司列表
|
||||
function sameArray(a: number[], b: number[]): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
const sa = new Set(a);
|
||||
return b.every((id) => sa.has(id));
|
||||
}
|
||||
|
||||
// 搜索公司
|
||||
async function searchCompanies() {
|
||||
companyLoading.value = true;
|
||||
try {
|
||||
@@ -66,7 +77,7 @@ async function selectCompany(company: CompanyVO.CompanyInfoVO) {
|
||||
await loadCompanyPermissions();
|
||||
}
|
||||
|
||||
// 加载公司权限
|
||||
// 加载公司已有权限
|
||||
async function loadCompanyPermissions() {
|
||||
if (!currentCompany.value?.id) return;
|
||||
permissionLoading.value = true;
|
||||
@@ -74,7 +85,6 @@ async function loadCompanyPermissions() {
|
||||
const result = await getCompanyPermissionIdsApi(currentCompany.value.id);
|
||||
companyPermissionIds.value = result || [];
|
||||
selectedPermissionIds.value = [...companyPermissionIds.value];
|
||||
checkedKeys.value = [...companyPermissionIds.value];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '加载权限失败');
|
||||
} finally {
|
||||
@@ -82,36 +92,42 @@ async function loadCompanyPermissions() {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载权限树
|
||||
// 加载权限树(全量树,用于分配)
|
||||
async function loadPermissionTree() {
|
||||
try {
|
||||
const result = await getPermissionTreeApi();
|
||||
permissionTree.value = result || [];
|
||||
// 默认全部展开
|
||||
expandedIds.value = new Set(result?.map((n: PermissionVO.PermissionInfoVO) => n.id) || []);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取权限树失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存
|
||||
// 保存(只保存叶子权限节点,模块节点仅作视觉分组)
|
||||
async function handleSave() {
|
||||
if (!currentCompany.value?.id) return;
|
||||
// 过滤掉模块节点,只保留叶子权限
|
||||
const leafIds = selectedPermissionIds.value.filter((id) => {
|
||||
const node = findNode(permissionTree.value, id);
|
||||
return node && (!node.children || node.children.length === 0);
|
||||
});
|
||||
try {
|
||||
await batchUpdateCompanyPermissionsApi(currentCompany.value.id, selectedPermissionIds.value);
|
||||
await batchUpdateCompanyPermissionsApi(currentCompany.value.id, leafIds);
|
||||
message.success('权限配置保存成功');
|
||||
companyPermissionIds.value = [...selectedPermissionIds.value];
|
||||
companyPermissionIds.value = [...leafIds];
|
||||
selectedPermissionIds.value = [...leafIds];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 重置搜索
|
||||
function resetSearch() {
|
||||
searchForm.value = { name: '', status: undefined };
|
||||
companyPagination.value.current = 1;
|
||||
searchCompanies();
|
||||
}
|
||||
|
||||
// 分页
|
||||
function handlePageChange(page: number, pageSize: number) {
|
||||
companyPagination.value.current = page;
|
||||
companyPagination.value.pageSize = pageSize;
|
||||
@@ -128,28 +144,41 @@ function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
|
||||
return count;
|
||||
}
|
||||
|
||||
// 转 Ant Design Tree 格式
|
||||
function toAntdTreeData(nodes: PermissionVO.PermissionInfoVO[]): any[] {
|
||||
return nodes.map((node) => ({
|
||||
key: node.id,
|
||||
title: node.name,
|
||||
code: node.code,
|
||||
type: node.type,
|
||||
children: node.children && node.children.length > 0 ? toAntdTreeData(node.children) : undefined,
|
||||
disabled: node.type === 'module',
|
||||
}));
|
||||
}
|
||||
|
||||
// 递归获取某节点下所有叶子权限ID
|
||||
// 获取所有叶子权限ID
|
||||
function getAllLeafIds(nodes: PermissionVO.PermissionInfoVO[]): number[] {
|
||||
const result: number[] = [];
|
||||
for (const node of nodes) {
|
||||
if (node.type !== 'module' && !node.children) result.push(node.id);
|
||||
else if (node.children) result.push(...getAllLeafIds(node.children));
|
||||
if (!node.children || node.children.length === 0) result.push(node.id);
|
||||
else result.push(...getAllLeafIds(node.children));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 全选(只选叶子节点)
|
||||
function selectAll() {
|
||||
selectedPermissionIds.value = getAllLeafIds(permissionTree.value);
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function selectNone() {
|
||||
selectedPermissionIds.value = [];
|
||||
}
|
||||
|
||||
// 单个 checkbox 变化
|
||||
function onCheck(permissionId: number, checked: boolean) {
|
||||
if (checked) {
|
||||
const toAdd = new Set<number>([permissionId]);
|
||||
getParentChain(permissionTree.value, permissionId).forEach((id) => toAdd.add(id));
|
||||
getDescendantIds(permissionId).forEach((id) => toAdd.add(id));
|
||||
const newSet = new Set(selectedPermissionIds.value);
|
||||
toAdd.forEach((id) => newSet.add(id));
|
||||
selectedPermissionIds.value = Array.from(newSet);
|
||||
} else {
|
||||
const toRemove = new Set<number>([permissionId, ...getDescendantIds(permissionId)]);
|
||||
selectedPermissionIds.value = selectedPermissionIds.value.filter((id) => !toRemove.has(id));
|
||||
}
|
||||
}
|
||||
|
||||
// 递归获取父节点链
|
||||
function getParentChain(nodes: PermissionVO.PermissionInfoVO[], targetId: number, path: number[] = []): number[] {
|
||||
for (const node of nodes) {
|
||||
@@ -162,54 +191,61 @@ function getParentChain(nodes: PermissionVO.PermissionInfoVO[], targetId: number
|
||||
return [];
|
||||
}
|
||||
|
||||
// 递归获取某节点下所有子孙ID
|
||||
function getDescendantIds(permissionId: number): number[] {
|
||||
const node = findNode(permissionTree.value, permissionId);
|
||||
if (!node || !node.children) return [];
|
||||
const result: number[] = [];
|
||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
||||
if (n.children) {
|
||||
for (const child of n.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of node.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 递归查找节点
|
||||
function findNodeById(nodes: PermissionVO.PermissionInfoVO[], id: number): PermissionVO.PermissionInfoVO | null {
|
||||
function findNode(nodes: PermissionVO.PermissionInfoVO[], id: number): PermissionVO.PermissionInfoVO | null {
|
||||
for (const node of nodes) {
|
||||
if (node.id === id) return node;
|
||||
if (node.children) {
|
||||
const found = findNodeById(node.children, id);
|
||||
const found = findNode(node.children, id);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Tree 勾选变化
|
||||
function handleTreeCheck(_checked: number[], info: any) {
|
||||
const { node, checked: isChecked } = info;
|
||||
const nodeId = node.key as number;
|
||||
const nodeData = findNodeById(permissionTree.value, nodeId);
|
||||
|
||||
let newSelected = new Set(selectedPermissionIds.value);
|
||||
|
||||
if (isChecked) {
|
||||
newSelected.add(nodeId);
|
||||
if (nodeData?.type !== 'module' && nodeData?.children) {
|
||||
getAllLeafIds([nodeData]).forEach((id) => newSelected.add(id));
|
||||
}
|
||||
// 自动勾选父节点链
|
||||
getParentChain(permissionTree.value, nodeId).forEach((pid) => newSelected.add(pid));
|
||||
} else {
|
||||
newSelected.delete(nodeId);
|
||||
if (nodeData?.children) {
|
||||
getAllLeafIds([nodeData]).forEach((id) => newSelected.delete(id));
|
||||
}
|
||||
// 节点是否全选
|
||||
function isNodeChecked(node: PermissionVO.PermissionInfoVO): boolean {
|
||||
if (!node.children || node.children.length === 0) {
|
||||
return selectedPermissionIds.value.includes(node.id);
|
||||
}
|
||||
|
||||
selectedPermissionIds.value = Array.from(newSelected);
|
||||
checkedKeys.value = [...newSelected];
|
||||
const allIds = getDescendantIds(node.id);
|
||||
return allIds.length > 0 && allIds.every((id) => selectedPermissionIds.value.includes(id));
|
||||
}
|
||||
|
||||
// 全选 / 取消全选
|
||||
function selectAll() {
|
||||
const allLeafIds = getAllLeafIds(permissionTree.value);
|
||||
selectedPermissionIds.value = allLeafIds;
|
||||
checkedKeys.value = [...allLeafIds];
|
||||
// 节点是否半选
|
||||
function isNodeIndeterminate(node: PermissionVO.PermissionInfoVO): boolean {
|
||||
if (!node.children || node.children.length === 0) return false;
|
||||
const allIds = getDescendantIds(node.id);
|
||||
const selectedCount = allIds.filter((id) => selectedPermissionIds.value.includes(id)).length;
|
||||
return selectedCount > 0 && selectedCount < allIds.length;
|
||||
}
|
||||
|
||||
function selectNone() {
|
||||
selectedPermissionIds.value = [];
|
||||
checkedKeys.value = [];
|
||||
// 展开/收起
|
||||
function toggleExpand(nodeId: number) {
|
||||
const newSet = new Set(expandedIds.value);
|
||||
if (newSet.has(nodeId)) newSet.delete(nodeId);
|
||||
else newSet.add(nodeId);
|
||||
expandedIds.value = newSet;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -320,49 +356,24 @@ onMounted(() => {
|
||||
<span>当前选择:<strong class="text-blue-600">{{ stats.selected }}</strong></span>
|
||||
<span v-if="stats.changed" class="text-orange-500">(有未保存的更改)</span>
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-gray-400">
|
||||
提示:勾选父节点会自动选中所有子权限
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 权限树 -->
|
||||
<!-- 权限树(完全自己控制,不用 antd checkable) -->
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<Spin :spinning="permissionLoading">
|
||||
<Tree
|
||||
v-if="permissionTree.length > 0"
|
||||
checkable
|
||||
:tree-data="toAntdTreeData(permissionTree)"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
:expanded-keys="permissionTree.map((n) => n.id)"
|
||||
:auto-expand-parent="true"
|
||||
:selectable="false"
|
||||
class="permission-tree"
|
||||
@check="(checked: number[], info: any) => handleTreeCheck(checked, info)"
|
||||
>
|
||||
<template #title="{ dataRef }">
|
||||
<div class="flex items-center justify-between gap-4 pr-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
:class="
|
||||
dataRef.type === 'module'
|
||||
? 'font-semibold text-[var(--text-primary)]'
|
||||
: 'text-[var(--text-secondary)]'
|
||||
"
|
||||
>
|
||||
{{ dataRef.title }}
|
||||
</span>
|
||||
<span class="text-xs text-gray-400">{{ dataRef.code }}</span>
|
||||
</div>
|
||||
<Tag
|
||||
v-if="dataRef.type !== 'module'"
|
||||
:color="selectedPermissionIds.includes(dataRef.key as number) ? 'green' : 'default'"
|
||||
class="text-xs"
|
||||
>
|
||||
{{ selectedPermissionIds.includes(dataRef.key as number) ? '已选' : '未选' }}
|
||||
</Tag>
|
||||
</div>
|
||||
<div v-if="permissionTree.length > 0" class="py-2">
|
||||
<!-- 递归渲染树节点 -->
|
||||
<template v-for="node in permissionTree" :key="node.id">
|
||||
<TreeNodeContent
|
||||
:node="node"
|
||||
:level="0"
|
||||
:expanded-ids="expandedIds"
|
||||
:selected-ids="selectedPermissionIds"
|
||||
@toggle="toggleExpand"
|
||||
@check="onCheck"
|
||||
/>
|
||||
</template>
|
||||
</Tree>
|
||||
</div>
|
||||
<div v-else-if="!permissionLoading" class="py-8 text-center text-gray-400">
|
||||
暂无可分配的权限
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user