import{ax as t,al as l,z as p,A as e,b5 as r,R as h,B as i,O as a}from"./chunks/framework.V2ssSR2R.js";const D=JSON.parse('{"title":"布局","description":"","frontmatter":{},"headers":[],"relativePath":"form-config/layout.md","filePath":"form-config/layout.md"}'),d={name:"form-config/layout.md"};function g(F,s,E,y,C,A){const n=l("demo-block");return e(),p("div",null,[s[0]||(s[0]=r(`

布局

配置类型

查看 ContainerCommonConfig / RowConfig / TabConfig / TabPaneConfig / FieldsetConfig / PanelConfig / StepConfig / FlexLayoutConfig / GroupListConfig / TableConfig / TableColumnConfig / TableGroupListCommonConfig 配置类型定义
ts
export interface ContainerCommonConfig<T = never> extends FormItem {
  items: FormConfig<T>;
  onInitValue?: (
    mForm: FormState | undefined,
    data: {
      formValue: FormValue;
      initValue: FormValue;
    },
  ) => FormValue;
  extensible?: boolean;
}
ts
export interface RowConfig<T = never> extends FormItem {
  type: 'row';
  span: number;
  items: ({ span?: number } & (ChildConfig<T> | EditorChildConfig | T))[];
}
ts
export interface TabConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
  type: 'tab' | 'dynamic-tab';
  tabType?: string;
  editable?: boolean;
  dynamic?: boolean;
  tabPosition?: 'top' | 'right' | 'bottom' | 'left';
  /** 当前激活的标签页,可以是固定值或动态函数 */
  active?:
    | string
    | ((mForm: FormState | undefined, data: { model: FormValue; formValue?: FormValue; prop: string }) => string);
  items: TabPaneConfig<T>[];
  onChange?: (mForm: FormState | undefined, data: any) => void;
  onTabAdd?: (mForm: FormState | undefined, data: any) => void;
  onTabRemove?: (mForm: FormState | undefined, tabName: string, data: any) => void;
  onTabClick?: (mForm: FormState | undefined, tab: any, data: any) => void;
  activeChange?: (mForm: FormState | undefined, tabName: string, data: any) => void;
}
ts
export interface TabPaneConfig<T = never> {
  status?: string;
  /** 标签页名称,用于关联 model 中的数据 */
  name?: string | number;
  title: string;
  lazy?: boolean;
  labelWidth?: string;
  items: FormConfig<T>;
  display?: boolean | 'expand' | FilterFunction<boolean | 'expand'>;
  onTabClick?: (mForm: FormState | undefined, tab: any, data: any) => void;
}
ts
export interface FieldsetConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
  type: 'fieldset';
  checkbox?:
    | boolean
    | {
        name: string;
        trueValue?: string | number;
        falseValue?: string | number;
      };
  expand?: boolean;
  legend?: string | FilterFunction<string>;
  schematic?: string;
}
ts
export interface PanelConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
  type: 'panel';
  expand?: boolean;
  title?: string;
  schematic?: string;
}
ts
export interface StepConfig<T = never> extends FormItem {
  type: 'step';
  /** 每个 step 的间距,不填写将自适应间距。支持百分比。 */
  space?: string | number;
  items: StepItemConfig<T>[];
}
ts
export interface FlexLayoutConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
  type: 'flex-layout';
  /** flex 子项间距,默认 '16px' */
  gap?: string;
}
ts
export interface GroupListConfig<T = never> extends TableGroupListCommonConfig {
  span?: number;
  items: FormConfig<T>;
  groupItems?: FormConfig<T>;
  tableItems?: FormConfig<T>;
  titleKey?: string;
  titlePrefix?: string;
  title?: string | FilterFunction<string>;
  itemExtra?: string | FilterFunction<string>;
  expandAll?: boolean;
  /**
   * 默认展开的数量,用于控制分组列表默认展示的项数
   * 当设置为数字时,表示默认展开指定数量的项
   * 当未设置时,默认展开第一项
   */
  defaultExpandQuantity?: number;
  delete?: (model: any, index: number | string | symbol, values: any) => boolean | boolean;
  copyable?: FilterFunction<boolean>;
  movable?: (
    mForm: FormState | undefined,
    index: number | string | symbol,
    model: any,
    groupModel: any,
  ) => boolean | boolean;
  moveSpecifyLocation?: boolean;
}
ts
export interface TableConfig<T = never> extends TableGroupListCommonConfig {
  items: TableColumnConfig<T>[];
  tableItems?: TableColumnConfig<T>[];
  groupItems?: TableColumnConfig<T>[];
  /** 最大高度 */
  maxHeight?: number | string;
  border?: boolean;
  /** 显示行号 */
  showIndex?: boolean;
  /** 操作栏宽度 */
  operateColWidth?: number | string;
  pagination?: boolean;
  /** 是否显示删除按钮 */
  delete?: (model: any, index: number, values: any) => boolean | boolean;
  copyable?: (model: any, data: any) => boolean | boolean;
  /** 是否显示导入按钮 */
  importable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
  /** 是否显示checkbox */
  selection?: (mForm: FormState | undefined, data: any) => boolean | boolean | 'single';
  copyHandler?: (mForm: FormState | undefined, data: any) => any;
  onSelect?: (mForm: FormState | undefined, data: any) => any;
  /** @deprecated 请使用 defaultSort */
  defautSort?: SortProp;
  defaultSort?: SortProp;
  /** 是否支持拖拽排序 */
  dropSort?: boolean;
  dropSortHandle?: boolean;
  dropActionButtonIcon?: any;
  copyActionButtonIcon?: any;
  deleteActionButtonIcon?: any;
  /** 是否显示全屏按钮 */
  enableFullscreen?: boolean;
  fixed?: boolean | 'left' | 'right';
  itemExtra?: string | FilterFunction<string>;
  titleTip?: FilterFunction<string>;
  rowKey?: string;
  sort?: boolean;
  sortKey?: string;
}
ts
export interface TableColumnConfig<T = never> extends FormItem {
  name?: string;
  label?: string;
  text?: string;
  width?: string | number;
  sortable?: boolean;
  items?: FormConfig<T>;
  itemsFunction?: (row: any) => FormConfig<T>;
  titleTip?: FilterFunction<string>;
  type?: string;
  addButtonConfig?: {
    props?: Record<string, any>;
    text?: string;
  };
}
ts
export interface TableGroupListCommonConfig extends FormItem {
  type: 'table' | 'groupList' | 'group-list';
  enableToggleMode?: boolean;
  /** 最大行数 */
  max?: number;
  enum?: any[];
  /** 是否显示添加按钮 */
  addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
  /** 新增的默认行,可以是函数动态生成或静态对象 */
  defaultAdd?: ((mForm: FormState | undefined, data: any) => any) | Record<string, any>;
  /** table 新增行时前置回调 */
  beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean | Promise<boolean>;
}
ts
export interface FormItem {
  /** vnode的key值,默认是遍历数组时的index */
  __key?: string | number;
  /** 表单域标签的的宽度,例如 '50px'。支持 auto。 */
  labelWidth?: string | number;
  /** label 标签的title属性 */
  labelTitle?: string;
  className?: string;
  /** 字段名 */
  name?: string | number;
  /** 额外的提示信息,和 help 类似,当提示文案同时出现时,可以使用这个。 */
  extra?: string | FilterFunction<string>;
  /** 配置提示信息 */
  tooltip?: ToolTipConfigType | FilterFunction<ToolTipConfigType>;
  /** 是否置灰 */
  disabled?: boolean | FilterFunction;
  /** 使用表单中的值作为key,例如配置了text,则使用model.text作为key */
  key?: string;
  /** 是否显示 */
  display?: boolean | 'expand' | FilterFunction<boolean | 'expand'>;
  /** 值发生改变时调用的方法 */
  onChange?: OnChangeHandler;
  /** label 标签的文本 */
  text?: string | FilterFunction<string>;
  /** 右侧感叹号 */
  tip?: string;

  filter?: 'number' | OnChangeHandler;
  /** 是否去除首尾空格 */
  trim?: boolean;
  /** 默认值 */
  defaultValue?: any | DefaultValueFunction;
  /** 表单验证规则 */
  rules?: Rule[];
  extensible?: boolean;
  dynamicKey?: string;
  /** 是否需要显示\`展开更多配置\` */
  expand?: boolean;
  style?: Record<string, any>;
  fieldStyle?: Record<string, any>;
  labelPosition?: 'top' | 'left' | 'right';
}

基础用法

`,4)),h(n,{type:"form",config:[{name:"text",text:"配置1"},{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}),s[1]||(s[1]=i("h2",{id:"行内布局",tabindex:"-1"},[a("行内布局 "),i("a",{class:"header-anchor",href:"#行内布局","aria-label":"Permalink to “行内布局”"},"​")],-1)),s[2]||(s[2]=i("p",null,"可以通过配置span,来指定行内的配置项占用多少位置,一行为24,例如一行要显示三个配置则 span 可以配置 8;四个则为 6。默认会自动调节在一行中显示。",-1)),h(n,{type:"form",config:[{type:"row",labelWidth:"100px",span:8,items:[{name:"text",text:"配置1"},{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]},{type:"row",span:12,labelWidth:"100px",items:[{name:"text4",text:"配置1"},{name:"text5",text:"配置2"},{name:"text6",text:"配置3"}]}]}),s[3]||(s[3]=i("h2",{id:"混合布局",tabindex:"-1"},[a("混合布局 "),i("a",{class:"header-anchor",href:"#混合布局","aria-label":"Permalink to “混合布局”"},"​")],-1)),h(n,{type:"form",config:[{name:"text0",labelWidth:"100px",text:"配置0"},{type:"row",labelWidth:"100px",items:[{name:"text",text:"配置1"},{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}),s[4]||(s[4]=i("h2",{id:"对象容器",tabindex:"-1"},[a("对象容器 "),i("a",{class:"header-anchor",href:"#对象容器","aria-label":"Permalink to “对象容器”"},"​")],-1)),s[5]||(s[5]=i("h3",{id:"object",tabindex:"-1"},[a("Object "),i("a",{class:"header-anchor",href:"#object","aria-label":"Permalink to “Object”"},"​")],-1)),h(n,{type:"form",config:[{name:"data",items:[{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}),s[6]||(s[6]=i("h3",{id:"fieldset",tabindex:"-1"},[a("fieldset "),i("a",{class:"header-anchor",href:"#fieldset","aria-label":"Permalink to “fieldset”"},"​")],-1)),h(n,{type:"form",config:[{type:"fieldset",labelWidth:"100px",legend:"fieldset",items:[{name:"text",text:"配置1"},{type:"row",items:[{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}]}),s[7]||(s[7]=i("p",null,[i("code",null,"legend"),a(" 除了支持字符串,也支持函数,函数返回值作为标题展示,可根据表单数据动态生成:")],-1)),h(n,{type:"form",config:[{type:"fieldset",labelWidth:"100px",legend:(o,{formValue:k})=>`当前值:${k.text||"空"}`,items:[{name:"text",text:"配置1"}]}]},null,8,["config"]),s[8]||(s[8]=i("h3",{id:"panel",tabindex:"-1"},[a("panel "),i("a",{class:"header-anchor",href:"#panel","aria-label":"Permalink to “panel”"},"​")],-1)),h(n,{type:"form",config:[{type:"panel",title:"panel",items:[{name:"text",text:"配置1"},{type:"row",items:[{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}]}),s[9]||(s[9]=i("h3",{id:"tabs",tabindex:"-1"},[a("tabs "),i("a",{class:"header-anchor",href:"#tabs","aria-label":"Permalink to “tabs”"},"​")],-1)),h(n,{type:"form",config:[{type:"tab",items:[{title:"tab1",items:[{name:"text",text:"配置1"}]},{title:"tab2",items:[{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}]}),s[10]||(s[10]=i("h2",{id:"数组容器",tabindex:"-1"},[a("数组容器 "),i("a",{class:"header-anchor",href:"#数组容器","aria-label":"Permalink to “数组容器”"},"​")],-1)),s[11]||(s[11]=i("h3",{id:"grouplist",tabindex:"-1"},[a("groupList "),i("a",{class:"header-anchor",href:"#grouplist","aria-label":"Permalink to “groupList”"},"​")],-1)),h(n,{type:"form",config:[{type:"groupList",name:"group",items:[{name:"text",text:"配置1"},{type:"row",items:[{name:"text2",text:"配置2"},{name:"text3",text:"配置3"}]}]}]}),s[12]||(s[12]=i("h3",{id:"table",tabindex:"-1"},[a("table "),i("a",{class:"header-anchor",href:"#table","aria-label":"Permalink to “table”"},"​")],-1)),h(n,{type:"form",config:[{type:"table",name:"table",items:[{name:"text",label:"配置1"}]}]}),s[13]||(s[13]=i("h3",{id:"step",tabindex:"-1"},[a("step "),i("a",{class:"header-anchor",href:"#step","aria-label":"Permalink to “step”"},"​")],-1)),h(n,{type:"form",config:[{type:"step",items:[{title:"步骤1",items:[{name:"text",text:"配置1"}]},{title:"步骤2",items:[{name:"text2",text:"配置2"}]}]}]}),s[14]||(s[14]=i("h3",{id:"flex-layout",tabindex:"-1"},[a("flex-layout "),i("a",{class:"header-anchor",href:"#flex-layout","aria-label":"Permalink to “flex-layout”"},"​")],-1)),h(n,{type:"form",config:[{type:"flex-layout",gap:"20px",items:[{name:"text",text:"配置1",span:12},{name:"text2",text:"配置2",span:12}]}]})])}const c=t(d,[["render",g]]);export{D as __pageData,c as default};