From 158b6957b79b1b008b9ecc037b4e218838622f43 Mon Sep 17 00:00:00 2001 From: wanglinfang Date: Thu, 23 Jun 2022 11:27:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/table-v2.md | 34 ++++++++++--------- packages/amis-core/src/store/crud.ts | 20 ++++++----- packages/amis/src/renderers/CRUD2.tsx | 2 +- .../src/renderers/Table-v2/ColumnToggler.tsx | 6 ++-- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/docs/zh-CN/components/table-v2.md b/docs/zh-CN/components/table-v2.md index 36eccf55e..97fc690a6 100755 --- a/docs/zh-CN/components/table-v2.md +++ b/docs/zh-CN/components/table-v2.md @@ -450,14 +450,15 @@ order: 67 "expandableOn": "this.record.id === 1 || this.record.id === 3", "keyField": "id", "expandedRowClassNameExpr": "<%= data.rowIndex % 2 ? 'bg-success' : '' %>", - "expandedRowKeys": ["3"] - }, - "expandableBody": [ - { - "type": "tpl", - "html": "
测试测试
" - } - ] + "expandedRowKeys": ["3"], + "type": "container", + "body": [ + { + "type": "tpl", + "html": "
测试测试
" + } + ] + } } ] } @@ -498,14 +499,15 @@ order: 67 "expandableOn": "this.record.id === 1 || this.record.id === 3", "keyField": "id", "expandedRowClassNameExpr": "<%= data.rowIndex % 2 ? 'bg-success' : '' %>", - "expandedRowKeysExpr": "data.record.id == '3'" - }, - "expandableBody": [ - { - "type": "tpl", - "html": "
测试测试
" - } - ] + "expandedRowKeysExpr": "data.record.id == '3'", + "type": "container", + "body": [ + { + "type": "tpl", + "html": "
测试测试
" + } + ] + } } ] } diff --git a/packages/amis-core/src/store/crud.ts b/packages/amis-core/src/store/crud.ts index e2e01a05c..2c6d3583c 100644 --- a/packages/amis-core/src/store/crud.ts +++ b/packages/amis-core/src/store/crud.ts @@ -164,13 +164,15 @@ export const CRUDStore = ServiceStore.named('CRUDStore') if (Array.isArray(options.columns)) { options.columns.forEach((column: any) => { let value: any; + // 兼容新老版本的name和key + const key = column.name || column.key; if ( column.searchable && - column.name && - (value = getVariable(self.query, column.name)) + key && + (value = getVariable(self.query, key)) ) { items = matchSorter(items, value, { - keys: [column.name] + keys: [key] }); } }); @@ -249,7 +251,6 @@ export const CRUDStore = ServiceStore.named('CRUDStore') hasNext, items: oItems, rows: oRows, - columns, ...rest } = result; @@ -308,13 +309,14 @@ export const CRUDStore = ServiceStore.named('CRUDStore') if (Array.isArray(options.columns)) { options.columns.forEach((column: any) => { let value: any; + const key = column.name || column.key; if ( column.searchable && - column.name && - (value = getVariable(self.query, column.name)) + key && + (value = getVariable(self.query, key)) ) { filteredItems = matchSorter(filteredItems, value, { - keys: [column.name] + keys: [key] }); } }); @@ -331,8 +333,8 @@ export const CRUDStore = ServiceStore.named('CRUDStore') data.count = data.total = filteredItems.length; } - if (Array.isArray(columns)) { - self.columns = columns.concat(); + if (Array.isArray(options.columns)) { + self.columns = options.columns.concat(); } else { self.columns = undefined; } diff --git a/packages/amis/src/renderers/CRUD2.tsx b/packages/amis/src/renderers/CRUD2.tsx index 29169444e..557c4588e 100644 --- a/packages/amis/src/renderers/CRUD2.tsx +++ b/packages/amis/src/renderers/CRUD2.tsx @@ -962,7 +962,7 @@ export default class CRUD2 extends React.Component { const {store} = this.props; store.updateColumns(store.columns.map((c: any, i: number) => ({ - ...c, toggled: (index === i ? toggled : c.toggled) + ...c, toggled: (index === i ? toggled : (c.toggled !== false)) }))); } diff --git a/packages/amis/src/renderers/Table-v2/ColumnToggler.tsx b/packages/amis/src/renderers/Table-v2/ColumnToggler.tsx index 4a868139f..65b2a7a3d 100644 --- a/packages/amis/src/renderers/Table-v2/ColumnToggler.tsx +++ b/packages/amis/src/renderers/Table-v2/ColumnToggler.tsx @@ -123,10 +123,10 @@ export class ColumnTogglerRenderer extends React.Component { const {data, dispatchEvent} = this.props; let columns = activeToggaleColumns.map((item: any) => item); - if (!column.toggled) { + if (column.toggled !== false) { columns.push(column); } else { - columns = columns.filter((c: any) => c.name !== column.name); + columns = columns.filter((c: any) => c.key !== column.key); } const rendererEvent = await dispatchEvent( 'columnToggled', @@ -139,7 +139,7 @@ export class ColumnTogglerRenderer extends React.Component