/** * @file ApiDsBuilder * @desc 外部 API 接口数据源构造器 */ import { DSBuilder } from './DSBuilder'; import type { EditorNodeType } from 'amis-editor-core'; import type { ButtonSchema } from 'amis'; import type { DSRendererType, DSFeatureType, GenericSchema, FormOperatorValue, ScaffoldField, FormScaffoldConfig, CRUDScaffoldConfig } from './type'; import type { DSBuilderBaseOptions } from './DSBuilder'; export interface ApiDSBuilderOptions extends DSBuilderBaseOptions { /** 渲染器类型 */ renderer: DSRendererType; /** 脚手架配置 */ scaffoldConfig?: R extends 'crud' ? CRUDScaffoldConfig : FormScaffoldConfig; /** 配置面板设置 */ sourceSettings?: { /** 数据源字段名 */ name?: string; /** 数据源字段标题 */ label?: any; renderLabel?: boolean; labelClassName?: string; mode?: 'horizontal' | 'normal'; horizontalConfig?: { justify: boolean; left?: number; right?: number; }; visibleOn?: string; }; /** 字段管理配置 */ fieldSettings?: { renderLabel?: boolean; }; /** 控件配置 */ controlSettings?: { fieldMapper?: >(option: any) => T | false; }; } export declare class ApiDSBuilder extends DSBuilder> { static key: string; isDefault: boolean; readonly name: string; readonly order: number; readonly features: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[]; /** * 获取键值。 */ get key(): string; match(schema: any, key?: string): boolean; getContextFields(options: ApiDSBuilderOptions): Promise; getAvailableContextFields(options: ApiDSBuilderOptions, target: EditorNodeType): Promise; getCRUDListFields>(options: ApiDSBuilderOptions): Promise; getCRUDSimpleQueryFields>(options: ApiDSBuilderOptions): Promise; makeSourceSettingForm(options: ApiDSBuilderOptions): any[]; makeFieldsSettingForm(options: ApiDSBuilderOptions): { type: string; name: string; label: string | boolean; renderer: DSRendererType; feat: "Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery"; fieldKeys: string[]; config: { showInputType: boolean; showDisplayType: boolean; }; onAutoGenerateFields: any; }[]; /** * 基于接口生成字段 * 注意CRUD的接口返回格式,目前兼容items、rows、options字段,否则取data下的首个数组元素(和CRUD加载逻辑对齐) */ autoGenerateFields({ api, props, setState }: { api: any; props: Record; setState: (state: any) => void; }): Promise; getApiKey(options: Partial<{ feat: DSFeatureType; [propName: string]: any; }>): string; getFieldsKey(options: Partial<{ feat: DSFeatureType; [propName: string]: any; }>): string; buildBaseButtonSchema(options: ApiDSBuilderOptions, schemaPatch?: { formSchema: GenericSchema; buttonSchema?: { label?: string; level?: ButtonSchema['level']; order?: number; [propName: string]: any; }; dialogSchema?: { title?: string; actions: GenericSchema[]; }; componentId?: string; }): GenericSchema; /** 构建表单按钮操作区 */ buildFormOperators(options: ApiDSBuilderOptions<'form'>, componentId: string): { type: string; label: string; onEvent: { click: { actions: { actionType: FormOperatorValue; componentId: string; }[]; }; }; }[]; /** * 为输入类控件追加的初始化Schema配置,避免某些类型组件渲染报错 */ appendSchema2InputControl(inputType: string): { items: { type: string; name: string; placeholder: string; }[]; } | { items?: undefined; }; buildBaseFormSchema(options: ApiDSBuilderOptions, schemaPatch?: GenericSchema, componentId?: string): { id?: string | undefined; } | { id: any; }; buildInsertSchema(options: ApiDSBuilderOptions, componentId?: string): Promise<{ id?: string | undefined; } | { id: any; }>; buildViewSchema(options: ApiDSBuilderOptions, componentId?: string): Promise<{ [x: string]: any; }>; buildEditSchema(options: ApiDSBuilderOptions, componentId?: string): Promise<{ id?: string | undefined; } | { id: any; }>; buildBulkEditSchema(options: ApiDSBuilderOptions, componentId?: string): Promise<{ id?: string | undefined; } | { id: any; }>; buildCRUDDeleteSchema(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; label: string; behavior: string; className: string; level: string; confirmText: string; onEvent: { click: { actions: ({ actionType: string; api: any; data: { '&': string; }; groupType?: undefined; componentId?: undefined; } | { actionType: string; groupType: string; componentId: string | undefined; api?: undefined; data?: undefined; })[]; }; }; }>; buildCRUDExportSchema(options: ApiDSBuilderOptions<'crud'>): Promise<{ type: string; label: string; behavior: string; className: string; onEvent: { click: { actions: { actionType: string; api: any; }[]; }; }; }>; buildCRUDBulkDeleteSchema(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; label: string; behavior: string; level: string; className: string; confirmText: string; disabledOn: string; onEvent: { click: { actions: ({ actionType: string; api: any; groupType?: undefined; componentId?: undefined; } | { actionType: string; groupType: string; componentId: string | undefined; api?: undefined; })[]; }; }; }>; buildSimpleQueryCollectionSchema(options: ApiDSBuilderOptions<'crud'>): Promise; buildCRUDFilterSchema(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; title: string; mode: string; columnCount: number; clearValueOnHidden: boolean; behavior: string[]; body: ({ items: { type: string; name: string; placeholder: string; }[]; type: string; size: string; required: boolean; behavior: string; label: string; name: string; } | { items?: undefined; type: string; size: string; required: boolean; behavior: string; label: string; name: string; })[]; actions: ({ type: string; label: string; level?: undefined; } | { type: string; label: string; level: string; })[]; }>; buildCRUDOpColumn(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; title: string; buttons: { [x: string]: any; }[]; }>; buildCRUDColumn(field: ScaffoldField, options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; title: string; name: string; }>; buildCRUDColumnsSchema(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<({ type: string; title: string; name: string; } | { type: string; title: string; buttons: { [x: string]: any; }[]; })[]>; buildToolbarContainer(align: 'left' | 'right', body?: GenericSchema[], behaviors?: DSFeatureType[]): { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }; buildToolbarFlex(position: 'header' | 'footer', left: GenericSchema[], right: GenericSchema[]): { type: string; direction: string; justify: string; alignItems: string; style: { position: string; }; items: { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }[]; }[]; buildHeaderToolbar(options: ApiDSBuilderOptions<'crud'>, componentId?: string): Promise<{ type: string; direction: string; justify: string; alignItems: string; style: { position: string; }; items: { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }[]; }[]>; buildFooterToolbar(options: ApiDSBuilderOptions<'crud'>, componentId: string): { type: string; direction: string; justify: string; alignItems: string; style: { position: string; }; items: { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }[]; }[]; guessFormScaffoldConfig(options: { schema: GenericSchema; [propName: string]: any; }): FormScaffoldConfig; guessCRUDScaffoldConfig(options: { schema: GenericSchema; [propName: string]: any; }): CRUDScaffoldConfig; buildCRUDSchema(options: ApiDSBuilderOptions<'crud'>): Promise<{ headerToolbar: { type: string; direction: string; justify: string; alignItems: string; style: { position: string; }; items: { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }[]; }[]; footerToolbar: { type: string; direction: string; justify: string; alignItems: string; style: { position: string; }; items: { body: GenericSchema[]; wrapperBody: boolean; style: { justifyContent?: string | undefined; flexGrow: number; flex: string; position: string; display: string; flexBasis: string; flexDirection: string; flexWrap: string; alignItems: string; }; behavior?: ("Edit" | "View" | "Delete" | "List" | "Insert" | "Import" | "Export" | "BulkEdit" | "BulkDelete" | "SimpleQuery" | "FuzzyQuery" | "AdvancedQuery")[] | undefined; type: string; align: "left" | "right"; }[]; }[]; columns: ({ type: string; title: string; name: string; } | { type: string; title: string; buttons: { [x: string]: any; }[]; })[]; filter?: { type: string; title: string; mode: string; columnCount: number; clearValueOnHidden: boolean; behavior: string[]; body: ({ items: { type: string; name: string; placeholder: string; }[]; type: string; size: string; required: boolean; behavior: string; label: string; name: string; } | { items?: undefined; type: string; size: string; required: boolean; behavior: string; label: string; name: string; })[]; actions: ({ type: string; label: string; level?: undefined; } | { type: string; label: string; level: string; })[]; } | undefined; quickSaveItemApi?: any; quickSaveApi?: any; primaryField: string; loadType: string; api: any; selectable?: boolean | undefined; multiple?: boolean | undefined; id: any; type: string; mode: string; dsType: string; syncLocation: boolean; }>; buildFormSchema(options: ApiDSBuilderOptions<'form'>): Promise<{ dsType: string; initApi?: any; } | { id: any; dsType: string; initApi?: any; }>; buildApiSchema(options: ApiDSBuilderOptions): Promise; }