@cloudbase/weda-ui 0.2.11 → 0.2.12

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 (108) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/package.json +61 -40
  3. package/src/.DS_Store +0 -0
  4. package/src/configs/.DS_Store +0 -0
  5. package/src/configs/components/button.json +7 -3
  6. package/src/configs/components/form/richText.json +1 -1
  7. package/src/configs/components/form/uploader.json +29 -1
  8. package/src/configs/components/form/uploaderFile.json +158 -0
  9. package/src/configs/components/image.json +12 -3
  10. package/src/configs/components/link.json +3 -3
  11. package/src/configs/components/richtextview.json +2 -2
  12. package/src/configs/components/scrollVeiw.json +5 -5
  13. package/src/configs/components/swiper.json +6 -6
  14. package/src/configs/components/tabs.json +3 -3
  15. package/src/configs/components/text.json +39 -4
  16. package/src/configs/index.js +5 -3
  17. package/src/mp/.gitignore +10 -0
  18. package/src/mp/components/button/index.js +1 -0
  19. package/src/mp/components/button/index.wxss +8 -0
  20. package/src/mp/components/form/select/index.js +18 -0
  21. package/src/mp/components/form/uploader/index.js +26 -29
  22. package/src/mp/components/form/uploaderFile/index.js +247 -0
  23. package/src/mp/components/form/uploaderFile/index.json +9 -0
  24. package/src/mp/components/form/uploaderFile/index.wxml +46 -0
  25. package/src/mp/components/form/uploaderFile/index.wxss +104 -0
  26. package/src/mp/components/text/index.js +33 -0
  27. package/src/mp/components/text/index.wxml +1 -1
  28. package/src/mp/components/text/index.wxss +18 -0
  29. package/src/mp/index.json +1 -0
  30. package/src/mp/utils/platform.js +20 -0
  31. package/src/mp/utils/tcb.js +11 -0
  32. package/src/web/.DS_Store +0 -0
  33. package/src/web/actions/showModal/{index.jsx → index.tsx} +53 -3
  34. package/src/web/components/auth/index.js +2 -2
  35. package/src/web/components/button/index.css +9 -0
  36. package/src/web/components/button/{index.jsx → index.tsx} +27 -41
  37. package/src/web/components/container/{index.jsx → index.tsx} +6 -10
  38. package/src/web/components/drawer/index.tsx +57 -0
  39. package/src/web/components/form/checkbox/{index.jsx → index.tsx} +24 -48
  40. package/src/web/components/form/enumSelect/{NormalSelect.jsx → NormalSelect.tsx} +2 -9
  41. package/src/web/components/form/form/index.tsx +48 -0
  42. package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
  43. package/src/web/components/form/input/index.css +4 -0
  44. package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
  45. package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
  46. package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
  47. package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
  48. package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
  49. package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
  50. package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
  51. package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
  52. package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
  53. package/src/web/components/form/select/time.jsx +2 -2
  54. package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
  55. package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
  56. package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
  57. package/src/web/components/form/types.d.ts +12 -0
  58. package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
  59. package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
  60. package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
  61. package/src/web/components/form/uploaderFile/fail.svg +12 -0
  62. package/src/web/components/form/uploaderFile/index.css +423 -0
  63. package/src/web/components/form/uploaderFile/index.jsx +30 -0
  64. package/src/web/components/form/uploaderFile/pending.svg +18 -0
  65. package/src/web/components/form/uploaderFile/success.svg +12 -0
  66. package/src/web/components/form/uploaderFile/uploadFile.h5.jsx +562 -0
  67. package/src/web/components/form/uploaderFile/uploadFile.pc.jsx +487 -0
  68. package/src/web/components/image/{image.jsx → image.tsx} +8 -21
  69. package/src/web/components/image/{index.jsx → index.tsx} +22 -37
  70. package/src/web/components/index.js +35 -1
  71. package/src/web/components/link/{index.jsx → index.tsx} +19 -36
  72. package/src/web/components/modal/{index.jsx → index.tsx} +22 -9
  73. package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
  74. package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
  75. package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
  76. package/src/web/components/richText/{const.js → const.ts} +0 -0
  77. package/src/web/components/richText/index.jsx +5 -2
  78. package/src/web/components/richTextView/index.tsx +67 -0
  79. package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
  80. package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
  81. package/src/web/components/swiper/index.css +1 -1
  82. package/src/web/components/swiper/{index.jsx → index.tsx} +66 -73
  83. package/src/web/components/tabs/index.tsx +33 -0
  84. package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
  85. package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
  86. package/src/web/components/text/index.css +18 -0
  87. package/src/web/components/text/index.tsx +69 -0
  88. package/src/web/components/uploaderFileView/index.css +11 -0
  89. package/src/web/components/uploaderFileView/index.jsx +75 -0
  90. package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
  91. package/src/web/types.d.ts +20 -0
  92. package/src/web/utils/constant.js +2 -0
  93. package/src/web/utils/loading-fallback.tsx +2 -0
  94. package/src/web/utils/platform.js +77 -6
  95. package/src/web/utils/useSetState.ts +14 -0
  96. package/src/web/utils/useSyncValue.ts +17 -0
  97. package/src/web/wedatheme/.git +1 -0
  98. package/src/web/wedatheme/.gitignore +5 -0
  99. package/src/web/wedatheme/.npmrc +1 -0
  100. package/src/web/wedatheme/package-lock.json +14335 -0
  101. package/src/configs/components/button.svg +0 -18
  102. package/src/web/components/drawer/index.jsx +0 -64
  103. package/src/web/components/form/form/index.jsx +0 -76
  104. package/src/web/components/link/test/__snapshots__/storybook.test.js.snap +0 -754
  105. package/src/web/components/richTextView/index.jsx +0 -89
  106. package/src/web/components/tabs/index.jsx +0 -10
  107. package/src/web/components/text/index.jsx +0 -71
  108. package/src/web/utils/useSyncValue.js +0 -14
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
2
  import { Checkbox as TeaCheckbox, ConfigProvider } from 'tea-component';
