Commit 9d41b271 by jack

修复树形回显导致浏览器假死

1 parent e0605af8
......@@ -138,17 +138,18 @@ export default {
// console.log(n,"浏览器存储");
//_this.flatData(n);
_this.mainWorker(n).then((res) => {
_this.showTree = true;
_this.loading = false;
if (o.id) {
_this.getInfo(o.id);
return false;
}
_this.loading = false;
_this.showTree = true;
});
return false;
}
_this.getMenuTree();
}, 10);
if (o.title == "add") {
this.type = 1; //后台要区分新增,和编辑,1:新增,2:编辑
} else if (o.title == "edit") {
......@@ -251,26 +252,6 @@ export default {
resolve(arr);
},
// 数据扁平化
flatData(arr, id, index) {
let n = this.newArr;
let _this = this;
let i = index || 0;
(arr || []).forEach((item) => {
item.pid = id || 0;
item.level = i;
n.push(item);
if (!id) {
_this.treedata.push(item);
}
item.childs && item.childs.length > 0
? _this.flatData(item.childs, item.id, i + 1)
: "";
//item.childs = ""; //如果扁平化后的数组需要显示父子层级,可以把这一项删除
});
},
//保存按钮,提交当前表单
submitForm() {
let _this = this;
......@@ -362,124 +343,22 @@ export default {
return false;
}
let o = res.data || {};
let typeList = o.typeIds || [];
let _models = []; //子节点
let _brand = []; // 品牌
let _subBrand = []; // 子品牌
let _series = []; // 车系
let list = this.newArr;
let _earr = []; // 默认展开的节点
// 半选数组
let _half = [];
// 全选数组
let _check = [];
typeList.map((k) => {
let m, b, f;
//寻找当前元素
let n = list.find((j) => j.id == k && j.level == 3);
// 找第三级
if (n) {
m = list.find((j) => j.id == n.pid && j.level == 2);
//_series.push(m);
_earr.push(m.id);
}
// 找第二级
if (m) {
b = list.find((j) => j.id == m.pid && j.level == 1);
//_subBrand.push(b);
_earr.push(b.id);
}
// 找第一级
if (b) {
f = list.find((j) => {
return j.id == b.pid && j.level == 0;
});
let _idx = _brand.findIndex((v) => v.id == f.id);
if (_idx < 0) {
_brand.push(f);
_earr.push(f.id);
}
}
let typeList = o.typeIds;
console.log(new Date().getTime());
_this.treeMainWorker(o).then((j) => {
console.log(j);
_this.expandedKey = j;
_this.$refs.tree.setCheckedKeys(typeList);
});
_this.expandedKey = _earr;
_this.$refs.tree.setCheckedKeys(typeList);
console.log(new Date().getTime());
this.addUpdateForm.name = o.name || "暂无";
this.addUpdateForm.initOrganize = o.tenantId;
this.addUpdateForm.enableStatus = o.enableStatus == 2 ? false : true;
this.typeList = o.typeIds || [];
//this.typeList = o.typeIds || [];
});
},
getExpandNode() {
let _this = this;
let typeList = this.typeList;
let _models = []; //子节点
let _brand = []; // 品牌
let _subBrand = []; // 子品牌
let _series = []; // 车系
let list = this.newArr;
console.log("1", list.length);
let _earr = []; // 默认展开的节点
// 半选数组
let _half = [];
// 全选数组
let _check = [];
typeList.map((k) => {
let m, b, f;
//寻找当前元素
let n = list.find((j) => j.id == k && j.level == 3);
// 找第三级
if (n) {
m = list.find((j) => j.id == n.pid && j.level == 2);
//_series.push(m);
_earr.push(m.id);
}
// 找第二级
if (m) {
b = list.find((j) => j.id == m.pid && j.level == 1);
//_subBrand.push(b);
_earr.push(b.id);
}
// 找第一级
if (b) {
f = list.find((j) => {
return j.id == b.pid && j.level == 0;
});
let _idx = _brand.findIndex((v) => v.id == f.id);
if (_idx < 0) {
_brand.push(f);
_earr.push(f.id);
}
}
});
_this.expandedKey = _earr;
console.log("typeList:", typeList);
console.log(_this.expandedKey.length, typeList.length, "长度");
setTimeout(() => {
_this.$refs.tree.setCheckedKeys(typeList);
}, 3000);
},
// 创建分线程
createWorker() {
let myWorker = function () {
......@@ -527,6 +406,7 @@ export default {
return new Promise((resolve, reject) => {
let _workerJs = _this.createWorker();
let webWorker = new Worker(window.URL.createObjectURL(_workerJs));
webWorker.postMessage(data);
webWorker.onmessage = function (e) {
let _obj = e.data;
......@@ -540,6 +420,90 @@ export default {
};
});
},
// 创建树形结构回显分线程
creatTreeWorker() {
let myWorker = function () {
let that = this;
let _tree = [];
let _allTree = [];
that.addEventListener("message", function (e) {
if (!e.data) {
return false;
}
console.log(e.data);
let _obj = e.data;
let list = _obj.list;
let typeList = _obj.typeList;
let _earr = [];
let _brand = [];
typeList.map((k) => {
let m, b, f;
//寻找当前元素
let n = list.find((j) => j.id == k && j.level == 3);
// 找第三级
if (n) {
m = list.find((j) => j.id == n.pid && j.level == 2);
//_series.push(m);
_earr.push(m.id);
}
// 找第二级
if (m) {
b = list.find((j) => j.id == m.pid && j.level == 1);
//_subBrand.push(b);
_earr.push(b.id);
}
// 找第一级
if (b) {
f = list.find((j) => {
return j.id == b.pid && j.level == 0;
});
let _idx = _brand.findIndex((v) => v.id == f.id);
if (_idx < 0) {
_brand.push(f);
_earr.push(f.id);
}
}
});
that.postMessage({ brand: _brand, expanded: _earr });
});
};
let workerData = new Blob(["(" + myWorker.toString() + ")()"], {
type: "text/javascript",
});
return workerData;
},
// 回显树形数据,主线程
treeMainWorker(data) {
let _this = this;
return new Promise((resolve, reject) => {
let _workerJs = _this.creatTreeWorker();
let webWorker = new Worker(window.URL.createObjectURL(_workerJs));
let oParams = {};
oParams.typeList = data.typeIds;
oParams.list = _this.newArr;
webWorker.postMessage(oParams);
webWorker.onmessage = function (e) {
let _obj = e.data;
// _this.treedata = _obj.tree;
// _this.newArr = _obj.data;
_this.showTree = true;
resolve(_obj.expanded);
};
// 监听文件失败
webWorker.onmessageerror = function (e) {
reject(e);
};
});
},
},
};
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!