@fairys/taro-tools-simple-form 0.0.1

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.
@@ -0,0 +1,176 @@
1
+ /**
2
+ * 表单配置
3
+ */
4
+ import { View } from '@tarojs/components';
5
+
6
+ import { Fragment, ReactNode } from 'react';
7
+ import type { FormItemProps, FormListProps } from '@carefrees/form-utils-react-taro';
8
+ import { FormItem, FormHideItem, FormHideList, FormList } from '@carefrees/form-utils-react-taro';
9
+ import { FairysTaroRadioGroupBase, FairysTaroRadioGroupProps } from 'components/radio.group';
10
+ import { FairysTaroCalendarBase, FairysTaroCalendarProps } from 'components/calendar';
11
+ import { FairysTaroCascaderBase, FairysTaroCascaderProps } from 'components/cascader';
12
+ import { FairysTaroCheckboxGroupBase, FairysTaroCheckboxGroupProps } from 'components/checkbox.group';
13
+ import { FairysTaroDatePickerBase, FairysTaroDatePickerProps } from 'components/date.picker';
14
+ import { FairysTaroPickerBase, FairysTaroPickerProps } from 'components/picker';
15
+ import { FairysTaroPopupSearchBase, FairysTaroPopupSearchProps } from 'components/popup.search';
16
+
17
+ import {
18
+ Input,
19
+ TaroInputProps,
20
+ InputNumber,
21
+ TaroInputNumberProps,
22
+ RadioGroup,
23
+ RadioGroupProps,
24
+ Radio,
25
+ RadioProps,
26
+ Range,
27
+ RangeProps,
28
+ Rate,
29
+ RateProps,
30
+ Signature,
31
+ SignatureProps,
32
+ Switch,
33
+ SwitchProps,
34
+ TextArea,
35
+ TextAreaProps,
36
+ Uploader,
37
+ UploaderProps,
38
+ } from '@nutui/nutui-react-taro';
39
+
40
+ export interface ItemType<T, K = TaroInputProps> extends FormItemProps {
41
+ /**输入框类型*/
42
+ type?: T;
43
+ /**输入框属性*/
44
+ attr?: K;
45
+ /**自定义渲染函数*/
46
+ render?: undefined;
47
+ /**是否添加隐藏组件*/
48
+ isHide?: boolean;
49
+ /**是否添加置空组件*/
50
+ isEmpty?: boolean;
51
+ }
52
+
53
+ type CustomType = {
54
+ isEmpty?: boolean;
55
+ type?: 'custom';
56
+ render?: any;
57
+ isHide?: boolean;
58
+ attr?: any;
59
+ label?: ReactNode | { text?: string };
60
+ } & FormItemProps;
61
+ type CustomRenderType = {
62
+ isEmpty?: boolean;
63
+ type?: 'render';
64
+ render?: React.ReactNode;
65
+ isHide?: boolean;
66
+ attr?: any;
67
+ label?: ReactNode | { text?: string };
68
+ } & FormItemProps;
69
+ type CustomFormListType = {
70
+ isEmpty?: boolean;
71
+ type?: 'formList';
72
+ isHide?: boolean;
73
+ attr?: any;
74
+ label?: ReactNode | { text?: string };
75
+ } & FormListProps;
76
+
77
+ export type InputConfigType =
78
+ | ItemType<'input', TaroInputProps>
79
+ | ItemType<'inputNumber', TaroInputNumberProps>
80
+ | ItemType<'fairysRadioGroup', FairysTaroRadioGroupProps>
81
+ | ItemType<'fairysCalendar', FairysTaroCalendarProps>
82
+ | ItemType<'fairysCascader', FairysTaroCascaderProps>
83
+ | ItemType<'fairysCheckboxGroup', FairysTaroCheckboxGroupProps>
84
+ | ItemType<'fairysDatePicker', FairysTaroDatePickerProps>
85
+ | ItemType<'fairysPicker', FairysTaroPickerProps>
86
+ | ItemType<'fairysPopupSearch', FairysTaroPopupSearchProps>
87
+ | ItemType<'radioGroup', RadioGroupProps>
88
+ | ItemType<'radio', RadioProps>
89
+ | ItemType<'range', RangeProps>
90
+ | ItemType<'rate', RateProps>
91
+ | ItemType<'signature', SignatureProps>
92
+ | ItemType<'switch', SwitchProps>
93
+ | ItemType<'textarea', TextAreaProps>
94
+ | ItemType<'uploader', UploaderProps>
95
+ | CustomType
96
+ | CustomRenderType
97
+ | CustomFormListType;
98
+
99
+ const create_itemConfig = (configList: InputConfigType[]) => {
100
+ return (
101
+ <Fragment>
102
+ {configList.map((item, index) => {
103
+ const { type, isHide, attr = {}, isEmpty, ...rest } = item;
104
+ const newItem = { attr, ...rest } as any;
105
+ /**自定义表单组件*/
106
+ if (type === 'custom') {
107
+ newItem.children = item.render || <Fragment />;
108
+ } else if (type === 'render') {
109
+ // 自定义渲染内容
110
+ return <Fragment key={index}>{item.render}</Fragment>;
111
+ } else if (type === 'formList') {
112
+ if (typeof item.children === 'function') {
113
+ if (isHide) {
114
+ return <FormHideList sort={`${index}`} key={index} {...rest} children={item.children} name={item.name} />;
115
+ }
116
+ return <FormList sort={`${index}`} key={index} {...rest} children={item.children} name={item.name} />;
117
+ }
118
+ return <Fragment key={index} />;
119
+ } else if (type === 'input') {
120
+ newItem.children = <Input align="right" clearable {...attr} />;
121
+ } else if (type === 'inputNumber') {
122
+ newItem.children = <InputNumber align="right" clearable {...attr} />;
123
+ } else if (type === 'fairysRadioGroup') {
124
+ newItem.children = <FairysTaroRadioGroupBase {...attr} />;
125
+ } else if (type === 'radioGroup') {
126
+ newItem.children = <RadioGroup {...attr} />;
127
+ } else if (type === 'radio') {
128
+ newItem.children = <Radio {...attr} />;
129
+ } else if (type === 'range') {
130
+ newItem.children = <Range {...attr} />;
131
+ } else if (type === 'rate') {
132
+ newItem.children = <Rate {...attr} />;
133
+ } else if (type === 'signature') {
134
+ newItem.children = <Signature {...attr} />;
135
+ } else if (type === 'switch') {
136
+ newItem.children = <Switch {...attr} />;
137
+ } else if (type === 'textarea') {
138
+ newItem.children = <TextArea {...attr} />;
139
+ } else if (type === 'uploader') {
140
+ newItem.children = <Uploader {...attr} />;
141
+ } else if (type === 'fairysCalendar') {
142
+ newItem.children = <FairysTaroCalendarBase {...attr} />;
143
+ } else if (type === 'fairysCascader') {
144
+ const title = attr.title || (typeof item.label === 'string' ? item.label : '') || '请选择';
145
+ newItem.children = <FairysTaroCascaderBase {...attr} title={title} />;
146
+ } else if (type === 'fairysCheckboxGroup') {
147
+ newItem.children = <FairysTaroCheckboxGroupBase {...attr} />;
148
+ } else if (type === 'fairysDatePicker') {
149
+ const title = attr.title || (typeof item.label === 'string' ? item.label : '') || '请选择';
150
+ newItem.children = <FairysTaroDatePickerBase {...attr} title={title} />;
151
+ } else if (type === 'fairysPicker') {
152
+ const title = attr.title || (typeof item.label === 'string' ? item.label : '') || '请选择';
153
+ newItem.children = <FairysTaroPickerBase {...attr} title={title} />;
154
+ } else if (type === 'fairysPopupSearch') {
155
+ const title = attr.title || (typeof item.label === 'string' ? item.label : '') || '请选择';
156
+ newItem.children = <FairysTaroPopupSearchBase {...attr} title={title} />;
157
+ }
158
+ if (isEmpty) {
159
+ return <View key={index} className="fairys-taro-simple-form-item-empty" />;
160
+ }
161
+ if (isHide) {
162
+ return <FormHideItem sort={`${index}`} key={index} {...newItem} />;
163
+ }
164
+ return <FormItem sort={`${index}`} key={index} {...newItem} />;
165
+ })}
166
+ </Fragment>
167
+ );
168
+ };
169
+
170
+ export const ConfigListItem = (props: { items: InputConfigType[] }) => {
171
+ return create_itemConfig(props.items);
172
+ };
173
+
174
+ export const ConfigItem = (config: InputConfigType) => {
175
+ return create_itemConfig([config]);
176
+ };
@@ -0,0 +1,17 @@
1
+ @import '@carefrees/form-utils-react-taro/assets/index.css';
2
+
3
+ @unocss preflights;
4
+ @unocss default;
5
+
6
+ .nut-cell.fairys-taro-popup-search-list-virtual-cell > .nut-cell-left > .nut-cell-title {
7
+ width: 100%;
8
+ }
9
+
10
+ .nut-cell.fairys-taro-popup-search-list-virtual-cell > .nut-cell-extra {
11
+ flex: none;
12
+ }
13
+
14
+ .fairys-taro-popup-search-list-table .nut-table-main-head-tr {
15
+ z-index: 10;
16
+ position: relative;
17
+ }