@cloudbase/weda-ui 0.2.10 → 0.2.14

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 (111) 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 +233 -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 +105 -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/MultipleSelect.jsx +1 -6
  41. package/src/web/components/form/enumSelect/{NormalSelect.jsx → NormalSelect.tsx} +3 -14
  42. package/src/web/components/form/form/index.tsx +48 -0
  43. package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
  44. package/src/web/components/form/input/index.css +39 -0
  45. package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
  46. package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
  47. package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
  48. package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
  49. package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
  50. package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
  51. package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
  52. package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
  53. package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
  54. package/src/web/components/form/select/time.jsx +2 -2
  55. package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
  56. package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
  57. package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
  58. package/src/web/components/form/types.d.ts +12 -0
  59. package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
  60. package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
  61. package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
  62. package/src/web/components/form/uploaderFile/fail.svg +12 -0
  63. package/src/web/components/form/uploaderFile/index.css +423 -0
  64. package/src/web/components/form/uploaderFile/index.jsx +30 -0
  65. package/src/web/components/form/uploaderFile/pending.svg +18 -0
  66. package/src/web/components/form/uploaderFile/success.svg +12 -0
  67. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +578 -0
  68. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +507 -0
  69. package/src/web/components/image/{image.jsx → image.tsx} +8 -21
  70. package/src/web/components/image/{index.jsx → index.tsx} +22 -37
  71. package/src/web/components/index.js +36 -1
  72. package/src/web/components/link/{index.jsx → index.tsx} +19 -36
  73. package/src/web/components/modal/{index.jsx → index.tsx} +22 -9
  74. package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
  75. package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
  76. package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
  77. package/src/web/components/richText/{const.js → const.ts} +0 -0
  78. package/src/web/components/richText/index.jsx +5 -2
  79. package/src/web/components/richTextView/index.tsx +67 -0
  80. package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
  81. package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
  82. package/src/web/components/swiper/index.css +1 -1
  83. package/src/web/components/swiper/{index.jsx → index.tsx} +73 -78
  84. package/src/web/components/tabs/index.tsx +33 -0
  85. package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
  86. package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
  87. package/src/web/components/text/index.css +18 -0
  88. package/src/web/components/text/index.tsx +69 -0
  89. package/src/web/components/uploaderFileView/index.css +11 -0
  90. package/src/web/components/uploaderFileView/index.jsx +75 -0
  91. package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
  92. package/src/web/types.d.ts +20 -0
  93. package/src/web/utils/constant.js +2 -0
  94. package/src/web/utils/loading-fallback.tsx +2 -0
  95. package/src/web/utils/platform.js +77 -6
  96. package/src/web/utils/tcb.js +0 -8
  97. package/src/web/utils/useSetState.ts +14 -0
  98. package/src/web/utils/useSyncValue.ts +17 -0
  99. package/src/web/wedatheme/.git +1 -0
  100. package/src/web/wedatheme/.gitignore +5 -0
  101. package/src/web/wedatheme/.npmrc +1 -0
  102. package/src/web/wedatheme/package-lock.json +14335 -0
  103. package/src/configs/components/button.svg +0 -18
  104. package/src/web/components/drawer/index.jsx +0 -64
  105. package/src/web/components/form/enumSelect/hooks/index.js +0 -49
  106. package/src/web/components/form/form/index.jsx +0 -76
  107. package/src/web/components/link/test/__snapshots__/storybook.test.js.snap +0 -754
  108. package/src/web/components/richTextView/index.jsx +0 -89
  109. package/src/web/components/tabs/index.jsx +0 -10
  110. package/src/web/components/text/index.jsx +0 -71
  111. package/src/web/utils/useSyncValue.js +0 -14
@@ -1,27 +1,49 @@
1
1
  import * as React from 'react';
2
- import { useState, useEffect, useRef, useCallback } from 'react';
3
- import * as propTypes from 'prop-types';
2
+ import { useState, useEffect, useRef } from 'react';
4
3
  import classNames from '../../utils/classnames';
5
4
  import Swipe from 'react-easy-swipe';
5
+ import {useDebouncedCallback, useEventListener, useResizeObserver} from '@react-hookz/web';
6
6
 
7
7
  import './index.css';
