@pointcloud/pcloud-components 0.1.3 → 0.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # pcloud-components
2
2
 
3
- pcloud-components 是一套基于 Antd v4.19.3 + React v17.0.0 开发的业务组件库。
3
+ pcloud-components 是一套基于 Antd v4.24.10 + React v17.0.0 开发的业务组件库。
4
4
 
5
5
  ## 开始
6
6
 
@@ -28,6 +28,12 @@ $ npm run docs:build
28
28
  $ npm run build
29
29
  ```
30
30
 
31
+ 发布 npm
32
+
33
+ ```bash
34
+ $ npm publish
35
+ ```
36
+
31
37
  发布文档站点
32
38
 
33
39
  ```bash
@@ -1,15 +1,11 @@
1
1
  import React from 'react';
2
2
  import { DefaultOptionType, CascaderProps, CascaderRef } from 'antd/lib/cascader';
3
3
  import './index.less';
4
- /**
5
- *
6
- * 如何只显示选中的子节点
7
- */
8
4
  export declare type DCascaderProps = Omit<CascaderProps<any>, 'options' | 'loadData' | 'loading'> & {
9
5
  /** antd的options属性,同onSearch属性,可以是一个options数组,或一个返回等价options数组的promise */
10
- options?: DefaultOptionType[] | ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | any[]>);
6
+ options?: DefaultOptionType[] | ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[]>);
11
7
  /** antd的loadData属性,动态加载子级列表数据,默认使用options所提供的方法,如果传入null,则表示不进行动态加载,该方法要求返回一个options数组或与其等价的Promise */
12
- loadData?: ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | any[]>) | null;
8
+ loadData?: ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | DefaultOptionType[]>) | null;
13
9
  /** 等同antd的loadData属性,用于监听antd loadData事件*/
14
10
  onLoadData?: (value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => void;
15
11
  /** antd的loading属性,是否显示加载中:传入数字表示延迟加载,单位毫秒,0等同于false */
@@ -17,9 +13,9 @@ export declare type DCascaderProps = Omit<CascaderProps<any>, 'options' | 'loadD
17
13
  };
18
14
  declare const DCascader: React.ForwardRefExoticComponent<Omit<CascaderProps<any>, "options" | "loading" | "loadData"> & {
19
15
  /** antd的options属性,同onSearch属性,可以是一个options数组,或一个返回等价options数组的promise */
20
- options?: DefaultOptionType[] | ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | any[]>) | undefined;
16
+ options?: DefaultOptionType[] | ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[]>) | undefined;
21
17
  /** antd的loadData属性,动态加载子级列表数据,默认使用options所提供的方法,如果传入null,则表示不进行动态加载,该方法要求返回一个options数组或与其等价的Promise */
22
- loadData?: ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | any[]>) | null | undefined;
18
+ loadData?: ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => Promise<DefaultOptionType[] | DefaultOptionType[]>) | null | undefined;
23
19
  /** 等同antd的loadData属性,用于监听antd loadData事件*/
24
20
  onLoadData?: ((value?: string, option?: DefaultOptionType, options?: DefaultOptionType[]) => void) | undefined;
25
21
  /** antd的loading属性,是否显示加载中:传入数字表示延迟加载,单位毫秒,0等同于false */
@@ -22,18 +22,35 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
22
22
  * @Author : wangfeihu
23
23
  * @Date : 2023-05-18 13:35:38
24
24
  * @LastEditors : wangfeihu
25
- * @LastEditTime : 2023-05-26 16:18:55
25
+ * @LastEditTime : 2023-06-30 16:19:18
26
26
  * @Description : 基于antd的Cascader组件
27
27
  */
28
28
  import React, { useRef, forwardRef, useState, useEffect, useMemo, useContext } from 'react';
29
29
  import { Cascader } from 'antd';
30
30
  import { ConfigContext } from "../ConfigProvider";
31
31
  import "./index.less";
