|
@@ -36,26 +36,31 @@ export const treeDept = ref([]);
|
|
export const postListTreeWithUserApi = async () => {
|
|
export const postListTreeWithUserApi = async () => {
|
|
const res = await postListTreeWithUser();
|
|
const res = await postListTreeWithUser();
|
|
treeDept.value = transformData(res.data);
|
|
treeDept.value = transformData(res.data);
|
|
|
|
+ console.log("res,data", res.data);
|
|
console.log("过滤的数据.", treeDept.value);
|
|
console.log("过滤的数据.", treeDept.value);
|
|
};
|
|
};
|
|
const transformData = data => {
|
|
const transformData = data => {
|
|
|
|
+ // 基本的转换逻辑
|
|
return data.map(item => {
|
|
return data.map(item => {
|
|
|
|
+ // 初始化一个转换后的项目
|
|
const transformedItem = {
|
|
const transformedItem = {
|
|
- userName: item.userName || item.deptName,
|
|
|
|
- userCode: item.userCode || item.deptCode,
|
|
|
|
- children: []
|
|
|
|
|
|
+ userName: item.deptName || item.userName, // 使用 deptName 或 userName
|
|
|
|
+ userCode: item.deptCode || item.userCode, // 使用 deptCode 或 userCode
|
|
|
|
+ children: [] // 用于存储子部门和用户数据
|
|
};
|
|
};
|
|
|
|
|
|
- if (item.childrenRes) {
|
|
|
|
- transformedItem.children = transformData(item.childrenRes);
|
|
|
|
|
|
+ // 递归处理子部门数据(childrenRes)
|
|
|
|
+ if (item.childrenRes && Array.isArray(item.childrenRes)) {
|
|
|
|
+ transformedItem.children.push(...transformData(item.childrenRes)); // 合并所有子部门
|
|
}
|
|
}
|
|
|
|
|
|
- if (item.childrenUserRes) {
|
|
|
|
|
|
+ // 处理当前部门的用户数据(childrenUserRes)
|
|
|
|
+ if (item.childrenUserRes && Array.isArray(item.childrenUserRes)) {
|
|
item.childrenUserRes.forEach(user => {
|
|
item.childrenUserRes.forEach(user => {
|
|
|
|
+ // 将每个用户添加到 children 数组
|
|
transformedItem.children.push({
|
|
transformedItem.children.push({
|
|
userName: user.userName,
|
|
userName: user.userName,
|
|
- userCode: user.userCode,
|
|
|
|
- children: []
|
|
|
|
|
|
+ userCode: user.userCode
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|