@pointcloud/pcloud-components 0.1.2 → 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;
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react';
2
+ import { InputProps, InputNumberProps, AutoCompleteProps, CascaderProps, SelectProps, TreeSelectProps, DatePickerProps, TimePickerProps, MentionProps, CheckboxProps, RadioProps, RateProps, SliderSingleProps, SwitchProps, TransferProps, UploadProps, ButtonProps, DividerProps, FormItemProps } from 'antd';
3
+ import { PasswordProps, TextAreaProps } from 'antd/lib/input';
4
+ import { RangePickerProps } from 'antd/lib/date-picker';
5
+ import { SliderRangeProps } from 'antd/lib/slider';
6
+ import { DInputProps } from '../DInput';
7
+ import { DSelectProps } from '../DSelect';
8
+ import { DCascaderProps } from '../DCascader';
9
+ import { DTreeSelectProps } from '../DTreeSelect';
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;
13
+ declare type DCustomItemProps = {
14
+ /** 渲染类型 */
15
+ renderType?: RenderTypeProps | 'other';
16
+ /** label标签文本,同antd Form.Item的label,只能是string */
17
+ label?: string;
18
+ /** name标签文本,同antd Form.Item的name */
19
+ name?: string;
20
+ /** 自定义渲染函数 renderType等于custom、other时生效 */
21
+ render?: (props: InternalItemProps, formItemProps: FormItemProps, allProps?: InternalItemProps) => ReactNode;
22
+ /** Form.Item 的其他属性 */
23
+ formItemProps?: FormItemProps;
24
+ children?: ReactNode;
25
+ };
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;
28
+ export default DItem;
@@ -0,0 +1,31 @@
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 = ["formItemProps", "label", "name", "renderType", "render", "children"];
3
+ 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; }
4
+ 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; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
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
+ 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
+ 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 itemsMap from "./DItemsMap";
11
+ function DItem(props) {
12
+ // @ts-ignore
13
+ var formItemProps = props.formItemProps,
14
+ _props$label = props.label,
15
+ label = _props$label === void 0 ? '' : _props$label,
16
+ name = props.name,
17
+ renderType = props.renderType,
18
+ render = props.render,
19
+ children = props.children,
20
+ otherProps = _objectWithoutProperties(props, _excluded);
21
+ var _formItemProps = _objectSpread({
22
+ label: label,
23
+ name: name
24
+ }, formItemProps);
25
+ if (renderType && renderType !== 'custom') {
26
+ return itemsMap[renderType](otherProps, _formItemProps, label, render, children, props);
27
+ } else {
28
+ return render ? render(otherProps, _formItemProps, props) : /*#__PURE__*/React.createElement(React.Fragment, null, children);
29
+ }
30
+ }
31
+ export default DItem;
@@ -0,0 +1,33 @@
1
+ import { ReactElement } from 'react';
2
+ import { FormItemProps } from 'antd';
3
+ import { InternalItemProps } from './DItem';
4
+ declare const renderMap: {
5
+ dInput: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
6
+ input: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
7
+ textArea: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
8
+ password: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
9
+ inputNumber: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
10
+ autoComplete: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
11
+ dSelect: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
12
+ select: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
13
+ dCascader: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
14
+ cascader: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
15
+ dTreeSelect: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
16
+ treeSelect: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
17
+ datePicker: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
18
+ timePicker: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
19
+ rangePicker: (props: InternalItemProps, formItemProps: FormItemProps) => ReactElement;
20
+ mentions: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
21
+ checkbox: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
22
+ radio: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
23
+ rate: (props: InternalItemProps, formItemProps: FormItemProps) => ReactElement;
24
+ slider: (props: InternalItemProps, formItemProps: FormItemProps) => ReactElement;
25
+ switch: (props: InternalItemProps, formItemProps: FormItemProps) => ReactElement;
26
+ transfer: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render']) => ReactElement;
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;
29
+ other: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label'], render: InternalItemProps['render'], children: InternalItemProps['children'], allProps: InternalItemProps) => ReactElement;
30
+ button: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
31
+ divider: (props: InternalItemProps, formItemProps: FormItemProps, label: InternalItemProps['label']) => ReactElement;
32
+ };
33
+ export default renderMap;
@@ -0,0 +1,148 @@
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
+ 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; }
3
+ 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; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
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
+ 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-30 16:45:59
13
+ * @Description : 根据renderType渲染对应的表单项组件
14
+ */
15
+
16
+ import React from 'react';
17
+ import { Input, InputNumber, AutoComplete, Select, Cascader, TreeSelect, DatePicker, TimePicker, Mentions, Checkbox, Radio, Rate, Slider, Switch, Transfer, Upload, Form, Button, Divider } from 'antd';
18
+ import DInput from "../DInput";
19
+ import DSelect from "../DSelect";
20
+ import DTreeSelect from "../DTreeSelect";
21
+ import DCascader from "../DCascader";
22
+ import DUpload from "../DUpload";
23
+ var renderMap = {
24
+ dInput: function dInput(props, formItemProps, label) {
25
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DInput, _extends({
26
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
27
+ }, props)));
28
+ },
29
+ input: function input(props, formItemProps, label) {
30
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Input, _extends({
31
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
32
+ }, props)));
33
+ },
34
+ textArea: function textArea(props, formItemProps, label) {
35
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Input.TextArea, _extends({
36
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
37
+ }, props)));
38
+ },
39
+ password: function password(props, formItemProps, label) {
40
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Input.Password, _extends({
41
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
42
+ }, props)));
43
+ },
44
+ inputNumber: function inputNumber(props, formItemProps, label) {
45
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(InputNumber, _extends({
46
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
47
+ }, props)));
48
+ },
49
+ autoComplete: function autoComplete(props, formItemProps, label) {
50
+ var _props = props;
51
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(AutoComplete, _extends({
52
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
53
+ }, _props)));
54
+ },
55
+ dSelect: function dSelect(props, formItemProps, label) {
56
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DSelect, _extends({
57
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
58
+ }, props)));
59
+ },
60
+ select: function select(props, formItemProps, label) {
61
+ var _props = props;
62
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Select, _extends({
63
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
64
+ }, _props)));
65
+ },
66
+ dCascader: function dCascader(props, formItemProps, label) {
67
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DCascader, _extends({
68
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
69
+ }, props)));
70
+ },
71
+ cascader: function cascader(props, formItemProps, label) {
72
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Cascader, _extends({
73
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
74
+ }, props)));
75
+ },
76
+ dTreeSelect: function dTreeSelect(props, formItemProps, label) {
77
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DTreeSelect, _extends({
78
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
79
+ }, props)));
80
+ },
81
+ treeSelect: function treeSelect(props, formItemProps, label) {
82
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(TreeSelect, _extends({
83
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
84
+ }, props)));
85
+ },
86
+ datePicker: function datePicker(props, formItemProps, label) {
87
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DatePicker, _extends({
88
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
89
+ }, props)));
90
+ },
91
+ timePicker: function timePicker(props, formItemProps, label) {
92
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(TimePicker, _extends({
93
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
94
+ }, props)));
95
+ },
96
+ rangePicker: function rangePicker(props, formItemProps) {
97
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(DatePicker.RangePicker, props));
98
+ },
99
+ mentions: function mentions(props, formItemProps, label) {
100
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Mentions, _extends({
101
+ placeholder: label ? "\u8BF7\u8F93\u5165".concat(label) : ''
102
+ }, props)));
103
+ },
104
+ checkbox: function checkbox(props, formItemProps, label) {
105
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Checkbox, props, label));
106
+ },
107
+ radio: function radio(props, formItemProps, label) {
108
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Radio, props, label));
109
+ },
110
+ rate: function rate(props, formItemProps) {
111
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Rate, props));
112
+ },
113
+ slider: function slider(props, formItemProps) {
114
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Slider, props));
115
+ },
116
+ switch: function _switch(props, formItemProps) {
117
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Switch, props));
118
+ },
119
+ transfer: function transfer(props, formItemProps, label, render) {
120
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Transfer, _extends({
121
+ render: render
122
+ }, props)));
123
+ },
124
+ upload: function upload(props, formItemProps, label, render, children) {
125
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, /*#__PURE__*/React.createElement(Upload, props, children || label || ''));
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
+ },
130
+ other: function other(props, formItemProps, label, render, children, allProps) {
131
+ // rangePicker要求placeholder类型为string数组,在此对rangePicker类型做特殊处理
132
+ var _placeholder = label ? "\u8BF7\u8F93\u5165".concat(label) : '';
133
+ var placeholder = allProps.renderType === 'rangePicker' ? props.placeholder : _placeholder;
134
+ return /*#__PURE__*/React.createElement(Form.Item, formItemProps, render ? render(_objectSpread({
135
+ placeholder: placeholder
136
+ }, props), formItemProps, allProps) : children);
137
+ },
138
+ button: function button(props, formItemProps, label) {
139
+ return /*#__PURE__*/React.createElement(Button, props, label || '');
140
+ },
141
+ divider: function divider(props, formItemProps, label) {
142
+ return /*#__PURE__*/React.createElement(Divider, _extends({
143
+ orientation: "left",
144
+ orientationMargin: 0
145
+ }, props), label);
146
+ }
147
+ };
148
+ export default renderMap;
@@ -0,0 +1,6 @@
1
+ /** 合并对象 */
2
+ declare function merge(object: any, sources: any, customizer?: (objValue: any, srcValue: any) => any): any;
3
+ declare const _default: {
4
+ merge: typeof merge;
5
+ };
6
+ export default _default;
@@ -0,0 +1,56 @@
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
+ /*
3
+ * @Author : wangfeihu
4
+ * @Date : 2023-06-07 15:08:06
5
+ * @LastEditors : wangfeihu
6
+ * @LastEditTime : 2023-06-12 17:35:15
7
+ * @Description : 合并两个对象中的所有字段
8
+ */
9
+
10
+ import mergeWith from 'lodash/mergeWith';
11
+ import cloneDeep from 'lodash/cloneDeep';
12
+ var TYPES = {
13
+ OPTION_TYPE_PRIMARY: 'primary',
14
+ OPTION_TYPE_OBJECT: 'object',
15
+ OPTION_TYPE_ARRAY: 'array'
16
+ };
17
+
18
+ // 获取某个字段的类型
19
+ function getType(value) {
20
+ if (typeof value === 'string') {
21
+ return TYPES.OPTION_TYPE_PRIMARY;
22
+ } else if (typeof value === 'number') {
23
+ return TYPES.OPTION_TYPE_PRIMARY;
24
+ } else if (typeof value === 'boolean') {
25
+ return TYPES.OPTION_TYPE_PRIMARY;
26
+ } else if (typeof value === 'undefined') {
27
+ return TYPES.OPTION_TYPE_PRIMARY;
28
+ } else if (_typeof(value) === 'symbol') {
29
+ return TYPES.OPTION_TYPE_PRIMARY;
30
+ } else if (value === null) {
31
+ return TYPES.OPTION_TYPE_PRIMARY;
32
+ } else if (typeof value === 'function') {
33
+ return TYPES.OPTION_TYPE_PRIMARY;
34
+ } else if (value instanceof Array) {
35
+ return TYPES.OPTION_TYPE_ARRAY;
36
+ } else if (Object.keys(value).length > 0) {
37
+ return TYPES.OPTION_TYPE_OBJECT;
38
+ } else {
39
+ return TYPES.OPTION_TYPE_PRIMARY;
40
+ }
41
+ }
42
+ var defaultCustomizer = function defaultCustomizer(objValue, srcValue) {
43
+ // 将空对象和空数组当成基本类型处理,不进行合并
44
+ if (srcValue instanceof Array && srcValue.length < 1 || getType(srcValue) === TYPES.OPTION_TYPE_PRIMARY) {
45
+ return srcValue;
46
+ }
47
+ };
48
+
49
+ /** 合并对象 */
50
+ function merge(object, sources) {
51
+ var customizer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCustomizer;
52
+ return mergeWith(cloneDeep(object), sources, customizer);
53
+ }
54
+ export default {
55
+ merge: merge
56
+ };
@@ -0,0 +1,20 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { FormProps, FormInstance } from 'antd';
3
+ import DItem, { DItemProps } from './DItem';
4
+ import './index.less';
5
+ declare type InternalFormProps = {
6
+ /** 表单项数组,可以通过数组的形式添加表单项 */
7
+ items?: DItemProps[];
8
+ /** 统一设置items的默认属性 */
9
+ defaultItemProps?: DItemProps;
10
+ /** children 方式添加表单项,如果同时设置了 items,则 children 在 items 下面 */
11
+ children?: ReactNode;
12
+ /** 布局方式 新增了行内垂直布局方式inlineVertical */
13
+ layout?: 'inline' | 'horizontal' | 'vertical' | 'inlineVertical';
14
+ };
15
+ export declare type DFormProps = Omit<FormProps, 'children' | 'layout'> & InternalFormProps;
16
+ declare function InternalForm(props: DFormProps, ref: React.Ref<FormInstance<any>>): React.JSX.Element;
17
+ declare const DForm: typeof InternalForm & {
18
+ Item: typeof DItem;
19
+ };
20
+ export default DForm;
@@ -0,0 +1,60 @@
1
+ var _excluded = ["className", "defaultItemProps", "items", "children", "layout"];
2
+ 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; }
3
+ 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; }
4
+ 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); }
5
+ /*
6
+ * @Author : wangfeihu
7
+ * @Date : 2023-06-02 09:29:11
8
+ * @LastEditors : wangfeihu
9
+ * @LastEditTime : 2023-06-16 09:09:24
10
+ * @Description : 基于antd的Form组件
11
+ */
12
+
13
+ import React, { forwardRef, useMemo, useContext } from 'react';
14
+ import { Form } from 'antd';
15
+ import { ConfigContext } from "../ConfigProvider";
16
+ import helper from "./helper";
17
+ import DItem from "./DItem";
18
+ import "./index.less";
19
+ function getChildren(items, children, _defaultItemProps) {
20
+ var list = [];
21
+ if (items instanceof Array && items.length > 0) {
22
+ list = items.map(function (item, index) {
23
+ var _item = helper.merge(_defaultItemProps, item);
24
+ return /*#__PURE__*/React.createElement(DItem, _extends({
25
+ key: (item === null || item === void 0 ? void 0 : item.name) || index
26
+ }, _item));
27
+ });
28
+ }
29
+ if (children) {
30
+ var childrenList = children instanceof Array ? children : [children];
31
+ list = list.concat(childrenList);
32
+ }
33
+ return list;
34
+ }
35
+ function InternalForm(props, ref) {
36
+ var _props$className = props.className,
37
+ className = _props$className === void 0 ? '' : _props$className,
38
+ defaultItemProps = props.defaultItemProps,
39
+ items = props.items,
40
+ children = props.children,
41
+ layout = props.layout,
42
+ otherProps = _objectWithoutProperties(props, _excluded);
43
+ var _useContext = useContext(ConfigContext),
44
+ getPrefixCls = _useContext.getPrefixCls;
45
+ var _className = "".concat(getPrefixCls('form'), " ").concat(className, " ").concat(layout === 'inlineVertical' ? 'inlineVertical' : '');
46
+ var _layout = layout === 'inlineVertical' ? 'inline' : layout;
47
+ var itemChildren = useMemo(function () {
48
+ return getChildren(items, children, defaultItemProps);
49
+ }, [items, children, defaultItemProps]);
50
+ return /*#__PURE__*/React.createElement(Form, _extends({}, otherProps, {
51
+ className: _className,
52
+ layout: _layout,
53
+ ref: ref
54
+ }), /*#__PURE__*/React.createElement("div", {
55
+ className: "form-wrapper"
56
+ }, itemChildren));
57
+ }
58
+ var DForm = /*#__PURE__*/forwardRef(InternalForm);
59
+ DForm.Item = DItem;
60
+ export default DForm;
@@ -0,0 +1,31 @@
1
+ @import '../commonStyle/index.less';
2
+ .@{prefix}-form {
3
+ .form-wrapper > * {
4
+ min-height: 32px;
5
+ margin-right: 0;
6
+ margin-bottom: 24px;
7
+ padding-right: 16px;
8
+ }
9
+ }
10
+
11
+ .@{prefix}-form.ant-form-horizontal .ant-form-item-label {
12
+ min-width: 80px;
13
+ }
14
+
15
+ .@{prefix}-form.ant-form-inline .form-wrapper,
16
+ .@{prefix}-form.ant-form-inline.inlineVertical .form-wrapper {
17
+ display: flex;
18
+ flex-wrap: wrap;
19
+ align-items: flex-end;
20
+ height: min-content;
21
+ }
22
+
23
+ .@{prefix}-form.ant-form-inline.inlineVertical {
24
+ .ant-form-item-row {
25
+ flex-direction: column;
26
+
27
+ .ant-form-item-label {
28
+ text-align: left;
29
+ }
30
+ }
31
+ }