8
+ import { CommonPropsType } from '../../types';
9
+
10
+ export interface PropsType extends CommonPropsType {
11
+ /**
12
+ * 是否启用指示点
13
+ */
14
+ indicatorDots: boolean;
15
+ /**
16
+ * 是否自动切换
17
+ */
18
+ autoplay: boolean;
19
+ /**
20
+ * 当前索引值
21
+ */
22
+ current: number;
23
+ interval: number;
24
+ duration: number;
25
+ circular: boolean;
26
+ vertical: boolean;
27
+ indicatorColor: string;
28
+ indicatorActiveColor: string;
29
+ }
8
30
 
9
31
  export default function Swiper({
10
32
  children,
11
33
  className,
12
34
  style = {},
13
- autoplay,
14
- circular,
15
- vertical,
35
+ autoplay = true,
36
+ circular = true,
37
+ vertical = false,
16
38
  indicatorDots,
17
- indicatorColor,
18
- indicatorActiveColor,
39
+ indicatorColor = 'rgba(200, 200, 200, 0.9)',
40
+ indicatorActiveColor = 'rgba(0, 0, 0, 0.9)',
19
41
  duration = 500,
20
42
  interval = 5000,
21
43
  current = 0,
22
44
  events = {},
23
45
  id,
24
- }) {
46
+ }: PropsType) {
25
47
  const itemCount = React.Children.count(children);
26
48
  current = Math.max(0, Math.min(itemCount - 1, current));
27
49
 
@@ -55,23 +77,11 @@ export default function Swiper({
55
77
  };
56
78
  }, [currentIndex, vertical]);
57
79
 
58
- const cb = useCallback(
59
- (node) => {
60
- if (node) {
61
- const h =
62
- node.children[0] &&
63
- node.children[0].getBoundingClientRect() &&
64
- node.children[0].getBoundingClientRect().height;
80
+ const outerWrapRef = useRef<HTMLDivElement>();
81
+ useEventListener(outerWrapRef, 'load', (e) => {
82
+ setHeight(e.target.clientHeight);
83
+ });
65
84
 
66
- if (h && height) {
67
- setHeight(Math.min(h, height));
68
- } else {
69
- setHeight(Math.max(h, height));
70
- }
71
- }
72
- },
73
- [height]
74
- );
75
85
 
