Skip to content

getAssociatedRecordsConfig

获取关联记录组件相关配置选项

类型

ts
interface GetAssociatedRecordsConfigOptions {
  /**
   * 是否是 APP 环境
   *  - 是的话, 将使用 APP 视图
   */
  isApp?: boolean;
  /**
   * 是否是在表格上显示
   *  - 是的话, 将使用 "表格显示字段"
   */
  isTable?: boolean;
}

/**
 * @param config 组件配置
 * @param options 配置项
 */
function getAssociatedRecordsConfig(
  config: TemplateFormAssociatedRecordsField,
  options?: GetAssociatedRecordsConfigOptions
): Promise<{
  /** 模板视图表格显示字段 */
  fields: TemplateFormField[];
  /** 模板字段列表 */
  columns: TemplateViewColumnAndConfig[];
  /** 显示字段 */
  labelKey: string | { label: string; prop: string }[];
  /** 搜索字段 */
  searchFields: { label: string; prop: string }[];
}>;

getAssociatedRecordsFiltersConfig

获取关联记录组件数据过滤配置

类型

ts
/**
 * @param config 组件配置
 * @param form 表单值 ( 行数据 )
 */
function getAssociatedRecordsFiltersConfig(
  config: Pick<TemplateFormAssociatedRecordsField, 'enableFilters' | 'filters'>,
  form: Record<string, any>
): { field: string; value: any }[];

getAssociatedRecordsDetail

获取关联记录组件数据详情

类型

ts
/**
 * @param id 数据ID
 * @param config 组件配置
 */
function getAssociatedRecordsDetail(
  id: string,
  config: TemplateFormAssociatedRecordsField
): Promise<Record<string, any>>;

getAssociatedRecordsList

获取关联记录组件数据列表

类型

ts
interface GetAssociatedRecordsListOptions {
  /** 当前页码 */
  current?: number;
  /** 每页条数 */
  size?: number;
  /** 搜索字段 */
  params?: Record<string, any>;
  /** 表单值 ( 行数据 ) */
  form: Record<string, any>;
}

/**
 * 获取关联记录组件数据列表
 * @param config 组件配置
 * @param options 组件配置
 */
function getAssociatedRecordsList(
  config: TemplateFormAssociatedRecordsField,
  options: GetAssociatedRecordsListOptions
): Promise<{
  tableData: Record<string, any>[];
  tableCurrent: number | undefined;
  tableSize: number | undefined;
  tableTotal: number | undefined;
}>;

associatedRecordsSystemAssociatedObject

所有关联记录组件的系统关联对象配置对应的信息定义

类型

ts
/**
 * 关联记录组件的系统关联对象配置对应的信息
 */
interface AssociatedRecordsSystemAssociatedObjectInfo {
  /** 名称 */
  name: string;
  /** 字段列表 */
  fields: TemplateViewColumn[];
  /**
   * 查询列表接口, 第一个参数传入分页数据及筛选条件, 第二个参数传入组件配置, 返回请求地址或配置项
   *  - 若返回值是请求地址, 将会使用 GET 请求, data 将会作为 params 传入
   *  - 若返回值是配置项且未传入 method, 将会使用 GET 请求
   */
  getList: ((data: { current: number; size: number; [key: string]: any }, config: TemplateFormAssociatedRecordsField) => string | AxiosRequestConfig);
  /**
   * 查询详情接口, 传入数据 ID, 返回请求请求地址或配置项
   *  - 若返回值是请求地址, 将会使用 GET 请求
   *  - 若返回值是配置项且未传入 method, 将会使用 GET 请求
   */
  getDetail: ((value: string) => string | AxiosRequestConfig);

  /**
   * 查询列表接口返回值数据转换
   * @default res => res.data?.data ?? {};
   */
  getListResultTransform?: (res: any) => any;

  /**
   * 查询列表接口/查询详情接口 通用返回值数据转换
   * @example
   * { sex: { 1: '男', 2: '女' } }
   * { sex: (value, row) => row.sex2 === 1 ? '男' : '女' }
   */
  commonDataTransform?: Record<
    string,
    Record<string, string> | ((value: any, row: any) => any)
  >;
}

const associatedRecordsSystemAssociatedObject: Record<
  NonNullable<TemplateFormAssociatedRecordsField['associatedObject']>,
  AssociatedRecordsSystemAssociatedObjectInfo
>;