32
-
33
- /**
34
- *
35
- * 如何只显示选中的子节点
36
- */
32
+ // 获取延时时间,默认800ms,true代表默认时间,false代表0
33
+ function getDelayTime(value) {
34
+ var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
35
+ if (value === true) {
36
+ return defaultValue;
37
+ } else if (value === false) {
38
+ return 0;
39
+ } else {
40
+ return typeof value === 'number' ? Number(value) || 0 : defaultValue;
41
+ }
42
+ }
43
+ function updateDropDom(dSelectDropDom, timestamp) {
44
+ var dSelectDom = document.querySelector(".d-cascader-".concat(timestamp));
45
+ var dSelectDropFirstMenu = dSelectDropDom.querySelector('ul.ant-cascader-menu');
46
+ if (dSelectDom) {
47
+ // 获取选择框宽度并恢复其初始样式
48
+ dSelectDropDom.style.minWidth = "".concat(dSelectDom.clientWidth, "px");
49
+ dSelectDropFirstMenu.style.minWidth = "".concat(dSelectDom.clientWidth, "px");
50
+ // className && dSelectDom.setAttribute('class', className.replace(`d-cascader-${timestamp}`, ''));
51
+ // dSelectDropDom.setAttribute('class', dSelectDropDom.className.replace(`d-cascader-dropdown-${timestamp}`, ''));
52
+ }
53
+ }
37
54
 
38
55
  function InternalCascader(props, ref) {
39
56
  var _props$className = props.className,
@@ -70,7 +87,7 @@ function InternalCascader(props, ref) {
70
87
  value: 'value',
71
88
  children: 'children'
72
89
  }, fieldNames);
73
- var _loadingState = getDelayTime(loading, 600); // loading: 默认600ms,false或0表示不开启
90
+ var _loadingState = getDelayTime(initLoading, 600); // loading: 默认600ms,false或0表示不开启
74
91
 
75
92
  var _loading = typeof initLoading === 'boolean' ? initLoading : loading;
76
93
 
@@ -84,37 +101,62 @@ function InternalCascader(props, ref) {
84
101
  // 设置加载中状态
85
102
  if (_loadingState > 0) {
86
103
  loadingRef.current.status = 'loading';
104
+ loadingParamsRef.current = value;
87
105
  clearTimeout(loadingRef.current.timer);
88
106
  loadingRef.current.timer = setTimeout(function () {
89
- loadingRef.current.status === 'loading' && setLoading(true);
107
+ if (loadingRef.current.status === 'loading') {
108
+ setLoading(true);
109
+ }
90
110
  }, _loadingState);
91
111
  }
92
112
  // 发起请求
93
- loadingParamsRef.current = value;
94
113
  fun === null || fun === void 0 ? void 0 : fun(value).then(function (response) {
95
114
  if (loadingParamsRef.current === value) {
96
115
  setOptions(response);
97
116
  setLoading(false);
117
+ loadingParamsRef.current = null;
98
118
  loadingRef.current.status = 'done';
99
119
  }
100
120
  }).catch(function () {
101
121
  if (loadingParamsRef.current === value) {
102
122
  setLoading(false);
123
+ loadingParamsRef.current = null;
103
124
  loadingRef.current.status = 'done';
104
125
  }
105
126
  });
106
127
  };
