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> <script>
import config from "@/config/table"; import config from "@/config/table";
import columnSetting from "./columnSetting"; import columnSetting from "./columnSetting";
import { genTree } from "@/utils/verificate";
export default { export default {
name: "scTable", name: "scTable",
@ -171,7 +172,7 @@ export default {
this.getData(); this.getData();
} else if (this.data) { } else if (this.data) {
if (this.isTree) { if (this.isTree) {
this.tableData = this.redata(this.data); this.tableData = genTree(this.data);
} else { } else {
this.tableData = this.data; this.tableData = this.data;
} }
@ -224,7 +225,7 @@ export default {
dataList = response.rows; dataList = response.rows;
} }
if (this.isTree) { if (this.isTree) {
this.tableData = this.redata(dataList); this.tableData = genTree(dataList);
} else { } else {
this.tableData = dataList || []; this.tableData = dataList || [];
} }
@ -237,6 +238,7 @@ export default {
this.$emit("dataChange", res, this.tableData); this.$emit("dataChange", res, this.tableData);
} }
} catch (error) { } catch (error) {
console.log(error);
this.loading = false; this.loading = false;
if (error.response && error.response.data) { if (error.response && error.response.data) {
this.emptyText = error.response.data.err_msg; this.emptyText = error.response.data.err_msg;
@ -246,28 +248,6 @@ export default {
return false; 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() { paginationChange() {
this.getData(); this.getData();