@cloudbase/weda-ui 3.1.2 → 3.1.6

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 (33) hide show
  1. package/dist/configs/components/carousel.json +2 -2
  2. package/dist/configs/components/form/checkbox.json +1 -0
  3. package/dist/configs/components/form/form.json +39 -15
  4. package/dist/configs/components/form/richText.json +17 -9
  5. package/dist/configs/components/form/select.json +1 -0
  6. package/dist/web/components/chart/common/core/eChartBar.js +3 -1
  7. package/dist/web/components/chart/common/core/eChartLine.js +3 -1
  8. package/dist/web/components/form/checkbox/index.js +1 -1
  9. package/dist/web/components/form/form/index.css +4 -0
  10. package/dist/web/components/form/form/index.d.ts +21 -2
  11. package/dist/web/components/form/form/index.js +90 -16
  12. package/dist/web/components/form/location/common/mapChoose.js +93 -35
  13. package/dist/web/components/form/select/dropdown-select/ui.d.ts +15 -0
  14. package/dist/web/components/form/select/dropdown-select/ui.js +55 -0
  15. package/dist/web/components/form/select/h5.d.ts +1 -1
  16. package/dist/web/components/form/select/h5.js +54 -152
  17. package/dist/web/components/form/select/index.d.ts +1 -1
  18. package/dist/web/components/form/select/index.js +33 -96
  19. package/dist/web/components/form/select/use-options.d.ts +26 -0
  20. package/dist/web/components/form/select/use-options.js +103 -0
  21. package/dist/web/components/form/uploader/index.css +10 -3
  22. package/dist/web/components/form/uploader/uploader.h5.d.ts +1 -1
  23. package/dist/web/components/form/uploader/uploader.h5.js +18 -19
  24. package/dist/web/components/form/uploader/uploader.pc.js +6 -3
  25. package/dist/web/components/richText/index.css +20 -6
  26. package/dist/web/components/richText/index.d.ts +2 -3
  27. package/dist/web/components/richText/index.js +121 -67
  28. package/dist/web/components/richText/richtext.module.css +5 -0
  29. package/dist/web/utils/tcb.d.ts +5 -1
  30. package/dist/web/utils/tcb.js +26 -3
  31. package/dist/web/utils/use-cloud-id-temp-url.d.ts +1 -0
  32. package/dist/web/utils/use-cloud-id-temp-url.js +13 -0
  33. package/package.json +41 -37
@@ -83,7 +83,7 @@
83
83
  "properties": {
84
84
  "title": {
85
85
  "type": "string",
86
- "title": "图片标题",
86
+ "title": "标题",
87
87
  "default": "图片1",
88
88
  "x-index": 20
89
89
  },
@@ -95,7 +95,7 @@
95
95
  "pattern": "^(((https?)://)|/resources/)[^\\s]+$"
96
96
  }
97
97
  ],
98
- "title": "图片1",
98
+ "title": "图片",
99
99
  "default": "https://main.qcloudimg.com/raw/828ee6644f137d166b063ad7f5dda842.png",
100
100
  "x-index": 30
101
101
  },
@@ -34,6 +34,7 @@
34
34
  "target": "range",
