@cloudbase/weda-ui 3.4.11 → 3.4.13
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.
- package/dist/configs/components/common/form-input-required.js +3 -3
- package/dist/configs/components/customer-service.js +3 -0
- package/dist/configs/components/dataView.js +20 -10
- package/dist/configs/components/form-checkbox.js +15 -2
- package/dist/configs/components/form-date.js +1 -1
- package/dist/configs/components/form-depart-tree-select.js +1 -1
- package/dist/configs/components/form-email.js +17 -2
- package/dist/configs/components/form-input.js +17 -2
- package/dist/configs/components/form-location.js +1 -1
- package/dist/configs/components/form-multi-region.js +1 -1
- package/dist/configs/components/form-phone.js +17 -2
- package/dist/configs/components/form-radio.js +15 -2
- package/dist/configs/components/form-rich-text.js +1 -1
- package/dist/configs/components/form-select-multiple.js +362 -0
- package/dist/configs/components/form-select.js +1 -1
- package/dist/configs/components/form-switch.js +16 -3
- package/dist/configs/components/form-text-area.js +15 -2
- package/dist/configs/components/form-time.js +1 -1
- package/dist/configs/components/form-url.js +17 -2
- package/dist/configs/components/form-user-tree-select.js +14 -1
- package/dist/configs/components/listView.js +32 -49
- package/dist/configs/components/table.json +1 -54
- package/dist/configs/components/wd-bubble.js +46 -8
- package/dist/configs/components/wd-button.js +3 -0
- package/dist/configs/components/wd-checkbox.js +464 -0
- package/dist/configs/components/wd-form.js +66 -10
- package/dist/configs/components/wd-input-email.js +37 -0
- package/dist/configs/components/wd-input-phone.js +43 -0
- package/dist/configs/components/wd-input-url.js +37 -0
- package/dist/configs/components/wd-input.js +94 -0
- package/dist/configs/components/wd-official-account.js +87 -0
- package/dist/configs/components/wd-radio.js +443 -0
- package/dist/configs/components/wd-switch.js +315 -0
- package/dist/configs/components/wd-table.js +11 -59
- package/dist/configs/components/wd-textarea.js +82 -0
- package/dist/configs/components/wd-tree.js +443 -0
- package/dist/configs/components/web-view.js +3 -0
- package/dist/configs/index.js +24 -1
- package/dist/configs/type-utils/type-form.js +681 -0
- package/dist/docs/common/components/json-schema-view.js +1 -1
- package/dist/docs/common/components/methods-view.js +1 -1
- package/dist/docs/common/components/properties-view.js +3 -1
- package/dist/docs/common/format.js +7 -7
- package/dist/docs/common/tableView.js +3 -1
- package/dist/enum/index.js +196 -0
- package/dist/style/index.scss +1 -1
- package/dist/web/actions/showMessage/index.js +4 -1
- package/dist/web/components/carousel/index.js +1 -1
- package/dist/web/components/customer-service/customer-service.js +19 -2
- package/dist/web/components/dataView/index.js +16 -3
- package/dist/web/components/flow/common/hooks/useCommonFlowData/flow-get.js +5 -1
- package/dist/web/components/flow/common/request.js +5 -5
- package/dist/web/components/flow/modules/operations/controls-items/flow-task-info-modal.js +90 -0
- package/dist/web/components/form/formcell/index.css +13 -1
- package/dist/web/components/form/formcell/index.js +1 -1
- package/dist/web/components/form/location/components/LocationH5/location.h5.js +1 -1
- package/dist/web/components/form/select/dropdown-select/index.js +9 -3
- package/dist/web/components/form/select/h5.js +18 -8
- package/dist/web/components/form/select/index.js +9 -10
- package/dist/web/components/form/select/region/index.js +1 -1
- package/dist/web/components/form/selectMultiple/dropdown-select/h5.js +111 -0
- package/dist/web/components/form/selectMultiple/dropdown-select/index.css +270 -0
- package/dist/web/components/form/selectMultiple/dropdown-select/index.js +206 -0
- package/dist/web/components/form/selectMultiple/dropdown-select/pc.js +115 -0
- package/dist/web/components/form/selectMultiple/dropdown-select/ui.js +113 -0
- package/dist/web/components/form/selectMultiple/h5.js +40 -0
- package/dist/web/components/form/selectMultiple/index.js +94 -0
- package/dist/web/components/form/selectMultiple/request.js +76 -0
- package/dist/web/components/form/selectMultiple/status/allEmpty.js +5 -0
- package/dist/web/components/form/selectMultiple/status/empty.js +19 -0
- package/dist/web/components/form/selectMultiple/status/index.css +63 -0
- package/dist/web/components/form/selectMultiple/status/index.js +7 -0
- package/dist/web/components/form/selectMultiple/status/loading.js +19 -0
- package/dist/web/components/form/selectMultiple/status/propsType.js +1 -0
- package/dist/web/components/form/selectMultiple/status/retry.js +19 -0
- package/dist/web/components/form/tips/index.css +9 -3
- package/dist/web/components/form/uploader/index.css +10 -0
- package/dist/web/components/form/uploader/uploader.h5.js +60 -62
- package/dist/web/components/form/uploader/uploader.pc.js +48 -41
- package/dist/web/components/form/uploaderFile/uploadFile.h5.js +8 -33
- package/dist/web/components/form/uploaderFile/uploadFile.pc.js +8 -37
- package/dist/web/components/form/userOrgSelect/common/fetch-data-service.js +76 -50
- package/dist/web/components/form/userOrgSelect/common/utils.js +24 -8
- package/dist/web/components/form/userOrgSelect/component/depart-select/depart-select-pc.js +3 -8
- package/dist/web/components/form/userOrgSelect/component/depart-select/index.js +14 -18
- package/dist/web/components/form/userOrgSelect/component/depart-select/org-modal-pc.js +20 -14
- package/dist/web/components/form/userOrgSelect/component/modal-select-h5.js +1 -1
- package/dist/web/components/form/userOrgSelect/component/org-tree.js +21 -9
- package/dist/web/components/form/userOrgSelect/component/user-select-h5/index.js +76 -15
- package/dist/web/components/form/userOrgSelect/component/user-select-pc/user-model.js +2 -7
- package/dist/web/components/form/userOrgSelect/component/user-select-pc/user-select-pc.js +6 -4
- package/dist/web/components/form/userOrgSelect/component/userOrgSelect.css +8 -2
- package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.h5.js +25 -51
- package/dist/web/components/form/userOrgSelect/hooks/use-depart-data.js +10 -6
- package/dist/web/components/form-input-hooks/index.js +41 -15
- package/dist/web/components/form-select-multiple/index.js +26 -0
- package/dist/web/components/form-upload-file/index.js +0 -1
- package/dist/web/components/form-user-tree-select/index.js +2 -2
- package/dist/web/components/formdetail/index.css +31 -1
- package/dist/web/components/formdetail/index.js +33 -1
- package/dist/web/components/index.js +27 -11
- package/dist/web/components/listView/index.js +20 -5
- package/dist/web/components/navigationBar/common.js +1 -1
- package/dist/web/components/navigationBar/horizontalMenu.js +1 -1
- package/dist/web/components/navigationBar/index.css +11 -0
- package/dist/web/components/navigationBar/index.js +8 -1
- package/dist/web/components/phone/index.js +26 -1
- package/dist/web/components/phoneCode/index.js +3 -1
- package/dist/web/components/richText/index.css +70 -67
- package/dist/web/components/richText/index.js +311 -251
- package/dist/web/components/richText/richtext.module.css +1 -0
- package/dist/web/components/richTextView/index.css +39 -0
- package/dist/web/components/richTextView/index.js +1 -1
- package/dist/web/components/share/index.js +26 -1
- package/dist/web/components/table/ImportFileModalByApi/uploadCSVFile.js +1 -1
- package/dist/web/components/wd-checkbox/checkbox.js +34 -0
- package/dist/web/components/wd-checkbox/index.js +3 -0
- package/dist/web/components/wd-checkbox-list/checkboxList.js +140 -0
- package/dist/web/components/wd-checkbox-list/index.js +3 -0
- package/dist/web/components/wd-form/hooks/use-remote-value.js +9 -2
- package/dist/web/components/wd-form/index.js +69 -34
- package/dist/web/components/wd-form/wd-form.js +42 -0
- package/dist/web/components/wd-form-cell/index.js +3 -0
- package/dist/web/components/wd-form-cell/wd-form-cell.js +42 -0
- package/dist/web/components/wd-form-item/index.js +4 -0
- package/dist/web/components/wd-form-item/wd-form-item.js +55 -0
- package/dist/web/components/wd-form-item/wd-input-group.js +24 -0
- package/dist/web/components/wd-icon/wd-icon.js +10 -2
- package/dist/web/components/wd-input/index.js +3 -0
- package/dist/web/components/wd-input/wd-input.js +155 -0
- package/dist/web/components/wd-input-email/index.js +3 -0
- package/dist/web/components/wd-input-email/wd-input-email.js +13 -0
- package/dist/web/components/wd-input-group/index.js +3 -0
- package/dist/web/components/wd-input-group/wd-input-group.js +10 -0
- package/dist/web/components/wd-input-phone/index.js +3 -0
- package/dist/web/components/wd-input-phone/wd-input-phone.js +14 -0
- package/dist/web/components/wd-input-url/index.js +3 -0
- package/dist/web/components/wd-input-url/wd-input-url.js +13 -0
- package/dist/web/components/wd-input-wrap/index.js +3 -0
- package/dist/web/components/wd-input-wrap/wd-input-wrap.js +18 -0
- package/dist/web/components/wd-official-account/index.css +29 -0
- package/dist/web/components/wd-official-account/index.js +36 -0
- package/dist/web/components/wd-radio/index.js +3 -0
- package/dist/web/components/wd-radio/wd-radio.js +30 -0
- package/dist/web/components/wd-radio-list/index.js +3 -0
- package/dist/web/components/wd-radio-list/wd-radio-list.js +104 -0
- package/dist/web/components/wd-switch/index.js +3 -0
- package/dist/web/components/wd-switch/wd-switch.js +52 -0
- package/dist/web/components/wd-table/components/FieldRender/index.js +5 -4
- package/dist/web/components/wd-table/components/FilterFieldsPanel/FilterFieldItem.js +4 -0
- package/dist/web/components/wd-table/components/Table/index.js +40 -9
- package/dist/web/components/wd-table/hooks/useQueryParams.js +4 -1
- package/dist/web/components/wd-table/hooks/useTableData.js +6 -1
- package/dist/web/components/wd-table/hooks/useViewFields.js +1 -1
- package/dist/web/components/wd-table/utils/index.js +6 -2
- package/dist/web/components/wd-table/wd-table.js +125 -99
- package/dist/web/components/wd-textarea/index.js +3 -0
- package/dist/web/components/wd-textarea/wd-textarea.js +78 -0
- package/dist/web/components/wd-tree/index.js +3 -0
- package/dist/web/components/wd-tree/utils.js +291 -0
- package/dist/web/components/wd-tree/wd-tree.js +193 -0
- package/dist/web/utils/constant.js +16 -0
- package/dist/web/utils/datasource.js +2 -2
- package/dist/web/utils/date.js +3 -3
- package/dist/web/utils/hooks/useFormLegacy.js +112 -0
- package/dist/web/utils/tool.js +12 -2
- package/dist/web/weda-ui.css +197 -3
- package/package.json +6 -5
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classNames from '../../utils/classnames';
|
|
3
|
+
import { useConfig } from '../../utils/config-context';
|
|
4
|
+
import { WdIcon } from '../wd-icon';
|
|
5
|
+
import { WdBubble } from '../wd-bubble';
|
|
6
|
+
import { usePlatform } from '../../utils/platform';
|
|
7
|
+
import { useLabelAlign, useLayout, useSize, convertPx, } from '../../utils/hooks/useFormLegacy';
|
|
8
|
+
/**
|
|
9
|
+
* 表单项包裹,包括标题、文本提示、校验
|
|
10
|
+
*/
|
|
11
|
+
export function WdFormItem(props) {
|
|
12
|
+
const { id, className, style, label, labelVisible, labelTips, labelWidth: _labelWidth, labelWrap, extra, required, readOnly, children, testId, requiredFlag, validateState, validateErrorMsg, readValue, borderedH5, borderedPc, classRoot, controlAlign, inputId, } = props;
|
|
13
|
+
const { classPrefix } = useConfig();
|
|
14
|
+
const platform = usePlatform();
|
|
15
|
+
const labelAlign = useLabelAlign(props);
|
|
16
|
+
const layout = useLayout(props);
|
|
17
|
+
const labelWidth = convertPx(_labelWidth);
|
|
18
|
+
const labelStyle = labelWidth ? { width: labelWidth } : {};
|
|
19
|
+
const _size = useSize(props);
|
|
20
|
+
const size = _size === 'xs' ? 'xs' : platform === 'h5' ? 'lg' : _size;
|
|
21
|
+
// 样式前缀定义
|
|
22
|
+
const root = `${classPrefix}-${classRoot}`;
|
|
23
|
+
const item = `${classPrefix}-form-item`;
|
|
24
|
+
const itemWrap = `${classPrefix}-form-item-wrap`;
|
|
25
|
+
const labelRoot = `${root}__label`;
|
|
26
|
+
// 表单项样式
|
|
27
|
+
const cls = classNames(item, className, `${classPrefix}-${platform}-form-item`, `${root}-root`, `${classPrefix}-${platform}-${classRoot}-root`, `item-size-height-${size}`, {
|
|
28
|
+
'is-required': requiredFlag && required,
|
|
29
|
+
'is-borderless': platform === 'h5' ? !borderedH5 : !borderedPc,
|
|
30
|
+
[`${item}--weui`]: platform === 'h5',
|
|
31
|
+
[`${item}--horizontal-left`]: layout === 'horizontal' && labelAlign === 'left',
|
|
32
|
+
[`${item}--horizontal-right`]: layout === 'horizontal' && labelAlign === 'right',
|
|
33
|
+
[`${item}--vertical-left`]: layout === 'vertical' && labelAlign === 'left',
|
|
34
|
+
[`${item}--vertical-right`]: layout === 'vertical' && labelAlign === 'right',
|
|
35
|
+
});
|
|
36
|
+
const labelCls = classNames(`${itemWrap}__label`, labelRoot, {
|
|
37
|
+
'is-nowrap': !labelWrap,
|
|
38
|
+
});
|
|
39
|
+
const controlWrapCls = classNames(`${itemWrap}__control-wrap`, {
|
|
40
|
+
[`${itemWrap}__control-wrap--right`]: controlAlign === 'right',
|
|
41
|
+
});
|
|
42
|
+
// 输入部分
|
|
43
|
+
const Item = (_jsx("div", { className: `${itemWrap}__control`, "data-testid": testId, children: _jsx("div", { className: controlWrapCls, children: readOnly ? (_jsx("div", { className: `${item}__readonly`, children: readValue })) : (children) }) }));
|
|
44
|
+
// 标题部分,含必填、提示
|
|
45
|
+
const Label = labelVisible && (_jsx("div", { className: labelCls, style: labelStyle, children: _jsxs("label", { htmlFor: inputId, children: [_jsx("span", { className: `${itemWrap}__label-text ${labelRoot}-text`, title: label, children: label }), labelTips && (_jsx("span", { className: `${itemWrap}__label-explain`, children: _jsx(WdBubble, { style: { display: 'inline' }, bubbleChildren: _jsx(WdIcon, { name: "td:help-circle" }), bubbleContent: labelTips, promptTheme: "dark" }) }))] }) }));
|
|
46
|
+
// 下方空白替代(改为距左对齐)
|
|
47
|
+
// const LabelSpace = labelVisible && layout === 'horizontal' && (
|
|
48
|
+
// <div className={labelCls} style={labelStyle}></div>
|
|
49
|
+
// );
|
|
50
|
+
// 下方提示部分
|
|
51
|
+
const Help = extra && (_jsx("p", { className: `${item}__help`, children: _jsx("span", { className: `${item}__help-text ${root}__help`, children: extra }) }));
|
|
52
|
+
// 校验提示文字部分
|
|
53
|
+
const Message = validateErrorMsg && (_jsx("p", { className: `${item}__help`, children: _jsx("span", { className: `${classPrefix}-g-text-${validateState} ${root}__error`, children: validateErrorMsg }) }));
|
|
54
|
+
return (_jsxs("div", { className: cls, id: id, style: style, children: [_jsxs("div", { className: itemWrap, children: [Label, Item] }), Message, Help] }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useConfig } from '../../utils/config-context';
|
|
3
|
+
import classNames from '../../utils/classnames';
|
|
4
|
+
import { useSize } from '../../utils/hooks/useFormLegacy';
|
|
5
|
+
/**
|
|
6
|
+
* 输入类组件包裹,添加前后文字
|
|
7
|
+
*/
|
|
8
|
+
export const WdInputGroup = (props) => {
|
|
9
|
+
const { before, after, block, children, classRoot = '' } = props;
|
|
10
|
+
const { classPrefix } = useConfig();
|
|
11
|
+
const size = useSize(props);
|
|
12
|
+
const root = `${classPrefix}-${classRoot}`;
|
|
13
|
+
const inputGroup = `${classPrefix}-form-input-group`;
|
|
14
|
+
const inputGroupCls = classNames(inputGroup, `size-height-${size}`, {
|
|
15
|
+
'size-width-hundred': block,
|
|
16
|
+
});
|
|
17
|
+
const beforeCls = `${inputGroup}__addon ${inputGroup}__addon-left ${root}__text-before`;
|
|
18
|
+
const afterCls = `${inputGroup}__addon ${inputGroup}__addon-right ${root}__text-after`;
|
|
19
|
+
const contentCls = `${inputGroup}__content`;
|
|
20
|
+
if (before || after) {
|
|
21
|
+
return (_jsxs("div", { className: inputGroupCls, children: [before && _jsx("div", { className: beforeCls, children: before }), _jsx("div", { className: contentCls, children: children }), after && _jsx("div", { className: afterCls, children: after })] }));
|
|
22
|
+
}
|
|
23
|
+
return _jsx(_Fragment, { children: children });
|
|
24
|
+
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import React, { forwardRef, useImperativeHandle, useState } from 'react';
|
|
3
3
|
import classNames from '../../utils/classnames';
|
|
4
4
|
import { emptyObject } from '../../utils/constant';
|
|
5
5
|
import { useConfig } from '../../utils/config-context';
|
|
6
6
|
import { usePlatform } from '../../utils/platform';
|
|
7
7
|
import { convertLegacyEnum } from '../../utils/tool';
|
|
8
8
|
import { WD_ICON_TYPE, WD_ICON_SIZE } from '../../../enum';
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
9
10
|
export const WdIcon = forwardRef(function WdIcon({ type: _type = 'inner', name, src, size: _size, events = emptyObject, className, style: _style, id, color: _color, ...props }, ref) {
|
|
11
|
+
const [isError, setIsError] = useState(false);
|
|
10
12
|
const platform = usePlatform();
|
|
11
13
|
// 兼容旧版组件的属性值 size/color
|
|
12
14
|
const remdiff = 2;
|
|
@@ -27,6 +29,7 @@ export const WdIcon = forwardRef(function WdIcon({ type: _type = 'inner', name,
|
|
|
27
29
|
const isTdIcon = /td/.test(name) && type === 'inner';
|
|
28
30
|
const isLegacyIcon = !isTdIcon && type === 'inner';
|
|
29
31
|
const iconName = name === null || name === void 0 ? void 0 : name.split(':')[1];
|
|
32
|
+
const showErrorIcon = isError && type === 'custom';
|
|
30
33
|
// 响应式css api
|
|
31
34
|
const platformCss = `${classPrefix}-${platform}-icon`;
|
|
32
35
|
const classes = {
|
|
@@ -40,6 +43,7 @@ export const WdIcon = forwardRef(function WdIcon({ type: _type = 'inner', name,
|
|
|
40
43
|
// 尺寸
|
|
41
44
|
[`${compClassName}--${size}`]: !!size,
|
|
42
45
|
[platformCss]: true,
|
|
46
|
+
[`${classPrefix}-icon-error`]: showErrorIcon,
|
|
43
47
|
};
|
|
44
48
|
const onClick = (e) => {
|
|
45
49
|
var _a;
|
|
@@ -68,6 +72,10 @@ export const WdIcon = forwardRef(function WdIcon({ type: _type = 'inner', name,
|
|
|
68
72
|
else {
|
|
69
73
|
return (_jsx("img", { className: classNames(classes, className), style: style, id: id, src: src
|
|
70
74
|
? src
|
|
71
|
-
: 'https://qcloudimg.tencent-cloud.cn/raw/4a29d51b504f12b4933ce4490110b4dc.svg',
|
|
75
|
+
: 'https://qcloudimg.tencent-cloud.cn/raw/4a29d51b504f12b4933ce4490110b4dc.svg', onLoad: () => {
|
|
76
|
+
setIsError(false);
|
|
77
|
+
}, onError: () => {
|
|
78
|
+
setIsError(true);
|
|
79
|
+
}, onClick: onClick, ...propsStartWithOn }));
|
|
72
80
|
}
|
|
73
81
|
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint max-lines: [error, 500] */
|
|
3
|
+
import { forwardRef, useImperativeHandle, useEffect, useMemo, useRef, useState, useCallback, } from 'react';
|
|
4
|
+
import { WdFormItem, WdInputGroup } from '../wd-form-item';
|
|
5
|
+
import { useFormInputTrait } from '../form-input-hooks';
|
|
6
|
+
import { WdIcon } from '../wd-icon';
|
|
7
|
+
import { filterPropsWithOn, getUuid } from '../../utils/tool';
|
|
8
|
+
import { FORM_MAX_LENGTH, KEY_DOWN_CODE } from '../../utils/constant';
|
|
9
|
+
import classNames from '../../utils/classnames';
|
|
10
|
+
import { useSyncValue } from '../../utils/hooks/useSyncValue';
|
|
11
|
+
import { usePlatform } from '../../utils/platform';
|
|
12
|
+
import { useSize, useRules, converValueFix, converInputValue, useStringProp, } from '../../utils/hooks/useFormLegacy';
|
|
13
|
+
import { useConfig } from '../../utils/config-context';
|
|
14
|
+
import isEqual from 'lodash.isequal';
|
|
15
|
+
const inputTypes = { idcard: 'text', digit: 'number' };
|
|
16
|
+
/**
|
|
17
|
+
* 标准化:单行输入组件
|
|
18
|
+
*/
|
|
19
|
+
export const WdInput = forwardRef(function WdInput(props, ref) {
|
|
20
|
+
const { name, password = false, type = 'text', placeholder = '请输入', focus: _focus = false, maxLength = FORM_MAX_LENGTH, clearable = true, events, block: _block, prefixType, prefixIcon, prefixSrc, suffixType, suffixIcon, suffixSrc, classRoot = 'input', wrapClassName = '', counterVisible, label, required, inputPattern, } = props;
|
|
21
|
+
const { before, after, inputValue } = useStringProp(props);
|
|
22
|
+
const [innerHandle, setInnerHandle] = useState({}); // hook里挂出的属性
|
|
23
|
+
const [currentInputValue, setCurrentInputValue] = useSyncValue(inputValue); // 监听inputValue
|
|
24
|
+
const formValue = useMemo(() => converValueFix(inputValue, before, after, type), [inputValue, before, after, type]);
|
|
25
|
+
const rules = useRules(props); // 含前后缀和必填时,仅对输入框校验
|
|
26
|
+
const traitProps = {
|
|
27
|
+
...props,
|
|
28
|
+
rules,
|
|
29
|
+
value: formValue,
|
|
30
|
+
inputRef: ref,
|
|
31
|
+
setInnerHandle,
|
|
32
|
+
};
|
|
33
|
+
const { value, // 代表组件值,含前后缀
|
|
34
|
+
onChange: _onChange, disabled, readOnly, validateErrorMsg, validateState, visible, layout, } = useFormInputTrait(traitProps);
|
|
35
|
+
const wrapRef = useRef(null);
|
|
36
|
+
const valueRef = useRef(value);
|
|
37
|
+
const size = useSize(props);
|
|
38
|
+
const block = usePlatform() === 'h5' ? true : _block;
|
|
39
|
+
const { classPrefix } = useConfig();
|
|
40
|
+
const startWithOnProps = useMemo(() => filterPropsWithOn(props), [props]);
|
|
41
|
+
const inputId = useMemo(() => getUuid(), []);
|
|
42
|
+
const [focus, setFocus] = useSyncValue(_focus);
|
|
43
|
+
const inputType = password ? 'password' : inputTypes[type] || type;
|
|
44
|
+
const hasClearIcon = clearable && focus && !disabled && (currentInputValue === null || currentInputValue === void 0 ? void 0 : currentInputValue.length) > 0;
|
|
45
|
+
const counter = typeof currentInputValue === 'string' ? currentInputValue.length : 0;
|
|
46
|
+
const root = `${classPrefix}-${classRoot}`;
|
|
47
|
+
const inputWrap = `${classPrefix}-form-input-wrap`;
|
|
48
|
+
const inputCls = `${classPrefix}-form-input-wrap__input`;
|
|
49
|
+
const contentCls = `${inputWrap}__content`;
|
|
50
|
+
const prefixCls = `${inputWrap}__before`;
|
|
51
|
+
const prefixIconCls = `${root}__icon-before`;
|
|
52
|
+
const suffixCls = `${inputWrap}__after`;
|
|
53
|
+
const suffixIconCls = `${root}__icon-after`;
|
|
54
|
+
const cls = classNames(inputWrap, wrapClassName, `size-width-${size} size-font-${size}`, `${root}-${classRoot}`, `size-height-${size}`, {
|
|
55
|
+
'size-width-hundred': block,
|
|
56
|
+
'is-disabled': disabled,
|
|
57
|
+
[`${inputWrap}--no-radius-left`]: before,
|
|
58
|
+
[`${inputWrap}--no-radius-right`]: after,
|
|
59
|
+
[`${inputWrap}--no-radius`]: before && after,
|
|
60
|
+
});
|
|
61
|
+
const countCls = `${classPrefix}-input__limit-number`;
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
// eslint-disable-next-line rulesdir/no-timer
|
|
64
|
+
setTimeout(() => changeForm(value));
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, []);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (isEqual(valueRef.current, value))
|
|
69
|
+
return; // 监听非输入引起的value变化,比如调用 setValue, clearValue
|
|
70
|
+
const currentInputValue = converInputValue(value, before, after);
|
|
71
|
+
setCurrentInputValue(currentInputValue);
|
|
72
|
+
}, [value, before, after, setCurrentInputValue]);
|
|
73
|
+
const changeForm = useCallback((val) => {
|
|
74
|
+
valueRef.current = val;
|
|
75
|
+
_onChange(val);
|
|
76
|
+
}, [_onChange]);
|
|
77
|
+
const onChange = (e) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const text = typeof e === 'string' ? e : e.target.value;
|
|
80
|
+
if (maxLength > 0 && text.length > maxLength) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const reg = new RegExp(inputPattern);
|
|
84
|
+
if (inputPattern && !reg.test(text)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setCurrentInputValue(text);
|
|
88
|
+
const newValue = converValueFix(text, before, after, type);
|
|
89
|
+
changeForm(newValue);
|
|
90
|
+
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: newValue }, { originEvent: e });
|
|
91
|
+
};
|
|
92
|
+
const onClear = (e) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
setCurrentInputValue('');
|
|
95
|
+
const newValue = converValueFix('', before, after, type);
|
|
96
|
+
changeForm(newValue);
|
|
97
|
+
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: newValue }, { originEvent: e });
|
|
98
|
+
(_b = events.clear) === null || _b === void 0 ? void 0 : _b.call(events, { originValue: value }, { originEvent: e });
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
};
|
|
101
|
+
const onKeyDown = (e) => {
|
|
102
|
+
if (e.key === 'enter' || e.keyCode === KEY_DOWN_CODE) {
|
|
103
|
+
events.confirm({ value: converValueFix(e.target.value, before, after, type) }, { originEvent: e });
|
|
104
|
+
}
|
|
105
|
+
if (inputType === 'number' && e.key === 'e') {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const onFocus = (e) => {
|
|
110
|
+
events.focus({ value: converValueFix(e.target.value, before, after, type) }, { originEvent: e });
|
|
111
|
+
setFocus(true);
|
|
112
|
+
};
|
|
113
|
+
const onBlur = (e) => {
|
|
114
|
+
events.blur({ value: converValueFix(e.target.value, before, after, type) }, { originEvent: e });
|
|
115
|
+
setFocus(false);
|
|
116
|
+
};
|
|
117
|
+
useImperativeHandle(ref, () => ({
|
|
118
|
+
...innerHandle,
|
|
119
|
+
name,
|
|
120
|
+
value,
|
|
121
|
+
label,
|
|
122
|
+
required,
|
|
123
|
+
visible,
|
|
124
|
+
disabled,
|
|
125
|
+
readOnly,
|
|
126
|
+
before,
|
|
127
|
+
after,
|
|
128
|
+
}), [
|
|
129
|
+
innerHandle,
|
|
130
|
+
name,
|
|
131
|
+
value,
|
|
132
|
+
label,
|
|
133
|
+
required,
|
|
134
|
+
visible,
|
|
135
|
+
disabled,
|
|
136
|
+
readOnly,
|
|
137
|
+
before,
|
|
138
|
+
after,
|
|
139
|
+
]);
|
|
140
|
+
const formItemProps = {
|
|
141
|
+
...props,
|
|
142
|
+
validateErrorMsg,
|
|
143
|
+
validateState,
|
|
144
|
+
readOnly,
|
|
145
|
+
readValue: value,
|
|
146
|
+
disabled,
|
|
147
|
+
classRoot,
|
|
148
|
+
inputId,
|
|
149
|
+
layout,
|
|
150
|
+
};
|
|
151
|
+
const inputGroupProps = { before, after, block, classRoot, size };
|
|
152
|
+
if (!visible)
|
|
153
|
+
return null;
|
|
154
|
+
return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(WdInputGroup, { ...inputGroupProps, children: _jsxs("div", { className: cls, 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, children: _jsx(WdIcon, { size: size, 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, disabled: disabled, name: name, autoFocus: focus, autoComplete: "off", maxLength: maxLength, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, ...startWithOnProps }) }), hasClearIcon && (_jsx("div", { className: suffixCls, children: _jsx(WdIcon, { className: `${classPrefix}-icon__trigger`, name: "td:close-circle-filled", onMouseDown: onClear }) })), !hasClearIcon && suffixType && (_jsx("div", { className: suffixCls, children: _jsx(WdIcon, { size: size, name: suffixIcon, type: suffixType, src: suffixSrc, className: suffixIconCls }) })), counterVisible && (_jsxs("span", { className: countCls, children: [counter, "/", maxLength] }))] }) }) }));
|
|
155
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { useConfig } from '../../utils/config-context';
|
|
4
|
+
import { WdInput } from '../wd-input';
|
|
5
|
+
const rules = [{ format: 'email', message: '邮箱校验失败' }];
|
|
6
|
+
/**
|
|
7
|
+
* 标准化:邮箱输入组件
|
|
8
|
+
*/
|
|
9
|
+
export const WdInputEmail = forwardRef(function WdInputEmail(props, ref) {
|
|
10
|
+
const { classPrefix } = useConfig();
|
|
11
|
+
const wrapCls = `${classPrefix}-form-input-email-wrap`;
|
|
12
|
+
return (_jsx(WdInput, { ...props, ref: ref, wrapClassName: wrapCls, classRoot: "input-email", rules: rules }));
|
|
13
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classNames from '../../utils/classnames';
|
|
3
|
+
import { useConfig } from '../../utils/config-context';
|
|
4
|
+
export const WdInputGroup = ({ before, after, className, children, }) => {
|
|
5
|
+
// 兼容旧版组件的属性值
|
|
6
|
+
const { classPrefix } = useConfig();
|
|
7
|
+
const compClassName = `${classPrefix}-form-input-group `;
|
|
8
|
+
const classList = [compClassName];
|
|
9
|
+
return (_jsxs("div", { className: classNames(...classList, className), children: [before && (_jsx("div", { className: `${classPrefix}-form-input-group__addon ${classPrefix}-form-input-group__addon-left`, children: before })), _jsx("div", { className: `${classPrefix}-form-input-group__content`, children: children }), after && (_jsx("div", { className: `${classPrefix}-form-input-group__addon ${classPrefix}-form-input-group__addon-right`, children: after }))] }));
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { useConfig } from '../../utils/config-context';
|
|
4
|
+
import { WdInput } from '../wd-input';
|
|
5
|
+
const rules = [{ format: 'mobile', message: '手机校验失败' }];
|
|
6
|
+
/**
|
|
7
|
+
* 标准化:电话输入组件
|
|
8
|
+
*/
|
|
9
|
+
export const WdInputPhone = forwardRef(function WdInputPhone(props, ref) {
|
|
10
|
+
const { classPrefix } = useConfig();
|
|
11
|
+
const wrapCls = `${classPrefix}-form-input-number-wrap `;
|
|
12
|
+
const pattern = '^[0-9\\-]{0,11}$';
|
|
13
|
+
return (_jsx(WdInput, { ...props, inputPattern: pattern, maxLength: 11, wrapClassName: wrapCls, classRoot: "input-phone", rules: rules, ref: ref }));
|
|
14
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { useConfig } from '../../utils/config-context';
|
|
4
|
+
import { WdInput } from '../wd-input';
|
|
5
|
+
const rules = [{ format: 'url', message: 'url校验失败' }];
|
|
6
|
+
/**
|
|
7
|
+
* 标准化:URL输入组件
|
|
8
|
+
*/
|
|
9
|
+
export const WdInputUrl = forwardRef(function WdInputUrl(props, ref) {
|
|
10
|
+
const { classPrefix } = useConfig();
|
|
11
|
+
const wrapCls = `${classPrefix}-form-input-url-wrap`;
|
|
12
|
+
return (_jsx(WdInput, { ...props, ref: ref, classRoot: "input-url", wrapClassName: wrapCls, rules: rules }));
|
|
13
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import classNames from '../../utils/classnames';
|
|
4
|
+
import { useConfig } from '../../utils/config-context';
|
|
5
|
+
// import { WdIcon } from '../index';
|
|
6
|
+
export const WdInputWrap = ({ className, children, before, after, }) => {
|
|
7
|
+
// 兼容旧版组件的属性值
|
|
8
|
+
const { classPrefix } = useConfig();
|
|
9
|
+
const compClassName = `${classPrefix}-form-input-wrap `;
|
|
10
|
+
const classList = [compClassName];
|
|
11
|
+
classList.push(className);
|
|
12
|
+
const InputWrap = React.useRef(null);
|
|
13
|
+
return (_jsxs("div", { className: classNames(...classList), ref: InputWrap, onFocus: () => {
|
|
14
|
+
InputWrap.current.classList.add('is-focused');
|
|
15
|
+
}, onBlur: () => {
|
|
16
|
+
InputWrap.current.classList.remove('is-focused');
|
|
17
|
+
}, children: [before && (_jsx("div", { className: `${classPrefix}-form-input-wrap__before`, children: before })), children && (_jsx("div", { className: `${classPrefix}-form-input-wrap__content`, children: children })), after && (_jsx("div", { className: `${classPrefix}-form-input-wrap__after`, children: after }))] }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.weda-official-account {
|
|
2
|
+
height: 106px;
|
|
3
|
+
background-color: #fff;
|
|
4
|
+
padding: 10px 15px;
|
|
5
|
+
border: 1px solid #f2f2f2;
|
|
6
|
+
border-radius: 2px;
|
|
7
|
+
}
|
|
8
|
+
.weda-official-account__title {
|
|
9
|
+
margin-bottom: 12px;
|
|
10
|
+
font-size: 12px;
|
|
11
|
+
}
|
|
12
|
+
.weda-official-account__left {
|
|
13
|
+
display: flex;
|
|
14
|
+
}
|
|
15
|
+
.weda-official-account__left__img {
|
|
16
|
+
height: 54px;
|
|
17
|
+
width: 54px;
|
|
18
|
+
border-radius: 100%;
|
|
19
|
+
margin-right: 8px;
|
|
20
|
+
}
|
|
21
|
+
.weda-official-account .weda-official-account__label {
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
}
|
|
24
|
+
.weda-official-account
|
|
25
|
+
.wedatea2td-justify-grid__col--right
|
|
26
|
+
.weda-official-account__btn {
|
|
27
|
+
border-color: var(--weui-WECHAT);
|
|
28
|
+
color: var(--weui-WECHAT);
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* @Date: 2023-04-18 19:14:42
|
|
4
|
+
* @LastEditTime: 2023-05-04 11:54:50
|
|
5
|
+
* @Description:
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { Text, Justify, ConfigProvider, Bubble } from 'tea-component';
|
|
9
|
+
import classNames from '../../utils/classnames';
|
|
10
|
+
import { WdButton } from '../../components/wd-button';
|
|
11
|
+
// @ts-ignore忽略ts交验
|
|
12
|
+
// eslint-disable-next-line rulesdir/no-phantom-deps,import/no-unresolved
|
|
13
|
+
import { autorun } from 'mobx';
|
|
14
|
+
import './index.css';
|
|
15
|
+
export default function WdOfficialAccount(props) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const { className, id, style } = props;
|
|
18
|
+
const [editorPlatforms, setEditorPlatforms] = React.useState([]);
|
|
19
|
+
const dispose = React.useMemo(() => {
|
|
20
|
+
return autorun(() => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
setEditorPlatforms((_b = (_a = window === null || window === void 0 ? void 0 : window.$w) === null || _a === void 0 ? void 0 : _a.wedaContext) === null || _b === void 0 ? void 0 : _b.editorPlatforms);
|
|
23
|
+
});
|
|
24
|
+
}, []);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
return () => {
|
|
27
|
+
dispose();
|
|
28
|
+
};
|
|
29
|
+
}, [dispose]);
|
|
30
|
+
return (_jsx(ConfigProvider, { classPrefix: "wedatea2td", children: ((_b = (_a = window.$w) === null || _a === void 0 ? void 0 : _a.wedaContext) === null || _b === void 0 ? void 0 : _b.isEditorMode) ||
|
|
31
|
+
(editorPlatforms === null || editorPlatforms === void 0 ? void 0 : editorPlatforms.includes('MP')) ? (_jsx(Bubble, { content: _jsxs(_Fragment, { children: ["\u8BF7\u53D1\u5E03\u540E\u5728\u5FAE\u4FE1\u4E2D\u67E5\u770B\u8BE5\u7EC4\u4EF6\u5B9E\u9645\u6548\u679C\uFF0C\u5F53\u524D\u7EC4\u4EF6\u4EC5\u5728\u7279\u5B9A\u5C0F\u7A0B\u5E8F\u6253\u5F00\u573A\u666F\u4E0B\u5C55\u793A\uFF0C", _jsx("br", {}), _jsx("a", { href: "https://developers.weixin.qq.com/miniprogram/dev/component/official-account.html", target: "_blank", rel: "noreferrer", children: "\u67E5\u770B\u8BF4\u660E" })] }), children: _jsxs("div", { className: classNames({
|
|
32
|
+
[className]: className,
|
|
33
|
+
'weda-ui': true,
|
|
34
|
+
'weda-official-account': true,
|
|
35
|
+
}), id: id, style: style, children: [_jsx(Text, { parent: "p", theme: "label", className: "weda-official-account__title", children: "\u67D0\u67D0\u5C0F\u7A0B\u5E8F\u5173\u8054\u7684\u516C\u4F17\u53F7" }), _jsx(Justify, { left: _jsxs("div", { className: "weda-official-account__left", children: [_jsx("img", { className: "weda-official-account__left__img", src: "https://qcloudimg.tencent-cloud.cn/raw/4a29d51b504f12b4933ce4490110b4dc.svg", alt: "" }), _jsxs("div", { children: [_jsx(Text, { reset: true, parent: "p", children: "\u516C\u4F17\u53F7\u540D\u79F0" }), _jsx(Text, { className: "weda-official-account__label", reset: true, parent: "p", theme: "label", children: "\u516C\u4F17\u53F7\u7B80\u4ECB" })] })] }), right: _jsx(WdButton, { theme: "primary", variant: "outline", style: { fontSize: '14px' }, text: "\u5173\u6CE8", size: "mini", className: "weda-official-account__btn" }) })] }) })) : null }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import classNames from '../../utils/classnames';
|
|
4
|
+
import { useConfig } from '../../utils/config-context';
|
|
5
|
+
import getLocalCounter from '../../utils/getLocalCounter';
|
|
6
|
+
export const WdRadio = ({ index, option, name, size, disabled, readOnly, checkedItemValue, getChangeHandler, }) => {
|
|
7
|
+
const { classPrefix } = useConfig();
|
|
8
|
+
const { label, value: optionValue } = option;
|
|
9
|
+
// 类名
|
|
10
|
+
const classList = [];
|
|
11
|
+
switch (size) {
|
|
12
|
+
case 'sm':
|
|
13
|
+
classList.push(`size-sm `);
|
|
14
|
+
break;
|
|
15
|
+
case 'md':
|
|
16
|
+
classList.push(`size-md `);
|
|
17
|
+
break;
|
|
18
|
+
case 'lg':
|
|
19
|
+
classList.push(`size-lg `);
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
classList.push();
|
|
23
|
+
}
|
|
24
|
+
// 现在低码组件往源码组件传入的id不唯一, 暂时使用hashcode替代
|
|
25
|
+
const hashcode = useMemo(() => getLocalCounter(), []);
|
|
26
|
+
const _id = `radio-${hashcode}-${index}`;
|
|
27
|
+
const _name = `radio-${hashcode}-${name}`;
|
|
28
|
+
const NUMBER_1 = 1;
|
|
29
|
+
return (_jsxs("label", { className: `${classPrefix}-radio-wrap ${classNames(classList)} ${`${checkedItemValue}` === `${optionValue}` ? 'is-checked' : ''} ${disabled || readOnly ? 'is-disabled' : ''} ${'radio' + (index + NUMBER_1)}`, onClick: getChangeHandler(optionValue), children: [_jsx("input", { className: `${classPrefix}-radio-input `, id: _id, name: _name, type: "radio", value: optionValue, disabled: disabled || readOnly, checked: `${checkedItemValue}` === `${optionValue}`, onChange: (e) => e.stopPropagation(), onClick: (e) => e.stopPropagation() }), _jsx("span", { className: `${classPrefix}-radio-inner ` }), label && _jsx("span", { className: `${classPrefix}-radio-label`, children: label })] }));
|
|
30
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import React, { useState, useEffect } from 'react';
|
|
4
|
+
import classNames from '../../utils/classnames';
|
|
5
|
+
import { useConfig } from '../../utils/config-context';
|
|
6
|
+
import { WdRadio } from '../index';
|
|
7
|
+
import { WdFormItem } from '../wd-form-item';
|
|
8
|
+
import { emptyObject } from '../../utils/constant';
|
|
9
|
+
import { usePlatform } from '../../utils/platform';
|
|
10
|
+
import { useSize } from '../../utils/hooks/useFormLegacy';
|
|
11
|
+
import { useFormInputTrait } from '../form-input-hooks';
|
|
12
|
+
import { callWedaApi } from '../../utils/tcb';
|
|
13
|
+
import destr from 'destr';
|
|
14
|
+
export const WdRadioList = React.forwardRef(function WdRadioList(props, inputRef) {
|
|
15
|
+
const { range, direction, events = emptyObject, format = '', enumName = '', label, } = props;
|
|
16
|
+
const size = useSize(props);
|
|
17
|
+
const [innerHandle, setInnerHandle] = React.useState({}); // hook里挂出的属性
|
|
18
|
+
/** 兼容从 Form 获取属性,必须引入,自动挂载组件方法 */
|
|
19
|
+
const traitProps = { ...props, inputRef, setInnerHandle };
|
|
20
|
+
const { value: defaultValue, onChange: outerOnChange, disabled, readOnly, validateErrorMsg, validateState, visible, name, value, required, layout, } = useFormInputTrait(traitProps);
|
|
21
|
+
const [options, setOptions] = React.useState(format === 'x-enum' ? [] : range);
|
|
22
|
+
const [checkedItemValue, setCheckedItemValue] = useState(defaultValue);
|
|
23
|
+
const { classPrefix } = useConfig();
|
|
24
|
+
const platform = usePlatform();
|
|
25
|
+
const compClassName = `${classPrefix}-radio-group `;
|
|
26
|
+
// 类名
|
|
27
|
+
const classList = [compClassName];
|
|
28
|
+
['inline'].includes(direction) &&
|
|
29
|
+
classList.push(`${classPrefix}-radio-group--inner `);
|
|
30
|
+
/**
|
|
31
|
+
* 在ios h5端, label和input的绑定不生效
|
|
32
|
+
* 导致 onChange 事件触发有问题, 所以改为监听 onClick 事件
|
|
33
|
+
*/
|
|
34
|
+
const getChangeHandler = function (value) {
|
|
35
|
+
const onChange = function (e) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
if (!disabled && !readOnly) {
|
|
39
|
+
if (checkedItemValue && `${checkedItemValue}` === `${value}`) {
|
|
40
|
+
setCheckedItemValue('');
|
|
41
|
+
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: '' }, { originEvent: e });
|
|
42
|
+
outerOnChange === null || outerOnChange === void 0 ? void 0 : outerOnChange('');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setCheckedItemValue(value);
|
|
46
|
+
(_b = events.change) === null || _b === void 0 ? void 0 : _b.call(events, { value }, { originEvent: e });
|
|
47
|
+
outerOnChange === null || outerOnChange === void 0 ? void 0 : outerOnChange(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return onChange;
|
|
52
|
+
};
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
setCheckedItemValue(defaultValue);
|
|
55
|
+
}, [defaultValue, options]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (format !== 'x-enum') {
|
|
58
|
+
setOptions(range);
|
|
59
|
+
}
|
|
60
|
+
}, [range, format]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
|
|
63
|
+
if (format === 'x-enum' && enumName) {
|
|
64
|
+
fetchData({ OptNameList: [enumName], PageIndex: 1, PageSize: 10 });
|
|
65
|
+
}
|
|
66
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
+
}, []);
|
|
68
|
+
React.useImperativeHandle(inputRef, () => ({
|
|
69
|
+
...innerHandle,
|
|
70
|
+
name,
|
|
71
|
+
value,
|
|
72
|
+
label,
|
|
73
|
+
required,
|
|
74
|
+
visible,
|
|
75
|
+
disabled,
|
|
76
|
+
readOnly,
|
|
77
|
+
}), [innerHandle, name, value, label, required, visible, disabled, readOnly]);
|
|
78
|
+
const fetchData = async (param) => {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
const data = await callWedaApi({
|
|
81
|
+
action: 'DescribeGeneralOptionsDetailList',
|
|
82
|
+
data: param,
|
|
83
|
+
});
|
|
84
|
+
const config = (_c = destr((_b = (_a = data === null || data === void 0 ? void 0 : data.Items) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.Config)) !== null && _c !== void 0 ? _c : [];
|
|
85
|
+
const enumOption = config.map((item) => {
|
|
86
|
+
return {
|
|
87
|
+
label: item.value,
|
|
88
|
+
value: item.key,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
setOptions(enumOption);
|
|
92
|
+
};
|
|
93
|
+
const labelSize = () => {
|
|
94
|
+
if (['h5'].includes(platform) ||
|
|
95
|
+
(['horizontal', ''].includes(layout) &&
|
|
96
|
+
['vertical'].includes(direction))) {
|
|
97
|
+
return 'xs';
|
|
98
|
+
}
|
|
99
|
+
return size;
|
|
100
|
+
};
|
|
101
|
+
return (visible && (_jsx(WdFormItem, { ...props, testId: "form-radio-group", validateErrorMsg: validateErrorMsg, validateState: validateState, readValue: defaultValue, disabled: disabled, classRoot: 'radio', size: labelSize(), layout: layout, children: _jsx("div", { className: classNames(classList), children: options === null || options === void 0 ? void 0 : options.map((Item, Index) => {
|
|
102
|
+
return (_createElement(WdRadio, { ...props, key: Index, index: Index, size: ['h5'].includes(platform) ? 'lg' : props === null || props === void 0 ? void 0 : props.size, option: Item, disabled: disabled, readOnly: readOnly, getChangeHandler: getChangeHandler, checkedItemValue: checkedItemValue }));
|
|
103
|
+
}) }) })));
|
|
104
|
+
});
|