@cloudbase/weda-ui 3.14.2 → 3.15.0

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 (49) hide show
  1. package/dist/configs/components/listView.d.ts +11 -0
  2. package/dist/configs/components/listView.js +53 -0
  3. package/dist/configs/components/wd-select-multiple.d.ts +72 -28
  4. package/dist/configs/components/wd-select-multiple.js +233 -19
  5. package/dist/configs/components/wd-select.d.ts +70 -29
  6. package/dist/configs/components/wd-select.js +211 -17
  7. package/dist/configs/index.d.ts +174 -60
  8. package/dist/configs/type-utils/type-form.js +65 -21
  9. package/dist/configs/type-utils/x-runtime-default.d.ts +2 -0
  10. package/dist/configs/type-utils/x-runtime-default.js +4 -0
  11. package/dist/style/index.css +15 -0
  12. package/dist/style/index.scss +1 -1
  13. package/dist/style/weda-ui.min.css +3 -3
  14. package/dist/web/components/form/uploader/uploader.h5.js +9 -10
  15. package/dist/web/components/form/uploader/uploader.pc.js +7 -7
  16. package/dist/web/components/form/uploader/util.js +7 -12
  17. package/dist/web/components/form/uploaderFile/uploadFile.h5.js +29 -37
  18. package/dist/web/components/form/uploaderFile/uploadFile.pc.js +15 -22
  19. package/dist/web/components/listView/index.css +4 -2
  20. package/dist/web/components/listView/index.js +25 -43
  21. package/dist/web/components/richText/index.js +13 -15
  22. package/dist/web/components/statusContent/index.js +1 -1
  23. package/dist/web/components/wd-input/wd-input.js +16 -20
  24. package/dist/web/components/wd-select/contexts/selectContext.d.ts +15 -0
  25. package/dist/web/components/wd-select/contexts/selectContext.js +13 -0
  26. package/dist/web/components/wd-select/hooks/useChooseList.d.ts +19 -0
  27. package/dist/web/components/wd-select/hooks/useChooseList.js +94 -0
  28. package/dist/web/components/wd-select/relationSelect/enumSelect.d.ts +2 -0
  29. package/dist/web/components/wd-select/relationSelect/enumSelect.js +48 -0
  30. package/dist/web/components/wd-select/relationSelect/index.d.ts +2 -0
  31. package/dist/web/components/wd-select/relationSelect/index.js +19 -0
  32. package/dist/web/components/wd-select/relationSelect/queryParams.d.ts +15 -0
  33. package/dist/web/components/wd-select/relationSelect/queryParams.js +15 -0
  34. package/dist/web/components/wd-select/relationSelect/relationSelect.d.ts +0 -2
  35. package/dist/web/components/wd-select/relationSelect/relationSelect.js +39 -83
  36. package/dist/web/components/wd-select/select/index.js +1 -1
  37. package/dist/web/components/wd-select/wd-select.css +8 -0
  38. package/dist/web/components/wd-select/wd-select.js +11 -8
  39. package/dist/web/components/wd-select-multiple/wd-select-multiple.js +11 -8
  40. package/dist/web/components/wd-table/components/FieldRender/index.js +3 -3
  41. package/dist/web/components/wd-table/components/FilterFieldsPanel/filterFieldsGenerate.js +8 -13
  42. package/dist/web/components/wd-table/components/deleteModal.d.ts +1 -1
  43. package/dist/web/components/wd-table/components/deleteModal.js +47 -30
  44. package/dist/web/utils/getModelParams.d.ts +6 -1
  45. package/dist/web/utils/getModelParams.js +16 -13
  46. package/dist/web/utils/platform.js +9 -13
  47. package/dist/web/utils/tcb.d.ts +4 -0
  48. package/dist/web/utils/tcb.js +11 -9
  49. package/package.json +3 -3
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useState, useEffect, useRef, useCallback, useMemo, } from 'react';
2
+ import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
3
3
  import { callDataSource } from '../../utils/tcb';
4
- import { isInIde, alertErrorMessage, usePlatform, getParseValue, textToString, } from '../../utils/platform';
4
+ import { isInIde, alertErrorMessage, usePlatform, getParseValue, textToString } from '../../utils/platform';
5
+ import { useConfig } from '../../utils/config-context';
5
6
  import classNames from '../../utils/classnames';
6
7
  import isequal from 'lodash.isequal';
7
8
  import './style';