4
3
 
5
4
  import classNames from '../../../utils/classnames';
@@ -8,23 +7,24 @@ import isObjectEqual from '../../../utils/isObjectEqual';
8
7
  import fromEntries from 'object.fromentries';
9
8
  import { usePlatform } from '../../../utils/platform';
10
9
  import { renderDecorator } from '../renderDecorator';
10
+ import { CommonFormPropsType } from '../types';
11
11
 
12
12
  export default function Checkbox({
13
13
  // 系统属性
14
14
  id,
15
15
  className,
16
16
  style,
17
- events,
17
+ events = {},
18
18
  // 组件属性
19
- name,
20
- label,
19
+ name = 'formCheckbox',
20
+ label = '标题',
21
21
  labelVisible = true,
22
- range,
23
- layout,
24
- disabled,
25
- requiredFlag,
22
+ range = [],
23
+ layout = 'horizontal',
24
+ disabled = false,
25
+ requiredFlag = false,
26
26
  decorator
27
- }) {
27
+ }: PropsType) {
28
28
  const cls = classNames({
29
29
  'weda-ui': true,
30
30
  'weda-checkbox': true,
@@ -45,7 +45,7 @@ export default function Checkbox({
45
45
  : range.filter(({checked}) => checked).map(({value}) => value)
46
46
  );
47
47
  // 两次range不同时, 需要刷新checkedItems
48
- const prevRangeRef = React.useRef();
48
+ const prevRangeRef = React.useRef<object[]>();
49
49
  React.useEffect(() => {
50
50
  if (!isObjectEqual(prevRangeRef.current, range)) {
51
51
  prevRangeRef.current = range;
@@ -64,15 +64,17 @@ export default function Checkbox({
64
64
  e.stopPropagation();
65
65
  const checked = !checkedItems[value];
66
66
  const newMap = Object.assign({}, checkedItems, { [value]: checked });
67
- setCheckedItems(newMap);
68
- events.change(
69
- {
70
- value: Object.entries(newMap)
71
- .filter(([, checked]) => checked)
72
- .map(([value]) => value),
73
- },
74
- { originEvent: e }
75
- );
67
+ if (!disabled) {
68
+ setCheckedItems(newMap);
69
+ events.change(
70
+ {
71
+ value: Object.entries(newMap)
72
+ .filter(([, checked]) => checked)
73
+ .map(([value]) => value),
74
+ },
75
+ { originEvent: e }
76
+ );
77
+ }
76
78
  };
77
79
  return onChange;
78
80
  };
@@ -164,32 +166,6 @@ export default function Checkbox({
164
166
  );
165
167
  }
166
168
 
167
- Checkbox.propTypes = {
168
- // 系统属性
169
- id: PropTypes.string,
170
- className: PropTypes.string,
171
- style: PropTypes.string,
172
- events: PropTypes.objectOf(PropTypes.func),
173
- // 组件属性
174
- name: PropTypes.string,
175
- label: PropTypes.string,
176
- labelVisible: PropTypes.bool,
177
- range: PropTypes.array,
178
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
179
- disabled: PropTypes.bool,
180
- requiredFlag: PropTypes.bool,
181
- decorator: PropTypes.oneOfType([PropTypes.array, PropTypes.node])
182
- };
183
-
184
- Checkbox.defaultProps = {
185
- // 系统属性
186
- events: {},
187
- // 组件属性
188
- name: 'formCheckbox',
189
- label: '标题',
190
- labelVisible: true,
191
- range: [],
192
- layout: 'horizontal',
193
- disabled: false,
194
- requiredFlag: false,
195
- };
169
+ export interface PropsType extends CommonFormPropsType {
170
+ range?: {label: string, value: any; [key: string]: any}[];
171
+ }
@@ -5,18 +5,11 @@ import SelectContainer from './SelectContainer';
5
5
 
6
6
  import { multipleProps } from './props/defaultProps';
7
7
  import { propTypes } from './props/propsTypes';
8
+ import { useSyncValue } from '../../../utils/useSyncValue';
8
9
 
9
10
  const { useState, useEffect } = React;
10
11
 
11
- const useValue = (value) => {
12
- const [selectedValue, setSelectedValue] = useState('');
13
12
 
14
- useEffect(() => {
15
- setSelectedValue(value);
16
- }, [value]);
17
-
18
- return [selectedValue, setSelectedValue];
19
- };
20
13
 
21
14
  const NormalSelect = ({
22
15
  // 系统属性
@@ -45,7 +38,7 @@ const NormalSelect = ({
45
38
  // 业务属性
46
39
  isModelApp,
47
40
  }) => {
48
- const [selectedValue, setSelectedValue] = useValue(value);
41
+ const [selectedValue, setSelectedValue] = useSyncValue(value);
49
42
 
50
43
  const onSelectChange = (value) => {
51
44
  // @ts-ignore
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ import classNames from '../../../utils/classnames';
3
+ import './index.css';
4
+ import {ConfigProvider, Form as TeaForm} from 'tea-component';
5
+ import { usePlatform } from '../../../utils/platform';
6
+ import { CommonFormPropsType } from '../types';
7
+
8
+ export default function Form({
9
+ // 系统属性
10
+ className,
11
+ // 组件属性
12
+ // title,
13
+ // description,
14
+ // tips,
15
+ contentSlot,
16
+ // buttonSlot,
17
+ style,
18
+ id,
19
+ }) {
20
+ const platform = usePlatform();
21
+ const cls = classNames({
22
+ 'weda-ui': true,
23
+ 'weda-form': true,
24
+ 'weui-form': platform === 'h5',
25
+ [className]: className,
26
+ });
27
+ if(platform === 'pc') {
28
+ return (
29
+ <ConfigProvider classPrefix="wedatea2td">
30
+ {/** @ts-expect-error tea form id */}
31
+ <TeaForm className={cls} style={style} id={id}>
32
+ {contentSlot}
33
+ </TeaForm>
34
+ </ConfigProvider>
35
+ );
36
+ }
37
+ return (
38
+ <div className={cls} style={style} id={id}>
39
+ <div className="weui-cells__group weui-cells__group_form">
40
+ {contentSlot}
41
+ </div>
42
+ </div>
43
+ );
44
+ }
45
+
46
+ export interface PropsType extends CommonFormPropsType {
47
+ contentSlot?: any;
48
+ }
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
2
 
4
3
  import classNames from '../../../utils/classnames';
5
4
  import './index.css';
6
5
  import { usePlatform } from '../../../utils/platform';
7
6
  import { ConfigProvider, Form as TeaForm } from 'tea-component';
7
+ import { CommonFormPropsType } from '../types';
8
8
 
9
9
  export default function FormCell({
10
10
  className,
@@ -15,7 +15,7 @@ export default function FormCell({
15
15
  multiCell,
16
16
  requiredFlag,
17
17
  size
18
- }) {
18
+ }: PropsType) {
19
19
  const platform = usePlatform();
20
20
  const isFlex = layout !== 'vertical';
21
21
 
@@ -78,14 +78,7 @@ export default function FormCell({
78
78
  );
79
79
  }
80
80
 
81
- FormCell.propTypes = {
82
- className: PropTypes.string,
83
- style: PropTypes.object,
84
- label: PropTypes.string,
85
- labelVisible: PropTypes.bool,
86
- layout: PropTypes.string,
87
- children: PropTypes.any,
88
- multiCell: PropTypes.bool,
89
- requiredFlag: PropTypes.bool,
90
- size: PropTypes.string
91
- };
81
+ export interface PropsType extends CommonFormPropsType {
82
+ multiCell?: boolean;
83
+ size?: string;
84
+ }
@@ -0,0 +1,4 @@
1
+ .wedatea2td-input {
2
+ background-color: transparent;
3
+ border: none;
4
+ }
@@ -1,34 +1,34 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
-
4
2
  import classNames from '../../../utils/classnames';
5
3
  import { usePlatform } from '../../../utils/platform';
6
- import { Input as TeaInput } from 'tea-component';
4
+ import { Input as TeaInput, ConfigProvider } from 'tea-component';
7
5
  import { renderDecorator } from '../renderDecorator';
8
6
  import { useSyncValue } from '../../../utils/useSyncValue';
7
+ import './index.css';
8
+ import { CommonFormPropsType } from '../types';
9
+
9
10
  export default function Input({
10
- // 系统属性
11
11
  id,
12
12
  className,
13
13
  style,
14
- events,
14
+ events = {},
15
15
  // 组件属性
16
- label,
17
- labelVisible,
18
- name,
19
- defaultValue,
20
- password,
21
- placeholder,
22
- type,
23
- maxLength,
24
- disabled,
25
- focus: autoFocus,
26
- layout,
27
- requiredFlag,
28
- size,
16
+ label = '标题',
17
+ labelVisible = true,
18
+ name = 'formInput',
19
+ defaultValue = '',
20
+ password = false,
21
+ placeholder = '请输入',
22
+ type = 'text',
23
+ maxLength = 140,
24
+ disabled = false,
25
+ focus: autoFocus = false,
26
+ layout = 'horizontal',
27
+ requiredFlag = false,
28
+ size = 'l',
29
+ clearable = true,
29
30
  decorator,
30
- clearable
31
- }) {
31
+ }: PropsType) {
32
32
  const platform = usePlatform();
33
33
  const cls = classNames({
34
34
  'weda-ui': true,
@@ -80,7 +80,6 @@ export default function Input({
80
80
  const onBlur = function (e) {
81
81
  events.blur({ value: e.target.value }, { originEvent: e });
82
82
  };
83
-
84
83
  const fieldEl = platform === 'h5' ? <div className={subCls}>
85
84
  <div className="weui-cell__bd weui-flex">
86
85
  <input
@@ -105,7 +104,8 @@ const fieldEl = platform === 'h5' ? <div className={subCls}>
105
104
  </button>
106
105
  }
107
106
  </div>
108
- </div> : <TeaInput
107
+ </div> : <ConfigProvider classPrefix="wedatea2td">
108
+ <TeaInput
109
109
  size={size}
110
110
  type={inputType}
111
111
  placeholder={placeholder}
@@ -117,7 +117,7 @@ const fieldEl = platform === 'h5' ? <div className={subCls}>
117
117
  onFocus={onFocus}
118
118
  onBlur={onBlur}
119
119
  onKeyDown={onKeyDown}
120
- />;
120
+ /></ConfigProvider>;
121
121
  return renderDecorator(fieldEl, decorator)({
122
122
  id,
123
123
  className: cls,
@@ -128,53 +128,19 @@ return renderDecorator(fieldEl, decorator)({
128
128
  requiredFlag,
129
129
  size
130
130
  });
131
-
132
-
133
131
  }
134
132
 
135
- Input.propTypes = {
136
- // 系统属性
137
- id: PropTypes.string,
138
- className: PropTypes.string,
139
- style: PropTypes.string,
140
- events: PropTypes.object,
141
- // 组件属性
142
- label: PropTypes.string,
143
- labelVisible: PropTypes.bool,
144
- name: PropTypes.string,
145
- defaultValue: PropTypes.string,
146
- password: PropTypes.bool,
147
- placeholder: PropTypes.string,
148
- type: PropTypes.oneOf(['text', 'number', 'idcard', 'digit']),
149
- maxLength: PropTypes.number,
150
- disabled: PropTypes.bool,
151
- focus: PropTypes.bool,
152
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
153
- requiredFlag: PropTypes.bool,
154
- size: PropTypes.oneOf(['s', 'm', 'l', 'full']),
155
- decorator: PropTypes.oneOfType([PropTypes.array, PropTypes.node]),
156
- clearable: PropTypes.bool
157
- };
133
+ export interface PropsType extends CommonFormPropsType {
134
+ defaultValue?: string;
135
+ password?: boolean;
136
+ placeholder?: string;
137
+ type?: "text" | "number" | "idcard" | "digit";
138
+ maxLength?: number;
139
+ focus?: boolean;
140
+ size?: "s" | "m" | "l" | "full";
141
+ clearable?: boolean;
142
+ }
158
143
 
159
- Input.defaultProps = {
160
- // 系统属性
161
- events: {},
162
- // 组件属性
163
- label: '标题',
164
- labelVisible: true,
165
- name: 'formInput',
166
- defaultValue: '',
167
- password: false,
168
- placeholder: '请输入',
169
- type: 'text',
170
- maxLength: 140,
171
- disabled: false,
172
- focus: false,
173
- layout: 'horizontal',
174
- requiredFlag: false,
175
- size: 'l',
176
- clearable: true
177
- };
178
144
 
179
145
  function getInputType(type, password) {
180
146
  if (password) {
@@ -1,31 +1,31 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
2
  import {ConfigProvider, Radio as TeaRadio} from 'tea-component';
4
3
 
5
4
  import {usePlatform} from '../../../utils/platform';
6
5
  import classNames from '../../../utils/classnames';
7
6
  import getLocalCounter from '../../../utils/getLocalCounter';
8
7
  import isObjectEqual from '../../../utils/isObjectEqual';
9
- import FormCell from '../formcell';
10
8
 
11
9
  import './index.css';
12
10
  import { renderDecorator } from '../renderDecorator';
11
+ import { CommonFormPropsType } from '../types';
12
+
13
13
  export default function Radio({
14
14
  // 系统属性
15
15
  id,
16
16
  className,
17
17
  style,
18
- events,
18
+ events = {},
19
19
  // 组件属性
20
- label,
21
- labelVisible,
22
- name,
23
- range,
24
- layout,
25
- disabled,
26
- requiredFlag,
20
+ label = '标题',
21
+ labelVisible = true,
22
+ name = 'formRadio',
23
+ range = [],
24
+ layout = 'horizontal',
25
+ disabled = false,
26
+ requiredFlag = false,
27
27
  decorator
28
- }) {
28
+ }: PropsType) {
29
29
  const platform = usePlatform();
30
30
  const isH5 = platform === 'h5';
31
31
  const cls = classNames({
@@ -44,7 +44,7 @@ export default function Radio({
44
44
  range.find((item) => item.checked)?.value
45
45
  );
46
46
  // 两次range不同时, 需要刷新checkedItemValue
47
- const prevRangeRef = React.useRef();
47
+ const prevRangeRef = React.useRef<PropsType['range']>();
48
48
  React.useEffect(() => {
49
49
  if (!isObjectEqual(prevRangeRef.current, range)) {
50
50
  prevRangeRef.current = range;
@@ -59,8 +59,10 @@ export default function Radio({
59
59
  const getChangeHandler = function (value) {
60
60
  const onChange = function (e) {
61
61
  e.stopPropagation();
62
- setCheckedItemValue(value);
63
- events.change({ value }, { originEvent: e });
62
+ if (!disabled) {
63
+ setCheckedItemValue(value);
64
+ events.change({ value }, { originEvent: e });
65
+ }
64
66
  };
65
67
  return onChange;
66
68
  };
@@ -128,32 +130,7 @@ export default function Radio({
128
130
  });
129
131
  }
130
132
 
131
- Radio.propTypes = {
132
- // 系统属性
133
- id: PropTypes.string,
134
- className: PropTypes.string,
135
- style: PropTypes.string,
136
- events: PropTypes.objectOf(PropTypes.func),
137
- // 组件属性
138
- label: PropTypes.string,
139
- labelVisible: PropTypes.bool,
140
- name: PropTypes.string,
141
- range: PropTypes.array,
142
- layout: PropTypes.string,
143
- disabled: PropTypes.bool,
144
- requiredFlag: PropTypes.bool,
145
- decorator: PropTypes.oneOfType([PropTypes.array, PropTypes.node])
146
- };
147
-
148
- Radio.defaultProps = {
149
- // 系统属性
150
- events: {},
133
+ export interface PropsType extends CommonFormPropsType {
151
134
  // 组件属性
152
- label: '标题',
153
- labelVisible: true,
154
- name: 'formRadio',
155
- range: [],
156
- layout: 'horizontal',
157
- disabled: false,
158
- requiredFlag: false,
159
- };
135
+ range?: ({label: string} & Record<string, any>)[];
136
+ }
@@ -3,11 +3,9 @@ import FormCell from "./formcell";
3
3
 
4
4
  /**
5
5
  *
6
- * @param {React.ReactNode} filedNode
7
- * @param {React.FC|[React.FC, any]} DecoratorComponent
8
6
  * @returns {(props: any) => JSX.Element}
9
7
  */
10
- export function renderDecorator(filedNode, DecoratorComponent = FormCell) {
8
+ export function renderDecorator<D=any>(filedNode: React.ReactNode, DecoratorComponent: React.FC<D> = FormCell) {
11
9
  if(!DecoratorComponent) {
12
10
  return function WedaFormField() {
13
11
  return (
@@ -1,13 +1,16 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
- import dayjs from 'dayjs';
2
+ import * as _moment from 'moment';
4
3
 
5
4
  import weui from '../../../utils/weui';
6
5
  import classNames from '../../../utils/classnames';
7
6
  import isObjectEqual from '../../../utils/isObjectEqual';
8
7
  import { timePicker } from './time';
9
8
  import { regionPicker } from './region';
9
+ import {PropsType} from './index';
10
+ import { defaultProps } from './index';
10
11
 
12
+ // @ts-expect-error TODO: fix 与plugin构建阶段效果不同
13
+ const moment = (typeof _moment === 'function' ? _moment : _moment.default) as _moment.moment;
11
14
  export default function Select({
12
15
  // 系统属性
13
16
  events,
@@ -18,7 +21,7 @@ export default function Select({
18
21
  mode,
19
22
  disabled = false,
20
23
  // selector mode
21
- range,
24
+ range = defaultProps.range,
22
25
  defaultValue,
23
26
  // date mode
24
27
  startDate,
@@ -31,7 +34,7 @@ export default function Select({
31
34
  // region mode
32
35
  defaultRegion,
33
36
  separator,
34
- }) {
37
+ }: PropsType) {
35
38
  const [date, setDate] = React.useState(
36
39
  decodeIsoDatetime(defaultDate, 'date')
37
40
  );
@@ -44,7 +47,7 @@ export default function Select({
44
47
  const [selectedValue, setSelectedValue] = React.useState(defaultValue);
45
48
 
46
49
  // 两次默认值不同, 需要刷新
47
- const prevDefaultRef = React.useRef({});
50
+ const prevDefaultRef = React.useRef<any>({});
48
51
  React.useEffect(() => {
49
52
  let hasChange = false;
50
53
  if (prevDefaultRef.current?.defaultValue !== defaultValue) {
@@ -82,7 +85,7 @@ export default function Select({
82
85
  });
83
86
 
84
87
  const onDateclick = function () {
85
- const options = {
88
+ const options: Record<string, any> = {
86
89
  className: 'weda-ui weda-picker',
87
90
  };
88
91
  !!date && (options.defaultDate = date);
@@ -92,7 +95,7 @@ export default function Select({
92
95
  weui.datePicker({
93
96
  ...options,
94
97
  onConfirm(result) {
95
- const value = dayjs()
98
+ const value = moment()
96
99
  .year(result[0].value)
97
100
  .month(result[1].value - 1)
98
101
  .date(result[2].value)
@@ -104,7 +107,7 @@ export default function Select({
104
107
  };
105
108
 
106
109
  const onTimeClick = function () {
107
- const options = {
110
+ const options: Record<string, any> = {
108
111
  className: 'weda-ui weda-picker',
109
112
  };
110
113
  !!time && (options.defaultTime = time);
@@ -114,7 +117,7 @@ export default function Select({
114
117
  timePicker({
115
118
  ...options,
116
119
  onConfirm(result) {
117
- const date = dayjs().hour(result[0].value).minute(result[1].value);
120
+ const date = moment().hour(result[0].value).minute(result[1].value);
118
121
  const value = date.format('HH:mm');
119
122
  setTime(value);
120
123
  events.change({
@@ -181,7 +184,7 @@ export default function Select({
181
184
 
182
185
  const result = React.useMemo(() => {
183
186
  return {
184
- selector: range.find((item) => item.value === selectedValue)?.label,
187
+ selector: (range ?? []).find((item) => item.value === selectedValue)?.label,
185
188
  date: date,
186
189
  time: time,
187
190
  region: (region || []).join(separator), // region 有可能是空串
@@ -207,53 +210,6 @@ export default function Select({
207
210
  );
208
211
  }
209
212
 
210
- Select.propTypes = {
211
- // 系统属性
212
- className: PropTypes.string,
213
- style: PropTypes.string,
214
- events: PropTypes.objectOf(PropTypes.func),
215
- // 组件属性
216
- name: PropTypes.string,
217
- placeholder: PropTypes.string,
218
- layout: PropTypes.string,
219
- mode: PropTypes.string,
220
- disabled: PropTypes.bool,
221
- // selector mode
222
- range: PropTypes.array,
223
- defaultValue: PropTypes.string,
224
- // date mode
225
- startDate: PropTypes.string,
226
- endDate: PropTypes.string,
227
- defaultDate: PropTypes.string,
228
- // time mode
229
- startTime: PropTypes.string,
230
- endTime: PropTypes.string,
231
- defaultTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
232
- // region mode
233
- defaultRegion: PropTypes.array,
234
- separator: PropTypes.string,
235
- };
236
-
237
- Select.defaultProps = {
238
- // 系统属性
239
- events: {},
240
- // 组件属性
241
- label: '标题',
242
- labelVisible: true,
243
- name: 'formSelect',
244
- placeholder: '请选择',
245
- layout: 'horizontal',
246
- mode: 'selector',
247
- disabled: false,
248
- requiredFlag: false,
249
- // selector mode
250
- range: [
251
- { name: '选项一', value: 'first' },
252
- { name: '选项二', value: 'second' },
253
- ],
254
- // region mode
255
- separator: ',',
256
- };
257
213
 
258
214
  export function decodeIsoDatetime(isoStringOrTimesnap, type) {
259
215
  if (!isoStringOrTimesnap) {
@@ -275,22 +231,22 @@ export function decodeIsoDatetime(isoStringOrTimesnap, type) {
275
231
  isoStringOrTimesnap.match &&
276
232
  isoStringOrTimesnap.match(/^(\d{2}):(\d{2})$/);
277
233
  if (time && time[1] < 24 && time[2] < 60) {
278
- return dayjs().hour(time[1]).minute(time[2]).format('HH:mm');
234
+ return moment().hour(time[1]).minute(time[2]).format('HH:mm');
279
235
  } else if (typeof isoStringOrTimesnap === 'number') {
280
236
  const timeSnap = Number(isoStringOrTimesnap);
281
237
  let day;
282
238
  try {
283
- day = dayjs()
239
+ day = moment()
284
240
  .hour(Math.floor(timeSnap / 3600000) % 24)
285
241
  .minute(Math.floor((timeSnap % 3600000) / 60000));
286
242
  } catch (e) {
287
- day = dayjs(timeSnap);
243
+ day = moment(timeSnap);
288
244
  }
289
245
  return day.format('HH:mm');
290
246
  } else {
291
- return dayjs(isoStringOrTimesnap).format('HH:mm');
247
+ return moment(isoStringOrTimesnap).format('HH:mm');
292
248
  }
293
249
  } else {
294
- return dayjs(isoStringOrTimesnap).format('YYYY-MM-DD');
250
+ return moment(isoStringOrTimesnap).format('YYYY-MM-DD');
295
251
  }
296
252
  }