Skip to content

Commit a9323f2

Browse files
committed
fix(ag-grid):整行编辑时,单元格中有多个自定义的amis控件时会只加载最后一个
1 parent a034ac4 commit a9323f2

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

packages/@steedos-widgets/ag-grid/src/amis/cellEditor/datetime.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 殷亮辉 [email protected]
33
* @Date: 2025-02-11 17:43:41
44
* @LastEditors: 殷亮辉 [email protected]
5-
* @LastEditTime: 2025-03-11 21:23:52
5+
* @LastEditTime: 2025-03-12 19:05:53
66
*/
77
import { ICellEditorComp, ICellEditorParams } from 'ag-grid-community';
88
// import * as amis from 'amis';
@@ -20,6 +20,7 @@ export class AmisDateTimeCellEditor implements ICellEditorComp {
2020
private amisData: any;
2121
private amisEnv: any;
2222
private params: ICellEditorParams;
23+
private cellFormId: string;
2324

2425

2526
init(params: ICellEditorParams): void {
@@ -42,7 +43,8 @@ export class AmisDateTimeCellEditor implements ICellEditorComp {
4243

4344
// 为 amis 组件创建一个唯一的容器 ID
4445
const cellClassName = 'amis-ag-grid-cell-editor';
45-
this.containerId = `${cellClassName}-${Math.random().toString(36).substring(2)}`;
46+
const random = Math.random().toString(36).substring(2);
47+
this.containerId = `${cellClassName}-${random}`;
4648
this.eGui.id = this.containerId + '-wrapper';
4749
this.eGui.className = `${cellClassName}-wrapper`;
4850

@@ -53,9 +55,10 @@ export class AmisDateTimeCellEditor implements ICellEditorComp {
5355
this.eGui.appendChild(containerDiv);
5456
let fieldConfig = (this.params as any).fieldConfig;
5557

58+
this.cellFormId = `cellForm__editor__datetime__${random}`;
5659
// 定义 amis 的 schema
5760
this.amisSchema = {
58-
id: 'cellForm',
61+
id: this.cellFormId,
5962
type: 'form',
6063
wrapWithPanel: false,
6164
body: [
@@ -87,7 +90,7 @@ export class AmisDateTimeCellEditor implements ICellEditorComp {
8790
const renderAmis = (window as any).renderAmis;
8891
if (renderAmis) {
8992
renderAmis(`#${this.containerId}`, this.amisSchema, this.amisData);
90-
this.amisScope = (window as any).SteedosUI.refs["cellForm"];
93+
this.amisScope = (window as any).SteedosUI.refs[this.cellFormId];
9194
}
9295
else {
9396
const amis = amisRequire("amis/embed");
@@ -99,7 +102,7 @@ export class AmisDateTimeCellEditor implements ICellEditorComp {
99102

100103
getValue(): any {
101104
// 从 amis 中获取当前数据
102-
const data = this.amisScope.getComponentById('cellForm')?.getValues();
105+
const data = this.amisScope.getComponentById(this.cellFormId)?.getValues();
103106
return (data || {})[this.name];
104107
}
105108

packages/@steedos-widgets/ag-grid/src/amis/cellEditor/lookup.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 殷亮辉 [email protected]
33
* @Date: 2025-02-11 17:43:41
44
* @LastEditors: 殷亮辉 [email protected]
5-
* @LastEditTime: 2025-03-05 12:02:56
5+
* @LastEditTime: 2025-03-12 19:05:57
66
*/
77
import { ICellEditorComp, ICellEditorParams } from 'ag-grid-community';
88
// import * as amis from 'amis';
@@ -20,6 +20,7 @@ export class AmisLookupCellEditor implements ICellEditorComp {
2020
private amisData: any;
2121
private amisEnv: any;
2222
private params: ICellEditorParams;
23+
private cellFormId: string;
2324

2425
init(params: ICellEditorParams): void {
2526
this.params = params;
@@ -41,7 +42,8 @@ export class AmisLookupCellEditor implements ICellEditorComp {
4142

4243
// 为 amis 组件创建一个唯一的容器 ID
4344
const cellClassName = 'amis-ag-grid-cell-editor';
44-
this.containerId = `${cellClassName}-${Math.random().toString(36).substring(2)}`;
45+
const random = Math.random().toString(36).substring(2);
46+
this.containerId = `${cellClassName}-${random}`;
4547
this.eGui.id = this.containerId + '-wrapper';
4648
this.eGui.className = `${cellClassName}-wrapper`;
4749

@@ -55,9 +57,10 @@ export class AmisLookupCellEditor implements ICellEditorComp {
5557

5658
const maxTagCount = fieldConfig.multiple ? (10 + Math.floor((originalWidth < minWidth ? minWidth : originalWidth) / 60)) : -1;
5759

60+
this.cellFormId = `cellForm__editor__lookup__${random}`;
5861
// 定义 amis 的 schema
5962
this.amisSchema = {
60-
id: 'cellForm',
63+
id: this.cellFormId,
6164
type: 'form',
6265
wrapWithPanel: false,
6366
// debug: true,
@@ -96,7 +99,7 @@ export class AmisLookupCellEditor implements ICellEditorComp {
9699
const renderAmis = (window as any).renderAmis;
97100
if (renderAmis) {
98101
renderAmis(`#${this.containerId}`, this.amisSchema, this.amisData);
99-
this.amisScope = (window as any).SteedosUI.refs["cellForm"];
102+
this.amisScope = (window as any).SteedosUI.refs[this.cellFormId];
100103
}
101104
else {
102105
const amis = amisRequire("amis/embed");
@@ -108,7 +111,7 @@ export class AmisLookupCellEditor implements ICellEditorComp {
108111

109112
getValue(): any {
110113
// 从 amis 中获取当前数据
111-
const data = this.amisScope.getComponentById('cellForm')?.getValues();
114+
const data = this.amisScope.getComponentById(this.cellFormId)?.getValues();
112115
return (data || {})[this.name];
113116
}
114117

packages/@steedos-widgets/ag-grid/src/amis/cellEditor/multiSelect.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 殷亮辉 [email protected]
33
* @Date: 2025-02-11 17:43:41
44
* @LastEditors: 殷亮辉 [email protected]
5-
* @LastEditTime: 2025-03-05 11:36:07
5+
* @LastEditTime: 2025-03-12 19:05:49
66
*/
77
import { ICellEditorComp, ICellEditorParams, ISelectCellEditorParams } from 'ag-grid-community';
88
// import * as amis from 'amis';
@@ -20,6 +20,7 @@ export class AmisMultiSelectCellEditor implements ICellEditorComp {
2020
private amisData: any;
2121
private amisEnv: any;
2222
private params: ICellEditorParams;
23+
private cellFormId: string;
2324

2425
init(params: ICellEditorParams): void {
2526
this.params = params;
@@ -43,7 +44,8 @@ export class AmisMultiSelectCellEditor implements ICellEditorComp {
4344

4445
// 为 amis 组件创建一个唯一的容器 ID
4546
const cellClassName = 'amis-ag-grid-cell-editor';
46-
this.containerId = `${cellClassName}-${Math.random().toString(36).substring(2)}`;
47+
const random = Math.random().toString(36).substring(2);
48+
this.containerId = `${cellClassName}-${random}`;
4749
this.eGui.id = this.containerId + '-wrapper';
4850
this.eGui.className = `${cellClassName}-wrapper`;
4951

@@ -57,9 +59,10 @@ export class AmisMultiSelectCellEditor implements ICellEditorComp {
5759
fieldOptions = fieldOptions && fieldOptions.map(function (n: string) { return { label: n, value: n } }) || [];
5860
let fieldConfig = (this.params as any).fieldConfig;
5961

62+
this.cellFormId = `cellForm__editor__select-multiple__${random}`;
6063
// 定义 amis 的 schema
6164
this.amisSchema = {
62-
id: 'cellForm',
65+
id: this.cellFormId,
6366
type: 'form',
6467
wrapWithPanel: false,
6568
body: [
@@ -101,7 +104,7 @@ export class AmisMultiSelectCellEditor implements ICellEditorComp {
101104
const renderAmis = (window as any).renderAmis;
102105
if (renderAmis) {
103106
renderAmis(`#${this.containerId}`, this.amisSchema, this.amisData);
104-
this.amisScope = (window as any).SteedosUI.refs["cellForm"];
107+
this.amisScope = (window as any).SteedosUI.refs[this.cellFormId];
105108

106109
// (window as any).Steedos.Page.render(`#${this.containerId}`, {
107110
// name: "agGridCellEditor",
@@ -119,7 +122,7 @@ export class AmisMultiSelectCellEditor implements ICellEditorComp {
119122

120123
getValue(): any {
121124
// // 从 amis 中获取当前数据
122-
const data = this.amisScope.getComponentById('cellForm')?.getValues();
125+
const data = this.amisScope.getComponentById(this.cellFormId)?.getValues();
123126
return (data || {})[this.name];
124127
}
125128

0 commit comments

Comments
 (0)