@@ -51,22 +52,27 @@ export default React.forwardRef(function ListView(props, ref) {
51
52
  appCloud = defaultCloudbase, beforeDataChange = defaultBeforeDataChange, refType = 'listView', loadButtonText, selectFieldType = 'main', // 查询字段范围类型
52
53
  ...rest } = props;
53
54
  const platform = usePlatform();
55
+ const { classPrefix } = useConfig();
54
56
  const isH5 = platform === 'h5';
57
+ // listView 组件的 class
58
+ const classList = {
59
+ 'weda-ui': true,
60
+ [`${classPrefix}-list-view`]: true,
61
+ [`${BLOCK_NAME}__container`]: true,
62
+ // 响应式css api
63
+ [`${classPrefix}-${platform}-list-view`]: true,
64
+ };
55
65
  const isSetStatus = dataSourceType !== 'expression' ? rawIsSetStatus : false;
56
66
  const isSetLoading = dataSourceType !== 'expression' ? rawIsSetLoading : true;
57
67
  const connectorParams = getParseValue(rawConnectorParams);
58
68
  const dataSourceData = getParseValue(rawDataSourceData);
59
- const methodName = getStringValue(dataSourceType === 'data-model'
60
- ? ((_a = datasource === null || datasource === void 0 ? void 0 : datasource.extra) === null || _a === void 0 ? void 0 : _a.methodName) || 'wedaGetRecords'
61
- : connectorMethod === null || connectorMethod === void 0 ? void 0 : connectorMethod.name);
69
+ const methodName = getStringValue(dataSourceType === 'data-model' ? ((_a = datasource === null || datasource === void 0 ? void 0 : datasource.extra) === null || _a === void 0 ? void 0 : _a.methodName) || 'wedaGetRecords' : connectorMethod === null || connectorMethod === void 0 ? void 0 : connectorMethod.name);
62
70
  const isV2protocol = methodName === 'wedaGetRecordsV2';
63
71
  const modelParams = getModelParams({
64
72
  ...props,
65
73
  supportManyRelated: isV2protocol,
66
74
  }); // 包括 where 和 order
67
- const dataSourceName = getStringValue(dataSourceType === 'data-model'
68
- ? datasource === null || datasource === void 0 ? void 0 : datasource.name
69
- : (_b = bindConnectMetadata === null || bindConnectMetadata === void 0 ? void 0 : bindConnectMetadata.datasource) === null || _b === void 0 ? void 0 : _b.name);
75
+ const dataSourceName = getStringValue(dataSourceType === 'data-model' ? datasource === null || datasource === void 0 ? void 0 : datasource.name : (_b = bindConnectMetadata === null || bindConnectMetadata === void 0 ? void 0 : bindConnectMetadata.datasource) === null || _b === void 0 ? void 0 : _b.name);
70
76
  useLoopRenderDetect({ limit: 600 });
71
77
  const [entry, setEntry] = useState(null); // 触底的observer对象
72
78
  const [_status, setStatus] = useState(''); // 查询状态
@@ -95,9 +101,7 @@ export default React.forwardRef(function ListView(props, ref) {
95
101
  initExpr: false,
96
102
  }); // 请求防抖、异步时使用最后一次请求
97
103
  const isIdeMockData = !(dataSourceName && methodName) && ((_c = appCloud === null || appCloud === void 0 ? void 0 : appCloud.isInIde) === null || _c === void 0 ? void 0 : _c.call(appCloud)); // 在ide环境且未绑定数据源时,存在mock数据逻辑
98
- const shouldBottomLoad = pagination === 'bottomLoad' &&
99
- (entry === null || entry === void 0 ? void 0 : entry.isIntersecting) &&
100
- ['', 'success'].includes(status); // 能否触底加载
104
+ const shouldBottomLoad = pagination === 'bottomLoad' && (entry === null || entry === void 0 ? void 0 : entry.isIntersecting) && ['', 'success'].includes(status); // 能否触底加载
101
105
  // 返回的错误信息
102
106
  const [err, setErr] = useState({
103
107
  code: '',
@@ -267,9 +271,7 @@ export default React.forwardRef(function ListView(props, ref) {
267
271
  clearTimeout(delayRef.current.statusTimer);
268
272
  delayRef.current.statusTimer = null;
269
273
  }
270
- delayRef.current.statusTimer = window.setTimeout(statusCb, pagination === 'bottomLoad' && dataSourceType === 'expression'
271
- ? 3000
272
- : 150);
274
+ delayRef.current.statusTimer = window.setTimeout(statusCb, pagination === 'bottomLoad' && dataSourceType === 'expression' ? 3000 : 150);
273
275
  }
274
276
  else {
275
277
  statusCb();
@@ -298,11 +300,7 @@ export default React.forwardRef(function ListView(props, ref) {
298
300
  var _a, _b, _c;
299
301
  setStatus('fail');
300
302
  const obj = {
301
- code: (e === null || e === void 0 ? void 0 : e.code)
302
- ? e === null || e === void 0 ? void 0 : e.code
303
- : refType === 'dataView'
304
- ? 'WdDataView.QueryError'
305
- : 'WdListView.QueryError',
303
+ code: (e === null || e === void 0 ? void 0 : e.code) ? e === null || e === void 0 ? void 0 : e.code : refType === 'dataView' ? 'WdDataView.QueryError' : 'WdListView.QueryError',
306
304
  message: `${e === null || e === void 0 ? void 0 : e.message}`,
307
305
  requestId: (_b = (_a = e === null || e === void 0 ? void 0 : e.original) === null || _a === void 0 ? void 0 : _a.original) === null || _b === void 0 ? void 0 : _b.requestId,
308
306
  };
@@ -426,11 +424,7 @@ export default React.forwardRef(function ListView(props, ref) {
426
424
  catch (e) {
427
425
  onFailCb(e);
428
426
  throw new WdCompError(`${e === null || e === void 0 ? void 0 : e.message}` || '', {
429
- code: (e === null || e === void 0 ? void 0 : e.code)
430
- ? e === null || e === void 0 ? void 0 : e.code
431
- : refType === 'dataView'
432
- ? 'WdDataView.QueryError'
433
- : 'WdListView.QueryError',
427
+ code: (e === null || e === void 0 ? void 0 : e.code) ? e === null || e === void 0 ? void 0 : e.code : refType === 'dataView' ? 'WdDataView.QueryError' : 'WdListView.QueryError',
434
428
  requestId: (_d = (_c = e === null || e === void 0 ? void 0 : e.original) === null || _c === void 0 ? void 0 : _c.original) === null || _d === void 0 ? void 0 : _d.requestId,
435
429
  original: e === null || e === void 0 ? void 0 : e.original,
436
430
  });
@@ -584,21 +578,12 @@ export default React.forwardRef(function ListView(props, ref) {
584
578
  },
585
579
  error: err,
586
580
  };
587
- }, [
588
- total,
589
- pageNo,
590
- statePageSize,
591
- methodDeleteOne,
592
- methodRefresh,
593
- dataRef.current.records,
594
- err,
595
- isV2protocol,
596
- ], ref);
581
+ }, [total, pageNo, statePageSize, methodDeleteOne, methodRefresh, dataRef.current.records, err, isV2protocol], ref);
597
582
  /**
598
583
  * 分页,加载更多
599
584
  */
600
585
  const renderLoadMore = () => {
601
- const MoreButton = (_jsx("div", { className: `${BLOCK_NAME}__more-text ${isH5 ? 'h5' : ''}`, onClick: () => {
586
+ const MoreButton = (_jsx("div", { className: `${BLOCK_NAME}__more-text ${classPrefix}-list-view__more-text ${isH5 ? 'h5' : ''}`, onClick: () => {
602
587
  var _a, _b;
603
588
  return fetchData({
604
589
  params: { pageNo: ((_b = (_a = paramRef.current) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.pageNo) + 1 },
@@ -614,9 +599,7 @@ export default React.forwardRef(function ListView(props, ref) {
614
599
  * 分页,底部刷新
615
600
  */
616
601
  const renderBottomLoad = () => {
617
- return (_jsx("div", { ref: nodeRefCallback, className: `${BLOCK_NAME}__bottom-load`, children: status === 'loading' && isSetLoading
618
- ? LoadingSymbol
619
- : !hasNextPage() && LoadEnd }));
602
+ return (_jsx("div", { ref: nodeRefCallback, className: `${BLOCK_NAME}__bottom-load`, children: status === 'loading' && isSetLoading ? LoadingSymbol : !hasNextPage() && LoadEnd }));
620
603
  };
621
604
  /**
622
605
  * 分页,分页器,含ideMockData的判断
@@ -635,7 +618,7 @@ export default React.forwardRef(function ListView(props, ref) {
635
618
  const renderStatus = () => {
636
619
  switch (status) {
637
620
  case 'empty':
638
- return (emptyText && (_jsx(EmptyContent, { emptyText: emptyText, component: "listview" })));
621
+ return emptyText && _jsx(EmptyContent, { emptyText: emptyText, component: "listview" });
639
622
  case 'fail':
640
623
  return (isSetStatus && (_jsx(EmptyContent, { emptyText: '数据加载失败', errorObj: err, icon: 'error', isH5: isH5, component: "listview", hasRecord: dataRef.current.records.length > 0 })));
641
624
  case 'loading':
@@ -650,10 +633,9 @@ export default React.forwardRef(function ListView(props, ref) {
650
633
  /**
651
634
  * 加载到底状态组件
652
635
  */
653
- const LoadEnd = status === 'success' && loadCompletedText && (_jsx("div", { className: `${BLOCK_NAME}__load-completed`, children: String(loadCompletedText) }));
654
- return (_jsxs("div", { ...rest, className: classNames('weda-ui', `${BLOCK_NAME}__container`, className), children: [children && (_jsxs("div", { className: classNames(`${BLOCK_NAME}__content`, {
636
+ const LoadEnd = status === 'success' && loadCompletedText && (_jsx("div", { className: `${BLOCK_NAME}__load-completed ${classPrefix}-list-view__load-completed`, children: String(loadCompletedText) }));
637
+ return (_jsxs("div", { ...rest, className: classNames(classList, className), children: [children && (_jsxs("div", { className: classNames(`${BLOCK_NAME}__content`, {
655
638
  [`${BLOCK_NAME}-card`]: template === 'cardList',
656
- [`${BLOCK_NAME}__content-blank`]: (status === 'empty' && emptyText) ||
657
- (status === 'fail' && isSetStatus),
639
+ [`${BLOCK_NAME}__content-blank`]: (status === 'empty' && emptyText) || (status === 'fail' && isSetStatus),
658
640
  }), children: [status === 'fail' && refType === 'dataView' ? (_jsx(EmptyContent, { emptyText: '数据加载失败', errorObj: err, icon: 'error', isH5: isH5 })) : (children), renderStatus()] })), _jsxs("div", { className: classNames(`${BLOCK_NAME}__more`, `${BLOCK_NAME}__more-${pagination}`), children: [pagination === 'bottomLoad' && renderBottomLoad(), pagination === 'loadMoreButton' && renderLoadMore(), pagination === 'pagination' && renderPagination()] })] }));
659
641
  });
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import classNames from '../../utils/classnames';
4
- import { getTempFileURL } from '../../utils/tcb';
4
+ import { getTempFileURL, getDefaultUploadPath } from '../../utils/tcb';
5
5
  import { v4 as uuidv4 } from 'uuid';
6
6
  import { LOAD_ERR_IMG_BASE64, RICH_TEXT_ICON_PACK, getWhitelist } from '../../utils/constant';
7
7
  import { renderDecorator } from '../form/renderDecorator';
8
- import { usePlatform } from '../../utils/platform';
8
+ import { usePlatform, alertErrorMessage } from '../../utils/platform';
9
9
  import { errorHandler } from '../../utils/error';
10
10
  import { isPrivate } from '../../utils/isPrivate';
11
11
  import './style';
@@ -98,10 +98,9 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
98
98
  }
99
99
  };
100
100
  const isSizeAccept = (file) => {
101
- var _a, _b;
102
101
  if (file.size > maxSize * 1024 * 1024) {
103
- (_b = (_a = window === null || window === void 0 ? void 0 : window.$w) === null || _a === void 0 ? void 0 : _a.utils) === null || _b === void 0 ? void 0 : _b.showToast({
104
- title: `文件大小超过上限${maxSize}M`,
102
+ alertErrorMessage({
103
+ message: `文件大小超过上限${maxSize}M`,
105
104
  icon: 'error',
106
105
  });
107
106
  return false;
@@ -109,11 +108,12 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
109
108
  return true;
110
109
  };
111
110
  const upload = async (file) => {
112
- var _a, _b, _c, _d, _e, _f, _g;
111
+ var _a, _b, _c, _d, _e;
113
112
  const tcb = await ((_b = (_a = window === null || window === void 0 ? void 0 : window.app) === null || _a === void 0 ? void 0 : _a.cloud) === null || _b === void 0 ? void 0 : _b.getCloudInstance());
114
113
  try {
115
114
  const fileType = (_e = (_d = (_c = file === null || file === void 0 ? void 0 : file.name) === null || _c === void 0 ? void 0 : _c.split('.')) === null || _d === void 0 ? void 0 : _d.pop()) === null || _e === void 0 ? void 0 : _e.toLowerCase();
116
- const path = `${cloudPath}/uploader-${uuidv4()}.${fileType}`;
115
+ const _uploadPath = getDefaultUploadPath(cloudPath);
116
+ const path = `${_uploadPath}/uploader-${uuidv4()}.${fileType}`;
117
117
  const { fileID } = await tcb.uploadFile({
118
118
  cloudPath: path,
119
119
  filePath: file,
@@ -133,8 +133,8 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
133
133
  error: e,
134
134
  id,
135
135
  });
136
- (_g = (_f = window === null || window === void 0 ? void 0 : window.$w) === null || _f === void 0 ? void 0 : _f.utils) === null || _g === void 0 ? void 0 : _g.showToast({
137
- title: '上传图片失败',
136
+ alertErrorMessage({
137
+ message: '上传图片失败',
138
138
  icon: 'error',
139
139
  });
140
140
  }
@@ -192,10 +192,9 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
192
192
  initialContent: syncedValue || initialContent,
193
193
  placeholder: placeholder,
194
194
  onCopy: (isSuccess) => {
195
- var _a, _b;
196
195
  if (isSuccess) {
197
- (_b = (_a = window === null || window === void 0 ? void 0 : window.$w) === null || _a === void 0 ? void 0 : _a.utils) === null || _b === void 0 ? void 0 : _b.showToast({
198
- title: '复制成功',
196
+ alertErrorMessage({
197
+ message: '复制成功',
199
198
  icon: 'success',
200
199
  });
201
200
  }
@@ -220,14 +219,13 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
220
219
  accept: acceptTypes.join(),
221
220
  inline: true,
222
221
  acceptFile: (file) => {
223
- var _a, _b;
224
222
  let typeRegex = new RegExp(`^((${acceptTypes.join(')|(').replaceAll('+', '\\+')}))$`);
225
223
  if (acceptTypes.join().includes('*')) {
226
224
  typeRegex = new RegExp(`^image/.+$`);
227
225
  }
228
226
  if (!typeRegex.test(file.type)) {
229
- (_b = (_a = window === null || window === void 0 ? void 0 : window.$w) === null || _a === void 0 ? void 0 : _a.utils) === null || _b === void 0 ? void 0 : _b.showToast({
230
- title: '文件格式不支持',
227
+ alertErrorMessage({
228
+ message: '文件格式不支持',
231
229
  icon: 'error',
232
230
  });
233
231
  return false;
@@ -20,7 +20,7 @@ export default function StatusContent(props) {
20
20
  isH5: isH5,
21
21
  'wd-status-content__content-white': hasRecord,
22
22
  'wd-status-content__content-grey': !hasRecord,
23
- })}`, children: [hasRecord ? (_jsx(_Fragment, {})) : (_jsx("span", { className: `wd-status-content__status-icon ${icon}` })), _jsx("p", { className: `wd-status-content__text-fail ${isH5 && 'isH5'}`, children: emptyText }), (errorObj === null || errorObj === void 0 ? void 0 : errorObj.code) ? (_jsxs("p", { className: `wd-status-content__code-fail ${isH5 && 'isH5'}`, children: ["\u9519\u8BEF\u7801: ", errorObj.code] })) : null, (errorObj === null || errorObj === void 0 ? void 0 : errorObj.message) ? (_jsxs("p", { className: `wd-status-content__detail-fail`, onClick: () => setVisible(true), children: [_jsx("span", { className: `wd-status-content__desc-fail ${isH5 && 'isH5'}`, children: "\u67E5\u770B\u8BE6\u7EC6\u5F02\u5E38\u4FE1\u606F" }), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "6", height: "10", viewBox: "0 0 6 10", fill: "none", children: _jsx("path", { d: "M1.45964 9.45972L0.540405 8.54048L4.08079 5.0001L0.540405 1.45972L1.45964 0.540478L5.91926 5.0001L1.45964 9.45972Z", fill: "black", fillOpacity: "0.9" }) })] })) : null] }) }), isH5 && visible ? (_jsx(Portal, { type: "div", disableOutsidePointerEvents: true, disableOutsideScroll: true, children: _jsxs("div", { className: "wd-status-content__picker", children: [_jsx("div", { className: "wd-status-content__backdrop", onClick: () => {
23
+ })}`, children: [hasRecord ? _jsx(_Fragment, {}) : _jsx("span", { className: `wd-status-content__status-icon ${icon}` }), _jsx("p", { className: `wd-status-content__text-fail wd-status-content__text ${isH5 && 'isH5'}`, children: emptyText }), (errorObj === null || errorObj === void 0 ? void 0 : errorObj.code) ? (_jsxs("p", { className: `wd-status-content__code-fail ${isH5 && 'isH5'}`, children: ["\u9519\u8BEF\u7801: ", errorObj.code] })) : null, (errorObj === null || errorObj === void 0 ? void 0 : errorObj.message) ? (_jsxs("p", { className: `wd-status-content__detail-fail`, onClick: () => setVisible(true), children: [_jsx("span", { className: `wd-status-content__desc-fail ${isH5 && 'isH5'}`, children: "\u67E5\u770B\u8BE6\u7EC6\u5F02\u5E38\u4FE1\u606F" }), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "6", height: "10", viewBox: "0 0 6 10", fill: "none", children: _jsx("path", { d: "M1.45964 9.45972L0.540405 8.54048L4.08079 5.0001L0.540405 1.45972L1.45964 0.540478L5.91926 5.0001L1.45964 9.45972Z", fill: "black", fillOpacity: "0.9" }) })] })) : null] }) }), isH5 && visible ? (_jsx(Portal, { type: "div", disableOutsidePointerEvents: true, disableOutsideScroll: true, children: _jsxs("div", { className: "wd-status-content__picker", children: [_jsx("div", { className: "wd-status-content__backdrop", onClick: () => {
24
24
  setVisible(false);
25
25
  } }), _jsxs("div", { className: "wd-status-content__picker-inner", children: [_jsxs("p", { className: "wd-status-content__picker-title", children: ["\u8BE6\u7EC6\u5F02\u5E38\u4FE1\u606F", _jsx("span", { onClick: () => {
26
26
  setVisible(false);
@@ -1,9 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /* eslint max-lines: [error, 500] */
3
- import { forwardRef, useImperativeHandle, useEffect, useMemo, useRef, useState, useCallback, } from 'react';
3
+ import { forwardRef, useImperativeHandle, useEffect, useMemo, useRef, useState, useCallback } from 'react';
4
4
  import { WdFormItem, WdInputGroup } from '../wd-form-item';
5
5
  import { useFormInputTrait } from '../form-input-hooks';
6
- import { WdIcon } from '../wd-icon';
6
+ import WdIcon from '../wd-icon';
7
7
  import { filterPropsWithOn, getUuid } from '../../utils/tool';
8
8
  import { KEY_DOWN_CODE } from '../../utils/constant';
9
9
  import classNames from '../../utils/classnames';
@@ -63,6 +63,7 @@ export const WdInput = forwardRef(function WdInput(props, ref) {
63
63
  const countCls = `${classPrefix}-input__limit-number`;
64
64
  const platform = usePlatform();
65
65
  const isH5 = platform === 'h5';
66
+ const [currentInputType, setCurrentInputType] = useState(inputType);
66
67
  useEffect(() => {
67
68
  if (isEqual(valueRef.current, value))
68
69
  return; // 监听非输入引起的value变化,比如调用 setValue, clearValue
@@ -135,18 +136,7 @@ export const WdInput = forwardRef(function WdInput(props, ref) {
135
136
  readOnly,
136
137
  before,
137
138
  after,
138
- }), [
139
- innerHandle,
140
- name,
141
- value,
142
- label,
143
- required,
144
- visible,
145
- disabled,
146
- readOnly,
147
- before,
148
- after,
149
- ]);
139
+ }), [innerHandle, name, value, label, required, visible, disabled, readOnly, before, after]);
150
140
  const formItemProps = {
151
141
  ...props,
152
142
  validateErrorMsg,
@@ -158,6 +148,9 @@ export const WdInput = forwardRef(function WdInput(props, ref) {
158
148
  inputId,
159
149
  layout: props.layout,
160
150
  readBeforeAfter: !isUnionValue,
151
+ className: classNames(props.className, {
152
+ 'password-input': password,
153
+ }),
161
154
  };
162
155
  const inputAdornmentClick = (type) => {
163
156
  var _a;
@@ -170,11 +163,14 @@ export const WdInput = forwardRef(function WdInput(props, ref) {
170
163
  size,
171
164
  onClick: inputAdornmentClick,
172
165
  };
166
+ const passwordIconRender = () => (_jsx("div", { className: `${classPrefix}-input-password-icon ${classPrefix}-${platform}-input-password-icon`, children: _jsx(WdIcon, { events: {
167
+ tap: () => {
168
+ setCurrentInputType(currentInputType === 'password' ? 'text' : 'password');
169
+ },
170
+ }, size: 'xs', name: currentInputType === 'password' ? 'td:browse-off' : 'td:browse', type: 'inner' }) }));
173
171
  if (!visible)
174
172
  return null;
175
- return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(WdInputGroup, { ...inputGroupProps, children: _jsxs("div", { className: `${cls} ${template === 'greySearchBox'
176
- ? 'wd-input-input-search template search-box color-grey is-pc-bordered'
177
- : ''} ${template === 'whiteSearchBox'
178
- ? 'wd-input-input-search template search-box color-white is-pc-bordered'
179
- : ''} ${isH5 ? 'is-h5-borderless' : ''}`, ref: wrapRef, onFocus: () => { var _a, _b; return (_b = (_a = wrapRef.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add('is-focused'); }, onBlur: () => { var _a, _b; return (_b = (_a = wrapRef.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove('is-focused'); }, children: [prefixType && (_jsx("div", { className: prefixCls, onClick: () => inputAdornmentClick('prefix'), children: _jsx(WdIcon, { size: iconSize, name: prefixIcon, type: prefixType, src: prefixSrc, className: prefixIconCls }) })), _jsx("div", { className: contentCls, children: _jsx("input", { id: inputId, className: inputCls, type: inputType, placeholder: placeholder, value: currentInputValue !== null && currentInputValue !== void 0 ? currentInputValue : '', disabled: disabled, name: name, autoFocus: focus, autoComplete: "off", maxLength: maxLength, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, onCompositionStart: handleZhStart, onCompositionEnd: handleZhEnd, ...startWithOnProps }) }), hasClearIcon && (_jsx("div", { className: suffixCls, children: _jsx(WdIcon, { size: iconSize, className: `${classPrefix}-icon__trigger`, name: "td:close-circle-filled", onMouseDown: onClear }) })), !hasClearIcon && suffixType && (_jsx("div", { className: suffixCls, onClick: () => inputAdornmentClick('suffix'), children: _jsx(WdIcon, { size: iconSize, name: suffixIcon, type: suffixType, src: suffixSrc, className: suffixIconCls }) })), counterVisible && (_jsxs("span", { className: countCls, children: [counter, "/", maxLength] }))] }) }) }));
173
+ return (_jsx(WdFormItem, { ...formItemProps, children: _jsxs(_Fragment, { children: [_jsx(WdInputGroup, { ...inputGroupProps, children: _jsxs("div", { className: `${cls} ${template === 'greySearchBox' ? 'wd-input-input-search template search-box color-grey is-pc-bordered' : ''} ${template === 'whiteSearchBox'
174
+ ? 'wd-input-input-search template search-box color-white is-pc-bordered'
175
+ : ''} ${isH5 ? 'is-h5-borderless' : ''}`, ref: wrapRef, onFocus: () => { var _a, _b; return (_b = (_a = wrapRef.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add('is-focused'); }, onBlur: () => { var _a, _b; return (_b = (_a = wrapRef.current) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove('is-focused'); }, children: [prefixType && (_jsx("div", { className: prefixCls, onClick: () => inputAdornmentClick('prefix'), children: _jsx(WdIcon, { size: iconSize, name: prefixIcon, type: prefixType, src: prefixSrc, className: prefixIconCls }) })), _jsx("div", { className: contentCls, children: _jsx("input", { id: inputId, className: inputCls, type: currentInputType, placeholder: placeholder, value: currentInputValue !== null && currentInputValue !== void 0 ? currentInputValue : '', disabled: disabled, name: name, autoFocus: focus, autoComplete: "off", maxLength: maxLength, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, onCompositionStart: handleZhStart, onCompositionEnd: handleZhEnd, ...startWithOnProps }) }), hasClearIcon && (_jsx("div", { className: suffixCls, children: _jsx(WdIcon, { size: iconSize, className: `${classPrefix}-icon__trigger`, name: "td:close-circle-filled", onMouseDown: onClear }) })), !hasClearIcon && suffixType && (_jsx("div", { className: suffixCls, onClick: () => inputAdornmentClick('suffix'), children: _jsx(WdIcon, { size: iconSize, name: suffixIcon, type: suffixType, src: suffixSrc, className: suffixIconCls }) })), counterVisible && (_jsxs("span", { className: countCls, children: [counter, "/", maxLength] }))] }) }), password && passwordIconRender()] }) }));
180
176
  });
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import type { DataType } from '../../../../configs/components/wd-select';
3
+ interface SelectContextValue {
4
+ options: DataType['range'];
5
+ setOptions?(options: DataType['range']): void;
6
+ value?: DataType['value'];
7
+ }
8
+ interface ISelectProvider {
9
+ children?: React.ReactNode;
10
+ options: DataType['range'];
11
+ setOptions: (options: DataType['range']) => void;
12
+ }
13
+ export declare function SelectProvider({ children, options, setOptions }: ISelectProvider): JSX.Element;
14
+ export declare function useSelectContext(): SelectContextValue | null;
15
+ export {};
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo, useContext } from 'react';
3
+ import { createContext } from '../../../utils/global-context';
4
+ const SelectContext = createContext({
5
+ options: [],
6
+ setOptions: () => { },
7
+ }, 'SelectContext');
8
+ export function SelectProvider({ children, options, setOptions }) {
9
+ return (_jsx(SelectContext.Provider, { value: useMemo(() => ({ options, setOptions }), [options, setOptions]), children: children }));
10
+ }
11
+ export function useSelectContext() {
12
+ return useContext(SelectContext);
13
+ }
@@ -0,0 +1,19 @@
1
+ export declare const mapResult: (records: any, primaryColumn: any) => any;
2
+ export declare const useChooseList: ({ dataSourceAPI, queryParams, childDbName, primaryColumn, value, isInsertSelectedValue, }: {
3
+ dataSourceAPI: any;
4
+ queryParams: any;
5
+ childDbName: any;
6
+ primaryColumn: any;
7
+ value: any;
8
+ isInsertSelectedValue?: boolean;
9
+ }) => {
10
+ result: {
11
+ disabled?: boolean;
12
+ label: string;
13
+ value: string;
14
+ }[];
15
+ total: number;
16
+ isValidating: boolean;
17
+ empty: () => void;
18
+ getRelationOptions: () => Promise<void>;
19
+ };
@@ -0,0 +1,94 @@
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import { useSelectContext } from '../contexts/selectContext';
3
+ const defaultPage = 1;
4
+ const getUniqueOption = (option) => {
5
+ var _a;
6
+ const optionMap = option.reduce((acc, item) => {
7
+ if (!acc[item.value]) {
8
+ acc[item.value] = item;
9
+ }
10
+ return acc;
11
+ }, {});
12
+ const uniqueOption = (_a = Object.values(optionMap)) === null || _a === void 0 ? void 0 : _a.filter((item) => item === null || item === void 0 ? void 0 : item.value);
13
+ return uniqueOption;
14
+ };
15
+ export const mapResult = (records, primaryColumn) => {
16
+ var _a;
17
+ return (_a = records === null || records === void 0 ? void 0 : records.filter((i) => i._id)) === null || _a === void 0 ? void 0 : _a.map((childItem) => ({
18
+ _id: childItem._id,
19
+ value: childItem._id,
20
+ text: childItem[primaryColumn] ? childItem[primaryColumn] : childItem._id,
21
+ label: childItem[primaryColumn] ? childItem[primaryColumn] : childItem._id,
22
+ extra: childItem,
23
+ }));
24
+ };
25
+ export const useChooseList = ({ dataSourceAPI, queryParams, childDbName, primaryColumn, value, isInsertSelectedValue = true, }) => {
26
+ const [total, setTotal] = useState(0);
27
+ const [loading, setLoading] = useState(true);
28
+ const { options, setOptions } = useSelectContext();
29
+ const unshiftVal = (transformedRecords, itemResult, originOption) => {
30
+ if (itemResult &&
31
+ transformedRecords.findIndex((item) => item._id === itemResult._id) < 0 &&
32
+ originOption.findIndex((item) => item._id === itemResult._id) < 0) {
33
+ return [itemResult, ...transformedRecords];
34
+ }
35
+ return transformedRecords;
36
+ };
37
+ const fetchData = useCallback(async () => {
38
+ setLoading(true);
39
+ const isMultiple = Array.isArray(value);
40
+ const promiseList = [
41
+ dataSourceAPI.getRecordListV2({ ...queryParams, pageNumber: queryParams.pageNo }, {
42
+ db: childDbName,
43
+ }),
44
+ ];
45
+ if (value && isInsertSelectedValue) {
46
+ if (isMultiple) {
47
+ value.forEach((i) => {
48
+ if (i) {
49
+ promiseList.push(dataSourceAPI.getRecord(i, {
50
+ db: childDbName,
51
+ }));
52
+ }
53
+ });
54
+ }
55
+ else {
56
+ promiseList.push(dataSourceAPI.getRecord(value, {
57
+ db: childDbName,
58
+ }));
59
+ }
60
+ }
61
+ const [result, ...rest] = await Promise.all(promiseList);
62
+ let transformedRecords = [...((result === null || result === void 0 ? void 0 : result.records) || [])];
63
+ const itemResult = [...rest];
64
+ // 若下拉列表中无选中值,则将选中值插到数组头部
65
+ if ((isMultiple && (value === null || value === void 0 ? void 0 : value.length) && isInsertSelectedValue) || (value && isInsertSelectedValue)) {
66
+ itemResult.forEach((i) => {
67
+ transformedRecords = unshiftVal(transformedRecords, i, options);
68
+ });
69
+ }
70
+ let optionRes = mapResult(transformedRecords, primaryColumn);
71
+ if ((queryParams === null || queryParams === void 0 ? void 0 : queryParams.pageNo) > defaultPage) {
72
+ optionRes = [...options, ...optionRes];
73
+ }
74
+ optionRes = getUniqueOption(optionRes);
75
+ setOptions(optionRes);
76
+ setTotal(result === null || result === void 0 ? void 0 : result.total);
77
+ setLoading(false);
78
+ // eslint-disable-next-line react-hooks/exhaustive-deps
79
+ }, [childDbName, primaryColumn, queryParams, value]);
80
+ useEffect(() => {
81
+ if (childDbName) {
82
+ fetchData();
83
+ }
84
+ }, [childDbName, fetchData]);
85
+ return {
86
+ result: options || [],
87
+ total: total,
88
+ isValidating: loading,
89
+ empty: () => {
90
+ setOptions([]);
91
+ },
92
+ getRelationOptions: fetchData,
93
+ };
94
+ };
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function EnumSelect(props: any): JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
3
+ import { useState, useImperativeHandle, useEffect, useCallback } from 'react';
4
+ import { LoadingTip } from 'tea-component';
5
+ import { SelectUI as Select } from '../select/selectUI';
6
+ import { requestEnumOption } from '../../form/select/request';
7
+ import { useSelectContext } from '../contexts/selectContext';
8
+ export function EnumSelect(props) {
9
+ const { placeholder, size, disabled, onChange, value, onSearch, addRelationButton, childRef, dataSourceName, enumName, primaryField, format, viewId, where, setRefreshStatus, mode, } = props;
10
+ const { options, setOptions } = useSelectContext();
11
+ const [isLoading, setLoading] = useState(false);
12
+ // 获取枚举字段类型的下拉选项
13
+ const getEnumOption = useCallback(async () => {
14
+ const params = {
15
+ format,
16
+ dataSourceName,
17
+ viewId,
18
+ where,
19
+ primaryField,
20
+ enumName,
21
+ };
22
+ setLoading(true);
23
+ const enumOptions = await requestEnumOption(params);
24
+ setOptions(enumOptions);
25
+ setLoading(false);
26
+ // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ }, [dataSourceName, enumName, format, primaryField, viewId, where]);
28
+ useEffect(() => {
29
+ getEnumOption();
30
+ }, [getEnumOption]);
31
+ useImperativeHandle(childRef, () => {
32
+ return {
33
+ refresh: async () => {
34
+ setRefreshStatus(true);
35
+ await getEnumOption();
36
+ // eslint-disable-next-line rulesdir/no-timer
37
+ const timer = setTimeout(() => {
38
+ setRefreshStatus(false);
39
+ clearTimeout(timer);
40
+ }, 500);
41
+ },
42
+ };
43
+ }, [getEnumOption, setRefreshStatus]);
44
+ const searchHandle = (keyword) => {
45
+ onSearch(keyword);
46
+ };
47
+ return (_jsx(Select, { ...props, mode: mode, searchable: true, matchButtonWidth: true, placeholder: placeholder, appearance: 'button', size: size, disabled: disabled, autoClearSearchValue: true, options: options, value: value, onChange: onChange, onSearch: searchHandle, footer: addRelationButton, bottomTips: isLoading ? _jsx(LoadingTip, {}) : undefined }));
48
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function CustomSelect(props: any): JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { LoadingTip } from 'tea-component';
4
+ import { EnumSelect } from './enumSelect';
5
+ import { RelationSelect } from './relationSelect';
6
+ import { WdIcon } from '../../wd-icon';
7
+ export function CustomSelect(props) {
8
+ const { format, addRelationButtonText, enableAddRelationButton, events } = props;
9
+ const isEnumType = format === 'x-enum';
10
+ const [refreshStatus, setRefreshStatus] = useState(false);
11
+ const addRelationButton = enableAddRelationButton && (_jsxs("span", { className: "wd-add-relation-button-wrap", onClick: () => {
12
+ var _a;
13
+ (_a = events === null || events === void 0 ? void 0 : events.onAddRelationButtonClick) === null || _a === void 0 ? void 0 : _a.call(events);
14
+ }, children: [_jsx(WdIcon, { size: 'xs', name: 'td:add-circle' }), addRelationButtonText] }));
15
+ if (refreshStatus) {
16
+ return _jsx(LoadingTip, {});
17
+ }
18
+ return isEnumType ? (_jsx(EnumSelect, { ...props, addRelationButton: addRelationButton, setRefreshStatus: setRefreshStatus })) : (_jsx(RelationSelect, { ...props, addRelationButton: addRelationButton, setRefreshStatus: setRefreshStatus }));
19
+ }
@@ -0,0 +1,15 @@
1
+ interface IqueryParams {
2
+ filter?: {
3
+ where?: object;
4
+ };
5
+ select?: {
6
+ [name: string]: boolean;
7
+ };
8
+ orderBy?: {
9
+ [name: string]: 'asc' | 'desc';
10
+ }[];
11
+ getCount?: boolean;
12
+ compatibleWithV1?: boolean;
13
+ }
14
+ export declare const getDefaultQuery: (props: any) => IqueryParams;
15
+ export {};
@@ -0,0 +1,15 @@
1
+ import { getFilter, getSelectFields, transformSorter } from '../../../utils/getModelParams';
2
+ import { getWhereList } from '../../../utils/platform';
3
+ export const getDefaultQuery = (props) => {
4
+ const params = {};
5
+ // 兼容旧的筛选条件
6
+ const queryCondition = props.supportManyRelated ? props.queryCondition : getWhereList(props.where);
7
+ // 支持多关联查询,需要将查询条件转换为filter
8
+ params.filter = getFilter(queryCondition);
9
+ params.select = getSelectFields(props);
10
+ // 处理排序字段
11
+ params.orderBy = transformSorter(props.sorter);
12
+ params.getCount = true;
13
+ params.compatibleWithV1 = true;
14
+ return params;
15
+ };
@@ -1,4 +1,2 @@
1
1
  /// <reference types="react" />
2
2
  export declare function RelationSelect(props: any): JSX.Element;
3
- export declare function EnumSelect(props: any): JSX.Element;
4
- export declare function CustomSelect(props: any): JSX.Element;