diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index 990a0d4f..ffc3575a 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -42,6 +42,9 @@ export declare type ActionDef; + label?: string; + color?: string; + key?: string; } | ED[T]['Action']; export declare type RowWithActions = Partial & { '#oakLegalActions': ActionDef[]; diff --git a/src/components/upsert/index.ts b/src/components/upsert/index.ts index d906cb7c..143b05c6 100644 --- a/src/components/upsert/index.ts +++ b/src/components/upsert/index.ts @@ -1,7 +1,7 @@ import { EntityDict } from 'oak-domain/lib/types/Entity'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { DataUpsertTransformer } from '../../types/AbstractComponent'; -import { makeDataUpsertTransformer } from '../../utils/usefulFn'; +import { analyzeDataUpsertTransformer } from '../../utils/usefulFn'; export default OakComponent({ isList: false, @@ -35,7 +35,7 @@ export default OakComponent({ const { attributes, entity } = this.props; const schema = this.features.cache.getSchema(); - const transformer = makeDataUpsertTransformer(schema, entity!, attributes!, (k, params) => this.t(k, params)); + const transformer = analyzeDataUpsertTransformer(schema, entity!, attributes!, (k, params) => this.t(k, params)); this.setState({ transformer, }); diff --git a/src/components/upsert/web.pc.tsx b/src/components/upsert/web.pc.tsx index 0aa6001c..137ecaa4 100644 --- a/src/components/upsert/web.pc.tsx +++ b/src/components/upsert/web.pc.tsx @@ -20,7 +20,8 @@ import dayjs from 'dayjs'; import { AttrRender, AttrUpsertRender, OakAbsRefAttrPickerRender, OakNativeAttrUpsertRender } from '../../types/AbstractComponent'; import { WebComponentProps } from '../../types/Page'; -function makeAttrInput(attrRender: AttrUpsertRender, onValueChange: (value: any) => void) { +type ED = EntityDict & BaseEntityDict; +function makeAttrInput(attrRender: AttrUpsertRender, onValueChange: (value: any) => void) { const { value, type, params, label, defaultValue, required } = attrRender as OakNativeAttrUpsertRender; switch (type) { case 'string': @@ -182,6 +183,9 @@ function makeAttrInput(attrRender: AttrUpsertRender ); } + case 'ref': { + const { mode, } = attrRender as OakAbsRefAttrPickerRender; + } default: { throw new Error(`【Abstract Update】无法支持的数据类别${type}的渲染`); } @@ -189,11 +193,11 @@ function makeAttrInput(attrRender: AttrUpsertRender } export default function render(props: WebComponentProps< - EntityDict & BaseEntityDict, + ED, keyof EntityDict, false, { - renderData: AttrUpsertRender[]; + renderData: AttrUpsertRender[]; children: any; }, { @@ -225,7 +229,7 @@ export default function render(props: WebComponentProps< { makeAttrInput(ele, (value) => { if (ele.type === 'ref') { - const { attr, entity } = ele as OakAbsRefAttrPickerRender; + const { attr, entity } = ele as OakAbsRefAttrPickerRender; if (attr) { update({ [attr]: value, diff --git a/src/types/AbstractComponent.ts b/src/types/AbstractComponent.ts index bbc14351..f671f4da 100644 --- a/src/types/AbstractComponent.ts +++ b/src/types/AbstractComponent.ts @@ -49,15 +49,13 @@ export interface OakAbsRefAttrPickerDef = Pick< - OakAbsRefAttrPickerDef, - 'mode' | 'projection' | 'entity' | 'projection' | 'title' | 'filter' | 'count' -> & { +export type OakAbsRefAttrPickerRender = { type: 'ref'; - attr?: string; // 为undefined意味着是entity/entityId的指针 + attr: string; label: string; value: any; required?: boolean; + mode: OakAbsRefAttrPickerDef['mode'], } export type OakAbsGeoAttrsDef = { diff --git a/src/types/Page.ts b/src/types/Page.ts index ffa47dd2..0833a93e 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -89,6 +89,9 @@ export type ActionDef< action: ED[T]['Action'], filter?: ED[T]['Selection']['filter']; data?: Partial; + label?: string; + color?: string; + key?: string; } | ED[T]['Action']; export type RowWithActions< diff --git a/src/utils/usefulFn.ts b/src/utils/usefulFn.ts index 2f8368b6..e4a35674 100644 --- a/src/utils/usefulFn.ts +++ b/src/utils/usefulFn.ts @@ -16,6 +16,7 @@ import { DataUpsertTransformer, AttrUpsertRender, OakAbsDerivedAttrDef, + OakAbsRefAttrPickerDef, } from '../types/AbstractComponent'; import { Attributes } from 'oak-domain/lib/types'; import { get } from 'oak-domain/lib/utils/lodash'; @@ -230,11 +231,14 @@ export function makeDataTransformer(data }); } -export function makeDataUpsertTransformer( +export function analyzeDataUpsertTransformer( dataSchema: StorageSchema, entity: string, attrUpsertDefs: OakAbsAttrUpsertDef[], t: (k: string, params?: object) => string): DataUpsertTransformer { + + const otmPickerDict: Record> = {}; + const transformerFixedPart = attrUpsertDefs.map( (ele) => { if (typeof ele === 'string') { @@ -260,14 +264,19 @@ export function makeDataUpsertTransformer) => title(data[attr]), label: label || t(`${refEntity}:name`),