@hw-component/form 1.6.2 → 1.6.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.
Files changed (33) hide show
  1. package/.eslintcache +1 -1
  2. package/es/Select/hooks/changeHooks.js +34 -143
  3. package/es/Select/hooks/norHooks.d.ts +6 -4
  4. package/es/Select/hooks/norHooks.js +137 -29
  5. package/es/Select/hooks/util.d.ts +10 -0
  6. package/es/Select/hooks/util.js +138 -0
  7. package/es/Select/index.js +17 -12
  8. package/es/Select/modal.d.ts +11 -2
  9. package/lib/Select/hooks/changeHooks.js +35 -144
  10. package/lib/Select/hooks/norHooks.d.ts +6 -4
  11. package/lib/Select/hooks/norHooks.js +136 -28
  12. package/lib/Select/hooks/util.d.ts +10 -0
  13. package/lib/Select/hooks/util.js +139 -0
  14. package/lib/Select/index.js +16 -11
  15. package/lib/Select/modal.d.ts +11 -2
  16. package/package.json +1 -1
  17. package/src/components/DialogForm/DrawerForm/index.tsx +1 -1
  18. package/src/components/DialogForm/ModalForm.tsx +1 -1
  19. package/src/components/Form/hooks/useDefaultRender.tsx +1 -1
  20. package/src/components/Form/hooks/useHForm.ts +1 -1
  21. package/src/components/Form/index.tsx +4 -4
  22. package/src/components/Input/ButtonInput.tsx +2 -2
  23. package/src/components/Select/hooks/changeHooks.tsx +30 -107
  24. package/src/components/Select/hooks/norHooks.ts +107 -17
  25. package/src/components/Select/hooks/util.ts +109 -0
  26. package/src/components/Select/index.tsx +7 -2
  27. package/src/components/Select/modal.ts +14 -2
  28. package/src/components/Submit/components.tsx +7 -3
  29. package/src/components/Upload/hooks/customRequest.ts +6 -6
  30. package/src/pages/DrawerForm/index.tsx +9 -9
  31. package/src/pages/Form/index.tsx +22 -29
  32. package/src/pages/Select/index.tsx +25 -3
  33. package/src/pages/Upload/index.tsx +16 -13
@@ -23,7 +23,7 @@ var AllSelect = require('./components/AllSelect.js');
23
23
  var index = require('../hooks/index.js');
24
24
  var HFormConnect = require('../Form/HFormConnect.js');
25
25
 
26
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat", "dispatch"],
26
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat", "dispatch", "isList", "onPopupScroll"],
27
27
  _excluded2 = ["value", "label"];
28
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
29
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -58,6 +58,8 @@ var Index = function Index(_ref) {
58
58
  addDispatchListener = _ref.addDispatchListener;
59
59
  _ref.addFormat;
60
60
  var dispatch = _ref.dispatch,
61
+ isList = _ref.isList,
62
+ propsOnPopupScroll = _ref.onPopupScroll,
61
63
  props = _objectWithoutProperties(_ref, _excluded);
62
64
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
63
65
  icon = _ref2.icon,
@@ -70,7 +72,7 @@ var Index = function Index(_ref) {
70
72
  filterOption: filterOption,
71
73
  serviceSearch: serviceSearch
72
74
  });
