Commit 26c7d56f by jack

优化树形展示

1 parent 224a23d7
......@@ -2,26 +2,10 @@
<div class="system-container">
<div class="container">
<div class="topform">
<rule-form
:ruleForm="addUpdateForm"
:rules="rules"
:ruleData="addUpdateData"
:labelWidth="'120px'"
ref="addUpdateForm"
>
<rule-form :ruleForm="addUpdateForm" :rules="rules" :ruleData="addUpdateData" :labelWidth="'120px'" ref="addUpdateForm">
<div slot="select-type">
<el-select
v-model="addUpdateForm.initOrganize"
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-select v-model="addUpdateForm.initOrganize" 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-select>
</div>
......@@ -31,35 +15,18 @@
</div> -->
</rule-form>
</div>
<div class="treebox" >
<div class="treebox">
<!-- <span class="el-icon-loading"></span> -->
<div class="layer" v-if="!showTree">正在加载中...</div>
<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"
>
<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">
</el-tree>
</div>
</div>
</div>
<div class="pull-right">
<el-button
type="primary"
@click="submitForm"
:loading="aloading"
v-if="!(setPageTitle == 'view')"
>保存</el-button
>
<el-button @click="handCancle('addUpdateForm')">取消</el-button>
</div>
<div class="pull-right">
<el-button type="primary" @click="submitForm" :loading="aloading" v-if="!(setPageTitle == 'view')">保存</el-button>
<el-button @click="handCancle('addUpdateForm')">取消</el-button>
</div>
</div>
</template>
......@@ -125,7 +92,7 @@ export default {
defaultProps: {
children: "childs",
label: "name",
isLeaf: 'leaf'
isLeaf: "leaf",
},
loading: true,
newArr: [],
......@@ -166,17 +133,20 @@ export default {
let o = _this.$route.query;
let n = _this.$store.getters.getTreeData;
//判断
this.getTenantList();
setTimeout(function () {
let n = localStorage.getItem("carTree")
? JSON.parse(localStorage.getItem("carTree"))
: [];
// let n = localStorage.getItem("carTree")
// ? JSON.parse(localStorage.getItem("carTree"))
// : [];
if (n && n.length > 0) {
// console.log(n,"浏览器存储");
_this.flatData(n);
//_this.flatData(n);
_this.mainWorker(n);
_this.showTree = true;
_this.loading = false;
return false;
......@@ -220,13 +190,18 @@ export default {
},
// 获取菜单权限列表
getMenuTree() {
let _this = this;
let oParams = {};
oParams.full = true;
getMenuTree(oParams).then((res) => {
localStorage.setItem("carTree", JSON.stringify(res.data || []));
console.log("开始处理数据" + new Date().getTime());
this.flatData(res.data);
console.log("结束处理数据" + new Date().getTime());
// 分线程处理数据
_this.mainWorker(res.data).then((e) => {
let _obj = e.data;
_this.$store.commit("updateVehicleTree", _obj.data);
_this.showTree = true;
_this.loading = false;
});
this.showTree = true;
this.loading = false;
});
......@@ -290,8 +265,8 @@ export default {
(arr || []).forEach((item) => {
item.pid = id || 0;
item.level = i;
if(item.level==3){
item.leaf=true;
if (item.level == 3) {
item.leaf = true;
}
n.push(item);
if (!id) {
......@@ -314,7 +289,7 @@ export default {
}
_this.checkList = [];
let _list = _this.$refs.tree.getCheckedNodes();
_this.getChilds(_list);
console.log(_this.checkList);
......@@ -356,7 +331,7 @@ export default {
// 取消保存
handCancle(formName) {
console.log("66")
console.log("66");
this.goBack();
},
......@@ -380,7 +355,7 @@ export default {
goBack() {
this.$refs.addUpdateForm.$children[0].resetFields();
this.$router.go(-1);
this.$refs.tree.setCheckedKeys([]);
this.$refs.tree.setCheckedKeys([]);
},
// 获取车型库详情
......@@ -447,6 +422,66 @@ export default {
_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>
......@@ -459,14 +494,14 @@ export default {
height: 385px;
overflow-y: scroll;
position: relative;
.layer{
.layer {
width: 100%;
height: 385px;
text-align: center;
line-height: 385px;
position: absolute;
z-index:10;
z-index: 10;
}
}
.pull-right {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!