@fairys/taro-tools-simple-form 0.0.3 → 0.0.4
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 +320 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,320 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 快捷表单
|
|
2
|
+
|
|
3
|
+
**引入**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { FairysTaroSimpleForm } from '@fairys/taro-tools-simple-form';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 组件参数
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { ReactNode } from 'react';
|
|
13
|
+
import type { FormItemProps, FormListProps } from '@carefrees/form-utils-react-taro';
|
|
14
|
+
import { FairysTaroRadioGroupProps } from './components/radio.group';
|
|
15
|
+
import { FairysTaroCalendarProps } from './components/calendar';
|
|
16
|
+
import { FairysTaroCascaderProps } from './components/cascader';
|
|
17
|
+
import { FairysTaroCheckboxGroupProps } from './components/checkbox.group';
|
|
18
|
+
import { FairysTaroDatePickerProps } from './components/date.picker';
|
|
19
|
+
import { FairysTaroPickerProps } from './components/picker';
|
|
20
|
+
import { FairysTaroPopupSearchProps } from './components/popup.search';
|
|
21
|
+
import { TaroInputProps, TaroInputNumberProps, RadioGroupProps, RadioProps, RangeProps, RateProps, SignatureProps, SwitchProps, TextAreaProps, UploaderProps } from '@nutui/nutui-react-taro';
|
|
22
|
+
export interface ItemType<T, K = TaroInputProps> extends FormItemProps {
|
|
23
|
+
/**输入框类型*/
|
|
24
|
+
type?: T;
|
|
25
|
+
/**输入框属性*/
|
|
26
|
+
attr?: K;
|
|
27
|
+
/**自定义渲染函数*/
|
|
28
|
+
render?: undefined;
|
|
29
|
+
/**是否添加隐藏组件*/
|
|
30
|
+
isHide?: boolean;
|
|
31
|
+
/**是否添加置空组件*/
|
|
32
|
+
isEmpty?: boolean;
|
|
33
|
+
}
|
|
34
|
+
type CustomType = {
|
|
35
|
+
isEmpty?: boolean;
|
|
36
|
+
type?: 'custom';
|
|
37
|
+
render?: any;
|
|
38
|
+
isHide?: boolean;
|
|
39
|
+
attr?: any;
|
|
40
|
+
label?: ReactNode | {
|
|
41
|
+
text?: string;
|
|
42
|
+
};
|
|
43
|
+
} & FormItemProps;
|
|
44
|
+
type CustomRenderType = {
|
|
45
|
+
isEmpty?: boolean;
|
|
46
|
+
type?: 'render';
|
|
47
|
+
render?: React.ReactNode;
|
|
48
|
+
isHide?: boolean;
|
|
49
|
+
attr?: any;
|
|
50
|
+
label?: ReactNode | {
|
|
51
|
+
text?: string;
|
|
52
|
+
};
|
|
53
|
+
} & FormItemProps;
|
|
54
|
+
type CustomFormListType = {
|
|
55
|
+
isEmpty?: boolean;
|
|
56
|
+
type?: 'formList';
|
|
57
|
+
isHide?: boolean;
|
|
58
|
+
attr?: any;
|
|
59
|
+
label?: ReactNode | {
|
|
60
|
+
text?: string;
|
|
61
|
+
};
|
|
62
|
+
} & FormListProps;
|
|
63
|
+
export type InputConfigType = ItemType<'input', TaroInputProps> | ItemType<'inputNumber', TaroInputNumberProps> | ItemType<'fairysRadioGroup', FairysTaroRadioGroupProps> | ItemType<'fairysCalendar', FairysTaroCalendarProps> | ItemType<'fairysCascader', FairysTaroCascaderProps> | ItemType<'fairysCheckboxGroup', FairysTaroCheckboxGroupProps> | ItemType<'fairysDatePicker', FairysTaroDatePickerProps> | ItemType<'fairysPicker', FairysTaroPickerProps> | ItemType<'fairysPopupSearch', FairysTaroPopupSearchProps> | ItemType<'radioGroup', RadioGroupProps> | ItemType<'radio', RadioProps> | ItemType<'range', RangeProps> | ItemType<'rate', RateProps> | ItemType<'signature', SignatureProps> | ItemType<'switch', SwitchProps> | ItemType<'textarea', TextAreaProps> | ItemType<'uploader', UploaderProps> | CustomType | CustomRenderType | CustomFormListType;
|
|
64
|
+
export declare const ConfigListItem: (props: {
|
|
65
|
+
items: InputConfigType[];
|
|
66
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
67
|
+
export declare const ConfigItem: (config: InputConfigType) => import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
/**
|
|
69
|
+
* 简版表单
|
|
70
|
+
* 用于快速创建表单,支持文本输入、选择框、单选框、复选框等常用表单元素。
|
|
71
|
+
* */
|
|
72
|
+
import { useForm } from '@carefrees/form-utils-react-taro';
|
|
73
|
+
import { FormProps } from '@carefrees/form-utils-react-taro';
|
|
74
|
+
export interface FairysTaroSimpleFormProps extends FormProps {
|
|
75
|
+
}
|
|
76
|
+
export declare const FairysTaroSimpleForm: {
|
|
77
|
+
(props: FairysTaroSimpleFormProps): import("react/jsx-runtime").JSX.Element;
|
|
78
|
+
Item: (config: InputConfigType) => import("react/jsx-runtime").JSX.Element;
|
|
79
|
+
ListItem: (props: {
|
|
80
|
+
items: InputConfigType[];
|
|
81
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
82
|
+
useForm: typeof useForm;
|
|
83
|
+
useWatch: (name: string, form?: import("@carefrees/form-utils").FormInstanceBase, callBack?: (value: any, form: import("@carefrees/form-utils").FormInstanceBase) => void) => [any, import("@carefrees/form-utils").FormInstanceBase, import("@carefrees/form-utils-react-taro").WatchInstanceBase];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
其他请参考[@carefrees/form-utils-react-taro](https://sunlxy.github.io/carefrees-form-utils/react/taro.html)
|
|
89
|
+
|
|
90
|
+
## 案例
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { View, Text } from '@tarojs/components';
|
|
94
|
+
import {
|
|
95
|
+
connectToastMessage,
|
|
96
|
+
FairysTaroMainPage,
|
|
97
|
+
FairysTaroMainPageSearch,
|
|
98
|
+
FairysTaroMainPageBody,
|
|
99
|
+
FairysTaroMainPageFooter,
|
|
100
|
+
globalDataInstance,
|
|
101
|
+
} from '@fairys/taro-tools-react';
|
|
102
|
+
import { Button } from '@nutui/nutui-react-taro';
|
|
103
|
+
import { FairysTaroSimpleForm } from '@fairys/taro-tools-simple-form';
|
|
104
|
+
|
|
105
|
+
function Index() {
|
|
106
|
+
const form = FairysTaroSimpleForm.useForm();
|
|
107
|
+
|
|
108
|
+
const onSubmit = () => {
|
|
109
|
+
form
|
|
110
|
+
.validate()
|
|
111
|
+
.then((values) => {
|
|
112
|
+
console.log(values);
|
|
113
|
+
globalDataInstance.showMessage({
|
|
114
|
+
type: 'success',
|
|
115
|
+
content: '表单成功',
|
|
116
|
+
});
|
|
117
|
+
})
|
|
118
|
+
.catch((error) => {
|
|
119
|
+
globalDataInstance.showMessage({
|
|
120
|
+
type: 'error',
|
|
121
|
+
content: error.message || '表单校验失败',
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<FairysTaroMainPage>
|
|
128
|
+
<FairysTaroMainPageSearch>
|
|
129
|
+
<FairysTaroSimpleForm form={form}>
|
|
130
|
+
<FairysTaroSimpleForm.Item label="用户名" name="username" type="fairysCalendar" />
|
|
131
|
+
<FairysTaroSimpleForm.Item
|
|
132
|
+
label="级联选择器"
|
|
133
|
+
name="cascader"
|
|
134
|
+
type="fairysCascader"
|
|
135
|
+
rules={[{ required: true, message: '请选择级联选择器' }]}
|
|
136
|
+
attr={{
|
|
137
|
+
options: [
|
|
138
|
+
{ value: 'A0', text: 'A0_1' },
|
|
139
|
+
{
|
|
140
|
+
value: 'B0',
|
|
141
|
+
text: 'B0_1',
|
|
142
|
+
children: [
|
|
143
|
+
{ value: 'B11', text: 'B11_1', leaf: true },
|
|
144
|
+
{ value: 'B12', text: 'B12_1' },
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
{ value: 'C0', text: 'C0_1' },
|
|
148
|
+
],
|
|
149
|
+
}}
|
|
150
|
+
/>
|
|
151
|
+
<FairysTaroSimpleForm.Item
|
|
152
|
+
label="复选框组"
|
|
153
|
+
name="checkboxGroup"
|
|
154
|
+
type="fairysCheckboxGroup"
|
|
155
|
+
rules={[{ required: true, message: '请选择复选框组' }]}
|
|
156
|
+
attr={{
|
|
157
|
+
items: [
|
|
158
|
+
{ value: 'A0', label: 'A0_1' },
|
|
159
|
+
{ value: 'B0', label: 'B0_1' },
|
|
160
|
+
{ value: 'C0', label: 'C0_1' },
|
|
161
|
+
],
|
|
162
|
+
}}
|
|
163
|
+
/>
|
|
164
|
+
<FairysTaroSimpleForm.Item
|
|
165
|
+
label="日期选择器"
|
|
166
|
+
name="datePicker"
|
|
167
|
+
type="fairysDatePicker"
|
|
168
|
+
rules={[{ required: true, message: '请选择日期选择器' }]}
|
|
169
|
+
attr={{
|
|
170
|
+
type: 'datetime',
|
|
171
|
+
}}
|
|
172
|
+
/>
|
|
173
|
+
<FairysTaroSimpleForm.Item
|
|
174
|
+
label="选择器"
|
|
175
|
+
name="picker"
|
|
176
|
+
type="fairysPicker"
|
|
177
|
+
attr={{
|
|
178
|
+
options: [
|
|
179
|
+
// 第一列
|
|
180
|
+
[
|
|
181
|
+
{ label: '周一', value: 'Monday' },
|
|
182
|
+
{ label: '周二', value: 'Tuesday' },
|
|
183
|
+
{ label: '周三', value: 'Wednesday' },
|
|
184
|
+
{ label: '周四', value: 'Thursday' },
|
|
185
|
+
{ label: '周五', value: 'Friday' },
|
|
186
|
+
],
|
|
187
|
+
// 第二列
|
|
188
|
+
[
|
|
189
|
+
{ label: '上午', value: 'Morning' },
|
|
190
|
+
{ label: '下午', value: 'Afternoon' },
|
|
191
|
+
{ label: '晚上', value: 'Evening' },
|
|
192
|
+
],
|
|
193
|
+
],
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
196
|
+
<FairysTaroSimpleForm.Item
|
|
197
|
+
label="搜索选择器"
|
|
198
|
+
name="popupSearch"
|
|
199
|
+
type="fairysPopupSearch"
|
|
200
|
+
attr={{
|
|
201
|
+
placeholder: '请选择',
|
|
202
|
+
mode: 'single',
|
|
203
|
+
options: [
|
|
204
|
+
{ value: 'A0', label: 'A0_1' },
|
|
205
|
+
{ value: 'B0', label: 'B0_1' },
|
|
206
|
+
{ value: 'C0', label: 'C0_1' },
|
|
207
|
+
{ value: 'D0', label: 'D0_1' },
|
|
208
|
+
{ value: 'E0', label: 'E0_1' },
|
|
209
|
+
{ value: 'F0', label: 'F0_1' },
|
|
210
|
+
{ value: 'G0', label: 'G0_1' },
|
|
211
|
+
{ value: 'H0', label: 'H0_1' },
|
|
212
|
+
{ value: 'I0', label: 'I0_1' },
|
|
213
|
+
{ value: 'J0', label: 'J0_1' },
|
|
214
|
+
{ value: 'K0', label: 'K0_1' },
|
|
215
|
+
{ value: 'L0', label: 'L0_1' },
|
|
216
|
+
{ value: 'M0', label: 'M0_1' },
|
|
217
|
+
],
|
|
218
|
+
}}
|
|
219
|
+
/>
|
|
220
|
+
<FairysTaroSimpleForm.Item
|
|
221
|
+
label="搜索选择器(表格)"
|
|
222
|
+
name="popupSearch-table"
|
|
223
|
+
type="fairysPopupSearch"
|
|
224
|
+
attr={{
|
|
225
|
+
placeholder: '请选择',
|
|
226
|
+
mode: 'single',
|
|
227
|
+
renderType: 'table',
|
|
228
|
+
columns: [
|
|
229
|
+
{ title: '选项值', key: 'value' },
|
|
230
|
+
{ title: '选项标签', key: 'label' },
|
|
231
|
+
],
|
|
232
|
+
options: [
|
|
233
|
+
{ value: 'A0', label: 'A0_1' },
|
|
234
|
+
{ value: 'B0', label: 'B0_1' },
|
|
235
|
+
{ value: 'C0', label: 'C0_1' },
|
|
236
|
+
{ value: 'D0', label: 'D0_1' },
|
|
237
|
+
{ value: 'E0', label: 'E0_1' },
|
|
238
|
+
{ value: 'F0', label: 'F0_1' },
|
|
239
|
+
{ value: 'G0', label: 'G0_1' },
|
|
240
|
+
{ value: 'H0', label: 'H0_1' },
|
|
241
|
+
{ value: 'I0', label: 'I0_1' },
|
|
242
|
+
{ value: 'J0', label: 'J0_1' },
|
|
243
|
+
{ value: 'K0', label: 'K0_1' },
|
|
244
|
+
{ value: 'L0', label: 'L0_1' },
|
|
245
|
+
{ value: 'M0', label: 'M0_1' },
|
|
246
|
+
],
|
|
247
|
+
}}
|
|
248
|
+
/>
|
|
249
|
+
|
|
250
|
+
<FairysTaroSimpleForm.Item
|
|
251
|
+
label="多选搜索选择器"
|
|
252
|
+
name="m-popupSearch"
|
|
253
|
+
type="fairysPopupSearch"
|
|
254
|
+
attr={{
|
|
255
|
+
placeholder: '请选择',
|
|
256
|
+
mode: 'multiple',
|
|
257
|
+
options: [
|
|
258
|
+
{ value: 'A0', label: 'A0_1' },
|
|
259
|
+
{ value: 'B0', label: 'B0_1' },
|
|
260
|
+
{ value: 'C0', label: 'C0_1' },
|
|
261
|
+
{ value: 'D0', label: 'D0_1' },
|
|
262
|
+
{ value: 'E0', label: 'E0_1' },
|
|
263
|
+
{ value: 'F0', label: 'F0_1' },
|
|
264
|
+
{ value: 'G0', label: 'G0_1' },
|
|
265
|
+
{ value: 'H0', label: 'H0_1' },
|
|
266
|
+
{ value: 'I0', label: 'I0_1' },
|
|
267
|
+
{ value: 'J0', label: 'J0_1' },
|
|
268
|
+
{ value: 'K0', label: 'K0_1' },
|
|
269
|
+
{ value: 'L0', label: 'L0_1' },
|
|
270
|
+
{ value: 'M0', label: 'M0_1' },
|
|
271
|
+
],
|
|
272
|
+
}}
|
|
273
|
+
/>
|
|
274
|
+
<FairysTaroSimpleForm.Item
|
|
275
|
+
label="多选搜索选择器(表格)"
|
|
276
|
+
name="m-popupSearch-table"
|
|
277
|
+
type="fairysPopupSearch"
|
|
278
|
+
attr={{
|
|
279
|
+
placeholder: '请选择',
|
|
280
|
+
mode: 'multiple',
|
|
281
|
+
renderType: 'table',
|
|
282
|
+
isNeedManage: true,
|
|
283
|
+
columns: [
|
|
284
|
+
{ title: '选项值', key: 'value' },
|
|
285
|
+
{ title: '选项标签', key: 'label' },
|
|
286
|
+
],
|
|
287
|
+
options: [
|
|
288
|
+
{ value: 'A0', label: 'A0_1' },
|
|
289
|
+
{ value: 'B0', label: 'B0_1' },
|
|
290
|
+
{ value: 'C0', label: 'C0_1' },
|
|
291
|
+
{ value: 'D0', label: 'D0_1' },
|
|
292
|
+
{ value: 'E0', label: 'E0_1' },
|
|
293
|
+
{ value: 'F0', label: 'F0_1' },
|
|
294
|
+
{ value: 'G0', label: 'G0_1' },
|
|
295
|
+
{ value: 'H0', label: 'H0_1' },
|
|
296
|
+
{ value: 'I0', label: 'I0_1' },
|
|
297
|
+
{ value: 'J0', label: 'J0_1' },
|
|
298
|
+
{ value: 'K0', label: 'K0_1' },
|
|
299
|
+
{ value: 'L0', label: 'L0_1' },
|
|
300
|
+
{ value: 'M0', label: 'M0_1' },
|
|
301
|
+
],
|
|
302
|
+
}}
|
|
303
|
+
/>
|
|
304
|
+
</FairysTaroSimpleForm>
|
|
305
|
+
</FairysTaroMainPageSearch>
|
|
306
|
+
<FairysTaroMainPageBody>
|
|
307
|
+
|
|
308
|
+
</FairysTaroMainPageBody>
|
|
309
|
+
<FairysTaroMainPageFooter
|
|
310
|
+
style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '0.3rem 0.5rem' }}
|
|
311
|
+
>
|
|
312
|
+
<Button block type="primary" onClick={onSubmit}>
|
|
313
|
+
提交
|
|
314
|
+
</Button>
|
|
315
|
+
</FairysTaroMainPageFooter>
|
|
316
|
+
</FairysTaroMainPage>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
export default connectToastMessage(Index);
|
|
320
|
+
```
|
package/package.json
CHANGED