update Table tree

This commit is contained in:
梁灏 2020-01-06 11:17:09 +08:00
parent 6885f5ec49
commit 1e2341aa5d
4 changed files with 44 additions and 24 deletions

View file

@ -6,7 +6,7 @@
</template>
<div class="ivu-table-cell-tree-level" v-if="showLevel" :style="treeLevelStyle"></div>
<div class="ivu-table-cell-tree" v-if="showChildren" @click="handleToggleTree">
<Icon type="ios-add" v-if="!row._isShowChildren" />
<Icon type="ios-add" v-if="!childrenExpand" />
<Icon type="ios-remove" v-else />
</div>
<div class="ivu-table-cell-tree ivu-table-cell-tree-empty" v-else-if="showTreeNode"></div>
@ -125,6 +125,10 @@
return {
'padding-left': this.treeLevel * this.tableRoot.indentSize + 'px'
};
},
childrenExpand () {
const data = this.tableRoot.getDataByRowKey(this.row._rowKey);
return data._isShowChildren;
}
},
methods: {

View file

@ -142,14 +142,15 @@
},
isTrShow (rowKey) {
let status = true;
this.data.forEach(row => {
for (let i in this.objData) {
const row = this.objData[i];
const showChildren = row._isShowChildren;
if (row._rowKey === rowKey) {
status = status && showChildren;
} else if (row.children && row.children.length) {
status = this.getTrStatus(rowKey, row, status && showChildren);
}
});
}
return status;
},
getTrStatus (rowKey, data, parentStatus) {

View file

@ -698,7 +698,7 @@
const data = this.getDataByRowKey(rowKey);
data._isShowChildren = !data._isShowChildren;
},
getDataByRowKey (rowKey, objData = this.rebuildData) {
getDataByRowKey (rowKey, objData = this.objData) {
let data = null;
for (let i in objData) {
const thisData = objData[i];
@ -962,11 +962,6 @@
row._index = index;
row._rowKey = (typeof this.rowKey) === 'string' ? row[this.rowKey] : rowKey++;
if (row.children && row.children.length) {
if (row._showChildren) {
row._isShowChildren = row._showChildren;
} else {
row._isShowChildren = false;
}
row.children = this.makeChildrenData(row);
}
});
@ -977,12 +972,7 @@
return data.children.map((row, index) => {
const newRow = deepCopy(row);
newRow._index = index;
newRow._rowKey = (typeof this.rowKey) === 'string' ? row[this.rowKey] : rowKey++;
if (newRow._showChildren) {
newRow._isShowChildren = newRow._showChildren;
} else {
newRow._isShowChildren = false;
}
newRow._rowKey = (typeof this.rowKey) === 'string' ? newRow[this.rowKey] : rowKey++;
if (newRow.children && newRow.children.length) {
newRow.children = this.makeChildrenData(newRow);
}
@ -1022,6 +1012,9 @@
makeObjBaseData (row) {
const newRow = deepCopy(row);
newRow._isHover = false;
if ((typeof this.rowKey) === 'string') {
newRow._rowKey = newRow[this.rowKey];
}
if (newRow._disabled) {
newRow._isDisabled = newRow._disabled;
} else {
@ -1049,12 +1042,11 @@
this.data.forEach((row, index) => {
const newRow = this.makeObjBaseData(row);
if (newRow.children && newRow.children.length) {
// todo objData _isShowChildren rebuildData rowKey
// if (newRow._showChildren) {
// newRow._isShowChildren = newRow._showChildren;
// } else {
// newRow._isShowChildren = false;
// }
if (newRow._showChildren) {
newRow._isShowChildren = newRow._showChildren;
} else {
newRow._isShowChildren = false;
}
newRow.children = this.makeChildrenObjData(newRow);
}
data[index] = newRow;
@ -1065,6 +1057,11 @@
if (data.children && data.children.length) {
return data.children.map(row => {
const newRow = this.makeObjBaseData(row);
if (newRow._showChildren) {
newRow._isShowChildren = newRow._showChildren;
} else {
newRow._isShowChildren = false;
}
if (newRow.children && newRow.children.length) {
newRow.children = this.makeChildrenObjData(newRow);
}