@cloudbase/weda-ui 0.2.15 → 0.2.16

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 (112) hide show
  1. package/package.json +10 -7
  2. package/src/configs/components/calendar.json +75 -0
  3. package/src/configs/components/carousel.json +273 -0
  4. package/src/configs/components/chart/statisticsCard.json +331 -0
  5. package/src/configs/components/dataView.json +139 -0
  6. package/src/configs/components/form/location.json +152 -0
  7. package/src/configs/components/form/uploaderFile.json +2 -1
  8. package/src/configs/components/graphicCard.json +399 -0
  9. package/src/configs/components/link.json +2 -2
  10. package/src/configs/components/listView.json +230 -0
  11. package/src/configs/components/navLayout.json +350 -0
  12. package/src/configs/components/swiper.json +3 -3
  13. package/src/configs/index.js +16 -0
  14. package/src/mp/components/button/index.js +12 -13
  15. package/src/mp/components/button/index.wxml +1 -1
  16. package/src/mp/components/calendar/arrowright--line.svg +11 -0
  17. package/src/mp/components/calendar/index.js +238 -0
  18. package/src/mp/components/calendar/index.json +4 -0
  19. package/src/mp/components/calendar/index.wxml +37 -0
  20. package/src/mp/components/calendar/index.wxss +178 -0
  21. package/src/mp/components/carousel/index.js +88 -0
  22. package/src/mp/components/carousel/index.json +7 -0
  23. package/src/mp/components/carousel/index.wxml +6 -0
  24. package/src/mp/components/chart/statisticsCard/index.js +226 -0
  25. package/src/mp/components/chart/statisticsCard/index.json +4 -0
  26. package/src/mp/components/chart/statisticsCard/index.wxml +9 -0
  27. package/src/mp/components/chart/statisticsCard/index.wxss +45 -0
  28. package/src/mp/components/dataView/index.js +34 -0
  29. package/src/mp/components/dataView/index.json +7 -0
  30. package/src/mp/components/dataView/index.wxml +15 -0
  31. package/src/mp/components/dataView/index.wxss +0 -0
  32. package/src/mp/components/form/location/components/mapChoose/index.js +201 -0
  33. package/src/mp/components/form/location/components/mapChoose/index.json +4 -0
  34. package/src/mp/components/form/location/components/mapChoose/index.wxml +42 -0
  35. package/src/mp/components/form/location/components/mapChoose/index.wxss +188 -0
  36. package/src/mp/components/form/location/index.js +341 -0
  37. package/src/mp/components/form/location/index.json +6 -0
  38. package/src/mp/components/form/location/index.wxml +25 -0
  39. package/src/mp/components/form/location/index.wxss +91 -0
  40. package/src/mp/components/form/uploader/index.js +39 -35
  41. package/src/mp/components/form/uploaderFile/index.js +61 -14
  42. package/src/mp/components/graphicCard/chevron-right.svg +3 -0
  43. package/src/mp/components/graphicCard/index.js +205 -0
  44. package/src/mp/components/graphicCard/index.json +4 -0
  45. package/src/mp/components/graphicCard/index.wxml +29 -0
  46. package/src/mp/components/graphicCard/index.wxss +157 -0
  47. package/src/mp/components/image/index.js +0 -1
  48. package/src/mp/components/listView/arrow-right-line.svg +3 -0
  49. package/src/mp/components/listView/index.js +286 -0
  50. package/src/mp/components/listView/index.json +4 -0
  51. package/src/mp/components/listView/index.wxml +40 -0
  52. package/src/mp/components/listView/index.wxss +150 -0
  53. package/src/mp/components/listView/more-line.svg +3 -0
  54. package/src/mp/components/navLayout/index.js +123 -0
  55. package/src/mp/components/navLayout/index.json +7 -0
  56. package/src/mp/components/navLayout/index.wxml +25 -0
  57. package/src/mp/components/navLayout/index.wxss +1193 -0
  58. package/src/mp/components/swiper/index.wxml +2 -0
  59. package/src/mp/index.json +9 -1
  60. package/src/mp/utils/debounce.js +133 -0
  61. package/src/mp/utils/dr_square_point.js +25 -0
  62. package/src/mp/utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js +1336 -0
  63. package/src/mp/utils/spark-md5.js +776 -0
  64. package/src/mp/utils/tcb.js +18 -0
  65. package/src/web/components/calendar/index.css +382 -0
  66. package/src/web/components/calendar/index.jsx +312 -0
  67. package/src/web/components/calendar/util.js +90 -0
  68. package/src/web/components/carousel/index.css +119 -0
  69. package/src/web/components/carousel/index.tsx +417 -0
  70. package/src/web/components/chart/statisticsCard/index.css +62 -0
  71. package/src/web/components/chart/statisticsCard/index.tsx +286 -0
  72. package/src/web/components/chart/statisticsCard/interface.ts +14 -0
  73. package/src/web/components/dataView/index.tsx +20 -0
  74. package/src/web/components/dataView/interface.ts +6 -0
  75. package/src/web/components/form/location/common/mapChoose.css +178 -0
  76. package/src/web/components/form/location/common/mapChoose.jsx +343 -0
  77. package/src/web/components/form/location/common/mapView.jsx +190 -0
  78. package/src/web/components/form/location/common/propsConfig.js +54 -0
  79. package/src/web/components/form/location/common/selectModal.css +44 -0
  80. package/src/web/components/form/location/common/selectModal.jsx +82 -0
  81. package/src/web/components/form/location/common/useLocationInfo.js +100 -0
  82. package/src/web/components/form/location/components/LocationH5/index.css +243 -0
  83. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +403 -0
  84. package/src/web/components/form/location/components/LocationPC/Header.jsx +109 -0
  85. package/src/web/components/form/location/components/LocationPC/index.css +44 -0
  86. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +323 -0
  87. package/src/web/components/form/location/constants.js +4 -0
  88. package/src/web/components/form/location/index.css +0 -0
  89. package/src/web/components/form/location/index.jsx +25 -0
  90. package/src/web/components/form/uploader/uploader.h5.tsx +16 -10
  91. package/src/web/components/form/uploader/uploader.pc.tsx +15 -11
  92. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +122 -107
  93. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +22 -19
  94. package/src/web/components/graphicCard/index.css +163 -0
  95. package/src/web/components/graphicCard/index.tsx +309 -0
  96. package/src/web/components/image/image.tsx +0 -1
  97. package/src/web/components/index.js +12 -0
  98. package/src/web/components/listView/arrow-right-line.svg +3 -0
  99. package/src/web/components/listView/index.css +139 -0
  100. package/src/web/components/listView/index.tsx +354 -0
  101. package/src/web/components/listView/interface.ts +98 -0
  102. package/src/web/components/navLayout/index.css +332 -0
  103. package/src/web/components/navLayout/index.tsx +247 -0
  104. package/src/web/components/tabs/index.tsx +2 -2
  105. package/src/web/components/tabs/tabs.h5.tsx +7 -4
  106. package/src/web/components/uploaderFileView/index.css +9 -9
  107. package/src/web/components/uploaderFileView/index.jsx +32 -23
  108. package/src/web/types.d.ts +15 -14
  109. package/src/web/utils/debounce.js +98 -0
  110. package/src/web/utils/platform.js +31 -0
  111. package/src/web/utils/tcb.js +35 -0
  112. package/src/web/utils/tmap.js +4 -0
