diff --git a/src/components/TreeTable/index.vue b/src/components/TreeTable/index.vue index 5e3452bf..f5e99a61 100644 --- a/src/components/TreeTable/index.vue +++ b/src/components/TreeTable/index.vue @@ -1,5 +1,9 @@ + {{ scope.row[item.key] }} @@ -45,11 +53,26 @@ export default { default: () => [] }, /* eslint-disable */ - evalFunc: { + renderContent: { type: Function }, - evalArgs: Object - /* eslint-enable */ + /* eslint-enable */ + defaultExpandAll: { + type: Boolean, + default: false + }, + defaultChildren: { + type: String, + default: 'children' + }, + spreadOffset: { + type: Number, + default: 50 + }, + checkboxOffset: { + type: Number, + default: 50 + } }, computed: { // 格式化数据源 @@ -60,11 +83,9 @@ export default { } else { tmp = this.data } - const func = this.evalFunc || treeToArray - const args = { ...this.evalArgs } - return func(tmp, args) + const func = this.renderContent || treeToArray + return func(tmp, { expand: this.defaultExpandAll, children: this.defaultChildren }) }, - // 自定义的children字段 children() { return this.evalArgs && this.evalArgs.children || 'children' @@ -86,17 +107,21 @@ export default { const record = this.res[trIndex] const expand = !record.__expand record.__expand = expand - // 收起是全部收起,展开是一级一级展开 - // if (!expand) { - // this.expandRecursion(record, expand) - // } }, - expandRecursion(row, expand) { - const children = row[this.children] - if (children && children.length > 0) { - children.map(child => { - child.__expand = expand - this.expandRecursion(child, expand) + handleCheckAllChange(row) { + this.selcetRecursion(row, row.__select, this.defaultChildren) + this.isIndeterminate = row.__select + }, + selcetRecursion(row, select, children = 'children') { + if (select) { + this.$set(row, '__expand', true) + this.$set(row, '__show', true) + } + const sub_item = row[children] + if (sub_item && sub_item.length > 0) { + sub_item.map(child => { + child.__select = select + this.selcetRecursion(child, select, children) }) } } diff --git a/src/components/TreeTable/readme.md b/src/components/TreeTable/readme.md index 64c7ad5e..78fea280 100644 --- a/src/components/TreeTable/readme.md +++ b/src/components/TreeTable/readme.md @@ -57,6 +57,8 @@ const data = [ const columns = [ // 建议第一列做展开收缩操作 { label: '', key: '__spread', width: '200' }, + // 如果添加复选框 + { label: '', key: '__checkbox', width: '200' }, { value: string, text: string, diff --git a/src/views/table/treeTable/customTreeTable.vue b/src/views/table/treeTable/customTreeTable.vue index a113e7c3..7b698e17 100644 --- a/src/views/table/treeTable/customTreeTable.vue +++ b/src/views/table/treeTable/customTreeTable.vue @@ -5,11 +5,24 @@ Documentation - -