修改bug
This commit is contained in:
@@ -253,6 +253,7 @@
|
||||
//一页显示条数
|
||||
SizeChange(page,pageSize){
|
||||
this.queryParams.pageSize = pageSize
|
||||
this.queryParams.pageNo=1
|
||||
this.loadData()
|
||||
},
|
||||
//选择框
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
v-if="treeData && treeData.length"
|
||||
v-model="checkedKeys"
|
||||
checkable
|
||||
:autoExpandParent="autoExpandParent"
|
||||
:expanded-keys="expandedKeys"
|
||||
:auto-expand-parent="autoExpandParent"
|
||||
:defaultExpandAll="true"
|
||||
:tree-data="treeData"
|
||||
:selected-keys="selectedKeys"
|
||||
@@ -24,10 +24,8 @@
|
||||
>
|
||||
<template slot="title" slot-scope="{ title }">
|
||||
<span v-if="title.indexOf(searchValue) > -1">
|
||||
{{ title.substr(0, title.indexOf(searchValue)) }}
|
||||
<span style="color: #f50">{{ searchValue }}</span>{{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
|
||||
</span>
|
||||
<span v-else>{{ title }}</span>
|
||||
{{ title.substr(0, title.indexOf(searchValue)) }}<span style="color: #f50">{{ searchValue }}</span>{{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
|
||||
</span><span v-else>{{ title }}</span>
|
||||
</template>
|
||||
</a-tree>
|
||||
</a-modal>
|
||||
@@ -59,7 +57,7 @@
|
||||
},
|
||||
watch: {
|
||||
checkedKeys(val) {
|
||||
console.log('onCheck', val);
|
||||
// console.log('onCheck', val);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
@@ -68,74 +66,139 @@
|
||||
this.visible=this.subVisible
|
||||
this.generateList(this.treeData)
|
||||
},
|
||||
methods:{
|
||||
methods: {
|
||||
//获取数据
|
||||
loadData(){
|
||||
let params = {
|
||||
|
||||
}
|
||||
|
||||
getAction(`sys/category/getSysCategoryTree`,params).then(res=> {
|
||||
if(res.success){
|
||||
console.log('result',res.result)
|
||||
this.data=[...res.result]
|
||||
this.treeData1=[...this.addAttr(this.data)]
|
||||
this.treeData=[...this.treeData1]
|
||||
loadData() {
|
||||
let params = {}
|
||||
getAction(`sys/category/getSysCategoryTree`, params).then(res => {
|
||||
if (res.success) {
|
||||
this.data = [...res.result]
|
||||
// let attDate=this.addAttr(this.data)
|
||||
// this.treeData1 = [...attDate]
|
||||
this.treeData = [...this.data]
|
||||
// console.log('treeData',this.treeData)
|
||||
}
|
||||
})
|
||||
},
|
||||
onSearch(){
|
||||
// this.treeData=[]
|
||||
// this.treeData=this.getSearch(this.data)
|
||||
// this.getSearch(this.searchValue,this.treeData1)
|
||||
onSearch() {
|
||||
let self = this;
|
||||
let tree = JSON.parse(JSON.stringify(this.data))
|
||||
this.expandedKeys=[]
|
||||
if (this.searchValue.trim() == "") {
|
||||
this.treeData=JSON.parse(JSON.stringify(this.data))
|
||||
return;
|
||||
}
|
||||
if (tree && tree.length > 0) {
|
||||
tree.forEach((n, i, a) => {
|
||||
self.searchEach(n,this.searchValue);
|
||||
});
|
||||
|
||||
// 没有叶子节点的根节点也要清理掉
|
||||
let length = tree.length;
|
||||
for (let i = length - 1; i >= 0; i--) {
|
||||
let e2 = tree[i];
|
||||
if (!this.isHasChildren(e2) && e2.title.indexOf(this.searchValue) <= -1) {
|
||||
tree.splice(i, 1);
|
||||
this.expandedKeys.push(e2.key)
|
||||
}
|
||||
}
|
||||
this.treeData=[...tree]
|
||||
}
|
||||
},
|
||||
//获取用户的订阅
|
||||
getSubscribtion(){
|
||||
postAction(`domain/domainUserRel/queryList`,{}).then(res=> {
|
||||
if(res.success){
|
||||
let ids=[]
|
||||
let data=res.result
|
||||
data.forEach(res=>{
|
||||
getSubscribtion() {
|
||||
postAction(`domain/domainUserRel/queryList`, {}).then(res => {
|
||||
if (res.success) {
|
||||
let ids = []
|
||||
let data = res.result
|
||||
data.forEach(res => {
|
||||
ids.push(res.domainId)
|
||||
})
|
||||
this.checkedKeys=[...ids]
|
||||
// this.selectedKeys=this.checkedKeys
|
||||
// console.log('checkKeys',this.checkedKeys)
|
||||
this.checkedKeys = [...ids]
|
||||
}
|
||||
})
|
||||
},
|
||||
addAttr(dataI){
|
||||
if((Array.isArray(dataI)) && dataI.length>0){
|
||||
dataI.forEach((item,index)=>{
|
||||
this.$set(item,'key',item.id)
|
||||
addAttr(dataI) {
|
||||
if ((Array.isArray(dataI)) && dataI.length > 0) {
|
||||
dataI.forEach((item, index) => {
|
||||
this.$set(item, 'key', item.id)
|
||||
let arr = [];
|
||||
this.addAttr(item.children,arr);
|
||||
this.addAttr(item.children, arr);
|
||||
});
|
||||
}
|
||||
// console.log('dataI',dataI)
|
||||
return dataI
|
||||
},
|
||||
getSearch(key,tree){
|
||||
let dataSearch=[]
|
||||
let parentKey;
|
||||
for (let i = 0; i < tree.length; i++) {
|
||||
const node = tree[i];
|
||||
searchEach(node, value) {
|
||||
let depth = this.getTreeDepth(node);
|
||||
let self = this;
|
||||
for (let i = 0; i < depth - 1; i++) {
|
||||
let spliceCounter = 0;
|
||||
this.traverseTree(node, n => {
|
||||
if (self.isHasChildren(n)) {
|
||||
let children = n.children;
|
||||
let length = children.length;
|
||||
for (let j = length - 1; j >= 0; j--) {
|
||||
let e3 = children[j];
|
||||
if (!self.isHasChildren(e3) && e3.title.indexOf(value) <= -1) {
|
||||
children.splice(j, 1);
|
||||
spliceCounter++;
|
||||
}else{
|
||||
this.expandedKeys.push(e3.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (spliceCounter == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 判断树形结构中的一个节点是否具有孩子节点
|
||||
isHasChildren(node){
|
||||
let flag = false;
|
||||
if (node.children && node.children.length > 0) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
},
|
||||
|
||||
if (node.children) {
|
||||
if (node.children.some(item => item.title.indexOf(key)>-1)) {
|
||||
console.log('titel',node)
|
||||
parentKey = node.key;
|
||||
this.parentItem.push(node)
|
||||
} else if (this.getParentKey(key, node.children)) {
|
||||
parentKey = this.getParentKey(key, node.children);
|
||||
// 通过传入根节点获得树的深度
|
||||
getTreeDepth(node){
|
||||
if (undefined == node || null == node) {
|
||||
return 0;
|
||||
}
|
||||
let r = 0;
|
||||
let currentLevelNodes = [node];
|
||||
while(currentLevelNodes.length > 0){
|
||||
r++;
|
||||
let nextLevelNodes = new Array();
|
||||
for(let i = 0; i < currentLevelNodes.length; i++) {
|
||||
let e = currentLevelNodes[i];
|
||||
if (this.isHasChildren(e)) {
|
||||
nextLevelNodes = nextLevelNodes.concat(e.children);
|
||||
}
|
||||
}
|
||||
currentLevelNodes = nextLevelNodes;
|
||||
}
|
||||
return r;
|
||||
},
|
||||
|
||||
traverseTree(node, callback) {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
let stack = [];
|
||||
stack.push(node);
|
||||
let tmpNode;
|
||||
while (stack.length > 0) {
|
||||
tmpNode = stack.pop();
|
||||
callback(tmpNode);
|
||||
if (tmpNode.children && tmpNode.children.length > 0) {
|
||||
for (let i = tmpNode.children.length - 1; i >= 0; i--) {
|
||||
stack.push(tmpNode.children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('dataSearch',this.parentItem)
|
||||
return this.parentItem
|
||||
|
||||
// return dataSearch
|
||||
},
|
||||
afterVisibleChange(val) {
|
||||
// console.log('visible', val);
|
||||
@@ -185,8 +248,9 @@
|
||||
return parentKey;
|
||||
},
|
||||
onExpand(expandedKeys){
|
||||
console.log('valkey',expandedKeys)
|
||||
this.expandedKeys = expandedKeys;
|
||||
this.autoExpandParent = false;
|
||||
this.autoExpandParent = true;
|
||||
},
|
||||
onChange(e) {
|
||||
// this.loadData()
|
||||
@@ -205,6 +269,7 @@
|
||||
searchValue: value,
|
||||
autoExpandParent: true,
|
||||
})
|
||||
this.onSearch()
|
||||
},
|
||||
onCheck(checkedKeys) {
|
||||
// console.log('onCheck', checkedKeys);
|
||||
|
||||
Reference in New Issue
Block a user