From 476cfb1f9c7326f7339dc16fad743b936066c66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chuailei000=E2=80=9D?= <2280131253@qq.com> Date: Thu, 3 Nov 2022 15:45:36 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20AutoDataTable=E7=BB=84=E4=BB=B6columns?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=BA=E7=A9=BA=E6=97=B6=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=89=80=E6=9C=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AutoDataTable/index.vue | 35 +++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/components/AutoDataTable/index.vue b/src/components/AutoDataTable/index.vue index 0ca6faf40..40d419073 100644 --- a/src/components/AutoDataTable/index.vue +++ b/src/components/AutoDataTable/index.vue @@ -230,23 +230,28 @@ export default { generateTotalColumns() { const config = _.cloneDeep(this.config) let columns = [] - for (let col of config.columns) { - if (typeof col === 'object') { - columns.push(col) - } else if (typeof col === 'string') { - col = this.generateColumn(col) - columns.push(col) + const configColumns = config?.columns || [] + if (configColumns.length > 0) { + for (let col of configColumns) { + if (typeof col === 'object') { + columns.push(col) + } else if (typeof col === 'string') { + col = this.generateColumn(col) + columns.push(col) + } } + columns = columns.filter(item => { + let has = item.has + if (has === undefined) { + has = true + } else if (typeof has === 'function') { + has = has() + } + return has + }) + } else { + columns = Object.keys(this.meta).map(key => this.generateColumn(key)) } - columns = columns.filter(item => { - let has = item.has - if (has === undefined) { - has = true - } else if (typeof has === 'function') { - has = has() - } - return has - }) // 第一次初始化时记录 totalColumns this.totalColumns = columns config.columns = columns