35
35
  "schema": {
36
36
  "items": {
37
+ "path": "range.*",
37
38
  "type": "object",
38
39
  "display": "label",
39
40
  "properties": {
@@ -2,24 +2,44 @@
2
2
  "$schema": "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/schema/lcds_component.json",
3
3
  "data": {
4
4
  "properties": {
5
+ "formType": {
6
+ "type": "string",
7
+ "title": "表单场景",
8
+ "default": "create"
9
+ },
10
+ "datasourceType": {
11
+ "type": "string",
12
+ "title": "数据源类型",
13
+ "default": "model"
14
+ },
15
+ "dataSourceName": {
16
+ "type": "string",
17
+ "title": "数据模型"
18
+ },
19
+ "_id": {
20
+ "type": "string",
21
+ "title": "数据标识(_id)"
22
+ },
23
+ "methodCreate": {
24
+ "type": "string",
25
+ "title": "新增方法"
26
+ },
27
+ "methodGetItem": {
28
+ "type": "string",
29
+ "title": "查询方法"
30
+ },
31
+ "paramGetItem": {
32
+ "type": "object",
33
+ "title": "查询入参"
34
+ },
35
+ "methodUpdate": {
36
+ "type": "string",
37
+ "title": "更新方法"
38
+ },
5
39
  "layout": {
6
- "x-platforms": ["PCWEB"],
7
- "enum": [
8
- {
9
- "label": "水平",
10
- "value": "horizontal"
11
- },
12
- {
13
- "label": "垂直",
14
- "value": "vertical"
15
- }
16
- ],
17
40
  "type": "string",
18
41
  "title": "布局方式",
19
- "default": "horizontal",
20
- "x-index": 50,
21
- "x-category": "基础属性",
22
- "remarks": "设置当前容器内表单类组件的标题和输入选择区域为左右布局或上下布局"
42
+ "default": "horizontal"
23
43
  },
24
44
  "contentSlot": {
25
45
  "type": "slot",
@@ -35,6 +55,10 @@
35
55
  {
36
56
  "name": "reset",
37
57
  "title": "重置"
58
+ },
59
+ {
60
+ "name": "onInitValue",
61
+ "title": "获取初始值"
38
62
  }
39
63
  ],
40
64
  "meta": {
@@ -7,21 +7,21 @@
7
7
  "default": "标题",
8
8
  "title": "标题",
9
9
  "x-category": "基础属性",
10
- "x-index": 1
10
+ "x-index": 10
11
11
  },
12
12
  "labelVisible": {
13
13
  "type": "boolean",
14
14
  "default": true,
15
15
  "title": "是否显示标题",
16
16
  "x-category": "基础属性",
17
- "x-index": 2
17
+ "x-index": 20
18
18
  },
19
19
  "requiredFlag": {
20
20
  "type": "boolean",
21
21
  "default": false,
22
22
  "title": "是否显示必填标记",
23
23
  "x-category": "基础属性",
24
- "x-index": 3
24
+ "x-index": 30
25
25
  },
26
26
  "layout": {
27
27
  "title": "布局方式",
@@ -38,35 +38,42 @@
38
38
  }
39
39
  ],
40
40
  "x-category": "基础属性",
41
- "x-index": 4
41
+ "x-index": 40
42
42
  },
43
43
  "name": {
44
44
  "type": "string",
45
45
  "default": "formRichText",
46
46
  "title": "提交后台所用字段",
47
47
  "x-category": "基础属性",
48
- "x-index": 5
48
+ "x-index": 50
49
49
  },
50
50
  "value": {
51
51
  "type": "string",
52
52
  "default": "",
53
53
  "title": "初始值",
54
54
  "x-category": "基础属性",
55
- "x-index": 6
55
+ "x-index": 60
56
56
  },
57
57
  "readOnly": {
58
58
  "type": "boolean",
59
59
  "default": false,
60
60
  "title": "是否只读",
61
61
  "x-category": "基础属性",
62
- "x-index": 7
62
+ "display": false,
63
+ "x-index": 70
64
+ },
65
+ "disabled": {
66
+ "type": "boolean",
67
+ "title": "禁用",
68
+ "default": false,
69
+ "x-index": 75
63
70
  },
64
71
  "maxSize": {
65
72
  "type": "number",
66
73
  "default": 10,
67
74
  "title": "单张图片最大(M)",
68
75
  "x-category": "基础属性",
69
- "x-index": 8
76
+ "x-index": 80
70
77
  },
71
78
  "acceptTypes": {
72
79
  "type": "array",
@@ -105,8 +112,9 @@
105
112
  }
106
113
  ]
107
114
  },
115
+ "display": false,
108
116
  "x-category": "基础属性",
109
- "x-index": 9
117
+ "x-index": 90
110
118
  }
111
119
  }
112
120
  },
@@ -341,6 +341,7 @@
341
341
  "target": "range",
