diff --git a/docs/components/demos/ProArrayTableWithShadow.tsx b/docs/components/demos/ProArrayTableWithShadow.tsx index 68e645a..770dbbc 100644 --- a/docs/components/demos/ProArrayTableWithShadow.tsx +++ b/docs/components/demos/ProArrayTableWithShadow.tsx @@ -53,11 +53,12 @@ const row: ISchema = { "x-component": "ProArrayTable.Column", "x-component-props": { title: "编辑", align: "center" }, properties: { - _trigger: { + // ↓ 不填写 act 属性的话, 就读这个 modal 了 (schema.name) + modal: { type: "void", "x-decorator": "ProArrayTable.DelegateAction", "x-decorator-props": { - act: "modal", + // act: "modal", // 这里不填写的话, 就读取上面 initLoader: (o: any) => { console.log("🚀 ~ o::", o); return o; @@ -83,7 +84,7 @@ const schema: ISchema = { "x-component": "ProArrayTable", items: row.items, properties: { - // ↓ 不填写 act 属性的话, 就读这个 modal 字段 + // ↓ 不填写 act 属性的话, 就读这个 modal 了 (schema.name) modal: { type: "void", "x-component": "ProArrayTable.ShadowModal", diff --git a/src/pro-array-table/mixin.pro.tsx b/src/pro-array-table/mixin.pro.tsx index d30bf5b..6b0b9c4 100644 --- a/src/pro-array-table/mixin.pro.tsx +++ b/src/pro-array-table/mixin.pro.tsx @@ -217,8 +217,8 @@ export const ArrayTableShowModal: React.FC< }; export const DelegateAction: React.FC<{ - /** 动作标志, 与 ShadowModal 对应 */ - act: string; + /** 动作标志, 与 ShadowModal 对应, 不填写的话去 schema 的名字 */ + act?: string; /** 当前列所属 index, 默认使用 ArrayBase.useIndex() 获取当前数据对应位置 */ index?: number; /** 数据初始化加载器, 默认使用 field.record 当前模型所对应 record */ @@ -231,19 +231,22 @@ export const DelegateAction: React.FC<{ }> = (props) => { const index = "index" in (props ?? {}) ? props.index : ArrayBase.useIndex(); const field = useField(); + const schema = useFieldSchema(); const record = useRecord(); const delegate = useContext(ArrayTableDelegateContext); + const actName = props.act ?? schema.name; + useEffect(() => { if (!delegate.initLoader) return; - if (delegate.act === props.act && delegate.index === index) { + if (delegate.act === actName && delegate.index === index) { delegate.initLoader.current = props.initLoader ? () => props.initLoader?.(record) : () => record; } }, [delegate.act, delegate.index, delegate.initLoader]); const dataInfo = { - [DATE_DELEGATE_ACT_KEY]: props.act, + [DATE_DELEGATE_ACT_KEY]: actName, [DATE_DELEGATE_INDEX_KEY]: index, };