107
128
  var _loadData = function _loadData(selectedOptions) {
108
129
  var targetOption = selectedOptions[selectedOptions.length - 1];
109
- onLoadData && onLoadData(targetOption[_fieldNames.value], targetOption, selectedOptions);
130
+ onLoadData === null || onLoadData === void 0 ? void 0 : onLoadData(targetOption[_fieldNames.value], targetOption, selectedOptions);
110
131
  var _getOptions = typeof initOptions === 'function' ? initOptions : null;
111
132
  var loadFn = loadData === null ? loadData : loadData || _getOptions;
112
133
  if (typeof loadFn === 'function') {
113
- loadFn === null || loadFn === void 0 ? void 0 : loadFn(targetOption[_fieldNames.value], targetOption, selectedOptions).then(function (response) {
134
+ // 设置加载中状态
135
+ if (_loadingState > 0) {
136
+ loadingRef.current.status = 'loading';
137
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current + 1 : 1;
138
+ clearTimeout(loadingRef.current.timer);
139
+ loadingRef.current.timer = setTimeout(function () {
140
+ if (loadingRef.current.status === 'loading') {
141
+ setLoading(true);
142
+ }
143
+ }, _loadingState);
144
+ }
145
+ loadFn(targetOption[_fieldNames.value], targetOption, selectedOptions).then(function (response) {
146
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current - 1 : null;
147
+ if (!loadingParamsRef.current) {
148
+ setLoading(false);
149
+ loadingRef.current.status = 'done';
150
+ }
114
151
  targetOption[_fieldNames.children] = response;
115
152
  targetOption.loading = false;
116
153
  setOptions(_toConsumableArray(options));
117
154
  }).catch(function () {
155
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current - 1 : null;
156
+ if (!loadingParamsRef.current) {
157
+ setLoading(false);
158
+ loadingRef.current.status = 'done';
159
+ }
118
160
  targetOption.loading = false;
119
161
  setOptions(_toConsumableArray(options));
120
162
  });
@@ -125,7 +167,6 @@ function InternalCascader(props, ref) {
125
167
  };
126
168
 
127
169
  // 初始加载数据
128
- // eslint-disable-next-line react-hooks/exhaustive-deps
129
170
  useEffect(function () {
130
171
  return updateOptions(getOptionsFun);
131
172
  }, [getOptionsFun]);
@@ -168,29 +209,5 @@ function InternalCascader(props, ref) {
168
209
  onChange: _onChange
169
210
  }));
170
211
  }
171
-
172
- // 获取延时时间,默认800ms,true代表默认时间,false代表0
173
- function getDelayTime(value) {
174
- var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
175
- if (value === true) {
176
- return defaultValue;
177
- } else if (value === false) {
178
- return 0;
179
- } else {
180
- return typeof value === 'number' ? Number(value) || 0 : defaultValue;
181
- }
182
- }
183
- function updateDropDom(dSelectDropDom, timestamp) {
184
- var dSelectDom = document.querySelector(".d-cascader-".concat(timestamp));
185
- var dSelectDropFirstMenu = dSelectDropDom.querySelector('ul.ant-cascader-menu');
186
- if (dSelectDom) {
187
- // 获取选择框宽度并恢复其初始样式
188
- dSelectDropDom.style.minWidth = "".concat(dSelectDom.clientWidth, "px");
189
- dSelectDropFirstMenu.style.minWidth = "".concat(dSelectDom.clientWidth, "px");
190
- // className && dSelectDom.setAttribute('class', className.replace(`d-cascader-${timestamp}`, ''));
191
- // dSelectDropDom.setAttribute('class', dSelectDropDom.className.replace(`d-cascader-dropdown-${timestamp}`, ''));
192
- }
193
- }
194
-
195
212
  var DCascader = /*#__PURE__*/forwardRef(InternalCascader);
196
213
  export default DCascader;
@@ -1,4 +1,4 @@
1
- import { ReactElement } from 'react';
1
+ import { ReactNode } from 'react';
2
2
  import { InputProps, InputNumberProps, AutoCompleteProps, CascaderProps, SelectProps, TreeSelectProps, DatePickerProps, TimePickerProps, MentionProps, CheckboxProps, RadioProps, RateProps, SliderSingleProps, SwitchProps, TransferProps, UploadProps, ButtonProps, DividerProps, FormItemProps } from 'antd';
3
3
  import { PasswordProps, TextAreaProps } from 'antd/lib/input';
4
4
  import { RangePickerProps } from 'antd/lib/date-picker';
@@ -7,8 +7,9 @@ import { DInputProps } from '../DInput';
7
7
  import { DSelectProps } from '../DSelect';
8
8
  import { DCascaderProps } from '../DCascader';
9
9
  import { DTreeSelectProps } from '../DTreeSelect';
10
- declare type RenderTypeProps = 'dInput' | 'input' | 'textArea' | 'password' | 'inputNumber' | 'autoComplete' | 'dSelect' | 'select' | 'dCascader' | 'cascader' | 'dTreeSelect' | 'treeSelect' | 'datePicker' | 'timePicker' | 'rangePicker' | 'mentions' | 'checkbox' | 'radio' | 'rate' | 'slider' | 'switch' | 'transfer' | 'upload' | 'other' | 'button' | 'divider' | 'custom';
11
- export declare type InternalItemProps = DCustomItemProps & DInputProps & InputProps & TextAreaProps & PasswordProps & InputNumberProps & AutoCompleteProps & DSelectProps & SelectProps & DCascaderProps & CascaderProps & DTreeSelectProps & TreeSelectProps & DatePickerProps & TimePickerProps & RangePickerProps & MentionProps & CheckboxProps & RadioProps & RateProps & SliderSingleProps & SliderRangeProps & SwitchProps & TransferProps<any> & UploadProps & ButtonProps & DividerProps;
10
+ import { DUploadProps } from '../DUpload';
11
+ declare type RenderTypeProps = 'dInput' | 'input' | 'textArea' | 'password' | 'inputNumber' | 'autoComplete' | 'dSelect' | 'select' | 'dCascader' | 'cascader' | 'dTreeSelect' | 'treeSelect' | 'datePicker' | 'timePicker' | 'rangePicker' | 'mentions' | 'checkbox' | 'radio' | 'rate' | 'slider' | 'switch' | 'transfer' | 'upload' | 'dupload' | 'other' | 'button' | 'divider' | 'custom';
12
+ export declare type InternalItemProps = DCustomItemProps & FormItemProps & DInputProps & InputProps & TextAreaProps & PasswordProps & InputNumberProps & AutoCompleteProps & DSelectProps & SelectProps & DCascaderProps & CascaderProps & DTreeSelectProps & TreeSelectProps & DatePickerProps & TimePickerProps & RangePickerProps & MentionProps & CheckboxProps & RadioProps & RateProps & SliderSingleProps & SliderRangeProps & SwitchProps & TransferProps<any> & UploadProps & DUploadProps & ButtonProps & DividerProps;
12
13
  declare type DCustomItemProps = {
13
14
  /** 渲染类型 */
14
15
  renderType?: RenderTypeProps | 'other';
@@ -17,10 +18,11 @@ declare type DCustomItemProps = {
17
18
  /** name标签文本,同antd Form.Item的name */
18
19
  name?: string;
19
20
  /** 自定义渲染函数 renderType等于custom、other时生效 */
20
- render?: (props: InternalItemProps, formItemProps: FormItemProps, allProps?: InternalItemProps) => ReactElement;
21
+ render?: (props: InternalItemProps, formItemProps: FormItemProps, allProps?: InternalItemProps) => ReactNode;
21
22
  /** Form.Item 的其他属性 */
22
23
  formItemProps?: FormItemProps;
24
+ children?: ReactNode;
23
25
  };
24
- export declare type DItemProps = DCustomItemProps | DInputProps | InputProps | TextAreaProps | PasswordProps | InputNumberProps | AutoCompleteProps | DSelectProps | SelectProps | DCascaderProps | CascaderProps | DTreeSelectProps | TreeSelectProps | DatePickerProps | TimePickerProps | RangePickerProps | MentionProps | CheckboxProps | RadioProps | RateProps | SliderSingleProps | SliderRangeProps | SwitchProps | TransferProps<any> | UploadProps | ButtonProps | DividerProps;
25
- declare function DItem(props: any): any;
26
+ export declare type DItemProps = FormItemProps | DCustomItemProps | DInputProps | InputProps | TextAreaProps | PasswordProps | InputNumberProps | AutoCompleteProps | DSelectProps | SelectProps | DCascaderProps | CascaderProps | DTreeSelectProps | TreeSelectProps | DatePickerProps | TimePickerProps | RangePickerProps | MentionProps | CheckboxProps | RadioProps | RateProps | SliderSingleProps | SliderRangeProps | SwitchProps | TransferProps<any> | UploadProps | DUploadProps | ButtonProps | DividerProps;
27
+ declare function DItem(props: InternalItemProps): string | number | boolean | import("react").ReactFragment | import("react").JSX.Element | null | undefined;
26
28
  export default DItem;
@@ -7,9 +7,9 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
7
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
- import React from 'react';
11
10
  import itemsMap from "./DItemsMap";
12
11
  function DItem(props) {
12
+ // @ts-ignore
13
13
  var formItemProps = props.formItemProps,
14
14
  _props$label = props.label,
15
15
  label = _props$label === void 0 ? '' : _props$label,
@@ -25,6 +25,7 @@ declare const renderMap: {
25
25
  switch: (props: InternalItemProps, formItemProps: FormItemProps) => ReactElement;
26
26
  transfer: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render']) => ReactElement;
27
27
  upload: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render'], children: InternalItemProps['children']) => ReactElement;
28
+ dupload: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render'], children: InternalItemProps['children']) => ReactElement;
28
29
  other: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render'], children: InternalItemProps['children'], allProps: InternalItemProps) => ReactElement;
29
30
  button: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
30
31
  divider: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
@@ -5,12 +5,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
8
- /*
9
- * @Author : wangfeihu
10
- * @Date : 2023-06-12 17:35:10
11
- * @LastEditors : wangfeihu
12
- * @LastEditTime : 2023-06-15 08:36:23
13
- * @Description : 根据renderType渲染对应的表单项组件
8
+ /*
9
+ * @Author : wangfeihu
10
+ * @Date : 2023-06-12 17:35:10
11
+ * @LastEditors : wangfeihu
12
+ * @LastEditTime : 2023-06-30 16:45:59
13
+ * @Description : 根据renderType渲染对应的表单项组件
14
14
  */
15
15
 
16
16
  import React from 'react';
@@ -19,6 +19,7 @@ import DInput from "../DInput";
19
19
  import DSelect from "../DSelect";
20
20
  import DTreeSelect from "../DTreeSelect";
21
21
  import DCascader from "../DCascader";
22
+ import DUpload from "../DUpload";
22
23
  var renderMap = {
23
24
  dInput: function dInput(props, formItemProps, label) {
24
25
  return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DInput, _extends({
@@ -123,6 +124,9 @@ var renderMap = {
123
124
  upload: function upload(props, formItemProps, label, render, children) {
124
125
  return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Upload, props, children || label || ''));
125
126
  },
127
+ dupload: function dupload(props, formItemProps, label, render, children) {
128
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DUpload, props, children));
129
+ },
126
130
  other: function other(props, formItemProps, label, render, children, allProps) {
127
131
  // rangePicker要求placeholder类型为string数组,在此对rangePicker类型做特殊处理
128
132
  var _placeholder = label ? "\u8BF7\u8F93\u5165".concat(label) : '';
@@ -6,7 +6,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
6
6
  * @Author : wangfeihu
7
7
  * @Date : 2023-06-02 09:29:11
8
8
  * @LastEditors : wangfeihu
9
- * @LastEditTime : 2023-06-15 08:28:12
9
+ * @LastEditTime : 2023-06-16 09:09:24
10
10
  * @Description : 基于antd的Form组件
11
11
  */
12
12
 
@@ -42,7 +42,7 @@ function InternalForm(props, ref) {
42
42
  otherProps = _objectWithoutProperties(props, _excluded);
43
43
  var _useContext = useContext(ConfigContext),
44
44
  getPrefixCls = _useContext.getPrefixCls;
45
- var _className = "".concat(getPrefixCls('d-form'), " ").concat(className, " ").concat(layout === 'inlineVertical' ? 'inlineVertical' : '');
45
+ var _className = "".concat(getPrefixCls('form'), " ").concat(className, " ").concat(layout === 'inlineVertical' ? 'inlineVertical' : '');
46
46
  var _layout = layout === 'inlineVertical' ? 'inline' : layout;
47
47
  var itemChildren = useMemo(function () {
48
48
  return getChildren(items, children, defaultItemProps);
@@ -12,7 +12,7 @@ export declare type DSelectProps = Omit<SelectProps, 'options' | 'onSearch' | 'l
12
12
  /** 是否开启防抖: true表示800毫秒,true表示默认值,false或0表示不开启 */
13
13
  debounce?: boolean | number;
14
14
  };
15
- declare const DSelect: React.ForwardRefExoticComponent<Omit<SelectProps<any, DefaultOptionType>, "onSearch" | "options" | "loading"> & {
15
+ declare const DSelect: React.ForwardRefExoticComponent<Omit<SelectProps<any, DefaultOptionType>, "options" | "onSearch" | "loading"> & {
16
16
  /** antd的onSearch属性,onSearch有效时showSearch自动为true */
17
17
  onSearch?: ((params?: any) => Promise<DefaultOptionType[] | any[]>) | undefined;
18
18
  /** antd的options属性,可以是一个options数组,或一个返回等价options数组的promise */
@@ -13,7 +13,7 @@ export declare type DTreeSelectProps = Omit<TreeSelectProps, 'treeData' | 'loadD
13
13
  /** antd的loading属性,是否显示加载中:传入数字表示延迟加载,单位毫秒,0等同于false */
14
14
  loading?: boolean | number;
15
15
  };
16
- declare const DTreeSelect: React.ForwardRefExoticComponent<Omit<TreeSelectProps<any, import("rc-tree-select/lib/TreeSelect").DefaultOptionType>, "loading" | "treeData" | "loadData"> & {
16
+ declare const DTreeSelect: React.ForwardRefExoticComponent<Omit<TreeSelectProps<any, import("rc-tree-select/lib/TreeSelect").DefaultOptionType>, "loading" | "loadData" | "treeData"> & {
17
17
  /** antd的treeData属性,可以是一个treeData数组,或一个返回等价treeData数组的promise */
18
18
  treeData?: import("rc-tree-select/lib/TreeSelect").DefaultOptionType[] | ((node?: DefaultOptionType) => Promise<TreeSelectProps['treeData']>) | undefined;
19
19
  /** antd的loadData属性,动态加载子级列表数据,默认使用treeData所提供的方法,如果传入null,则表示不进行动态加载,该方法要求返回一个treeData数组或与其等价的Promise */
@@ -1,5 +1,5 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _excluded = ["className", "popupClassName", "treeData", "fieldNames", "treeNodeFilterProp", "loadData", "onLoadData", "loading"];
2
+ var _excluded = ["className", "popupClassName", "treeData", "fieldNames", "loadData", "onLoadData", "loading"];
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -18,30 +18,53 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
18
18
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
19
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
20
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
- /*
22
- * @Author : wangfeihu
23
- * @Date : 2023-05-22 10:38:17
24
- * @LastEditors : wangfeihu
25
- * @LastEditTime : 2023-06-13 15:39:42
26
- * @Description : 基于antd的TreeSelect组件
21
+ /*
22
+ * @Author : wangfeihu
23
+ * @Date : 2023-05-22 10:38:17
24
+ * @LastEditors : wangfeihu
25
+ * @LastEditTime : 2023-06-30 16:24:47
26
+ * @Description : 基于antd的TreeSelect组件
27
27
  */
28
28
 
29
29
  import React, { useRef, forwardRef, useState, useEffect, useMemo, useContext } from 'react';
30
30
  import { TreeSelect } from 'antd';
31
31
  import { ConfigContext } from "../ConfigProvider";
32
32
  import "./index.less";
33
- /**
34
- *
35
- * loading相关代码
36
- */
33
+ // eslint-disable-next-line no-unused-vars
34
+ function deepFind(node, fn) {
35
+ var childrenName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
36
+ if (fn instanceof Function) {
37
+ var treelist = node instanceof Array ? node : [node];
38
+ for (var i = 0; i < treelist.length; i++) {
39
+ if (fn(treelist[i], i)) {
40
+ return treelist[i];
41
+ } else {
42
+ var target = deepFind(treelist[i][childrenName] || [], fn, childrenName);
43
+ if (target) return target;
44
+ }
45
+ }
46
+ } else {
47
+ return undefined;
48
+ }
49
+ }
37
50
 
51
+ // 获取延时时间,默认800ms,true代表默认时间,false代表0
52
+ function getDelayTime(value) {
53
+ var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
54
+ if (value === true) {
55
+ return defaultValue;
56
+ } else if (value === false) {
57
+ return 0;
58
+ } else {
59
+ return typeof value === 'number' ? Number(value) || 0 : defaultValue;
60
+ }
61
+ }
38
62
  function InternalTreeSelect(props, ref) {
39
63
  var _props$className = props.className,
40
64
  className = _props$className === void 0 ? '' : _props$className,
41
65
  popupClassName = props.popupClassName,
42
66
  initOptions = props.treeData,
43
67
  fieldNames = props.fieldNames,
44
- treeNodeFilterProp = props.treeNodeFilterProp,
45
68
  loadData = props.loadData,
46
69
  onLoadData = props.onLoadData,
47
70
  initLoading = props.loading,
@@ -70,27 +93,31 @@ function InternalTreeSelect(props, ref) {
70
93
  children: 'children'
71
94
  }, fieldNames);
72
95
  var _treeNodeFilterProp = _fieldNames.label;
73
- var _loadingState = getDelayTime(loading, 600); // loading: 默认600ms,false或0表示不开启
96
+ var _loadingState = getDelayTime(initLoading, 600); // loading: 默认600ms,false或0表示不开启
74
97
 
75
98
  var _loading = typeof initLoading === 'boolean' ? initLoading : loading;
76
99
 
77
100
  // 将外部传入的options转化为统一的异步请求方法
78
- var getOptionsFun = useMemo(function () {
101
+ var getOptionsFun = useMemo(
102
+ // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
103
+ function () {
79
104
  return typeof initOptions === 'function' ? initOptions : function (params) {
80
105
  return Promise.resolve(initOptions || []);
81
106
  };
82
107
  }, [initOptions]);
108
+
109
+ // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
83
110
  var updateOptions = function updateOptions(fun, value) {
84
111
  // 设置加载中状态
85
112
  if (_loadingState > 0) {
86
113
  loadingRef.current.status = 'loading';
114
+ loadingParamsRef.current = value;
87
115
  clearTimeout(loadingRef.current.timer);
88
116
  loadingRef.current.timer = setTimeout(function () {
89
- loadingRef.current.status === 'loading' && setLoading(true);
117
+ if (loadingRef.current.status === 'loading') setLoading(true);
90
118
  }, _loadingState);
91
119
  }
92
120
  // 发起请求
93
- loadingParamsRef.current = value;
94
121
  fun === null || fun === void 0 ? void 0 : fun(value).then(function (response) {
95
122
  if (loadingParamsRef.current === value) {
96
123
  setTreeData(response);
@@ -105,19 +132,41 @@ function InternalTreeSelect(props, ref) {
105
132
  });
106
133
  };
107
134
  var _loadData = function _loadData(selectedOption) {
108
- onLoadData && onLoadData(selectedOption);
135
+ if (onLoadData) onLoadData(selectedOption);
109
136
  var _getOptions = typeof initOptions === 'function' ? initOptions : null;
110
137
  var loadFn = loadData === null ? loadData : loadData || _getOptions;
111
138
  if (typeof loadFn === 'function') {
112
- var loadFnPromise = loadFn === null || loadFn === void 0 ? void 0 : loadFn(selectedOption);
139
+ // 设置加载中状态
140
+ if (_loadingState > 0) {
141
+ loadingRef.current.status = 'loading';
142
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current + 1 : 1;
143
+ clearTimeout(loadingRef.current.timer);
144
+ loadingRef.current.timer = setTimeout(function () {
145
+ if (loadingRef.current.status === 'loading') {
146
+ setLoading(true);
147
+ }
148
+ }, _loadingState);
149
+ }
150
+ var loadFnPromise = loadFn(selectedOption);
113
151
  if (typeof loadFnPromise['then'] === 'function') {
114
152
  loadFnPromise.then(function (response) {
153
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current - 1 : null;
154
+ if (!loadingParamsRef.current) {
155
+ setLoading(false);
156
+ loadingRef.current.status = 'done';
157
+ }
115
158
  var list = treeData || [];
116
159
  var node = deepFind(list, function (item) {
117
160
  return item[_fieldNames.value] === selectedOption[_fieldNames.value];
118
161
  }, _fieldNames.children);
119
- node && (node[_fieldNames.children] = response);
162
+ if (node) node[_fieldNames.children] = response;
120
163
  setTreeData(_toConsumableArray(list));
164
+ }).catch(function () {
165
+ loadingParamsRef.current = loadingParamsRef.current ? loadingParamsRef.current - 1 : null;
166
+ if (!loadingParamsRef.current) {
167
+ setLoading(false);
168
+ loadingRef.current.status = 'done';
169
+ }
121
170
  });
122
171
  }
123
172
  return loadFnPromise;
@@ -142,33 +191,5 @@ function InternalTreeSelect(props, ref) {
142
191
  loading: _loading
143
192
  }));
144
193
  }
145
-
146
- // 获取延时时间,默认800ms,true代表默认时间,false代表0
147
- function getDelayTime(value) {
148
- var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
149
- if (value === true) {
150
- return defaultValue;
151
- } else if (value === false) {
152
- return 0;
153
- } else {
154
- return typeof value === 'number' ? Number(value) || 0 : defaultValue;
155
- }
156
- }
157
- function deepFind(node, fn) {
158
- var childrenName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
159
- if (fn instanceof Function) {
160
- var treelist = node instanceof Array ? node : [node];
161
- for (var i = 0; i < treelist.length; i++) {
162
- if (fn(treelist[i], i)) {
163
- return treelist[i];
164
- } else {
165
- var target = deepFind(treelist[i][childrenName] || [], fn, childrenName);
166
- if (target) return target;
167
- }
168
- }
169
- } else {
170
- return undefined;
171
- }
172
- }
173
194
  var DTreeSelect = /*#__PURE__*/forwardRef(InternalTreeSelect);
174
195
  export default DTreeSelect;
@@ -0,0 +1,105 @@
1
+ import { UploadFile } from 'antd';
2
+ declare type DUploadFile = Omit<UploadFile, 'uid'> & {
3
+ /** 文件id */
4
+ id?: string | number;
5
+ /** 文件uid,系统自动生成 */
6
+ uid?: string | number;
7
+ /** 文件来源 upload:文件对话框,remote:已上传的文件对象 */
8
+ source?: 'upload' | 'remote';
9
+ };
10
+ /** 转换base64时的参数 */
11
+ declare type CompressProps = {
12
+ width?: number;
13
+ /** 图像高度 */
14
+ height?: number;
15
+ /** 图像质量 */
16
+ quality?: number;
17
+ };
18
+ declare type ThumbOptionProps = {
19
+ /** 对目标文件进行过滤,默认只对图片格式生成缩略图 */
20
+ filter?: ((file: DUploadFile) => boolean) | Array<string>;
21
+ /** 文件大小,当上传文件大于指定值时会对缩略图进行压缩,单位为字节,默认2MB */
22
+ size?: number;
23
+ /** 缩略图压缩参数,默认为 {width:300,height:200,quality:0.7} */
24
+ compress?: CompressProps | null;
25
+ /** 缩略图生成失败时的回调函数 */
26
+ onError?: (err: Error) => void;
27
+ /** 自定义生成base64缩略图的方法 */
28
+ getThumbUrl?: (file: DUploadFile, option: ThumbOptionProps) => Promise<string>;
29
+ };
30
+ /**
31
+ * @description : 将图像文件转换为Base64格式
32
+ * @param {Blob} blob 图像文件
33
+ * @param {CompressProps} options 指定图像压缩参数,其格式为: {width:300,height:200,quality:0.7}
34
+ * @return {Promise<string>} 包含Base64字符串的Promise对象
35
+ * @example : imageToBase64(file,{ width: 300, height: 200, quality: 0.7 }).then( url => console.log( url ) )
36
+ */
37
+ declare function imageToBase64(blob: Blob, options?: CompressProps | null): Promise<string>;
38
+ /**
39
+ * @description : 将传入的文件转换为UploadFile数组
40
+ * @param {any} files 目标文件对象
41
+ * @return {UploadFile[]} UploadFile数组
42
+ * @example :
43
+ */
44
+ declare function getUploadFile(files: any, maxCount?: number): any[];
45
+ /**
46
+ * @description : 根据传入的option对象获取缩略图参数
47
+ * @param {ThumbOptionProps} option 缩略图参数对象
48
+ * @return {ThumbOptionProps} ThumbOption对象
49
+ * @example :
50
+ */
51
+ declare function getThumbOption(option?: ThumbOptionProps | null): {
52
+ size: number;
53
+ filter: (file: DUploadFile) => boolean;
54
+ compress: {
55
+ width: number;
56
+ height: number;
57
+ quality: number;
58
+ } | null;
59
+ onError: ((err: Error) => void) | undefined;
60
+ getThumbUrl: ((file: DUploadFile, option: ThumbOptionProps) => Promise<string>) | undefined;
61
+ };
62
+ /**
63
+ * @description : a标签下载文件
64
+ * @param {Blob | string} url a标签的下载url或文件流
65
+ * @param {string} fileName 下载文件的名称,如果缺省则尝试从url中获取,默认为: "新建文件"
66
+ * @return {*}
67
+ * @example :
68
+ */
69
+ declare function downloadFile(url: Blob | string, fileName?: string): void;
70
+ /**
71
+ * @description : a标签预览文件
72
+ * @param {Blob | string} url a标签的预览url或文件流
73
+ * @return {*}
74
+ * @example :
75
+ */
76
+ declare function previewFile(url: Blob | string): void;
77
+ /**
78
+ * @description : 以递归方式深度查找一个对象
79
+ * @param {Record} object 待查找的对象
80
+ * @param {function} fn 查找函数,每次递归时执行,如果执行结果为true,则递归过程并返回当前对象
81
+ * @param {number} maxDepth 递归的最大深度,默认10
82
+ * @return {*} 查找到的对象,未查找到则返回undefined
83
+ * @example :
84
+ */
85
+ declare function deepFindObject(object: Record<string, any>, fn: (item: any, parent: any, fieldMap: any) => boolean, maxDepth?: number): any;
86
+ /**
87
+ * @description : 以递归方式深度查找一个Jsx对象
88
+ * @param {Record} object 待查找的Jsx对象
89
+ * @param {function} fn 查找函数,每次递归时执行,如果执行结果为true,则停止递归过程并返回当前对象
90
+ * @param {number} maxDepth 递归的最大深度,默认10
91
+ * @return {*} 查找到的对象,未查找到则返回undefined
92
+ * @example :
93
+ */
94
+ declare function deepFindJsx(object: Record<string, any>, fn: (item: any, parent: any) => boolean, maxDepth?: number): any;
95
+ declare const _default: {
96
+ imageToBase64: typeof imageToBase64;
97
+ getUploadFile: typeof getUploadFile;
98
+ getThumbOption: typeof getThumbOption;
99
+ downloadFile: typeof downloadFile;
100
+ previewFile: typeof previewFile;
101
+ deepFindObject: typeof deepFindObject;
102
+ deepFindJsx: typeof deepFindJsx;
103
+ };
104
+ export default _default;
105
+ export type { DUploadFile, ThumbOptionProps };