Commit 26c7d56f by jack

优化树形展示

1 parent 224a23d7
...@@ -2,26 +2,10 @@ ...@@ -2,26 +2,10 @@
<div class="system-container"> <div class="system-container">
<div class="container"> <div class="container">
<div class="topform"> <div class="topform">
<rule-form <rule-form :ruleForm="addUpdateForm" :rules="rules" :ruleData="addUpdateData" :labelWidth="'120px'" ref="addUpdateForm">
:ruleForm="addUpdateForm"
:rules="rules"
:ruleData="addUpdateData"
:labelWidth="'120px'"
ref="addUpdateForm"
>
<div slot="select-type"> <div slot="select-type">
<el-select <el-select v-model="addUpdateForm.initOrganize" placeholder="请选择" :disabled="this.$route.query.title == 'view' || this.$route.query.title=='edit'" filterable>
v-model="addUpdateForm.initOrganize" <el-option v-for="i in tenantList" :key="i.tenantId" :label="i.departmentName" :value="i.tenantId">
placeholder="请选择"
:disabled="this.$route.query.title == 'view' || this.$route.query.title=='edit'"
filterable
>
<el-option
v-for="i in tenantList"
:key="i.tenantId"
:label="i.departmentName"
:value="i.tenantId"
>
</el-option> </el-option>
</el-select> </el-select>
</div> </div>
...@@ -31,35 +15,18 @@ ...@@ -31,35 +15,18 @@
</div> --> </div> -->
</rule-form> </rule-form>
</div> </div>
<div class="treebox" > <div class="treebox">
<!-- <span class="el-icon-loading"></span> --> <!-- <span class="el-icon-loading"></span> -->
<div class="layer" v-if="!showTree">正在加载中...</div> <div class="layer" v-if="!showTree">正在加载中...</div>
<el-tree <el-tree v-if="showTree" :data="treedata" :default-expanded-keys="expandedKey" :props="defaultProps" show-checkbox node-key="id" ref="tree" highlight-current lazy :load="loadNode">
v-if="showTree"
:data="treedata"
:default-expanded-keys="expandedKey"
:props="defaultProps"
show-checkbox
node-key="id"
ref="tree"
highlight-current
lazy
:load="loadNode"
>
</el-tree> </el-tree>
</div>
</div> </div>
</div>
<div class="pull-right"> <div class="pull-right">
<el-button <el-button type="primary" @click="submitForm" :loading="aloading" v-if="!(setPageTitle == 'view')">保存</el-button>
type="primary" <el-button @click="handCancle('addUpdateForm')">取消</el-button>
@click="submitForm" </div>
:loading="aloading"
v-if="!(setPageTitle == 'view')"
>保存</el-button
>
<el-button @click="handCancle('addUpdateForm')">取消</el-button>
</div>
</div> </div>
</template> </template>
...@@ -125,7 +92,7 @@ export default { ...@@ -125,7 +92,7 @@ export default {
defaultProps: { defaultProps: {
children: "childs", children: "childs",
label: "name", label: "name",
isLeaf: 'leaf' isLeaf: "leaf",
}, },
loading: true, loading: true,
newArr: [], newArr: [],
...@@ -166,17 +133,20 @@ export default { ...@@ -166,17 +133,20 @@ export default {
let o = _this.$route.query; let o = _this.$route.query;
let n = _this.$store.getters.getTreeData;
//判断 //判断
this.getTenantList(); this.getTenantList();
setTimeout(function () { setTimeout(function () {
let n = localStorage.getItem("carTree") // let n = localStorage.getItem("carTree")
? JSON.parse(localStorage.getItem("carTree")) // ? JSON.parse(localStorage.getItem("carTree"))
: []; // : [];
if (n && n.length > 0) { if (n && n.length > 0) {
// console.log(n,"浏览器存储"); // console.log(n,"浏览器存储");
_this.flatData(n); //_this.flatData(n);
_this.mainWorker(n);
_this.showTree = true; _this.showTree = true;
_this.loading = false; _this.loading = false;
return false; return false;
...@@ -220,13 +190,18 @@ export default { ...@@ -220,13 +190,18 @@ export default {
}, },
// 获取菜单权限列表 // 获取菜单权限列表
getMenuTree() { getMenuTree() {
let _this = this;
let oParams = {}; let oParams = {};
oParams.full = true; oParams.full = true;
getMenuTree(oParams).then((res) => { getMenuTree(oParams).then((res) => {
localStorage.setItem("carTree", JSON.stringify(res.data || [])); localStorage.setItem("carTree", JSON.stringify(res.data || []));
console.log("开始处理数据" + new Date().getTime()); // 分线程处理数据
this.flatData(res.data); _this.mainWorker(res.data).then((e) => {
console.log("结束处理数据" + new Date().getTime()); let _obj = e.data;
_this.$store.commit("updateVehicleTree", _obj.data);
_this.showTree = true;
_this.loading = false;
});
this.showTree = true; this.showTree = true;
this.loading = false; this.loading = false;
}); });
...@@ -290,8 +265,8 @@ export default { ...@@ -290,8 +265,8 @@ export default {
(arr || []).forEach((item) => { (arr || []).forEach((item) => {
item.pid = id || 0; item.pid = id || 0;
item.level = i; item.level = i;
if(item.level==3){ if (item.level == 3) {
item.leaf=true; item.leaf = true;
} }
n.push(item); n.push(item);
if (!id) { if (!id) {
...@@ -314,7 +289,7 @@ export default { ...@@ -314,7 +289,7 @@ export default {
} }
_this.checkList = []; _this.checkList = [];
let _list = _this.$refs.tree.getCheckedNodes(); let _list = _this.$refs.tree.getCheckedNodes();
_this.getChilds(_list); _this.getChilds(_list);
console.log(_this.checkList); console.log(_this.checkList);
...@@ -356,7 +331,7 @@ export default { ...@@ -356,7 +331,7 @@ export default {
// 取消保存 // 取消保存
handCancle(formName) { handCancle(formName) {
console.log("66") console.log("66");
this.goBack(); this.goBack();
}, },
...@@ -380,7 +355,7 @@ export default { ...@@ -380,7 +355,7 @@ export default {
goBack() { goBack() {
this.$refs.addUpdateForm.$children[0].resetFields(); this.$refs.addUpdateForm.$children[0].resetFields();
this.$router.go(-1); this.$router.go(-1);
this.$refs.tree.setCheckedKeys([]); this.$refs.tree.setCheckedKeys([]);
}, },
// 获取车型库详情 // 获取车型库详情
...@@ -447,6 +422,66 @@ export default { ...@@ -447,6 +422,66 @@ export default {
_this.$refs.tree.setCheckedKeys(typeList); _this.$refs.tree.setCheckedKeys(typeList);
}); });
}, },
// 创建分线程
createWorker() {
let myWorker = function () {
let that = this;
let _tree = [];
let _allTree = [];
that.addEventListener("message", function (e) {
console.log(e);
if (e.data) {
flatData(e.data);
that.postMessage({ tree: _tree, data: _allTree });
}
});
// 数据扁平化
let flatData = function (arr, id, index) {
let n = _allTree;
let i = index || 0;
(arr || []).forEach((item) => {
item.pid = id || 0;
item.level = i;
n.push(item);
if (!id) {
_tree.push(item);
}
item.childs && item.childs.length > 0
? flatData(item.childs, item.id, i + 1)
: "";
//item.childs = ""; //如果扁平化后的数组需要显示父子层级,可以把这一项删除
});
};
};
let workerData = new Blob(["(" + myWorker.toString() + ")()"], {
type: "text/javascript",
});
return workerData;
},
// 主线程
mainWorker(data) {
let _this = this;
return new Promise((resolve, reject) => {
let _workerJs = _this.createWorker();
let webWorker = new Worker(window.URL.createObjectURL(_workerJs));
webWorker.postMessage(data);
webWorker.onmessage = function (e) {
console.log(e);
let _obj = e.data;
_this.treedata = _obj.tree;
_this.newArr = _obj.data;
resolve(_obj);
};
// 监听文件失败
webWorker.onmessageerror = function (e) {
reject(e);
};
});
},
}, },
}; };
</script> </script>
...@@ -459,14 +494,14 @@ export default { ...@@ -459,14 +494,14 @@ export default {
height: 385px; height: 385px;
overflow-y: scroll; overflow-y: scroll;
position: relative; position: relative;
.layer{ .layer {
width: 100%; width: 100%;
height: 385px; height: 385px;
text-align: center; text-align: center;
line-height: 385px; line-height: 385px;
position: absolute; position: absolute;
z-index:10; z-index: 10;
} }
} }
.pull-right { .pull-right {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!