feat: scTable 使用genTree

This commit is contained in:
caoqianming 2024-06-03 14:35:01 +08:00
parent 51e4d527d4
commit c69d47a98d
1 changed files with 4 additions and 24 deletions

View File

@ -81,6 +81,7 @@
<script>
import config from "@/config/table";
import columnSetting from "./columnSetting";
import { genTree } from "@/utils/verificate";
export default {
name: "scTable",
@ -171,7 +172,7 @@ export default {
this.getData();
} else if (this.data) {
if (this.isTree) {
this.tableData = this.redata(this.data);
this.tableData = genTree(this.data);
} else {
this.tableData = this.data;
}
@ -224,7 +225,7 @@ export default {
dataList = response.rows;
}
if (this.isTree) {
this.tableData = this.redata(dataList);
this.tableData = genTree(dataList);
} else {
this.tableData = dataList || [];
}
@ -237,6 +238,7 @@ export default {
this.$emit("dataChange", res, this.tableData);
}
} catch (error) {
console.log(error);
this.loading = false;
if (error.response && error.response.data) {
this.emptyText = error.response.data.err_msg;
@ -246,28 +248,6 @@ export default {
return false;
}
},
redata(postList) {
let posts = [];
postList.forEach((item) => {
let obj = new Object();
obj = { ...item };
obj.parentId = item.parent;
posts.push(obj);
});
let obj = posts.reduce((res, v) => ((res[v.id] = v), res), {}); //Object
let arr = [];
for (let item of posts) {
if (item.parentId == null) {
arr.push(item);
continue;
}
let parent = obj[item.parentId];
parent.children = parent.children ? parent.children : [];
parent.children.push(item);
}
console.log(arr);
return arr;
},
//
paginationChange() {
this.getData();