@fairys/taro-tools-simple-form 0.0.2 → 0.0.3

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.
Files changed (46) hide show
  1. package/esm/components/calendar/index.d.ts +10 -0
  2. package/esm/components/calendar/index.js +35 -0
  3. package/esm/components/cascader/index.d.ts +10 -0
  4. package/esm/components/cascader/index.js +85 -0
  5. package/esm/components/checkbox.group/index.d.ts +5 -0
  6. package/esm/components/checkbox.group/index.js +14 -0
  7. package/esm/components/clear/index.d.ts +21 -0
  8. package/esm/components/clear/index.js +31 -0
  9. package/esm/components/date.picker/index.d.ts +18 -0
  10. package/esm/components/date.picker/index.js +122 -0
  11. package/esm/components/index.d.ts +8 -0
  12. package/esm/components/index.js +8 -0
  13. package/esm/components/picker/index.d.ts +9 -0
  14. package/esm/components/picker/index.js +45 -0
  15. package/esm/components/popup.search/base.d.ts +2 -0
  16. package/esm/components/popup.search/base.js +70 -0
  17. package/esm/components/popup.search/index.d.ts +9 -0
  18. package/esm/components/popup.search/index.js +157 -0
  19. package/esm/components/popup.search/instance.d.ts +169 -0
  20. package/esm/components/popup.search/instance.js +319 -0
  21. package/esm/components/popup.search/list.table.d.ts +1 -0
  22. package/esm/components/popup.search/list.table.js +89 -0
  23. package/esm/components/popup.search/list.virtual.d.ts +1 -0
  24. package/esm/components/popup.search/list.virtual.js +60 -0
  25. package/esm/components/radio.group/index.d.ts +5 -0
  26. package/esm/components/radio.group/index.js +13 -0
  27. package/esm/index.d.ts +17 -0
  28. package/esm/index.js +15 -0
  29. package/esm/interface.d.ts +3 -0
  30. package/esm/interface.js +0 -0
  31. package/esm/item.config.d.ts +57 -0
  32. package/esm/item.config.js +125 -0
  33. package/esm/styles/index.css +167 -0
  34. package/lib/index.js +91 -0
  35. package/package.json +2 -2
  36. package/src/components/calendar/index.tsx +10 -11
  37. package/src/components/cascader/index.tsx +9 -11
  38. package/src/components/clear/index.tsx +49 -0
  39. package/src/components/date.picker/index.tsx +11 -11
  40. package/src/components/index.ts +8 -0
  41. package/src/components/picker/index.tsx +9 -11
  42. package/src/components/popup.search/index.tsx +86 -64
  43. package/src/components/popup.search/instance.ts +40 -9
  44. package/src/components/popup.search/list.table.tsx +3 -2
  45. package/src/components/popup.search/list.virtual.tsx +3 -2
  46. package/src/index.tsx +4 -1
@@ -1,7 +1,7 @@
1
- import { View, Text, ViewProps } from '@tarojs/components';
1
+ import { View, ViewProps } from '@tarojs/components';
2
2
  import { Calendar, CalendarProps } from '@nutui/nutui-react-taro';
3
- import { useMemo, useState } from 'react';
4
- import clsx from 'clsx';
3
+ import { useState } from 'react';
4
+ import { FairysTaroTextClearBase } from 'components/clear';
5
5
 