73
- var _useOptionReq = norHooks.useOptionReq({
75
+ var _useSelectReq = norHooks.useSelectReq({
74
76
  options: options,
75
77
  manual: manual,
76
78
  fieldNames: fieldNames,
@@ -78,15 +80,17 @@ var Index = function Index(_ref) {
78
80
  serviceSearch: serviceSearch,
79
81
  showSearch: showSearch,
80
82
  onSearch: propsOnSearch,
81
- dispatch: dispatch
83
+ dispatch: dispatch,
84
+ isList: isList
82
85
  }),
83
- run = _useOptionReq.run,
84
- loading = _useOptionReq.loading,
85
- resultData = _useOptionReq.data,
86
- error = _useOptionReq.error,
87
- onSearch = _useOptionReq.onSearch,
88
- mathShowSearch = _useOptionReq.mathShowSearch,
89
- reload = _useOptionReq.reload;
86
+ run = _useSelectReq.run,
87
+ loading = _useSelectReq.loading,
88
+ resultData = _useSelectReq.data,
89
+ error = _useSelectReq.error,
90
+ onSearch = _useSelectReq.onSearch,
91
+ mathShowSearch = _useSelectReq.mathShowSearch,
92
+ reload = _useSelectReq.reload,
93
+ onPopupScroll = _useSelectReq.onPopupScroll;
90
94
  var data = index.useChangeOptions({
91
95
  options: resultData,
92
96
  fieldNames: fieldNames
@@ -132,7 +136,8 @@ var Index = function Index(_ref) {
132
136
  optionFilterProp: optionFilterProp,
133
137
  filterOption: selfFilterOption,
134
138
  showSearch: mathShowSearch,
135
- labelInValue: true
139
+ labelInValue: true,
140
+ onPopupScroll: propsOnPopupScroll || onPopupScroll
136
141
  }, props), {}, {
137
142
  children: data === null || data === void 0 ? void 0 : data.map(function (item) {
138
143
  var optionValue = item.value,
@@ -3,7 +3,6 @@ import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
4
  import type { addFormatItemModal, argsFn, DispatchModal } from "../Form/modal";
5
5
  export type OptionType = Record<string, any>;
6
- export type PartialHSelectProps = Partial<HSelectProps>;
7
6
  export type RenderFn = (data: OptionType) => React.ReactNode;
8
7
  interface ModeConfigItem {
9
8
  icon?: React.ReactNode | null;
@@ -14,9 +13,17 @@ export interface ModeConfig {
14
13
  tags?: ModeConfigItem;
15
14
  }
16
15
  type FilterProviderFn = (item: any) => string;
16
+ type OptionsListType = OptionType[];
17
+ export interface OptionsPageResultModal {
18
+ page: number;
19
+ size: number;
20
+ data: OptionsListType;
21
+ total: number;
22
+ }
23
+ export type OptionsDataType = OptionsListType | OptionsPageResultModal;
17
24
  export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder"> {
18
25
  style?: React.CSSProperties;
19
- request?: PromiseFnResult<any, OptionType[]>;
26
+ request?: PromiseFnResult<any, OptionsDataType>;
20
27
  manual?: boolean;
21
28
  modeConfig?: ModeConfig;
22
29
  filterProvider?: FilterProviderFn | string;
@@ -28,9 +35,11 @@ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder
28
35
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
29
36
  placeholder?: string;
30
37
  dispatch?: DispatchModal;
38
+ isList?: boolean;
31
39
  }
32
40
  export interface FilterDataModal {
33
41
  value: any;
34
42
  index: number;
35
43
  }
44
+ export type PartialHSelectProps = Partial<HSelectProps>;
36
45
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -104,7 +104,7 @@ export default ({
104
104
  footer={footerComponent()}
105
105
  >
106
106
  <FormConfigProvider {...providerConfig}>
107
- {contentRender ? contentRender(node, currentForm,params) : node}
107
+ {contentRender ? contentRender(node, currentForm, params) : node}
108
108
  </FormConfigProvider>
109
109
  </Drawer>
110
110
  );
@@ -98,7 +98,7 @@ export default ({
98
98
  footer={defaultFooter}
99
99
  >
100
100
  <FormConfigProvider {...providerConfig}>
101
- {contentRender ? contentRender?.(node, currentForm,formParams) : node}
101
+ {contentRender ? contentRender?.(node, currentForm, formParams) : node}
102
102
  </FormConfigProvider>
103
103
  </Modal>
104
104
  );
@@ -30,7 +30,7 @@ export const useDefaultRender = (
30
30
  Component = (dom as ConfigComponentModal).Component;
31
31
  }
32
32
  const node = Component && (
33
- <Component {...componentProps} {...itemProps} form={form}/>
33
+ <Component {...componentProps} {...itemProps} form={form} />
34
34
  );
35
35
  if (render) {
36
36
  const resultNode = render(props, node, form);
@@ -86,7 +86,7 @@ export default () => {
86
86
  return newValue;
87
87
  }, //转化方法
88
88
  dispatch(...args) {
89
- const [action,...dispatchArgs]=args;
89
+ const [action, ...dispatchArgs] = args;
90
90
  const { key, name } = action;
91
91
  const items = dispatchSourceData[key];
92
92
  if (!items) {
@@ -1,4 +1,4 @@
1
- import {Form, Input, Row} from "antd";
1
+ import { Form, Input, Row } from "antd";
2
2
  import type { HFormProps, HItemProps } from "./modal";
3
3
  import Item from "./FormItem";
4
4
  import { useCurrentForm, useInfoReq, useValuesChange } from "./hooks";
@@ -62,9 +62,9 @@ export default ({
62
62
  hForm.removeDispatchListener();
63
63
  };
64
64
  }, []);
65
- const defaultOnPressEnter=()=>{
65
+ const defaultOnPressEnter = () => {
66
66
  hForm.submit();
67
- }
67
+ };
68
68
  return (
69
69
  <PageHandler
70
70
  loading={infoLoading}
@@ -93,7 +93,7 @@ export default ({
93
93
  colon: itemColon,
94
94
  } = itemData;
95
95
  const defaultItemProps = {
96
- onPressEnter:defaultOnPressEnter,
96
+ onPressEnter: defaultOnPressEnter,
97
97
  ...formItemProps,
98
98
  ...itemProps,
99
99
  };
@@ -14,7 +14,7 @@ const Index: React.FC<HButtonInputProps> = ({
14
14
  const {
15
15
  onClick,
16
16
  type = "primary",
17
- ghost=true,
17
+ ghost = true,
18
18
  loading: btnLoading,
19
19
  ...oProps
20
20
  } = buttonProps;
@@ -42,7 +42,7 @@ const Index: React.FC<HButtonInputProps> = ({
42
42
  type={type}
43
43
  onClick={click}
44
44
  loading={loading || btnLoading}
45
- style={{ marginLeft: 8,borderRadius:4 }}
45
+ style={{ marginLeft: 8, borderRadius: 4 }}
46
46
  ghost={ghost}
47
47
  {...oProps}
48
48
  >
@@ -1,113 +1,9 @@
1
1
  import type {
2
- OptionType,
3
2
  PartialHSelectProps,
4
3
  } from "@/components/Select/modal";
5
4
  import { useEffect, useState } from "react";
6
- import type { FilterDataModal } from "@/components/Select/modal";
7
5
  import { itemOpProvider } from "../utils";
8
-
9
- const single = ({ options, value, noMatchItemRender }: PartialHSelectProps) => {
10
- const newOptions = options || [];
11
- const index = newOptions.findIndex((item) => {
12
- return item.value === value;
13
- });
14
- if (index !== -1) {
15
- const { label } = newOptions[index];
16
- return {
17
- value,
18
- label,
19
- };
20
- }
21
- return {
22
- value,
23
- label: noMatchItemRender?.({ value }) || value,
24
- };
25
- }; //单选模式
26
- const findNewValInOldVal = (val, oldVal?: any[]) => {
27
- if (!oldVal) {
28
- return -1;
29
- }
30
- return oldVal.findIndex((item) => {
31
- return item.value === val;
32
- });
33
- }; //查询新增的 value
34
- const sourceDataProvider = (
35
- { options, value }: PartialHSelectProps,
36
- oldVal?: any[]
37
- ) => {
38
- const oldData: FilterDataModal[] = [];
39
- const newData: FilterDataModal[] = [];
40
- value.forEach((item, i) => {
41
- const index = findNewValInOldVal(item, oldVal);
42
- if (index === -1) {
43
- newData.push({
44
- value: item,
45
- index: i,
46
- });
47
- return;
48
- }
49
- const newVal = oldVal?.[index];
50
- oldData.push({
51
- ...newVal,
52
- index: i,
53
- });
54
- });
55
- return {
56
- oldData,
57
- newData,
58
- };
59
- }; //创建新旧数据
60
- const resultProvider = (
61
- newData: FilterDataModal[],
62
- oldData: FilterDataModal[],
63
- value: any[]
64
- ) => {
65
- const newResult = new Array(value.length);
66
- oldData.forEach((item) => {
67
- const { index, ...val } = item;
68
- newResult[index] = {
69
- ...val,
70
- };
71
- });
72
- newData.forEach((item) => {
73
- const { index, ...val } = item;
74
- newResult[index] = {
75
- ...val,
76
- };
77
- });
78
- return newResult;
79
- };
80
- const multiple = (
81
- { options, value, noMatchItemRender }: PartialHSelectProps,
82
- oldVal?: any[]
83
- ) => {
84
- const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
85
- const newMatchVal = newData.map((item) => {
86
- const { value: itemVal, index } = item;
87
- const newItem = single({ options, value: itemVal, noMatchItemRender });
88
- return {
89
- ...newItem,
90
- index,
91
- };
92
- });
93
- return resultProvider(newMatchVal, oldData, value);
94
- }; //多选
95
- const tag = ({ options, value }: PartialHSelectProps, oldVal?: any[]) => {
96
- const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
97
- return resultProvider(newData, oldData, value);
98
- }; //tags模式
99
- const matchNotFind = (
100
- { options, value, mode, noMatchItemRender }: PartialHSelectProps,
101
- oldVale?: OptionType[]
102
- ) => {
103
- if (!mode) {
104
- return single({ options, value, noMatchItemRender });
105
- }
106
- if (mode === "multiple") {
107
- return multiple({ options, value, noMatchItemRender }, oldVale) || [];
108
- }
109
- return tag({ options, value }, oldVale);
110
- }; //不匹配
6
+ import {matchNotFind} from './util'
111
7
  export const useValueChange = (params: PartialHSelectProps) => {
112
8
  const {
113
9
  labelInValue,
@@ -155,9 +51,36 @@ export const useValueChange = (params: PartialHSelectProps) => {
155
51
  return matchNotFind(params, oldVale);
156
52
  });
157
53
  }
158
- }, [value, options, mode, noMatchItemRender]);
54
+ }, [value, options, mode]);
55
+ const itemMaker=(item)=>{
56
+ const {value:itemVal,label,noMatch}=item;
57
+ if (noMatch){
58
+ return {
59
+ value:itemVal,
60
+ label: noMatchItemRender?.({ value }) || value,
61
+ }
62
+ }
63
+ return {
64
+ value:itemVal,
65
+ label
66
+ }
67
+ }
68
+ const valuesMaker=()=>{
69
+ if (labelInValue){
70
+ return val;
71
+ }
72
+ if (!val){
73
+ return val;
74
+ }
75
+ if (Array.isArray(val)){
76
+ return val.map((item)=>{
77
+ return itemMaker(item);
78
+ })
79
+ }
80
+ return itemMaker(val);
81
+ }
159
82
  return {
160
- val,
83
+ val:valuesMaker(),
161
84
  change,
162
85
  };
163
86
  };
@@ -1,36 +1,84 @@
1
- import { useEffect, useState } from "react";
1
+ import {useEffect, useMemo, useState} from "react";
2
2
  import type {
3
3
  OptionType,
4
4
  PartialHSelectProps,
5
- } from "@/components/Select/modal";
5
+ } from "../modal";
6
6
  import { useRequest } from "ahooks";
7
7
  import { useFormContext } from "../../Form/Context";
8
+ import {OptionsPageResultModal} from "../modal";
8
9
 
9
10
  interface ParamsModal {
10
11
  options?: OptionType[];
11
12
  params?: any;
12
13
  }
13
- export const useOptionReq = ({
14
- manual,
14
+ const useSaveParams=()=>{
15
+ const saveParams=useMemo(()=>{
16
+ return {
17
+ listParams:{
18
+ isEnd:false,
19
+ page:1,
20
+ size:100,
21
+ reqParams:{}
22
+ }
23
+ }
24
+ },[]);
25
+ const resetSaveParams=()=>{
26
+ saveParams.listParams={
27
+ isEnd:false,
28
+ page:1,
29
+ size:100,
30
+ reqParams:{}
31
+ }
32
+ }
33
+ const nextPage=(data:OptionsPageResultModal)=>{
34
+ const {size,total,page}=data;
35
+ saveParams.listParams.size=size;
36
+ saveParams.listParams.page=page+1;
37
+ saveParams.listParams.isEnd=size*page>=total;
38
+ }
39
+ return {
40
+ saveParams,
41
+ resetSaveParams,
42
+ nextPage
43
+ }
44
+ }
45
+ const useOptionsRequest = ({
15
46
  request,
16
- options,
17
- serviceSearch,
18
- showSearch,
19
- onSearch: propsOnSearch,
20
47
  dispatch = {},
48
+ manual,
49
+ options,
50
+ isList
21
51
  }: PartialHSelectProps) => {
22
- const { manual: dispatchManual } = dispatch;
52
+ const {saveParams,resetSaveParams,nextPage}=useSaveParams();
23
53
  const { form } = useFormContext();
54
+ const { manual: dispatchManual } = dispatch;
24
55
  const [data, setData] = useState<OptionType[] | undefined>();
56
+ const paramsProvider=(params:Record<string, any>)=>{
57
+ if (isList){
58
+ const page=saveParams.listParams.page;
59
+ const size=saveParams.listParams.size;
60
+ return {
61
+ ...params,
62
+ page,
63
+ size
64
+ }
65
+ }
66
+ return params;
67
+ }
25
68
  const { run, loading, error } = useRequest(
26
- async (requestParams = {}) => {
27
- const { params = {}, values, type = "init" } = requestParams;
69
+ async (requestParams = {},type="init") => {
70
+ const { params = saveParams.listParams.reqParams, values} = requestParams;
28
71
  const formData = values || form?.getFieldsValue();
29
72
  if (type === "init") {
73
+ resetSaveParams();
30
74
  setData(undefined);
31
75
  }
76
+ saveParams.listParams.reqParams=params;
77
+ if (isList&&saveParams.listParams.isEnd){
78
+ return data;
79
+ }
32
80
  if (request) {
33
- return request(params, formData);
81
+ return request(paramsProvider(params), formData);
34
82
  }
35
83
  return Promise.resolve(options);
36
84
  },
@@ -38,12 +86,48 @@ export const useOptionReq = ({
38
86
  manual: dispatchManual === false ? true : manual,
39
87
  debounceInterval: 300,
40
88
  onSuccess: (resultData) => {
41
- setData(resultData);
89
+ if (Array.isArray(resultData)||!resultData){
90
+ return setData(resultData);
91
+ }
92
+ const oldData=data||[];
93
+ const {data:resultOption}=resultData;
94
+ const op = resultOption||[];
95
+ nextPage(resultData);
96
+ setData([
97
+ ...oldData,
98
+ ...op
99
+ ]);
42
100
  },
43
101
  }
44
102
  );
103
+ return {
104
+ loading,
105
+ run,
106
+ error,
107
+ data,
108
+ setData,
109
+ };
110
+ };
111
+
112
+ export const useSelectReq = ({
113
+ manual,
114
+ request,
115
+ options,
116
+ serviceSearch,
117
+ showSearch,
118
+ onSearch: propsOnSearch,
119
+ dispatch = {},
120
+ isList,
121
+ }: PartialHSelectProps) => {
122
+ const { run, loading, error, data, setData } = useOptionsRequest({
123
+ request,
124
+ dispatch,
125
+ manual,
126
+ options,
127
+ isList
128
+ });
45
129
  const reload = (reloadParams?: ParamsModal) => {
46
- const { options: changeOpts, params }=reloadParams||{};
130
+ const { options: changeOpts, params } = reloadParams || {};
47
131
  if (changeOpts) {
48
132
  return setData(changeOpts);
49
133
  }
@@ -61,6 +145,13 @@ export const useOptionReq = ({
61
145
  setData(options);
62
146
  }
63
147
  }, [options]);
148
+ const onPopupScroll=(e)=>{
149
+ const {target} = e;
150
+ const changeTarget=(target as any);
151
+ if (changeTarget.scrollTop + changeTarget.offsetHeight === changeTarget.scrollHeight) {
152
+ run({},"page");
153
+ }
154
+ }
64
155
  const mathShowSearch = showSearch || serviceSearch;
65
156
  return {
66
157
  run,
@@ -70,6 +161,7 @@ export const useOptionReq = ({
70
161
  onSearch: mathShowSearch ? onSearch : propsOnSearch,
71
162
  mathShowSearch: showSearch || serviceSearch,
72
163
  reload,
164
+ onPopupScroll:isList?onPopupScroll:undefined
73
165
  };
74
166
  };
75
167
 
@@ -78,9 +170,7 @@ export const useFilterOption = ({
78
170
  serviceSearch,
79
171
  }: PartialHSelectProps) => {
80
172
  if (serviceSearch) {
81
- return () => {
82
- return true;
83
- };
173
+ return false
84
174
  }
85
175
  return filterOption;
86
176
  };
@@ -0,0 +1,109 @@
1
+ import {FilterDataModal, OptionType, PartialHSelectProps} from "@/components/Select/modal";
2
+
3
+ const findNewValInOldVal = (val, oldVal?: any[]) => {
4
+ if (!oldVal) {
5
+ return -1;
6
+ }
7
+ return oldVal.findIndex((item) => {
8
+ return item.value === val;
9
+ });
10
+ }; //查询新增的 value
11
+
12
+ const sourceDataProvider = (
13
+ { value }: PartialHSelectProps,
14
+ oldVal?: any[]
15
+ ) => {
16
+ const oldData: FilterDataModal[] = [];
17
+ const newData: FilterDataModal[] = [];
18
+ value.forEach((item, i) => {
19
+ const index = findNewValInOldVal(item, oldVal);
20
+ if (index === -1) {
21
+ newData.push({
22
+ value: item,
23
+ index: i,
24
+ });
25
+ return;
26
+ }
27
+ const newVal = oldVal?.[index];
28
+ oldData.push({
29
+ ...newVal,
30
+ index: i,
31
+ });
32
+ });
33
+ return {
34
+ oldData,
35
+ newData,
36
+ };
37
+ }; //创建新旧数据
38
+
39
+
40
+ const single = ({ options, value }: PartialHSelectProps) => {
41
+ const newOptions = options || [];
42
+ const index = newOptions.findIndex((item) => {
43
+ return item.value === value;
44
+ });
45
+ if (index !== -1) {
46
+ const { label } = newOptions[index];
47
+ return {
48
+ value,
49
+ label,
50
+ };
51
+ }
52
+ return {
53
+ value,
54
+ label:value,
55
+ noMatch:true
56
+ };
57
+ }; //单选模式
58
+ const resultProvider = (
59
+ newData: FilterDataModal[],
60
+ oldData: FilterDataModal[],
61
+ value: any[]
62
+ ) => {
63
+ const newResult = new Array(value.length);
64
+ oldData.forEach((item) => {
65
+ const { index, ...val } = item;
66
+ newResult[index] = {
67
+ ...val,
68
+ };
69
+ });
70
+ newData.forEach((item) => {
71
+ const { index, ...val } = item;
72
+ newResult[index] = {
73
+ ...val,
74
+ };
75
+ });
76
+ return newResult;
77
+ };
78
+ const multiple = (
79
+ { options, value }: PartialHSelectProps,
80
+ oldVal?: any[]
81
+ ) => {
82
+ const { newData, oldData } = sourceDataProvider({ value }, oldVal);
83
+ const newMatchVal = newData.map((item) => {
84
+ const { value: itemVal, index } = item;
85
+ const newItem = single({ options, value: itemVal });
86
+ return {
87
+ ...newItem,
88
+ index,
89
+ };
90
+ });
91
+ return resultProvider(newMatchVal, oldData, value);
92
+ }; //多选
93
+
94
+ const tag = ({ options, value }: PartialHSelectProps, oldVal?: any[]) => {
95
+ const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
96
+ return resultProvider(newData, oldData, value);
97
+ }; //tags模式
98
+ export const matchNotFind = (
99
+ { options, value, mode }: PartialHSelectProps,
100
+ oldVale?: OptionType[]
101
+ ) => {
102
+ if (!mode) {
103
+ return single({ options, value });
104
+ }
105
+ if (mode === "multiple") {
106
+ return multiple({ options, value }, oldVale) || [];
107
+ }
108
+ return tag({ options, value }, oldVale);
109
+ }; //不匹配
@@ -1,6 +1,6 @@
1
1
  import { Select } from "antd";
2
2
  import React from "react";
3
- import { useFilterOption, useOptionReq } from "./hooks/norHooks";
3
+ import {useFilterOption, useSelectReq} from "./hooks/norHooks";
4
4
  import { useValueChange } from "./hooks/changeHooks";
5
5
  import type { HSelectProps } from "./modal";
6
6
  import { defaultModeConfig, defaultSelectConfig } from "./defaultConfig";
@@ -33,6 +33,8 @@ const Index: React.FC<HSelectProps> = ({
33
33
  addDispatchListener,
34
34
  addFormat,
35
35
  dispatch,
36
+ isList,
37
+ onPopupScroll:propsOnPopupScroll,
36
38
  ...props
37
39
  }) => {
38
40
  const { icon, render } = modeConfig?.[mode || ""] || {};
@@ -46,7 +48,8 @@ const Index: React.FC<HSelectProps> = ({
46
48
  onSearch,
47
49
  mathShowSearch,
48
50
  reload,
49
- } = useOptionReq({
51
+ onPopupScroll
52
+ } = useSelectReq({
50
53
  options,
51
54
  manual,
52
55
  fieldNames,
@@ -55,6 +58,7 @@ const Index: React.FC<HSelectProps> = ({
55
58
  showSearch,
56
59
  onSearch: propsOnSearch,
57
60
  dispatch,
61
+ isList
58
62
  }); //options
59
63
 
60
64
  const data = useChangeOptions({ options: resultData, fieldNames });
@@ -103,6 +107,7 @@ const Index: React.FC<HSelectProps> = ({
103
107
  filterOption={selfFilterOption}
104
108
  showSearch={mathShowSearch}
105
109
  labelInValue={true}
110
+ onPopupScroll={propsOnPopupScroll||onPopupScroll}
106
111
  {...props}
107
112
  >
108
113
  {data?.map((item) => {