@@ -0,0 +1,354 @@
1
+ import React, {
2
+ useState,
3
+ useEffect,
4
+ useRef,
5
+ useMemo,
6
+ useCallback,
7
+ } from 'react';
8
+ import { IListView } from './interface';
9
+ import { callDataSource } from '../../utils/tcb';
10
+ import { isInIde } from '../../utils/platform';
11
+ import classNames from '../../utils/classnames';
12
+ import isequal from 'lodash.isequal';
13
+ import './index.css';
14
+
15
+ const REL_DICT = {
16
+ equal: 'eq', // 等于
17
+ unequal: 'neq', // 不等于
18
+ include: 'search', // 包含
19
+ exclude: '_exclude', // 不包含
20
+ begin_with: '_begin_with', // 开头是
21
+ greater: 'gt', // 大于
22
+ greater_or_equal: 'gte', // 大于等于
23
+ bigger_or_equal: 'gte', //大于等于
24
+ less: 'lt', // 小于
25
+ less_or_equal: 'lte', // 小于等于
26
+ in: 'in', // 多选值
27
+ not_in: 'nin', // 不在多选值
28
+ };
29
+ const ORDERTYPE = ['asc', 'desc'];
30
+ const BLOCK_NAME = 'weda-list-view';
31
+ const isNull = (val) => [undefined, null].includes(val);
32
+ const getIdeMockData = (length = 3) => Array.from({ length }).map((d) => ({}));
33
+ const getWhereList = (where) => {
34
+ let result = [];
35
+ Array.isArray(where) &&
36
+ where.forEach((item1) => {
37
+ if (item1?.groupLogic !== 'or' && Array.isArray(item1?.logicData)) {
38
+ item1?.logicData.forEach((item2) => {
39
+ let [rel, val] = [REL_DICT[item2?.rel], item2?.value];
40
+ if ('_begin_with' === rel) {
41
+ rel = 'regex';
42
+ val = `^${val}`;
43
+ }
44
+ if ('_exclude' === rel) {
45
+ rel = 'regex';
46
+ val = `^((?!${val}).)*$`;
47
+ }
48
+ if (item2?.logic !== 'or' && item2?.key && rel && !isNull(val)) {
49
+ result.push({ key: item2.key, rel, val });
50
+ }
51
+ });
52
+ }
53
+ });
54
+ return result;
55
+ };
56
+
57
+ /**
58
+ * 数据容器-列表视图
59
+ */
60
+ export default function ListView(props: IListView) {
61
+ const {
62
+ datasource,
63
+ orderBy,
64
+ orderType,
65
+ where,
66
+ template = 'simpleList',
67
+ pageSize = 5,
68
+ pagination = 'loadMoreButton',
69
+ events,
70
+ className,
71
+ children,
72
+ appCloud = { callDataSource, isInIde },
73
+ beforeDataChange = (v) => v,
74
+ ...rest
75
+ } = props;
76
+
77
+ const methodName = useMemo(
78
+ () => datasource?.extra?.methodName || 'wedaGetRecords',
79
+ [datasource?.extra?.methodName]
80
+ ); // 默认方法名
81
+ const [pageNo, setPageNo] = useState(1); // 分页状态
82
+ const [loading, setLoading] = useState(false); // 触底刷新加载状态
83
+ const [entry, setEntry] = useState(null); // 触底的observer对象
84
+ const paramRef = useRef({
85
+ dataSourceName: datasource.name,
86
+ methodName,
87
+ params: { orderBy, orderType, where, pageNo: 1, pageSize },
88
+ pagination,
89
+ }); // 最新请求参数
90
+ const dataRef = useRef({ total: 0, records: [] }); // 最新数据列表
91
+ const observeRef = useRef(null); // 当前监听对象
92
+ const isIdeMockData = !datasource?.name && appCloud?.isInIde?.(); // 在ide环境且未绑定数据源时,存在mock数据逻辑
93
+ const shouldBottomLoad =
94
+ pagination === 'bottomLoad' && entry?.isIntersecting && !loading; // 能否触底加载
95
+
96
+ // 组件卸载时触发
97
+ useEffect(() => {
98
+ return () => {
99
+ observeRef.current?.disconnect();
100
+ events?.onDataChange?.({ data: beforeDataChange([]) });
101
+ };
102
+ }, []);
103
+
104
+ // props 基本类型监听,需重新分页;处于 ide 且未绑定数据源时返回mock数据
105
+ useEffect(() => {
106
+ dataRef.current = { total: 0, records: [] };
107
+ if (datasource?.name) {
108
+ fetchData({
109
+ dataSourceName: datasource.name,
110
+ methodName,
111
+ params: {
112
+ ...paramRef.current?.params,
113
+ orderBy,
114
+ orderType,
115
+ pageNo: 1,
116
+ pageSize,
117
+ },
118
+ pagination,
119
+ });
120
+ } else {
121
+ if (isIdeMockData) {
122
+ events?.onDataChange?.({
123
+ data: beforeDataChange(getIdeMockData(pageSize)),
124
+ });
125
+ }
126
+ }
127
+ }, [datasource?.name, methodName, pageSize, pagination, orderBy, orderType]);
128
+
129
+ // props 对象类型监听,需重新分页
130
+ useEffect(() => {
131
+ if (!isequal(paramRef.current?.params?.where, where)) {
132
+ dataRef.current = { total: 0, records: [] };
133
+ fetchData({
134
+ params: { pageNo: 1, where },
135
+ });
136
+ }
137
+ });
138
+
139
+ // 监听触底加载事件,这里面的 setLoading 用 setTimeout包裹起来,所以会先执行新的children渲染,再执行 loading
140
+ useEffect(() => {
141
+ if (shouldBottomLoad && hasNextPage()) {
142
+ fetchData({
143
+ params: { pageNo: (paramRef.current?.params?.pageNo || 1) + 1 },
144
+ });
145
+ }
146
+ }, [shouldBottomLoad]);
147
+
148
+ // 触底监控对象
149
+ const nodeRefCallback = useCallback((node) => {
150
+ if (node) {
151
+ observeRef.current?.disconnect();
152
+ observeRef.current = new IntersectionObserver((entries) => {
153
+ setEntry(entries?.[0]);
154
+ });
155
+ observeRef.current.observe(node);
156
+ }
157
+ }, []);
158
+
159
+ // 能否点击下一页
160
+ const hasNextPage = () => {
161
+ const { pageNo = 1, pageSize = 5 } = paramRef.current?.params || {};
162
+ const { total = 0 } = dataRef.current || {};
163
+ return pageNo * pageSize < total;
164
+ };
165
+
166
+ /**
167
+ * 列表视图拉取数据
168
+ * 方法仅依赖入参和paramRef的参数
169
+ */
170
+ const fetchData = async (param: {
171
+ dataSourceName?: string;
172
+ methodName?: string;
173
+ params?: any;
174
+ pagination?: any;
175
+ }) => {
176
+ if (loading) return;
177
+ setLoading(true);
178
+ // 合并参数
179
+ const fetchParam = {
180
+ ...paramRef.current,
181
+ ...param,
182
+ params: { ...paramRef.current.params, ...param?.params },
183
+ };
184
+ const { dataSourceName, methodName, params } = fetchParam;
185
+ const { orderBy, orderType, pageNo, pageSize, where } = params || {};
186
+ const tcbParams = {};
187
+ // tcb分页参数
188
+ if (!isNull(pageNo) && !isNull(pageSize)) {
189
+ tcbParams['pageNo'] = pageNo;
190
+ tcbParams['pageSize'] = pageSize;
191
+ }
192
+ // tcb排序参数
193
+ if (orderBy && ORDERTYPE.includes(orderType)) {
194
+ tcbParams['orderBy'] = orderBy;
195
+ tcbParams['orderType'] = orderType;
196
+ }
197
+ // tcb过滤参数
198
+ const whereEffected = [].concat(getWhereList(where));
199
+ whereEffected.length > 0 && (tcbParams['where'] = whereEffected);
200
+ // tcb结果和事件
201
+ const data = await appCloud?.callDataSource({
202
+ dataSourceName,
203
+ methodName,
204
+ params: tcbParams,
205
+ });
206
+ paramRef.current = fetchParam;
207
+ onEnvets(data);
208
+ };
209
+
210
+ /**
211
+ * 根据fetchData方法返回值,回调给外部事件
212
+ * datasource 是对象类型,所以总能拿到最新的值
213
+ */
214
+ const onEnvets = (data) => {
215
+ const fetchRecords = [].concat(data?.records || []);
216
+ const total = data?.total || fetchRecords.length;
217
+ if (
218
+ ['loadMoreButton', 'bottomLoad'].includes(paramRef.current.pagination)
219
+ ) {
220
+ dataRef.current = {
221
+ total,
222
+ records: [...dataRef.current.records, ...fetchRecords],
223
+ };
224
+ } else {
225
+ dataRef.current = { total, records: fetchRecords };
226
+ }
227
+ events?.onDataChange?.({
228
+ data: beforeDataChange(dataRef.current.records || []),
229
+ });
230
+ if (JSON.stringify(data) === '{}') {
231
+ events?.queryFail?.({ datasource });
232
+ } else {
233
+ if (total === 0) {
234
+ events?.queryEmpty?.({ datasource, data: beforeDataChange([]) });
235
+ }
236
+ events?.querySuccess?.({
237
+ datasource,
238
+ data: beforeDataChange(dataRef.current.records),
239
+ });
240
+ }
241
+ setPageNo(paramRef.current?.params?.pageNo || 1);
242
+ window.setTimeout(() => setLoading(false));
243
+ };
244
+
245
+ /**
246
+ * 分页,加载更多
247
+ */
248
+ const renderLoadMore = () => {
249
+ let disabled = !hasNextPage();
250
+ if (isIdeMockData) {
251
+ disabled = false;
252
+ }
253
+ return (
254
+ !disabled &&
255
+ (loading ? (
256
+ LoadingSymbol
257
+ ) : (
258
+ <div
259
+ className={`${BLOCK_NAME}__more-text`}
260
+ onClick={() => fetchData({ params: { pageNo: pageNo + 1 } })}
261
+ >
262
+ 加载更多
263
+ </div>
264
+ ))
265
+ );
266
+ };
267
+
268
+ /**
269
+ * 分页,底部刷新
270
+ */
271
+ const renderBottomLoad = () => {
272
+ return (
273
+ <div ref={nodeRefCallback} className={`${BLOCK_NAME}__bottom-load`}>
274
+ {loading ? LoadingSymbol : !hasNextPage() && LoadEnd}
275
+ </div>
276
+ );
277
+ };
278
+
279
+ /**
280
+ * 分页,分页器,含ideMockData的判断
281
+ */
282
+ const renderPagination = () => {
283
+ const preDisabeld = pageNo <= 1;
284
+ const nextDisabeld = !hasNextPage();
285
+ const total = dataRef.current?.total || 0;
286
+ return (
287
+ <div className={`${BLOCK_NAME}__more-pagination`}>
288
+ <div
289
+ className={classNames(
290
+ `${BLOCK_NAME}__pagination-pre`,
291
+ preDisabeld ? '' : 'active'
292
+ )}
293
+ onClick={() =>
294
+ !preDisabeld && fetchData({ params: { pageNo: pageNo - 1 } })
295
+ }
296
+ >
297
+ 上一页
298
+ </div>
299
+ <div className={classNames(`${BLOCK_NAME}__pagination-text`)}>
300
+ <span className="active">
301
+ {isIdeMockData ? 1 : total ? pageNo : 0}
302
+ </span>
303
+ /{isIdeMockData ? 1 : Math.ceil(total / pageSize)}
304
+ </div>
305
+ <div
306
+ className={classNames(
307
+ `${BLOCK_NAME}__pagination-next`,
308
+ nextDisabeld ? '' : 'active'
309
+ )}
310
+ onClick={() =>
311
+ !nextDisabeld && fetchData({ params: { pageNo: pageNo + 1 } })
312
+ }
313
+ >
314
+ 下一页
315
+ </div>
316
+ </div>
317
+ );
318
+ };
319
+
320
+ /**
321
+ * 加载中状态组件
322
+ */
323
+ const LoadingSymbol = (
324
+ <div className={`${BLOCK_NAME}__more-symbol`}>
325
+ <div className={`${BLOCK_NAME}__symbol-item`}></div>
326
+ <div className={`${BLOCK_NAME}__symbol-item`}></div>
327
+ <div className={`${BLOCK_NAME}__symbol-item`}></div>
328
+ </div>
329
+ );
330
+
331
+ /**
332
+ * 加载到底状态组件
333
+ */
334
+ const LoadEnd = <div></div>;
335
+
336
+ return (
337
+ <div
338
+ // eslint-disable-next-line react/jsx-props-no-spreading
339
+ {...rest}
340
+ className={classNames('weda-ui', `${BLOCK_NAME}__containor`, className)}
341
+ >
342
+ {children && (
343
+ <div className={template === 'cardList' ? `${BLOCK_NAME}-card` : ''}>
344
+ {children}
345
+ </div>
346
+ )}
347
+ <div className={classNames(`${BLOCK_NAME}__more`)}>
348
+ {pagination === 'bottomLoad' && renderBottomLoad()}
349
+ {pagination === 'loadMoreButton' && renderLoadMore()}
350
+ {pagination === 'pagination' && renderPagination()}
351
+ </div>
352
+ </div>
353
+ );
354
+ }
@@ -0,0 +1,98 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * 数据容器公共属性
5
+ */
6
+ export interface IDataContainer {
7
+ /**
8
+ * 数据模型
9
+ */
10
+ datasource?: {
11
+ name?: string;
12
+ extra?: {
13
+ viewId?: string;
14
+ methodName?: string;
15
+ };
16
+ };
17
+ /**
18
+ * 数据筛选
19
+ */
20
+ where?: {
21
+ groupLogic?: null | 'or' | 'and';
22
+ logicData?: {
23
+ keyType?: 'field' | 'var-font';
24
+ key: string;
25
+ rel: 'eq' | 'neq' | 'lt' | 'gt' | 'gte' | 'lte' | 'in' | 'nin' | 'search';
26
+ value: any;
27
+ valueType?: 'const' | 'var-font' | 'relative-amount' | 'field';
28
+ expression?: string | boolean;
29
+ logic?: null | 'or' | 'and' | string;
30
+ extra?: {
31
+ type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | string;
32
+ format?: string | null;
33
+ isExpression?: boolean;
34
+ };
35
+ }[];
36
+ }[];
37
+ /**
38
+ * 容器事件
39
+ */
40
+ events?: {
41
+ queryEmpty?: any;
42
+ querySuccess?: any;
43
+ queryFail?: any;
44
+ onDataChange?: (param: any) => any;
45
+ };
46
+ /**
47
+ * 类
48
+ */
49
+ className?: string;
50
+ /**
51
+ * app.cloud 对象依赖,默认会从 window.app 取值
52
+ */
53
+ appCloud?: { callDataSource?: any; isInIde?: any };
54
+ /**
55
+ * 子元素
56
+ */
57
+ children?: React.ReactNode | undefined;
58
+ /**
59
+ * 其他属性
60
+ */
61
+ [key: string]: any;
62
+ }
63
+
64
+ /**
65
+ * 数据容器-列表视图
66
+ */
67
+ export interface IListView extends IDataContainer {
68
+ /**
69
+ * 数据字段
70
+ */
71
+ orderBy?: string;
72
+ /**
73
+ * 数据类型
74
+ */
75
+ orderType?: 'desc' | 'asc';
76
+ /**
77
+ * 模板
78
+ */
79
+ template?:
80
+ | 'simpleList'
81
+ | 'detailList'
82
+ | 'imageTextList'
83
+ | 'cardList'
84
+ | 'none';
85
+ /**
86
+ * 显示行数
87
+ */
88
+ pageSize?: number;
89
+ /**
90
+ * 分页类型,加载更多|底部刷新|分页器
91
+ */
92
+ pagination?: 'loadMoreButton' | 'bottomLoad' | 'pagination' | 'none';
93
+
94
+ /**
95
+ * 调用 onDataChange 之前的数据转换,如列表视图需要接受 array,而数据视图需要接受 object
96
+ */
97
+ beforeDataChange?: (param: any) => any;
98
+ }