From a15ce0b77ff44b76c27ad61c9b62cb011826ec67 Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 28 Jan 2021 17:55:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=A1=A8=E6=A0=BC=E5=88=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ColumnSettingPopover.vue | 10 ++++- src/components/AutoDataTable/index.vue | 40 +++++++++++-------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/components/AutoDataTable/components/ColumnSettingPopover.vue b/src/components/AutoDataTable/components/ColumnSettingPopover.vue index 5a9a66379..18b3c8a11 100644 --- a/src/components/AutoDataTable/components/ColumnSettingPopover.vue +++ b/src/components/AutoDataTable/components/ColumnSettingPopover.vue @@ -24,7 +24,11 @@ > {{ item.label }} @@ -50,6 +54,10 @@ export default { currentColumns: { type: Array, default: () => [] + }, + minColumns: { + type: Array, + default: () => [] } }, data() { diff --git a/src/components/AutoDataTable/index.vue b/src/components/AutoDataTable/index.vue index 1951a1668..8a229d7df 100644 --- a/src/components/AutoDataTable/index.vue +++ b/src/components/AutoDataTable/index.vue @@ -4,6 +4,7 @@ @@ -40,7 +41,8 @@ export default { totalColumns: [], currentColumns: [], defaultColumns: [], - totalColumnsList: [] + totalColumnsList: [], + minColsList: [] } }, computed: { @@ -69,8 +71,10 @@ export default { this.meta = data.actions[this.method.toUpperCase()] || {} this.generateColumns() }).then(() => { - this.generateDefaultColumns() + // 生成给子组件使用的TotalColList + this.generateColsList() }).then(() => { + // 根据当前列重新生成最终渲染表格 this.generateCurrentColumns(this.currentColumns) }).catch((error) => { this.$log.error('Error occur: ', error) @@ -205,25 +209,15 @@ export default { config.columns = columns this.iConfig = config }, - generateCurrentColumns(col) { - const currentColumns = [] - this.totalColumns.forEach((v, k) => { - if (col.indexOf(v.prop) !== -1 || - v.prop === 'id') { - currentColumns.push(this.totalColumns[k]) - } - }) - this.iConfig.columns = currentColumns - }, - generateDefaultColumns() { + // 生成给子组件使用的TotalColList + generateColsList() { let defaultColumns = [] const totalColumnsList = [] - this.totalColumns.forEach((v, k) => { - if (!this.iConfig.defaultColumns) { + if (!_.get(this.iConfig['columnsShow'], 'default', false)) { defaultColumns.push(v.prop) } else { - defaultColumns = this.iConfig.defaultColumns + defaultColumns = _.get(this.iConfig['columnsShow'], 'default') } totalColumnsList.push({ prop: v.prop, @@ -232,8 +226,22 @@ export default { }) this.defaultColumns = defaultColumns this.totalColumnsList = totalColumnsList + this.minColsList = _.get(this.iConfig['columnsShow'], 'min', []) this.currentColumns = _.get(this.tableConfig[this.$route.name], 'currentColumns', this.defaultColumns) }, + generateCurrentColumns(col) { + const currentColumns = [] + this.totalColumns.forEach((v, k) => { + // 过滤展示表格 + if (col.indexOf(v.prop) !== -1 || + // 根据必须展示列过滤展示表格 + this.minColsList.indexOf(v.prop) !== -1 || + v.prop === 'id') { + currentColumns.push(this.totalColumns[k]) + } + }) + this.iConfig.columns = currentColumns + }, handleColumnsChange(val) { this.currentColumns = val this.tableConfig[this.$route.name] = {