342
342
  "schema": {
343
343
  "items": {
344
+ "path": "range.*",
344
345
  "display": "label",
345
346
  "type": "object",
346
347
  "properties": {
@@ -43,7 +43,9 @@ class EchartBar extends EchartBase {
43
43
  data: [],
44
44
  };
45
45
  sortedXAxisData.forEach((itemSource, index) => {
46
- this.config.series[j].name = itemSource.YLabels[j].Cn_Name;
46
+ var _a, _b;
47
+ this.config.series[j].name =
48
+ (_b = (_a = itemSource.YLabels[j]) === null || _a === void 0 ? void 0 : _a.Cn_Name) !== null && _b !== void 0 ? _b : itemSource.YLabels[j].Name;
47
49
  if ((itemSource.YLabels[j].Value === undefined ||
48
50
  itemSource.YLabels[j].Value === null) &&
49
51
  !xIsCountEmpty) {
@@ -43,7 +43,9 @@ class EchartLine extends EchartBase {
43
43
  data: [],
44
44
  };
45
45
  sortedXAxisData.forEach((itemSource, index) => {
46
- this.config.series[j].name = itemSource.YLabels[j].Cn_Name;
46
+ var _a, _b;
47
+ this.config.series[j].name =
48
+ (_b = (_a = itemSource.YLabels[j]) === null || _a === void 0 ? void 0 : _a.Cn_Name) !== null && _b !== void 0 ? _b : itemSource.YLabels[j].Name;
47
49
  if ((itemSource.YLabels[j].Value === undefined ||
48
50
  itemSource.YLabels[j].Value === null) &&
49
51
  !xIsCountEmpty) {
@@ -35,7 +35,7 @@ name = 'formCheckbox', label = '标题', labelVisible = true, format = '', enumN
35
35
  // 两次range不同时, 需要刷新checkedItems
36
36
  const prevRangeRef = React.useRef();
37
37
  React.useEffect(() => {
38
- if (!isObjectEqual(prevRangeRef.current, option)) {
38
+ if (!isObjectEqual(prevRangeRef.current, option, true)) {
39
39
  prevRangeRef.current = JSON.parse(JSON.stringify(option));
40
40
  setCheckedItems(fromEntries(option.map(({ value, checked }) => [value, !!checked])));
41
41
  }
@@ -7,3 +7,7 @@
7
7
  padding-left: 1.71429rem;
8
8
  padding-right: 1.71429rem;
9
9
  }
10
+
11
+ .weda-form-toast .weui-icon_toast {
12
+ display: none !important;
13
+ }
@@ -1,13 +1,32 @@
1
1
  /// <reference types="react" />
2
- import './index.css';
3
2
  import type { CommonFormPropsType } from '../types';
4
- export default function Form({ className, contentSlot, style, id, layout, }: {
3
+ import './index.css';
4
+ /**
5
+ * 表单容器组件
6
+ */
7
+ export default function Form({ className, contentSlot, style, id, layout, formType, datasourceType, dataSourceName, _id, methodGetItem, paramGetItem, events, appCloud, }: {
5
8
  className: any;
6
9
  contentSlot: any;
7
10
  style: any;
8
11
  id: any;
9
12
  layout: any;
13
+ formType: any;
14
+ datasourceType: any;
15
+ dataSourceName: any;
16
+ _id: any;
17
+ methodGetItem: any;
18
+ paramGetItem: any;
19
+ events: any;
20
+ appCloud?: any;
10
21
  }): JSX.Element;
11
22
  export interface PropsType extends CommonFormPropsType {
12
23
  contentSlot?: any;
24
+ formType?: string;
25
+ datasourceType?: string;
26
+ dataSourceName?: string;
27
+ _id?: string;
28
+ methodCreate?: string;
29
+ methodGetItem?: string;
30
+ paramGetItem?: any;
31
+ methodUpdate?: string;
13
32
  }
@@ -1,19 +1,16 @@
1
1
  import * as React from 'react';
2
2
  import classNames from '../../../utils/classnames';
3
+ import { ConfigProvider, Form as TeaForm, message as TeaMessage, } from 'tea-component';
4
+ import { usePlatform, isInIde } from '../../../utils/platform';
5
+ import { callDataSource, callConnector } from '../../../utils/tcb';
6
+ import weui from '../../../utils/weui';
3
7
  import './index.css';
4
- import { ConfigProvider, Form as TeaForm } from 'tea-component';
5
- import { usePlatform } from '../../../utils/platform';
6
- export default function Form({
7
- // 系统属性
8
- className,
9
- // 组件属性
10
- // title,
11
- // description,
12
- // tips,
13
- contentSlot,
14
- // buttonSlot,
15
- style, id, layout, }) {
16
- const platform = usePlatform();
8
+ /**
9
+ * 表单容器组件
10
+ */
11
+ export default function Form({ className, contentSlot, style, id, layout, formType, datasourceType, dataSourceName, _id, methodGetItem, paramGetItem, events, appCloud = { callDataSource, callConnector }, }) {
12
+ const platform = usePlatform(); // h5 | web
13
+ const isDataModel = !['connector', 'custom-connector'].includes(datasourceType); // 是否为数据模型,兼容历史 undefined
17
14
  const cls = classNames({
18
15
  'weda-ui': true,
19
16
  'weda-form': true,
@@ -22,10 +19,87 @@ style, id, layout, }) {
22
19
  'gsd-h5-react-form-pc': platform === 'pc',
23
20
  [className]: className,
24
21
  });
25
- if (platform === 'pc') {
22
+ const timeRef = React.useRef(null);
23
+ React.useEffect(() => {
24
+ const getData = async () => {
25
+ var _a, _b;
26
+ try {
27
+ let initValue = {};
28
+ if (isDataModel) {
29
+ // 数据模型查询条件
30
+ if (formType === 'edit' && dataSourceName) {
31
+ initValue = await appCloud.callDataSource({
32
+ dataSourceName,
33
+ methodName: 'wedaGetItem',
34
+ params: { _id },
35
+ }, true);
36
+ if (Object.keys(initValue).length !== 0) {
37
+ (_a = events === null || events === void 0 ? void 0 : events.onInitValue) === null || _a === void 0 ? void 0 : _a.call(events, initValue);
38
+ }
39
+ else {
40
+ alertError(platform);
41
+ }
42
+ }
43
+ }
44
+ else {
45
+ // 连接器查询条件
46
+ if (formType === 'edit' &&
47
+ dataSourceName &&
48
+ methodGetItem &&
49
+ paramGetItem) {
50
+ initValue = await appCloud.callConnector({
51
+ dataSourceName,
52
+ methodName: methodGetItem,
53
+ params: paramGetItem,
54
+ }, true);
55
+ if (Object.keys(initValue).length !== 0) {
56
+ (_b = events === null || events === void 0 ? void 0 : events.onInitValue) === null || _b === void 0 ? void 0 : _b.call(events, initValue);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ catch (e) {
62
+ alertError(platform);
63
+ }
64
+ };
65
+ if (dataSourceName && formType === 'edit') {
66
+ if ((isDataModel && _id) ||
67
+ (!isDataModel && paramGetItem && methodGetItem)) {
68
+ clearTimeout(timeRef.current);
69
+ timeRef.current = setTimeout(() => getData(), 100);
70
+ }
71
+ }
72
+ }, [
73
+ formType,
74
+ isDataModel,
75
+ dataSourceName,
76
+ _id,
77
+ platform,
78
+ methodGetItem,
79
+ paramGetItem,
80
+ ]);
81
+ // pc 渲染
82
+ const renderPc = () => {
26
83
  return (React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
27
84
  React.createElement(TeaForm, { layout: layout, className: cls, style: style, id: id }, contentSlot)));
85
+ };
86
+ // h5 渲染
87
+ const renderH5 = () => {
88
+ return (React.createElement("div", { className: cls, style: style, id: id },
89
+ React.createElement("div", { className: "weui-cells__group weui-cells__group_form" }, contentSlot)));
90
+ };
91
+ return platform === 'pc' ? renderPc() : renderH5();
92
+ }
93
+ /**
94
+ * 根据平台不同,展示不同的错误提示消息
95
+ */
96
+ function alertError(platform = 'h5', message = '更新场景下未查询到数据') {
97
+ if (isInIde())
98
+ return;
99
+ if (platform === 'h5') {
100
+ weui.toast(message, { className: 'weda-form-toast' });
101
+ }
102
+ else {
103
+ TeaMessage.error({ content: message });
28
104
  }
29
- return (React.createElement("div", { className: cls, style: style, id: id },
30
- React.createElement("div", { className: "weui-cells__group weui-cells__group_form" }, contentSlot)));
31
105
  }
@@ -123,9 +123,7 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
123
123
  ],
124
124
  });
125
125
  // 监听中心点变化事件,更新marker的位置
126
- map.on('center_changed', updateCenter);
127
- map.on('drag', clearChooseLoc);
128
- map.on('zoom', clearChooseLoc);
126
+ map.on('drag', mapDrag);
129
127
  }
130
128
  };
131
129
  const initCircle = (TMap, map) => {
@@ -153,23 +151,14 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
153
151
  new TMap.MultiCircle(circle);
154
152
  }
155
153
  };
156
- const clearChooseLoc = () => {
157
- setChooseLoc({});
158
- };
159
- const updateCenter = () => {
154
+ const mapDrag = () => {
160
155
  const TMap = getTMap();
161
156
  const canLoad = TMap && lat && lng && mapRef.current;
162
157
  if (canLoad) {
163
158
  const currentLocationsLatlng = currentLocations.latlng;
164
- const nowPosition = new TMap.LatLng(currentLocationsLatlng.lat, currentLocationsLatlng.lng);
165
159
  let centerPosition = mapRef.current.getCenter();
166
160
  centerRef.current = centerPosition;
167
161
  markerRef.current.updateGeometries([
168
- {
169
- id: `pointer-origin-${mapDomName}`,
170
- styleId: 'originPointer',
171
- position: nowPosition,
172
- },
173
162
  {
174
163
  id: `pointer-${mapDomName}`,
175
164
  styleId: 'pointer',
@@ -178,21 +167,27 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
178
167
  ]);
179
168
  exploreNear('updateCenter');
180
169
  // 计算距离
181
- if (getRadius()) {
182
- let latlng1 = {
183
- latitude: currentLocationsLatlng.lat,
184
- longitude: currentLocationsLatlng.lng,
185
- };
186
- let latlng2 = {
187
- latitude: centerPosition.getLat(),
188
- longitude: centerPosition.getLng(),
189
- };
190
- const distance = calculateDistance(latlng1, latlng2);
191
- let isOutof = getRadius() && getRadius() < distance;
192
- setIsOutofrange(isOutof);
193
- if (!isPC) {
194
- changeSearchBoxHeight(false, isOutof);
195
- }
170
+ compareDistance(currentLocationsLatlng, {
171
+ lat: centerPosition.getLat(),
172
+ lng: centerPosition.getLng(),
173
+ });
174
+ }
175
+ };
176
+ const compareDistance = (currentLocation, centerPosition) => {
177
+ if (getRadius()) {
178
+ let latlng1 = {
179
+ latitude: currentLocation.lat,
180
+ longitude: currentLocation.lng,
181
+ };
182
+ let latlng2 = {
183
+ latitude: centerPosition.lat,
184
+ longitude: centerPosition.lng,
185
+ };
186
+ const distance = calculateDistance(latlng1, latlng2);
187
+ let isOutof = getRadius() && getRadius() < distance;
188
+ setIsOutofrange(isOutof);
189
+ if (!isPC) {
190
+ changeSearchBoxHeight(false, isOutof, true);
196
191
  }
197
192
  }
198
193
  };
@@ -221,23 +216,88 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
221
216
  let list = [...exploreList, ...res.data];
222
217
  if (searchListPageSize.current === 1) {
223
218
  list = res.data;
219
+ setRealLocation({ lat, lng }, list);
220
+ }
221
+ else {
222
+ setExploreList(list);
224
223
  }
225
- setExploreList(list);
224
+ }
225
+ else {
226
+ setRealLocation({ lat, lng }, []);
226
227
  }
227
228
  })
228
229
  .catch((error) => {
229
230
  setSearchLoadingStatus(false);
231
+ setRealLocation({ lat, lng }, []);
230
232
  console.log('explore error', error);
231
233
  });
232
234
  }, 500);
235
+ // 逆解析查询当前经纬度地址
236
+ const setRealLocation = (location, list) => {
237
+ const { lat, lng } = location;
238
+ let TMap = getTMap();
239
+ const Geocoder = new TMap.service.Geocoder();
240
+ Geocoder.getAddress({
241
+ location: new TMap.LatLng(lat, lng),
242
+ })
243
+ .then(({ status, result }) => {
244
+ var _a;
245
+ if (status == 0) {
246
+ let address = result.address;
247
+ let title = (_a = result === null || result === void 0 ? void 0 : result.formatted_addresses) === null || _a === void 0 ? void 0 : _a.recommend;
248
+ let item = {
249
+ id: 'current-location',
250
+ location: {
251
+ lat,
252
+ lng,
253
+ },
254
+ title: title ? title : address,
255
+ address,
256
+ };
257
+ setChooseLoc(item);
258
+ changeLocation(item);
259
+ setExploreList([item, ...list]);
260
+ }
261
+ })
262
+ .catch((error) => {
263
+ console.log('getAddress error', error);
264
+ let item = {
265
+ id: 'current-location',
266
+ location: {
267
+ lat,
268
+ lng,
269
+ },
270
+ title: '[位置]',
271
+ address: '暂无地址信息',
272
+ };
273
+ setChooseLoc(item);
274
+ changeLocation(item);
275
+ setExploreList([item]);
276
+ });
277
+ };
233
278
  const chooseLoction = (value, type) => {
234
279
  const TMap = getTMap();
235
280
  //定义地图中心点坐标
236
281
  const center = new TMap.LatLng(value.location.lat, value.location.lng);
237
282
  mapRef.current.setCenter(center);
283
+ markerRef.current.updateGeometries([
284
+ {
285
+ id: `pointer-${mapDomName}`,
286
+ styleId: 'pointer',
287
+ position: center,
288
+ },
289
+ ]);
238
290
  setChooseLoc(value);
239
291
  changeLocation(value);
240
- type && cancleSearch();
292
+ if (type) {
293
+ setExploreList([]);
294
+ cancleSearch();
295
+ mapDrag();
296
+ }
297
+ else {
298
+ const currentLocationsLatlng = currentLocations.latlng;
299
+ compareDistance(currentLocationsLatlng, value.location);
300
+ }
241
301
  };
242
302
  const changeSearchValue = (event) => {
243
303
  if (event.target.value) {
@@ -288,12 +348,9 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
288
348
  document.getElementsByClassName('map-choose-header_search_input')[0].blur();
289
349
  touchCoordinate.current.startY = event.changedTouches[0].clientY;
290
350
  };
291
- const changeSearchBoxHeight = (status, currentOutofrange) => {
351
+ const changeSearchBoxHeight = (status, currentOutofrange, isInDrag) => {
292
352
  // 搜索区域默认 328px ,上拉 75% ,当超出范围多一个超出提示 46px
293
- let isOut = isOutofrange;
294
- if (currentOutofrange) {
295
- isOut = currentOutofrange;
296
- }
353
+ let isOut = isInDrag ? currentOutofrange : isOutofrange;
297
354
  const boxHeight = Math.ceil(clientHeight * 0.75);
298
355
  let searchBoxHeights = isOut ? 328 - 46 : 328;
299
356
  if (status) {
@@ -404,6 +461,7 @@ export default function MapChoose({ changeLocation, onConfirm, onClose, currentL
404
461
  mapRef.current.setCenter(nowPosition);
405
462
  searchListPageSize.current = 1;
406
463
  setChooseLoc({});
464
+ mapDrag();
407
465
  }
408
466
  };
409
467
  const getConfirm = () => {
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { SelectProps } from 'tea-component';
3
+ interface IPureSelectProps extends Pick<SelectProps, 'size' | 'disabled' | 'value' | 'placeholder'> {
4
+ name?: string;
5
+ options: {
6
+ label: string;
7
+ value: string;
8
+ }[];
9
+ onChange: (v: string) => void;
10
+ layout?: 'horizontal' | 'vertical';
11
+ className?: string;
12
+ }
13
+ export declare function PureSelectPc(props: IPureSelectProps): JSX.Element;
14
+ export declare function PureSelectH5(props: IPureSelectProps): JSX.Element;
15
+ export {};
@@ -0,0 +1,55 @@
1
+ import React, { useMemo } from 'react';
2
+ import { ConfigProvider, Select as TeaSelect, } from 'tea-component';
3
+ import classNames from '../../../../utils/classnames';
4
+ import { noop } from '../../../../utils/constant';
5
+ import { useSyncValue } from '../../../../utils/useSyncValue';
6
+ import weui from '../../../../utils/weui';
7
+ export function PureSelectPc(props) {
8
+ const { size, onChange = noop, disabled, placeholder } = props;
9
+ const [value, setValue] = useSyncValue(props.value);
10
+ const options = useMemo(() => {
11
+ var _a;
12
+ return ((_a = props.options) !== null && _a !== void 0 ? _a : []).map((opt) => ({
13
+ text: opt.label,
14
+ value: opt.value,
15
+ }));
16
+ }, [props.options]);
17
+ return (React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
18
+ React.createElement("div", { "data-testid": "form-select" },
19
+ React.createElement(TeaSelect, { matchButtonWidth: true, size: size, onChange: (v) => {
20
+ onChange(v);
21
+ setValue(v);
22
+ }, disabled: disabled, value: value, type: "simulate", appearance: "button", placeholder: placeholder, options: options }))));
23
+ }
24
+ export function PureSelectH5(props) {
25
+ const { placeholder, name, disabled, onChange = noop, options, layout, className, } = props;
26
+ const [value, setValue] = useSyncValue(props.value);
27
+ const subCls = classNames({
28
+ 'weui-cell': true,
29
+ 'weui-cell_active': true,
30
+ 'weui-cell_form': true,
31
+ 'weui-flex__item': layout !== 'vertical',
32
+ 'weui-cell_disabled': disabled,
33
+ });
34
+ const onClick = () => {
35
+ weui.picker(options, {
36
+ id: String(Date.now()),
37
+ defaultValue: [value || options[0].value],
38
+ onConfirm(result) {
39
+ const item = result[0];
40
+ setValue(item.value);
41
+ onChange(item.value);
42
+ },
43
+ className,
44
+ });
45
+ };
46
+ const currentLabel = useMemo(() => {
47
+ const currentOpt = options.find((opt) => opt.value === value);
48
+ if (!currentOpt)
49
+ return '';
50
+ return currentOpt.label;
51
+ }, [options, value]);
52
+ return (React.createElement("div", { className: subCls },
53
+ React.createElement("div", { className: "weui-cell__bd weui-flex" },
54
+ React.createElement("input", { onClick: onClick, className: "weui-input", type: "select", name: name, placeholder: placeholder, value: currentLabel, disabled: disabled, autoComplete: 'off', readOnly: true, "data-testid": "form-item-select" }))));
55
+ }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { PropsType } from './index';
3
- export default function Select({ events, name, placeholder, layout, mode, dateMode, disabled, range, where, primaryField, tipBlock, enumName, dataSourceName, viewId, format, defaultValue, startDate, endDate, defaultDate, startTime, endTime, defaultTime, defaultRegion, defaultMutiRegion, regionType, separator, onChange, }: PropsType): JSX.Element;
3
+ export default function Select({ events, name, placeholder, layout, mode, dateMode, disabled, range, where, primaryField, enumName, dataSourceName, viewId, format, defaultValue, startDate, endDate, defaultDate, startTime, endTime, defaultTime, defaultRegion, defaultMutiRegion, separator, regionType, onChange, }: PropsType): JSX.Element;
4
4
  export declare function decodeIsoDatetime(isoStringOrTimesnap: any, type: any, dateMode?: string): any;
5
5
  /**
6
6
  * 根据时间模式,构造 new Date()的传参格式单个日期和时间组件值