76
86
  const itemsClone = React.Children.map(children, (x, i) => {
77
87
  return (
@@ -148,9 +158,7 @@ export default function Swiper({
148
158
  vertical: vertical,
149
159
  })}
150
160
  style={{ height: height ? height : 'auto', ...style }}
151
- onLoad={(e) => {
152
- cb(e.target.closest('.g-swiper-item'));
153
- }}
161
+ ref={outerWrapRef}
154
162
  id={id}
155
163
  >
156
164
  {itemCount > 0 ? (
@@ -173,17 +181,7 @@ export default function Swiper({
173
181
  >
174
182
  {itemsClone[itemCount - 1]}
175
183
  {React.Children.map(children, (x, i) => {
176
- return (
177
- <div
178
- className={classNames('g-swiper-item', {
179
- current: i === currentIndex,
180
- })}
181
- ref={cb}
182
- data-index={i}
183
- >
184
- {x}
185
- </div>
186
- );
184
+ return <SwiperItem setHeight={setHeight} currentIndex={currentIndex} index={i}>{x}</SwiperItem>;
187
185
  })}
188
186
  {itemsClone[0]}
189
187
  </Swipe>
@@ -213,18 +211,20 @@ export default function Swiper({
213
211
  false
214
212
  )}
215
213
  <a
216
- href="javascript:;"
214
+ href="#"
217
215
  className="g-swiper__turn-pre"
218
- onClick={() => {
216
+ onClick={(ev) => {
217
+ ev.preventDefault();
219
218
  setIndex(currentIndex - 1);
220
219
  }}
221
220
  >
222
221
  上一页
223
222
  </a>
224
223
  <a
225
- href="javascript:;"
224
+ href="#"
226
225
  className="g-swiper__turn-next"
227
- onClick={() => {
226
+ onClick={(ev) => {
227
+ ev.preventDefault();
228
228
  setIndex(currentIndex + 1);
229
229
  }}
230
230
  >
@@ -234,40 +234,35 @@ export default function Swiper({
234
234
  );
235
235
  }
236
236
 
237
- Swiper.defaultProps = {
238
- current: 0,
239
- duration: 500,
240
- indicatorDots: true,
241
- autoplay: true,
242
- circular: true,
243
- interval: 5000,
244
- vertical: false,
245
- indicatorColor: 'rgba(200, 200, 200, 0.9)',
246
- indicatorActiveColor: 'rgba(0, 0, 0, 0.9)',
247
- };
237
+ const SwiperItem: React.FC<{
238
+ setHeight: React.Dispatch<React.SetStateAction<number>>,
239
+ currentIndex: number,
240
+ index: number,
241
+ children?: React.ReactNode
242
+ }> = ({setHeight, children, currentIndex, index}) => {
243
+ const firstChildRef = useRef<HTMLDivElement>(null);
244
+ const syncHeight = useDebouncedCallback((e) => {
245
+ setHeight(e.contentRect.height);
246
+ }, [setHeight], 500, 2000); // 必须debounce延迟,让resize完成后再设置高度
248
247
 
249
- Swiper.propTypes = {
250
- /**
251
- * 是否启用指示点
252
- */
253
- indicatorDots: propTypes.bool,
254
- /**
255
- * 是否自动切换
256
- */
257
- autoplay: propTypes.bool,
258
- /**
259
- * 当前索引值
260
- */
261
- current: propTypes.number,
262
- interval: propTypes.number,
263
- duration: propTypes.number,
264
- circular: propTypes.bool,
265
- vertical: propTypes.bool,
266
- indicatorColor: propTypes.string,
267
- indicatorActiveColor: propTypes.string,
268
- children: propTypes.any,
269
- className: propTypes.string,
270
- style: propTypes.object,
271
- events: propTypes.objectOf(propTypes.func),
272
- id: propTypes.string,
273
- };
248
+ // 因为有loading 所以得用resizeobserver
249
+ // @ts-ignore
250
+ useResizeObserver(firstChildRef, (e) => {
251
+ if(currentIndex === index) {
252
+ syncHeight(e);
253
+ }
254
+ });
255
+ const wrapRef = useRef<HTMLDivElement>();
256
+ return (
257
+ <div
258
+ className={classNames('g-swiper-item', {
259
+ current: index === currentIndex,
260
+ })}
261
+ data-index={index}
262
+ >
263
+ <div ref={firstChildRef}>
264
+ {children}
265
+ </div>
266
+ </div>
267
+ );
268
+ };
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ import loadable from '@loadable/component';
3
+ import { CommonPropsType } from '../../types';
4
+ import { usePlatform } from '../../utils/platform';
5
+ import { fallback } from '../../utils/loading-fallback';
6
+ import TabsH5 from './tabs.h5';
7
+ import TabsPc from './tabs.pc';
8
+
9
+ // const TabsH5 = loadable(() => import('./tabs.h5'), { fallback });
10
+ // const TabsPc = loadable(() => import('./tabs.pc'), { fallback });
11
+
12
+ export interface PropsType extends CommonPropsType {
13
+ tabs: {
14
+ title: string;
15
+
16
+ // @deprecated
17
+ name?: string;
18
+ }[];
19
+ selectedIndex: number
20
+ [key: string]: React.ReactNode
21
+ // [panel: `panel${number}`]: React.ReactNode; // require typescript@4.4
22
+ }
23
+
24
+ export default function Tabs(props: PropsType) {
25
+ const platform = usePlatform();
26
+ if (props?.showType === 'pc') {
27
+ return <TabsPc {...props} />;
28
+ }
29
+ if (props?.showType === 'h5') {
30
+ return <TabsH5 {...props} />;
31
+ }
32
+ return platform === 'h5' ? <TabsH5 {...props} /> : <TabsPc {...props} />;
33
+ }
@@ -1,9 +1,9 @@
1
1
  import React, { useMemo } from 'react';
2
- import * as PropTypes from 'prop-types';
3
2
 
4
3
  import './index.css';
5
4
  import classNames from '../../utils/classnames';
6
5
  import { useSyncValue } from '../../utils/useSyncValue';
6
+ import {PropsType} from './index';
7
7
 
8
8
  export default function TabsH5({
9
9
  tabs,
@@ -12,7 +12,7 @@ export default function TabsH5({
12
12
  className,
13
13
  style,
14
14
  ...restProps
15
- }) {
15
+ }: PropsType) {
16
16
  const [currentIndex, setCurrentIndex] = useSyncValue(selectedIndex);
17
17
  const stickyStyle = useMemo(() => {
18
18
  const length = tabs.length;
@@ -23,7 +23,7 @@ export default function TabsH5({
23
23
  }, [tabs, currentIndex]);
24
24
 
25
25
  return (
26
- <div className={classNames("weda-tabs weda-ui", {
26
+ <div data-testid="tabs" className={classNames("weda-tabs weda-ui", {
27
27
  [className]: className
28
28
  })} style={style}>
29
29
  <div className="weda-tabs__nav">
@@ -63,33 +63,4 @@ export default function TabsH5({
63
63
  </div>
64
64
  </div>
65
65
  );
66
- }
67
-
68
-
69
- TabsH5.propTypes = {
70
- tabs: PropTypes.array,
71
- className: PropTypes.string,
72
- style: PropTypes.object,
73
- selectedIndex: PropTypes.number,
74
- events: PropTypes.objectOf(PropTypes.func),
75
- panel1: PropTypes.node,
76
- panel2: PropTypes.node,
77
- panel3: PropTypes.node,
78
- panel4: PropTypes.node,
79
- panel5: PropTypes.node,
80
- panel6: PropTypes.node,
81
- panel7: PropTypes.node,
82
- panel8: PropTypes.node,
83
- panel9: PropTypes.node,
84
- panel10: PropTypes.node,
85
- panel11: PropTypes.node,
86
- panel12: PropTypes.node,
87
- panel13: PropTypes.node,
88
- panel14: PropTypes.node,
89
- panel15: PropTypes.node,
90
- panel16: PropTypes.node,
91
- panel17: PropTypes.node,
92
- panel18: PropTypes.node,
93
- panel19: PropTypes.node,
94
- panel20: PropTypes.node,
95
- };
66
+ }
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
2
  import { Tabs as TeaTabs, TabPanel, ConfigProvider } from 'tea-component';
4
3
  import classNames from '../../utils/classnames';
5
4
  import { useSyncValue } from '../../utils/useSyncValue';
5
+ import { PropsType } from './index';
6
6
 
7
7
 
8
8
  export default function TabsPc({
@@ -12,28 +12,23 @@ export default function TabsPc({
12
12
  className,
13
13
  style,
14
14
  ...restProps
15
- }) {
15
+ }: PropsType) {
16
16
 
17
17
  const [activeIndex, setActiveIndex] = useSyncValue(selectedIndex);
18
18
  const _tabs = Array.isArray(tabs) && tabs.length && tabs.map((item, index) => {
19
19
  return {
20
- id: index,
20
+ id: index.toString(),
21
21
  label: item.title
22
22
  };
23
23
  });
24
24
 
25
-
26
-
27
- // React.useEffect(() => {
28
- // console.log('render');
29
- // });
30
25
  const onActive = (e) => {
31
26
  setActiveIndex(e.id);
32
27
  events && events.change(e);
33
28
  };
34
29
  return (
35
30
  <ConfigProvider classPrefix="wedatea2td">
36
- <TeaTabs style={style} tabs={_tabs} activeId={activeIndex} onActive={onActive} className={classNames(
31
+ <TeaTabs style={style} tabs={_tabs} activeId={String(activeIndex)} onActive={onActive} className={classNames(
37
32
  "weda-tabs_pc",
38
33
  {
39
34
  [className]: className
@@ -44,7 +39,6 @@ export default function TabsPc({
44
39
  <TabPanel
45
40
  key={item.id}
46
41
  id={item.id}
47
- label={item.label}
48
42
  >
49
43
  {restProps[`panel${index + 1}`]}
50
44
  </TabPanel>
@@ -53,32 +47,4 @@ export default function TabsPc({
53
47
  </TeaTabs>
54
48
  </ConfigProvider>
55
49
  );
56
- }
57
-
58
- TabsPc.propTypes = {
59
- tabs: PropTypes.array,
60
- className: PropTypes.string,
61
- selectedIndex: PropTypes.number,
62
- style: PropTypes.object,
63
- events: PropTypes.objectOf(PropTypes.func),
64
- panel1: PropTypes.node,
65
- panel2: PropTypes.node,
66
- panel3: PropTypes.node,
67
- panel4: PropTypes.node,
68
- panel5: PropTypes.node,
69
- panel6: PropTypes.node,
70
- panel7: PropTypes.node,
71
- panel8: PropTypes.node,
72
- panel9: PropTypes.node,
73
- panel10: PropTypes.node,
74
- panel11: PropTypes.node,
75
- panel12: PropTypes.node,
76
- panel13: PropTypes.node,
77
- panel14: PropTypes.node,
78
- panel15: PropTypes.node,
79
- panel16: PropTypes.node,
80
- panel17: PropTypes.node,
81
- panel18: PropTypes.node,
82
- panel19: PropTypes.node,
83
- panel20: PropTypes.node,
84
- };
50
+ }
@@ -6,3 +6,21 @@
6
6
  /* -webkit-line-clamp: 1;
7
7
  white-space: pre-line; */
8
8
  }
9
+ .weda-text.level_1 {
10
+ font-size: 64px !important;
11
+ }
12
+ .weda-text.level_2 {
13
+ font-size: 56px !important;
14
+ }
15
+ .weda-text.level_3 {
16
+ font-size: 48px !important;
17
+ }
18
+ .weda-text.level_4 {
19
+ font-size: 40px !important;
20
+ }
21
+ .weda-text.level_5 {
22
+ font-size: 32px !important;
23
+ }
24
+ .weda-text.level_6 {
25
+ font-size: 24px !important;
26
+ }
@@ -0,0 +1,69 @@
1
+ import * as React from 'react';
2
+ import classNames from '../../utils/classnames';
3
+ import { CommonPropsType, unknownFunction } from '../../types';
4
+ import './index.css';
5
+
6
+ export interface PropsType extends CommonPropsType {
7
+ text: string,
8
+ level: string,
9
+ maxLines: number,
10
+ space: boolean,
11
+ userSelect: boolean,
12
+ textAlign: string,
13
+ textColor: string,
14
+ contenteditable: HTMLParagraphElement['contentEditable'],
15
+ onInput: unknownFunction,
16
+ onBlur: unknownFunction
17
+
18
+ }
19
+ export default function Text({
20
+ text = '文本内容',
21
+ maxLines = 2,
22
+ space = false,
23
+ userSelect = true,
24
+ textAlign = '',
25
+ textColor = '',
26
+ style = {},
27
+ className,
28
+ events,
29
+ id,
30
+ level = '0',
31
+ contenteditable,
32
+ onInput,
33
+ onBlur
34
+ }: PropsType) {
35
+ const textStyle: React.CSSProperties = {
36
+ WebkitLineClamp: maxLines,
37
+ whiteSpace: space ? 'pre-wrap' : 'pre-line',
38
+ };
39
+
40
+ if (!userSelect) {
41
+ textStyle.userSelect = 'none';
42
+ }
43
+ const levelName = level === '0' ? '' : `level_${level}`;
44
+
45
+ // 添加文本颜色属性
46
+ let style2 = {};
47
+ if (textColor !== "") {
48
+ style2 = {color: textColor};
49
+ }
50
+
51
+ // 添加对齐属性
52
+ if (textAlign !== "") {
53
+ style2 = {...style2, textAlign};
54
+ }
55
+ return (
56
+ <p
57
+ //@ts-expect-error contentEditable type def sucks
58
+ contentEditable={contenteditable}
59
+ onInput={onInput}
60
+ onBlur={onBlur}
61
+ style={{ ...style, ...textStyle, ...style2 }}
62
+ className={classNames('weda-text', 'weda-ui', className, levelName)}
63
+ id={id}
64
+ onClick={(e) => events.tap({}, { originEvent: e })}
65
+ >
66
+ {text}
67
+ </p>
68
+ );
69
+ }
@@ -0,0 +1,11 @@
1
+ a.weda-file-view-pc__single{
2
+ display: inline-block;
3
+ vertical-align: middle;
4
+ white-space: nowrap;
5
+ overflow: hidden;
6
+ text-overflow: ellipsis;
7
+ max-width: 100%;
8
+ }
9
+ a.weda-file-view-pc__single:hover{
10
+ text-decoration: underline;
11
+ }
@@ -0,0 +1,75 @@
1
+ import * as React from 'react';
2
+ import { UploadFilePc } from '../form/uploaderFile/uploadFile.pc';
3
+ import {
4
+ filterStrList,
5
+ isCloudFileID,
6
+ downloadFile,
7
+ } from '../../utils/platform';
8
+ import { getTempFileURL } from '../../utils/tcb';
9
+ import './index.css';
10
+
11
+ const CLASS_PREFIX = 'weda-file-view-pc';
12
+
13
+ /**
14
+ * 上传文件回显
15
+ * single 表示单个文件回显
16
+ */
17
+ export default function UploaderFileView({
18
+ value,
19
+ className,
20
+ single = true,
21
+ ...rest
22
+ }) {
23
+ const fileIDList = filterStrList(value);
24
+ if(single){
25
+ return <FileView fileID={fileIDList[0]}/>
26
+ }else{
27
+ return (
28
+ <UploadFilePc
29
+ className={`${CLASS_PREFIX} ${className}`}
30
+ decorator={null}
31
+ {...rest}
32
+ value={fileIDList}
33
+ isEdit={false}
34
+ />
35
+ )
36
+ }
37
+ }
38
+
39
+ /**
40
+ * 单个文件回显
41
+ */
42
+ const FileView = ({ fileID }) => {
43
+ const [src, setSrc] = React.useState('');
44
+
45
+ React.useEffect(() => {
46
+ const fetchFileId = async (id) => {
47
+ if (isCloudFileID(id)) {
48
+ try {
49
+ const fileSrc = await getTempFileURL(id);
50
+ setSrc(fileSrc);
51
+ } catch (e) {}
52
+ } else {
53
+ setSrc(id);
54
+ }
55
+ };
56
+ fetchFileId(fileID);
57
+ }, [fileID]);
58
+
59
+ const title = React.useMemo(() => {
60
+ if (isCloudFileID(fileID)) {
61
+ const uuidReg = /file-[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}-/;
62
+ const lastIndex = `${fileID}`.lastIndexOf('/');
63
+ const name = `${fileID}`.slice(lastIndex + 1);
64
+ const title = name.replace(uuidReg, '');
65
+ return title;
66
+ } else {
67
+ return fileID;
68
+ }
69
+ }, [fileID]);
70
+ return (
71
+ <a title={title} onClick={() => downloadFile(src)} className={`${CLASS_PREFIX}__single`}>
72
+ {title}
73
+ </a>
74
+ )
75
+ };
@@ -3,6 +3,7 @@ import * as PropTypes from 'prop-types';
3
3
  import { TcbImage } from '../form/uploader/uploader.pc';
4
4
  import classNames from '../../utils/classnames';
5
5
  import './index.css';
6
+ import { CommonPropsType } from '../../types';
6
7
 
7
8
  const CLASS_PREFIX = 'g-uploader-view';
8
9
 
@@ -20,8 +21,8 @@ export default function UploaderView({
20
21
  isEmptyPlace = true,
21
22
  className,
22
23
  id,
23
- style
24
- }) {
24
+ style,
25
+ }: PropsType) {
25
26
  const cls = classNames({
26
27
  [CLASS_PREFIX]: true,
27
28
  [className]: className,
@@ -80,16 +81,12 @@ export default function UploaderView({
80
81
  );
81
82
  }
82
83
 
83
- UploaderView.propTypes = {
84
- srcList: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), // 图片 src 列表
85
- alt: PropTypes.string, // 替代文字
86
- isZoom: PropTypes.bool, // 能否点击放大
87
- gutter: PropTypes.number, // 图片间距
88
- height: PropTypes.number, // 图片最大高度
89
- width: PropTypes.number, // 图片最大宽度
90
- isEmptyPlace: PropTypes.bool, // 是否展示空值
91
- events: PropTypes.objectOf(PropTypes.func), // 组件事件
92
- className: PropTypes.string, // 类,修改测试story,测试2
93
- id: PropTypes.string,
94
- style: PropTypes.object
95
- };
84
+ export interface PropsType extends CommonPropsType {
85
+ srcList?: string[] | string;
86
+ alt?: string; // 替代文字
87
+ isZoom?: boolean; // 能否点击放大
88
+ gutter?: number; // 图片间距
89
+ height?: number; // 图片最大高度
90
+ width?: number; // 图片最大宽度
91
+ isEmptyPlace?: boolean; // 是否显示空值
92
+ }
@@ -0,0 +1,20 @@
1
+ /// <reference types="resize-observer-browser" />
2
+
3
+ import * as React from "react";
4
+ export type unknownFunction = (...args: unknown[]) => unknown
5
+ export interface CommonPropsType {
6
+ style?: React.CSSProperties,
7
+ id?: string,
8
+ events?: Record<string, unknownFunction>;
9
+ className?: string,
10
+ children?: React.ReactNode | undefined
11
+ }
12
+
13
+
14
+ declare global {
15
+ var app: any
16
+ interface Window {
17
+ app: any;
18
+ }
19
+
20
+ }
@@ -3,3 +3,5 @@ export const TitleType = {
3
3
  TOP: 'top',
4
4
  NONE: 'none',
5
5
  };
6
+
7
+ export const LOAD_ERR_IMG_BASE64 = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIiBmaWxsPSJub25lIj4KICA8cGF0aCBkPSJNMjUuMzIgMTYuMzU5N0MyNi4wNzY0IDE2LjM1OTcgMjYuODI1NCAxNi41MDg3IDI3LjUyNDMgMTYuNzk4MUMyOC4yMjMxIDE3LjA4NzYgMjguODU4MSAxNy41MTE5IDI5LjM5MjkgMTguMDQ2OEMyOS45Mjc4IDE4LjU4MTYgMzAuMzUyMSAxOS4yMTY2IDMwLjY0MTYgMTkuOTE1NEMzMC45MzEgMjAuNjE0MyAzMS4wOCAyMS4zNjMzIDMxLjA4IDIyLjExOTdDMzEuMDggMjIuODc2MSAzMC45MzEgMjMuNjI1MSAzMC42NDE2IDI0LjMyMzlDMzAuMzUyMSAyNS4wMjI4IDI5LjkyNzggMjUuNjU3OCAyOS4zOTI5IDI2LjE5MjZDMjguODU4MSAyNi43Mjc1IDI4LjIyMzEgMjcuMTUxOCAyNy41MjQzIDI3LjQ0MTJDMjYuODI1NCAyNy43MzA3IDI2LjA3NjQgMjcuODc5NyAyNS4zMiAyNy44Nzk3QzIzLjc5MjQgMjcuODc5NyAyMi4zMjczIDI3LjI3MjggMjEuMjQ3MSAyNi4xOTI2QzIwLjE2NjkgMjUuMTEyNCAxOS41NiAyMy42NDczIDE5LjU2IDIyLjExOTdDMTkuNTYgMjAuNTkyIDIwLjE2NjkgMTkuMTI3IDIxLjI0NzEgMTguMDQ2OEMyMi4zMjczIDE2Ljk2NjUgMjMuNzkyNCAxNi4zNTk3IDI1LjMyIDE2LjM1OTdaTTI4IDMuNTU5NjlWMTQuODc2OEMyNy4xNzc3IDE0LjU4NjYgMjYuMTkyIDE0LjQzODggMjUuMzIgMTQuNDM5N0MyNC4wMzEgMTQuNDM5NyAyMi44MTU3IDE0Ljc1NzEgMjEuNzQ4OCAxNS4zMTg0TDIwLjc5NTIgMTMuMTU5N0wxNi4wMjU5IDIwLjAyNzVMOC40NDU3NiAxNi40NDFMMy41NiAyMy4zOTk3SDE3Ljc0NjJDMTcuOTg2NyAyNC44MjkgMTguNjI4MiAyNi4xNjA2IDE5LjU5NTggMjcuMjM5N0gxVjMuNTU5NjlIMjhaTTI1Ljk2IDI0LjAzOTdIMjQuNjhWMjUuMzE5N0gyNS45NlYyNC4wMzk3Wk0yNS45NiAxOC45MTk3SDI0LjY4VjIzLjM5OTdIMjUuOTZWMTguOTE5N1pNNi4xMiAxMC41OTk3QzYuMTIgMTEuOTk4MSA3LjE5OTA0IDEzLjEwODUgOC42MDc2OCAxMy4xNTg0QzEwLjAyMDggMTMuMjA3NyAxMS4yNCAxMi4wNDggMTEuMjQgMTAuNTk5N0MxMS4yNCA5LjI0NjA5IDEwLjA2NDMgOC4wODU3NyA4Ljc1MjMyIDguMDQwOTdDNy4yOTU2OCA3Ljk5MTY5IDYuMTIgOS4xNTEzNyA2LjEyIDEwLjU5OTdaIiBmaWxsPSIjQkNDNEQwIj48L3BhdGg+Cjwvc3ZnPgo=';
@@ -0,0 +1,2 @@
1
+ import * as React from "react";
2
+ export const fallback = <div>组件加载中...</div>;