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

perf: 修改站点管理区域树

parent f58bd4e3
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<!-- <span style="font-weight: 600">站点结构</span> --> <!-- <span style="font-weight: 600">站点结构</span> -->
<div class="box"> <div class="box">
<a-tree <a-tree
:load-data="onLoadData"
:tree-data="treeData" :tree-data="treeData"
:expandedKeys.sync="expandedKeys" :expandedKeys.sync="expandedKeys"
:replaceFields="{ title: 'label', key: 'id' }" :replaceFields="{ title: 'label', key: 'id' }"
...@@ -18,6 +17,7 @@ ...@@ -18,6 +17,7 @@
// api // api
import { import {
getListByParentId, getListByParentId,
authAreaTree,
// areaList, // areaList,
// getSiteList // getSiteList
} from "@/services/basicsetFun"; } from "@/services/basicsetFun";
...@@ -32,39 +32,66 @@ export default { ...@@ -32,39 +32,66 @@ export default {
}, },
created() { created() {
this.getAreaList(); this.authAreaTree();
this.getTopArea();
}, },
methods: { methods: {
// 获取区域 editLeaf(arr) {
async getAreaList() { 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 }); let res = await getListByParentId({ parentId: 0 });
const { data, code } = res.data; const { data, code } = res.data;
if (code === 1) { if (code === 1) {
this.treeData = data.data; return data.data[0];
// let obj = { } else {
// dataRef: { return {};
// id: data.data[0].id,
// },
// };
// this.onLoadData(obj);
this.expandedKeys = [data.data[0].id];
} }
}, },
// 异步获取子区域 // 异步获取子区域
onLoadData(treeNode) { // onLoadData(treeNode) {
return new Promise((resolve) => { // return new Promise((resolve) => {
getListByParentId({ // getListByParentId({
parentId: treeNode.dataRef.id, // parentId: treeNode.dataRef.id,
}).then((res) => { // }).then((res) => {
const { data } = res.data; // const { data } = res.data;
treeNode.dataRef.children = data.data; // treeNode.dataRef.children = data.data;
this.treeData = [...this.treeData]; // this.treeData = [...this.treeData];
resolve(); // resolve();
}); // });
}); // });
}, // },
// 选中区域 // 选中区域
onSelect(num, node) { onSelect(num, node) {
if (num && node.selectedNodes.length > 0) { if (num && node.selectedNodes.length > 0) {
...@@ -94,4 +121,4 @@ export default { ...@@ -94,4 +121,4 @@ export default {
overflow-y: auto; overflow-y: auto;
} }
} }
</style> </style>
\ No newline at end of file
...@@ -30,7 +30,8 @@ module.exports = { ...@@ -30,7 +30,8 @@ module.exports = {
treeselect: `${BASE_URL}/base/area/treeselect`, treeselect: `${BASE_URL}/base/area/treeselect`,
save: `${BASE_URL}/base/area/save`, save: `${BASE_URL}/base/area/save`,
delete: `${BASE_URL}/base/area/delete`, 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: { site: {
......
...@@ -19,6 +19,10 @@ export async function getListByParentId(data) { ...@@ -19,6 +19,10 @@ export async function getListByParentId(data) {
export async function treeselect(data) { export async function treeselect(data) {
return request(area.treeselect, METHOD.POST, 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) { export async function getSiteList(data) {
return request(site.list, METHOD.POST, 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