zy-react-library 2.2.32 → 2.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -122,31 +122,29 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
|
|
122
122
|
| `itemsField` | `ItemsFieldConfig` | 否 | `{ valueKey: "bianma", labelKey: "name" }` | `select`、`radio`、`checkbox` | 其他 render 不可用。 |
|
|
123
123
|
| `checkboxCol` | `number` | 否 | - | `checkbox` | 其他 render 不可用;不传时 checkbox 不使用栅格布局。 |
|
|
124
124
|
| `formListUniqueProps` | `FormListUniqueProps \| ((formValues) => FormListUniqueProps)` | 否 | 见 `FormListUniqueProps` 默认值 | `formList` | 其他 render 不可用。 |
|
|
125
|
-
| `rowStyle` | `CSSProperties \| ((field, fieldIndex) => CSSProperties)` | 否 | - | `formList` | 其他 render 不可用。 |
|
|
126
|
-
| `rowTitle` | `ReactNode \| ((field, fieldIndex) => ReactNode)` | 否 | - | `formList` | 其他 render 不可用。 |
|
|
127
125
|
|
|
128
126
|
### render 可用性矩阵
|
|
129
127
|
|
|
130
128
|
| render | 可用参数 | 不可用参数 | 内置默认值 |
|
|
131
129
|
| --- | --- | --- | --- |
|
|
132
|
-
| `input` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
133
|
-
| `textarea` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
134
|
-
| `inputNumber` / `number` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
135
|
-
| `integer` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
136
|
-
| `select` | 通用参数、`componentProps`、`items`、`itemsField` | `checkboxCol`、`formListUniqueProps
|
|
137
|
-
| `radio` | 通用参数、`componentProps`、`items`、`itemsField` | `checkboxCol`、`formListUniqueProps
|
|
138
|
-
| `checkbox` | 通用参数、`componentProps`、`items`、`itemsField`、`checkboxCol` | `formListUniqueProps
|
|
139
|
-
| `date` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
130
|
+
| `input` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `maxLength: 50`,关闭约束时 `maxLength: 9999` |
|
|
131
|
+
| `textarea` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `maxLength: 500`、`showCount: true`、`rows: 3`;关闭约束时 `maxLength: 9999` |
|
|
132
|
+
| `inputNumber` / `number` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `style: { width: "100%" }`,默认校验最多两位小数且绝对值不超过 `999999999` |
|
|
133
|
+
| `integer` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `style: { width: "100%" }`,默认校验整数且绝对值不超过 `999999999` |
|
|
134
|
+
| `select` | 通用参数、`componentProps`、`items`、`itemsField` | `checkboxCol`、`formListUniqueProps` | `allowClear: true`、`showSearch: { optionFilterProp: "children" }` |
|
|
135
|
+
| `radio` | 通用参数、`componentProps`、`items`、`itemsField` | `checkboxCol`、`formListUniqueProps` | 选项来自 `items` |
|
|
136
|
+
| `checkbox` | 通用参数、`componentProps`、`items`、`itemsField`、`checkboxCol` | `formListUniqueProps` | 传 `checkboxCol` 时每个选项包一层 `Col` |
|
|
137
|
+
| `date` | 通用参数、`componentProps` | `items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `format: "YYYY-MM-DD"`、`style: { width: "100%" }` |
|
|
140
138
|
| `dateMonth` | 通用参数、`componentProps` | 同 `date` | `picker: "month"`、`format: "YYYY-MM"`、`style: { width: "100%" }` |
|
|
141
139
|
| `dateYear` | 通用参数、`componentProps` | 同 `date` | `picker: "year"`、`format: "YYYY"`、`style: { width: "100%" }` |
|
|
142
140
|
| `dateWeek` | 通用参数、`componentProps` | 同 `date` | `picker: "week"`、`format: "YYYY-wo"`、`style: { width: "100%" }` |
|
|
143
141
|
| `dateRange` | 通用参数、`componentProps` | 同 `date` | `format: "YYYY-MM-DD"`、`style: { width: "100%" }`,默认开始/结束占位文案 |
|
|
144
142
|
| `datetime` | 通用参数、`componentProps` | 同 `date` | `showTime: true`、`format: "YYYY-MM-DD HH:mm:ss"`、`style: { width: "100%" }` |
|
|
145
143
|
| `datetimeRange` | 通用参数、`componentProps` | 同 `date` | `showTime: true`、`format: "YYYY-MM-DD HH:mm:ss"`、`style: { width: "100%" }`,默认开始/结束占位文案 |
|
|
146
|
-
| `divider` | `label`、`span`、`componentProps`、`colStyle` | `name`、`required`、`rules`、`placeholder`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
147
|
-
| `formList` | 通用布局参数、`componentProps`、`formListUniqueProps
|
|
148
|
-
| ReactNode 自定义渲染 | `render`、`customizeRender`、`span`、`colStyle` | `componentProps`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
149
|
-
| `onlyForLabel=true` | `name`、`onlyForLabel` | `span`、`required`、`rules`、`componentProps`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps
|
|
144
|
+
| `divider` | `label`、`span`、`componentProps`、`colStyle` | `name`、`required`、`rules`、`placeholder`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | `span: 24`,渲染 `Divider`,`orientation: "left"` |
|
|
145
|
+
| `formList` | 通用布局参数、`componentProps`、`formListUniqueProps` | 当前层的 `items`、`itemsField`、`checkboxCol` | 子项通过 `formListUniqueProps.options(field, fieldIndex, operations)` 返回 |
|
|
146
|
+
| ReactNode 自定义渲染 | `render`、`customizeRender`、`span`、`colStyle` | `componentProps`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps`、内置校验相关参数 | `customizeRender=true` 时直接渲染传入节点 |
|
|
147
|
+
| `onlyForLabel=true` | `name`、`onlyForLabel` | `span`、`required`、`rules`、`componentProps`、`items`、`itemsField`、`checkboxCol`、`formListUniqueProps` | 渲染隐藏 `input`,不显示到页面 |
|
|
150
148
|
|
|
151
149
|
### OptionItem
|
|
152
150
|
|
|
@@ -175,6 +173,9 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
|
|
175
173
|
| `options` | `(field, fieldIndex, operations) => FormListOption[]` | 是 | `[]` | 当前行的表单项配置函数。 |
|
|
176
174
|
| `addDefaultValue` | `DeepPartial<Values>` | 否 | `{}` | 点击新增时插入的默认值。 |
|
|
177
175
|
| `addInsertIndex` | `number` | 否 | `undefined` | 点击新增时插入的位置。 |
|
|
176
|
+
| `rowStyle` | `CSSProperties \| ((field, fieldIndex) => CSSProperties)` | 否 | - | 当前行的内联样式,支持按行计算。 |
|
|
177
|
+
| `rowTitle` | `ReactNode \| ((field, fieldIndex) => ReactNode)` | 否 | - | 当前行起始位置渲染的节点,支持按行计算。 |
|
|
178
|
+
| `useDefaultRowStyle` | `boolean` | 否 | `false` | 未传 `rowStyle` 时是否使用默认卡片样式。 |
|
|
178
179
|
|
|
179
180
|
### FormListOperations
|
|
180
181
|
|
|
@@ -74,6 +74,12 @@ export interface FormListUniqueProps<Values = any, AllValues = Values> {
|
|
|
74
74
|
addDefaultValue?: DeepPartial<Values>;
|
|
75
75
|
/** 点击新增按钮时插入的索引位置 */
|
|
76
76
|
addInsertIndex?: number;
|
|
77
|
+
/** 每行的内联样式,支持按行计算 */
|
|
78
|
+
rowStyle?: CSSProperties | ((field: FormListFieldData, fieldIndex: number) => CSSProperties);
|
|
79
|
+
/** 每行起始位置渲染的节点,支持按行计算 */
|
|
80
|
+
rowTitle?: ReactNode | ((field: FormListFieldData, fieldIndex: number) => ReactNode);
|
|
81
|
+
/** 未传 rowStyle 时是否使用默认卡片样式 */
|
|
82
|
+
useDefaultRowStyle?: boolean;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/**
|
|
@@ -161,10 +167,6 @@ export type FormOptionByRender<
|
|
|
161
167
|
checkboxCol?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "checkbox" ? number : never>;
|
|
162
168
|
/** Form.List 独有的属性 */
|
|
163
169
|
formListUniqueProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "formList" ? FormListUniqueProps | ((formValues: AllValues) => FormListUniqueProps) : never>;
|
|
164
|
-
/** FormList 每行的内联样式,仅 render 为 formList 时可用,支持函数按行计算 */
|
|
165
|
-
rowStyle?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "formList" ? CSSProperties | ((field: FormListFieldData, fieldIndex: number) => CSSProperties) : never>;
|
|
166
|
-
/** FormList 每行起始位置渲染的标题节点,仅 render 为 formList 时可用,支持函数按行计算 */
|
|
167
|
-
rowTitle?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "formList" ? ReactNode | ((field: FormListFieldData, fieldIndex: number) => ReactNode) : never>;
|
|
168
170
|
};
|
|
169
171
|
|
|
170
172
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InfoCircleOutlined as e}from"@ant-design/icons";import{Input as r,DatePicker as t,TimePicker as n,Form as l,Col as o,Divider as s,Row as a,Button as i,Checkbox as d,Radio as p,Select as u,InputNumber as c,Tooltip as m}from"antd";import h from"dayjs";import{FORM_ITEM_RENDER_ENUM as y}from"../../enum/formItemRender/index.js";import{getDataType as E}from"../../utils/index.js";import{jsx as
|
|
1
|
+
import{InfoCircleOutlined as e}from"@ant-design/icons";import{Input as r,DatePicker as t,TimePicker as n,Form as l,Col as o,Divider as s,Row as a,Button as i,Checkbox as d,Radio as p,Select as u,InputNumber as c,Tooltip as m}from"antd";import h from"dayjs";import{FORM_ITEM_RENDER_ENUM as y}from"../../enum/formItemRender/index.js";import{getDataType as E}from"../../utils/index.js";import{jsx as f,Fragment as T,jsxs as v}from"react/jsx-runtime";const{TextArea:I}=r,{RangePicker:b}=t,{RangePicker:A}=n,R={marginBottom:16,padding:"20px 20px 4px",border:"1px solid #e8ebf0",borderRadius:6,background:"#fafbfc"},w=({options:w,layout:D="horizontal",labelCol:M,gutter:Y=24,span:x=12,collapse:N=!1,useAutoGenerateRequired:g=!0,initialValues:P})=>{const C=l.useFormInstance(),U=()=>{const e=C.getFieldsValue();return 0===Object.keys(e).length&&P?P:e},_=e=>"function"==typeof e.componentProps?e.componentProps(U()):e.componentProps||{},F=e=>{const r="function"==typeof e.formItemProps?e.formItemProps(U()):e.formItemProps||{};return((e,r)=>{[y.DATE,y.DATE_MONTH,y.DATE_YEAR,y.DATETIME].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?h(e):void 0})),[y.DATE_WEEK].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?h(e,"YYYY-wo"):void 0})),[y.DATE_RANGE,y.DATETIME_RANGE].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:Array.isArray(e)?e.map(e=>e?h(e):void 0):void 0})),[y.TIME].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?h(`2000-01-01 ${e}`):void 0})),[y.TIME_RANGE].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:Array.isArray(e)?e.map(e=>e?h(`2000-01-01 ${e}`):void 0):void 0}))})(e,r),r},B=e=>"function"==typeof e?e(U()):e??!0,V=e=>{if(e.render===y.DIVIDER)return[];const r=[];switch(e.render||y.INPUT){case y.INPUT:!1!==e.useConstraints&&r.push({max:50,message:"最多输入50字符"});break;case y.TEXTAREA:!1!==e.useConstraints&&r.push({max:500,message:"最多输入500字符"});break;case y.INPUT_NUMBER:case y.NUMBER:!1!==e.useConstraints&&r.push({pattern:/^(\d+)(\.\d{1,2})?$/,message:"请输入正确的数字,最多保留两位小数"}),!1!==e.useConstraints&&r.push({validator:(e,r)=>r&&Math.abs(Number.parseFloat(r))>999999999?Promise.reject("输入数值超出安全范围"):Promise.resolve()});break;case y.INTEGER:!1!==e.useConstraints&&r.push({pattern:/^(\d+)$/,message:"请输入正确的整数"}),!1!==e.useConstraints&&r.push({validator:(e,r)=>r&&Math.abs(Number.parseFloat(r))>999999999?Promise.reject("输入数值超出安全范围"):Promise.resolve()})}if(!g)return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r;if(B(e.required)){const t=!e.render||[y.INPUT,y.TEXTAREA,y.INPUT_NUMBER,y.NUMBER,y.INTEGER].includes(e.render);r.push({required:!0,message:`${t?"请输入":"请选择"}${e.label}`})}return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r},k=e=>e.key||("Array"===E(e.name)?e.name.join("."):e.name),S=e=>{const r=e.render===y.DIVIDER?24:e.span??x;if("vertical"===D)return{span:r};const t=e.labelCol??(24===r?{span:M.span/2}:M);return{span:r,labelCol:t,wrapperCol:e.wrapperCol??{span:24-t.span}}},G=e=>"function"==typeof e.colStyle?e.colStyle(U()):e.colStyle,L=e=>"function"==typeof e.colTitle?e.colTitle(U()):e.colTitle,$=(e,r)=>(e.shouldUpdate??e.dependencies)||(r.shouldUpdate??r.dependencies),H=e=>"function"==typeof e?e(U()):e??!1,K=(e,r)=>({value:e[r.valueKey],label:"function"==typeof r.labelKey?r.labelKey(e):e[r.labelKey],disabled:e.disabled}),q=e=>{const l=_(e),s=(e=>({valueKey:e?.itemsField?.valueKey||"bianma",labelKey:e?.itemsField?.labelKey||"name"}))(e),i=e.render??y.INPUT,m=e.placeholder??`请${[y.INPUT,y.TEXTAREA,y.INPUT_NUMBER,y.NUMBER,y.INTEGER].includes(i)?"输入":"选择"}${e.label}`;switch(i){case y.INPUT:return f(r,{placeholder:m,maxLength:!1!==e.useConstraints?50:9999,...l});case y.TEXTAREA:return f(I,{placeholder:m,maxLength:!1!==e.useConstraints?500:9999,showCount:!0,rows:3,...l});case y.INPUT_NUMBER:case y.NUMBER:case y.INTEGER:return f(c,{placeholder:m,style:{width:"100%"},...l});case y.SELECT:return f(u,{placeholder:m,showSearch:{optionFilterProp:"label"},allowClear:!0,options:(e.items||[]).map(e=>K(e,s)),...l});case y.RADIO:return f(p.Group,{options:(e.items||[]).map(e=>K(e,s)),...l});case y.CHECKBOX:{const r=(e.items||[]).map(e=>K(e,s));return e.checkboxCol?f(d.Group,{...l,style:{width:"100%",...l.style||{}},children:f(a,{children:r.map(({value:r,label:t,disabled:n})=>f(o,{span:e.checkboxCol,children:f(d,{value:r,disabled:n,children:t})},r))})}):f(d.Group,{options:r,...l})}case y.DATE:return f(t,{placeholder:m,format:"YYYY-MM-DD",style:{width:"100%"},...l});case y.DATE_MONTH:return f(t,{picker:"month",placeholder:m,format:"YYYY-MM",style:{width:"100%"},...l});case y.DATE_YEAR:return f(t,{picker:"year",placeholder:m,format:"YYYY",style:{width:"100%"},...l});case y.DATE_WEEK:return f(t,{picker:"week",placeholder:m,format:"YYYY-wo",style:{width:"100%"},...l});case y.DATE_RANGE:return f(b,{placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD",style:{width:"100%"},...l});case y.DATETIME:return f(t,{showTime:!0,placeholder:m,format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...l});case y.DATETIME_RANGE:return f(b,{showTime:!0,placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...l});case y.TIME:return f(n,{placeholder:m,format:"HH:mm:ss",style:{width:"100%"},...l});case y.TIME_RANGE:return f(A,{placeholder:m,format:"HH:mm:ss",style:{width:"100%"},...l});case y.DIVIDER:return null;default:return i}},j=r=>r.tip?v(T,{children:[r.label,f(m,{title:r.tip,children:f(e,{style:{marginLeft:4,fontSize:12}})})]}):r.label,O=({option:e,style:r,col:t,index:n,preserve:s})=>{const a=F(e);return delete a.dependencies,delete a.shouldUpdate,H(e.hidden)?null:v(o,{span:t.span,style:{...r,...G(e)},children:[L(e),f(l.Item,{name:e.name,label:j(e),rules:V(e),labelCol:t.labelCol,wrapperCol:t.wrapperCol,preserve:s,required:!!g&&" "!==j(e)&&B(e.required),colon:" "!==j(e),...a,children:q(e)})]},k(e)||n)},X=({option:e,style:r,col:t,index:n,preserve:a})=>{const i=_(e);return H(e.hidden)?null:e.customizeRender?f(o,{span:t.span,style:r,children:e.render},k(e)||n):e.onlyForLabel?f(l.Item,{name:e.name,noStyle:!0,preserve:a,children:f("input",{type:"hidden"})},k(e)||n):e.render===y.DIVIDER?f(o,{span:t.span,style:r,children:f(s,{titlePlacement:"start",...i,children:e.label})},k(e)||n):null},z=({option:e,index:r,col:t,style:n})=>{const s=(e=>{const r={showAddButton:!0,showRemoveButton:!0,addButtonText:"添加",removeButtonText:"删除",options:[],addDefaultValue:{},addInsertIndex:void 0};return"function"==typeof e.formListUniqueProps?{...r,...e.formListUniqueProps(U())}:{...r,...e.formListUniqueProps||{}}})(e),d=_(e);return H(e.hidden)?null:v(o,{span:t.span,style:{...n,...G(e)},children:[L(e),f(l.List,{name:e.name,...d,children:(e,{add:r,remove:t,move:d})=>f(T,{children:e.map((e,p)=>{const u=((e,r,t,n,l,o)=>"function"==typeof e?e(r,t,{field:r,fieldIndex:t,add:n,remove:l,move:o}):e??[])(s.options,e,p,r,t,d),c=((e,r,t,n)=>void 0!==e?"function"==typeof e?e(t,n):e:r?R:void 0)(s.rowStyle,s.useDefaultRowStyle,e,p),m=((e,r,t)=>"function"==typeof e?e(r,t):e)(s.rowTitle,e,p);return v(a,{gutter:Y,style:c,children:[m,u.map((a,d)=>{const c=S(a),m=F(a),h={option:a,style:n,col:c,index:`${p}_${d}`,preserve:!0};if($(a,m))return W(h);const E=X(h);return E||(a.render===y.FORM_LIST?z(h):d===(()=>{for(let e=u.length-1;e>=0;e--){const r=u[e];if(!H(r.hidden)&&!r.onlyForLabel&&r.render!==y.FORM_LIST)return e}return-1})()?(delete m.dependencies,delete m.shouldUpdate,v(o,{span:c.span,style:{...n,...G(a)},children:[L(a),f(l.Item,{label:j(a),labelCol:c.labelCol,wrapperCol:c.wrapperCol,preserve:!1,required:!!g&&" "!==j(a)&&B(a.required),colon:" "!==j(a),...m,children:v("div",{style:{display:"flex",gap:10,alignItems:"center",justifyContent:"space-between"},children:[f("div",{style:{flex:1,minWidth:0},children:f(l.Item,{noStyle:!0,rules:V(a),name:a.name,children:q(a)})}),p>=1?s.showRemoveButton&&f(i,{type:"primary",danger:!0,onClick:()=>t(e.name),children:s.removeButtonText}):s.showAddButton&&f(i,{type:"primary",onClick:()=>r(s.addDefaultValue,s.addInsertIndex),children:s.addButtonText})]})})]},k(a)||d)):O(h))})]},e.key)})})})]},k(e)||r)},W=({option:e,index:r,style:t,col:n,preserve:o})=>{const s=F(e);return f(l.Item,{noStyle:!0,preserve:o,shouldUpdate:e.shouldUpdate??s.shouldUpdate,dependencies:e.dependencies??s.dependencies,children:()=>X({option:e,style:t,col:n,index:r,preserve:o})||(e.render===y.FORM_LIST?z({option:e,index:r,col:n,style:t}):O({option:e,style:t,col:n,index:r,preserve:o}))},k(e)||r)};return f(T,{children:w.map((e,r)=>{const t=S(e),n=(e=>N&&e>=3?{display:"none"}:void 0)(r),l=F(e),o={option:e,style:n,col:t,index:r,preserve:!1};if($(e,l))return W(o);return X(o)||(e.render===y.FORM_LIST?z(o):O(o))})})};w.displayName="FormItemsRenderer";export{w as default};
|