6
6
  export interface FairysTaroCalendarProps extends Partial<CalendarProps> {
7
7
  placeholder?: string;
@@ -14,18 +14,17 @@ export interface FairysTaroCalendarProps extends Partial<CalendarProps> {
14
14
  export const FairysTaroCalendarBase = (props: FairysTaroCalendarProps) => {
15
15
  const { placeholder = '请选择', value, className, style, onChange, ...rest } = props;
16
16
  const [visible, setVisible] = useState(false);
17
- const clsx_text = useMemo(() => {
18
- return clsx('fairys-taro-calendar-text', {
19
- 'fairys-taro-calendar-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !value,
20
- 'fairys-taro-calendar-text-value fairystaroform__text-black': value,
21
- });
22
- }, [value]);
23
17
 
24
18
  return (
25
19
  <View className={`fairys-taro-calendar ${className || ''}`} style={style}>
26
- <Text onClick={() => setVisible(true)} className={clsx_text}>
20
+ <FairysTaroTextClearBase
21
+ warpClassName="fairys-taro-calendar-text"
22
+ isValue={!!value}
23
+ onTextClick={() => setVisible(true)}
24
+ onClearClick={() => onChange?.(undefined, undefined)}
25
+ >
27
26
  {value || placeholder}
28
- </Text>
27
+ </FairysTaroTextClearBase>
29
28
  <Calendar
30
29
  {...rest}
31
30
  visible={visible}
@@ -1,7 +1,7 @@
1
- import { View, Text } from '@tarojs/components';
1
+ import { View } from '@tarojs/components';
2
2
  import { Cascader, CascaderProps, CascaderOption } from '@nutui/nutui-react-taro';
3
3
  import { useMemo, useState } from 'react';
4
- import clsx from 'clsx';
4
+ import { FairysTaroTextClearBase } from 'components/clear';
5
5
 
6
6
  export interface FairysTaroCascaderProps
7
7
  extends Omit<Partial<CascaderProps>, 'visible' | 'onClose' | 'onChange' | 'value'> {
@@ -74,13 +74,6 @@ export const FairysTaroCascaderBase = (props: FairysTaroCascaderProps) => {
74
74
  return '';
75
75
  }, [value, labelInValue, valueKey, textKey]);
76
76
 
77
- const clsx_text = useMemo(() => {
78
- return clsx('fairys-taro-cascader-text', {
79
- 'fairys-taro-cascader-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !render,
80
- 'fairys-taro-cascader-text-value fairystaroform__text-black': render,
81
- });
82
- }, [render]);
83
-
84
77
  const _value = useMemo(() => {
85
78
  if (Array.isArray(value) && value.length) {
86
79
  return value
@@ -100,9 +93,14 @@ export const FairysTaroCascaderBase = (props: FairysTaroCascaderProps) => {
100
93
 
101
94
  return (
102
95
  <View className={`fairys-taro-cascader ${className || ''}`} style={style}>
103
- <Text onClick={() => setVisible(true)} className={clsx_text}>
96
+ <FairysTaroTextClearBase
97
+ warpClassName="fairys-taro-cascader-text"
98
+ isValue={!!render}
99
+ onTextClick={() => setVisible(true)}
100
+ onClearClick={() => onChange?.(undefined, undefined)}
101
+ >
104
102
  {render || placeholder}
105
- </Text>
103
+ </FairysTaroTextClearBase>
106
104
  <Cascader
107
105
  {...rest}
108
106
  className={`fairys-taro-cascader-body fairystaroform__text-left ${bodyClassName || ''}`}
@@ -0,0 +1,49 @@
1
+ import { Close2 } from '@nutui/icons-react-taro';
2
+ import { View, Text, ITouchEvent } from '@tarojs/components';
3
+ import clsx from 'clsx';
4
+ import { Fragment, useMemo } from 'react';
5
+
6
+ export interface SVG_IconProps {
7
+ className?: string;
8
+ style?: React.CSSProperties;
9
+ viewBox?: string;
10
+ name?: string;
11
+ color?: string;
12
+ width?: string | number;
13
+ height?: string | number;
14
+ size?: string | number;
15
+ svg64?: string;
16
+ svgSrc?: string;
17
+ children?: React.ReactNode;
18
+ fallback?: boolean;
19
+ isValue?: boolean;
20
+ warpClassName?: string;
21
+ warpStyle?: React.CSSProperties;
22
+ onTextClick?: (event: ITouchEvent) => void;
23
+ onClearClick?: (event: React.MouseEvent) => void;
24
+ }
25
+
26
+ export const FairysTaroTextClearBase = (props: SVG_IconProps) => {
27
+ const { isValue = true, children, warpClassName, warpStyle, onTextClick, onClearClick, ...rest } = props;
28
+
29
+ const clsx_text = useMemo(() => {
30
+ return clsx('fairys-taro-text fairystaroform__flex-1', {
31
+ 'fairys-taro-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !isValue,
32
+ 'fairys-taro-text-value fairystaroform__text-black': isValue,
33
+ });
34
+ }, [isValue]);
35
+
36
+ return (
37
+ <View
38
+ className={`fairys-taro-clear fairystaroform__flex fairystaroform__items-center fairystaroform__gap-1 ${
39
+ warpClassName || ''
40
+ }`}
41
+ style={warpStyle}
42
+ >
43
+ <Text onClick={onTextClick} className={clsx_text}>
44
+ {children}
45
+ </Text>
46
+ {isValue ? <Close2 color="#c2c4cc" onClick={onClearClick} {...rest} /> : <Fragment />}
47
+ </View>
48
+ );
49
+ };
@@ -1,7 +1,8 @@
1
- import { View, Text } from '@tarojs/components';
2
- import { DatePicker, DatePickerProps, CascaderOption } from '@nutui/nutui-react-taro';
1
+ import { View } from '@tarojs/components';
2
+ import { DatePicker, DatePickerProps } from '@nutui/nutui-react-taro';
3
3
  import { useMemo, useState } from 'react';
4
4
  import clsx from 'clsx';
5
+ import { FairysTaroTextClearBase } from 'components/clear';
5
6
 
6
7
  export interface FairysTaroDatePickerProps extends Omit<Partial<DatePickerProps>, 'value' | 'onChange'> {
7
8
  placeholder?: string;
@@ -131,22 +132,21 @@ export const FairysTaroDatePickerBase = (props: FairysTaroDatePickerProps) => {
131
132
  const { placeholder = '请选择', value, className, style, onChange, type = 'date', ...rest } = props;
132
133
  const [visible, setVisible] = useState(false);
133
134
 
134
- const clsx_text = useMemo(() => {
135
- return clsx('fairys-taro-date-picker-text', {
136
- 'fairys-taro-date-picker-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !value,
137
- 'fairys-taro-date-picker-text-value fairystaroform__text-black': value,
138
- });
139
- }, [value]);
140
-
141
135
  const render = useMemo(() => {
142
136
  return renderDate(value, type);
143
137
  }, [value, type]);
144
138
 
145
139
  return (
146
140
  <View className={`fairys-taro-date-picker ${className || ''}`} style={style}>
147
- <Text onClick={() => setVisible(true)} className={clsx_text}>
141
+ <FairysTaroTextClearBase
142
+ warpClassName="fairys-taro-date-picker-text"
143
+ isValue={!!render.renderStr}
144
+ onTextClick={() => setVisible(true)}
145
+ onClearClick={() => onChange?.(undefined)}
146
+ >
148
147
  {render.renderStr || placeholder}
149
- </Text>
148
+ </FairysTaroTextClearBase>
149
+
150
150
  <DatePicker
151
151
  type={type}
152
152
  showChinese
@@ -0,0 +1,8 @@
1
+ export * from './calendar';
2
+ export * from './cascader';
3
+ export * from './checkbox.group';
4
+ export * from './clear';
5
+ export * from './date.picker';
6
+ export * from './picker';
7
+ export * from './popup.search';
8
+ export * from './radio.group';
@@ -1,7 +1,7 @@
1
- import { View, Text } from '@tarojs/components';
1
+ import { View } from '@tarojs/components';
2
2
  import { Picker, TaroPickerProps, PickerOptions } from '@nutui/nutui-react-taro';
3
3
  import { useMemo, useState } from 'react';
4
- import clsx from 'clsx';
4
+ import { FairysTaroTextClearBase } from 'components/clear';
5
5
 
6
6
  export interface FairysTaroPickerProps extends Omit<Partial<TaroPickerProps>, 'value' | 'onChange'> {
7
7
  placeholder?: string;
@@ -23,13 +23,6 @@ export const FairysTaroPickerBase = (props: FairysTaroPickerProps) => {
23
23
  return undefined;
24
24
  }, [value]);
25
25
 
26
- const clsx_text = useMemo(() => {
27
- return clsx('fairys-taro-picker-text', {
28
- 'fairys-taro-picker-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !_renderValue,
29
- 'fairys-taro-picker-text-value fairystaroform__text-black': _renderValue,
30
- });
31
- }, [_renderValue]);
32
-
33
26
  const _value = useMemo(() => {
34
27
  if (Array.isArray(value)) {
35
28
  return value.map((item) => item.value);
@@ -39,9 +32,14 @@ export const FairysTaroPickerBase = (props: FairysTaroPickerProps) => {
39
32
 
40
33
  return (
41
34
  <View className={`fairys-taro-picker ${className || ''}`} style={style}>
42
- <Text onClick={() => setVisible(true)} className={clsx_text}>
35
+ <FairysTaroTextClearBase
36
+ warpClassName="fairys-taro-picker-text"
37
+ isValue={!!_renderValue}
38
+ onTextClick={() => setVisible(true)}
39
+ onClearClick={() => onChange?.(undefined)}
40
+ >
43
41
  {_renderValue || placeholder}
44
- </Text>
42
+ </FairysTaroTextClearBase>
45
43
  <Picker
46
44
  {...rest}
47
45
  className={`fairys-taro-picker-body fairystaroform__text-left ${bodyClassName || ''}`}
@@ -1,12 +1,16 @@
1
1
  import { View, Text } from '@tarojs/components';
2
2
  import { Popup, TaroPopupProps } from '@nutui/nutui-react-taro';
3
- import { Fragment, useMemo } from 'react';
4
- import clsx from 'clsx';
5
- import { useFairysTaroPopupSearchBaseInstance, FairysTaroPopupSearchBaseInstanceContext } from './instance';
3
+ import { Fragment, useEffect, useMemo } from 'react';
4
+ import {
5
+ useFairysTaroPopupSearchBaseInstance,
6
+ FairysTaroPopupSearchBaseInstanceContext,
7
+ useFairysTaroPopupSearchBaseInstanceContext,
8
+ } from './instance';
6
9
  import type { FairysTaroPopupSearchBaseInstanceMount } from './instance';
7
10
  import { FairysTaroPopupSearchFooterBase, FairysTaroPopupSearchInputBase } from './base';
8
11
  import { FairysTaroPopupSearchListVirtual } from './list.virtual';
9
12
  import { FairysTaroPopupSearchListTable } from './list.table';
13
+ import { FairysTaroTextClearBase } from 'components/clear';
10
14
 
11
15
  /**
12
16
  * 如果是多选,怎么移除某几个选中项
@@ -16,22 +20,62 @@ export interface FairysTaroPopupSearchProps<T = any>
16
20
  extends Partial<TaroPopupProps>,
17
21
  FairysTaroPopupSearchBaseInstanceMount<T> {
18
22
  placeholder?: string;
19
- /**是否显示删除按钮*/
20
- showDeleteButton?: boolean;
21
- /**是否显示搜索框*/
22
- showSearch?: boolean;
23
- /**选中项*/
24
- value?: T | T[];
25
- /**选择数据*/
26
- options?: ({
27
- label?: string;
28
- value?: string | number;
29
- [x: string]: any;
30
- } & T)[];
31
- /**
32
- * 最大渲染个数数量
33
- */
34
- maxTagCount?: number;
23
+ }
24
+
25
+ function RenderList<T = any>() {
26
+ const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext<T>();
27
+ const renderList = instance.renderList;
28
+ const _tempFilterDataList = state._tempFilterDataList as T[];
29
+ const operationStatus = state.operationStatus;
30
+ return renderList?.(_tempFilterDataList || [], operationStatus, instance) || <Fragment />;
31
+ }
32
+
33
+ function FairysTaroPopupSearchBodyBase<T = any>() {
34
+ const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext<T>();
35
+ const renderType = instance.renderType;
36
+ const showSearch = instance.showSearch;
37
+ const mode = instance.mode;
38
+ const columns = instance.columns;
39
+ const options = instance.options;
40
+ const isNeedManage = instance.isNeedManage;
41
+ const value = instance.value;
42
+ const visible = state.visible;
43
+
44
+ useMemo(() => {
45
+ if (isNeedManage || instance.isUseOptions()) {
46
+ instance.updateState({ value, _tempValue: value });
47
+ } else {
48
+ instance.updateState({ value, _tempValue: undefined });
49
+ }
50
+ }, [value, isNeedManage, visible]);
51
+
52
+ useMemo(() => instance.updateState({ dataList: options || [], _tempFilterDataList: options || [] }), [options]);
53
+ useMemo(() => instance.updateState({ mode }), [mode]);
54
+ useMemo(() => instance.updateState({ columns }), [columns]);
55
+
56
+ useEffect(() => {
57
+ if (visible && typeof instance.onLoadData === 'function') {
58
+ instance.onSearch('');
59
+ }
60
+ }, [visible]);
61
+
62
+ return (
63
+ <View className="fairys-taro-popup-search-content-inner fairystaroform__flex fairystaroform__flex-1 fairystaroform__flex-col fairystaroform__overflow-hidden">
64
+ {showSearch ? <FairysTaroPopupSearchInputBase /> : <Fragment />}
65
+ <View style={{ flex: 1, overflow: 'hidden' }}>
66
+ {renderType === 'list' ? (
67
+ <FairysTaroPopupSearchListVirtual<T> />
68
+ ) : renderType === 'table' ? (
69
+ <FairysTaroPopupSearchListTable<T> />
70
+ ) : renderType === 'custom' ? (
71
+ <RenderList<T> />
72
+ ) : (
73
+ <Fragment />
74
+ )}
75
+ </View>
76
+ {mode === 'multiple' ? <FairysTaroPopupSearchFooterBase<T> /> : <Fragment />}
77
+ </View>
78
+ );
35
79
  }
36
80
 
37
81
  export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchProps<T>) {
@@ -47,7 +91,7 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
47
91
  maxHeight,
48
92
  renderText,
49
93
  renderListItemText,
50
- showDeleteButton = true,
94
+ showRowDeleteButton = true,
51
95
  showSearch = true,
52
96
  renderList,
53
97
  options,
@@ -59,14 +103,14 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
59
103
  displayField = 'label',
60
104
  /**渲染类型*/
61
105
  renderType = 'list',
62
- maxTagCount = 5,
106
+ maxTagCount = 9,
63
107
  /**表格属性*/
64
108
  tableProps = {},
65
109
  useTableProps,
66
- isReplace = false,
110
+ isNeedManage = false,
111
+ isUseOptionsChecked = true,
67
112
  ...rest
68
113
  } = props;
69
-
70
114
  const [state, instance] = useFairysTaroPopupSearchBaseInstance<T>();
71
115
 
72
116
  instance.maxWidth = maxWidth;
@@ -79,7 +123,8 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
79
123
  instance.renderListItemText = renderListItemText;
80
124
  instance.tableProps = tableProps;
81
125
  instance.useTableProps = useTableProps;
82
- instance.isReplace = isReplace;
126
+ instance.isNeedManage = isNeedManage;
127
+ instance.isUseOptionsChecked = isUseOptionsChecked;
83
128
 
84
129
  instance.rowKey = rowKey;
85
130
  instance.displayField = displayField;
@@ -87,26 +132,20 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
87
132
  instance.columns = columns;
88
133
  instance.renderType = renderType;
89
134
 
135
+ instance.showRowDeleteButton = showRowDeleteButton;
136
+ instance.showSearch = showSearch;
137
+ instance.maxTagCount = maxTagCount;
138
+ instance.options = options;
139
+ instance.value = value;
140
+
90
141
  const operationStatus = state.operationStatus;
91
142
  const visible = state.visible;
92
143
 
93
144
  useMemo(() => instance.ctor(), [maxWidth, maxHeight]);
94
145
 
95
- useMemo(() => {
96
- if (!isReplace) {
97
- instance.updateState({ value, _tempValue: value });
98
- } else {
99
- instance.updateState({ value, _tempValue: undefined });
100
- }
101
- }, [value, isReplace, visible]);
102
-
103
- useMemo(() => instance.updateState({ dataList: options || [], _tempFilterDataList: options || [] }), [options]);
104
- useMemo(() => instance.updateState({ mode }), [mode]);
105
- useMemo(() => instance.updateState({ columns }), [columns]);
106
-
107
146
  const renderTextValue = useMemo(() => {
108
147
  if (instance.renderText) {
109
- return instance.renderText(value);
148
+ return instance.renderText(value, instance);
110
149
  }
111
150
  if (instance.mode === 'multiple') {
112
151
  if (Array.isArray(value)) {
@@ -123,28 +162,23 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
123
162
  return value?.[instance.displayField];
124
163
  }, [value, mode, maxTagCount]);
125
164
 
126
- const clsx_text = useMemo(() => {
127
- // 文本溢出显示...
128
- return clsx('fairys-taro-popup-search-text', {
129
- 'fairys-taro-popup-search-text-placeholder fairystaroform__text-gray-600 fairystaroform__font-normal': !value,
130
- 'fairys-taro-popup-search-text-value fairystaroform__text-black': value,
131
- });
132
- }, [value]);
133
-
134
165
  return (
135
166
  <View className={`fairys-taro-popup-search ${className || ''}`} style={style}>
136
- <View className="fairys-taro-popup-search-text-container fairystaroform__break-all">
137
- <Text onClick={() => instance.updateState({ visible: true })} className={clsx_text}>
138
- {renderTextValue || placeholder}
139
- </Text>
140
- </View>
167
+ <FairysTaroTextClearBase
168
+ warpClassName="fairys-taro-popup-search-text-container"
169
+ isValue={!!renderTextValue}
170
+ onTextClick={() => instance.updateState({ visible: true })}
171
+ onClearClick={() => onChange?.(undefined)}
172
+ >
173
+ {renderTextValue || placeholder}
174
+ </FairysTaroTextClearBase>
141
175
  <Popup
142
176
  lockScroll
143
177
  position="bottom"
144
178
  closeable
145
179
  {...rest}
146
180
  left={
147
- mode === 'multiple' && !isReplace ? (
181
+ mode === 'multiple' && isNeedManage ? (
148
182
  <Text onClick={instance.updateOperationStatus}>{operationStatus == 'select' ? '管理' : '完成'}</Text>
149
183
  ) : (
150
184
  <Fragment />
@@ -156,19 +190,7 @@ export function FairysTaroPopupSearchBase<T = any>(props: FairysTaroPopupSearchP
156
190
  className="fairys-taro-popup-search-content fairystaroform__flex fairystaroform__flex-col fairystaroform__overflow-hidden"
157
191
  >
158
192
  <FairysTaroPopupSearchBaseInstanceContext.Provider value={instance}>
159
- <View className="fairys-taro-popup-search-content-inner fairystaroform__flex fairystaroform__flex-1 fairystaroform__flex-col fairystaroform__overflow-hidden">
160
- {showSearch ? <FairysTaroPopupSearchInputBase /> : <Fragment />}
161
- <View style={{ flex: 1, overflow: 'hidden' }}>
162
- {renderType === 'list' ? (
163
- <FairysTaroPopupSearchListVirtual />
164
- ) : renderType === 'table' ? (
165
- <FairysTaroPopupSearchListTable />
166
- ) : (
167
- <Fragment />
168
- )}
169
- </View>
170
- {mode === 'multiple' ? <FairysTaroPopupSearchFooterBase /> : <Fragment />}
171
- </View>
193
+ {visible ? <FairysTaroPopupSearchBodyBase<T> /> : <Fragment />}
172
194
  </FairysTaroPopupSearchBaseInstanceContext.Provider>
173
195
  </Popup>
174
196
  </View>
@@ -7,15 +7,19 @@ export class FairysTaroPopupSearchBaseInstanceMount<T = any> {
7
7
  /**选中项改变时触发*/
8
8
  onChange?: (value: T[] | T | undefined) => void;
9
9
  // 1. 直接传递值 ,2. 请求接口获取值
10
- onLoadData?: (params: any) => Promise<T[]>;
10
+ onLoadData?: (params: any, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => Promise<T[]>;
11
11
  /**其他请求参数*/
12
- otherRequestParams?: (params: any) => any;
12
+ otherRequestParams?: (params: any, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => any;
13
13
  /**自定义输入框显示文本*/
14
- renderText?: (data: T | T[]) => React.ReactNode;
14
+ renderText?: (data: T | T[], instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
15
15
  /**自定义渲染列表项文本*/
16
- renderListItemText?: (data: T) => React.ReactNode;
16
+ renderListItemText?: (data: T, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
17
17
  /**自定义渲染列表数据*/
18
- renderList?: (dataList: T[], type: 'select' | 'manage') => React.ReactNode;
18
+ renderList?: (
19
+ dataList: T[],
20
+ type: 'select' | 'manage',
21
+ instance: FairysTaroPopupSearchBaseInstanceMount<T>,
22
+ ) => React.ReactNode;
19
23
  /**选择模式*/
20
24
  mode?: 'multiple' | 'single' = 'single';
21
25
  /**列表项的唯一键值*/
@@ -28,13 +32,15 @@ export class FairysTaroPopupSearchBaseInstanceMount<T = any> {
28
32
  maxWidth?: number;
29
33
  /**最大弹窗高度*/
30
34
  maxHeight?: number;
31
- /**直接替换已选择的数据*/
32
- isReplace?: boolean = false;
35
+ /**是否需要管理已选择的数据*/
36
+ isNeedManage?: boolean = false;
37
+ /**是否选中状态,在使用 options 参数渲染固定列数据的时候是否需要选中状态*/
38
+ isUseOptionsChecked?: boolean = true;
33
39
  /**
34
40
  * 渲染类型
35
41
  * @default 'list'
36
42
  * */
37
- renderType?: 'list' | 'table' = 'list';
43
+ renderType?: 'list' | 'table' | 'custom' = 'list';
38
44
  /**表格属性*/
39
45
  tableProps?: Partial<TaroTableProps> = {};
40
46
  /**自定义表格属性*/
@@ -42,6 +48,22 @@ export class FairysTaroPopupSearchBaseInstanceMount<T = any> {
42
48
  tableProps: Partial<TaroTableProps>,
43
49
  instance: FairysTaroPopupSearchBaseInstanceMount<T>,
44
50
  ) => Partial<TaroTableProps>;
51
+ /**是否显示删除按钮*/
52
+ showRowDeleteButton?: boolean;
53
+ /**是否显示搜索框*/
54
+ showSearch?: boolean;
55
+ /**选中项*/
56
+ value?: T | T[];
57
+ /**选择数据*/
58
+ options?: ({
59
+ label?: string;
60
+ value?: string | number;
61
+ [x: string]: any;
62
+ } & T)[];
63
+ /**
64
+ * 最大渲染个数数量
65
+ */
66
+ maxTagCount?: number;
45
67
  }
46
68
 
47
69
  export interface FairysTaroPopupSearchBaseInstanceState<T = any> {
@@ -152,16 +174,25 @@ export class FairysTaroPopupSearchBaseInstance<T = any> extends FairysTaroPopupS
152
174
  }
153
175
  };
154
176
 
177
+ /**判断是否使用 options 参数,并且不是管理模式*/
178
+ isUseOptions = () => {
179
+ if (Array.isArray(this.options) && !this.onLoadData && !this.isNeedManage) {
180
+ return this.isUseOptionsChecked;
181
+ }
182
+ return false;
183
+ };
184
+
155
185
  /**搜索*/
156
186
  onSearch = async (keyword: string) => {
157
187
  this.state.search = keyword;
188
+
158
189
  const _keyword = `${keyword || ''}`.trim();
159
190
  try {
160
191
  if (this.onLoadData && this.state.operationStatus === 'select') {
161
192
  // 延时 0.5s 搜索,避免用户输入过快导致请求次数过多
162
193
  await new Promise((resolve) => setTimeout(resolve, 500));
163
194
  const search = { keyword: _keyword };
164
- const dataList = await this.onLoadData(this.otherRequestParams?.(search) || search);
195
+ const dataList = await this.onLoadData(this.otherRequestParams?.(search, this) || search, this);
165
196
  if (Array.isArray(dataList)) {
166
197
  this.updateState({ _tempFilterDataList: dataList || [], dataList: dataList || [] });
167
198
  } else {
@@ -50,6 +50,7 @@ export function FairysTaroPopupSearchListTable<T = any>() {
50
50
  const operationStatus = state.operationStatus;
51
51
  const columns = (state.columns || []) as TableColumnProps[];
52
52
  const tableProps = instance.useTableProps?.(instance.tableProps || {}, instance) || instance.tableProps || {};
53
+ const showRowDeleteButton = instance.showRowDeleteButton;
53
54
 
54
55
  const _newColumns = useMemo(() => {
55
56
  const list = [
@@ -61,7 +62,7 @@ export function FairysTaroPopupSearchListTable<T = any>() {
61
62
  render: (rowData: T) => <TableItemCheckBox rowData={rowData} />,
62
63
  } as TableColumnProps,
63
64
  ].concat([...columns]);
64
- if (operationStatus === 'manage' && instance.mode === 'multiple') {
65
+ if (operationStatus === 'manage' && instance.mode === 'multiple' && showRowDeleteButton) {
65
66
  return [
66
67
  ...list,
67
68
  {
@@ -74,7 +75,7 @@ export function FairysTaroPopupSearchListTable<T = any>() {
74
75
  ];
75
76
  }
76
77
  return list;
77
- }, [columns, operationStatus]);
78
+ }, [columns, operationStatus, showRowDeleteButton]);
78
79
 
79
80
  return (
80
81
  <Table
@@ -16,8 +16,9 @@ function VirtualListItem<T = any>(props: { rowData: T; dataIndex: number; index:
16
16
  const _tempValue = state._tempValue;
17
17
  const operationStatus = state.operationStatus;
18
18
  const manageSelectedDataList = state.manageSelectedDataList;
19
+ const showRowDeleteButton = instance.showRowDeleteButton;
19
20
  const renderText = useMemo(() => {
20
- return renderListItemText?.(rowData) || rowData[instance.displayField];
21
+ return renderListItemText?.(rowData, instance) || rowData[instance.displayField];
21
22
  }, [rowData, instance.displayField, renderListItemText]);
22
23
 
23
24
  const checked = useMemo(
@@ -38,7 +39,7 @@ function VirtualListItem<T = any>(props: { rowData: T; dataIndex: number; index:
38
39
  </Checkbox>
39
40
  }
40
41
  extra={
41
- operationStatus === 'manage' ? (
42
+ operationStatus === 'manage' && showRowDeleteButton ? (
42
43
  <Button
43
44
  size="mini"
44
45
  fill="none"
package/src/index.tsx CHANGED
@@ -2,12 +2,15 @@
2
2
  * 简版表单
3
3
  * 用于快速创建表单,支持文本输入、选择框、单选框、复选框等常用表单元素。
4
4
  * */
5
- import { Form } from '@carefrees/form-utils-react-taro';
5
+ import { Form, useForm, useWatch } from '@carefrees/form-utils-react-taro';
6
6
  import { FairysTaroSimpleFormProps } from './interface';
7
7
  import { ConfigListItem, ConfigItem, InputConfigType } from './item.config';
8
+ export * from './components';
8
9
 
9
10
  export const FairysTaroSimpleForm = (props: FairysTaroSimpleFormProps) => {
10
11
  return <Form labelMode="between" colCount={1} inputBordered={false} {...props} />;
11
12
  };
12
13
  FairysTaroSimpleForm.Item = ConfigItem;
13
14
  FairysTaroSimpleForm.ListItem = ConfigListItem;
15
+ FairysTaroSimpleForm.useForm = useForm;
16
+ FairysTaroSimpleForm.useWatch = useWatch;