Commit a8362b93 authored by “yiyousong”'s avatar “yiyousong”

perf: 修改站点管理区域树

parent f58bd4e3
......@@ -3,7 +3,6 @@
<!-- <span style="font-weight: 600">站点结构</span> -->
<div class="box">
<a-tree
:load-data="onLoadData"
:tree-data="treeData"
:expandedKeys.sync="expandedKeys"
:replaceFields="{ title: 'label', key: 'id' }"
......@@ -18,6 +17,7 @@
// api
import {
getListByParentId,
authAreaTree,
// areaList,
// getSiteList
} from "@/services/basicsetFun";
......@@ -32,39 +32,66 @@ export default {
},
created() {
this.getAreaList();
this.authAreaTree();
this.getTopArea();
},
methods: {
// 获取区域
async getAreaList() {
editLeaf(arr) {
return arr.map((v) => {
if (v.children && v.children.length > 0) {
this.editLeaf(v.children);
} else {
v.isLeaf = true;
}
return v;
});
},
// 获取个人区域数据
async authAreaTree() {
let res = await authAreaTree();
if (res.data.code == 1) {
let { data } = res.data.data;
if (data.length) {
let firstData = data[0];
if (firstData.areaLevel > 2 || data.length > 1) {
let TopParent = await this.getTopArea();
TopParent.selectable = false;
TopParent.children = this.editLeaf(data);
this.treeData = [TopParent];
} else {
this.treeData = this.editLeaf(data);
}
this.expandedKeys = [this.treeData[0].id];
}
}
},
// 获取顶层区域
async getTopArea() {
let res = await getListByParentId({ parentId: 0 });
const { data, code } = res.data;
if (code === 1) {
this.treeData = data.data;
// let obj = {
// dataRef: {
// id: data.data[0].id,
// },
// };
// this.onLoadData(obj);
this.expandedKeys = [data.data[0].id];
return data.data[0];
} else {
return {};
}
},
// 异步获取子区域
onLoadData(treeNode) {
return new Promise((resolve) => {
getListByParentId({
parentId: treeNode.dataRef.id,
}).then((res) => {
const { data } = res.data;
treeNode.dataRef.children = data.data;
this.treeData = [...this.treeData];
resolve();
});
});
},
// onLoadData(treeNode) {
// return new Promise((resolve) => {
// getListByParentId({
// parentId: treeNode.dataRef.id,
// }).then((res) => {
// const { data } = res.data;
// treeNode.dataRef.children = data.data;
// this.treeData = [...this.treeData];
// resolve();
// });
// });
// },
// 选中区域
onSelect(num, node) {
if (num && node.selectedNodes.length > 0) {
......@@ -94,4 +121,4 @@ export default {
overflow-y: auto;
}
}
</style>
\ No newline at end of file
</style>
......@@ -30,7 +30,8 @@ module.exports = {
treeselect: `${BASE_URL}/base/area/treeselect`,
save: `${BASE_URL}/base/area/save`,
delete: `${BASE_URL}/base/area/delete`,
init: `${BASE_URL}/base/base/area/genSubAreaByAreaName `,
init: `${BASE_URL}/base/area/genSubAreaByAreaName`,
authAreaTree: `${BASE_URL}/base/area/authAreaTree`,
},
// 站点
site: {
......
......@@ -19,6 +19,10 @@ export async function getListByParentId(data) {
export async function treeselect(data) {
return request(area.treeselect, METHOD.POST, data);
}
// 查看个人区域列表
export async function authAreaTree(data) {
return request(area.authAreaTree, METHOD.POST, data);
}
// 查看站点列表
export async function getSiteList(data) {
return request(site.list, METHOD.POST, data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment