@cloudbase/weda-ui 3.15.8 → 3.17.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.
- package/dist/configs/components/container.js +0 -3
- package/dist/configs/components/wd-ad.d.ts +4 -0
- package/dist/configs/components/wd-ad.js +23 -0
- package/dist/configs/components/wd-cascader.d.ts +4 -0
- package/dist/configs/components/wd-checkbox.d.ts +4 -0
- package/dist/configs/components/wd-code-editor.d.ts +4 -0
- package/dist/configs/components/wd-date-range.d.ts +4 -0
- package/dist/configs/components/wd-date.d.ts +4 -0
- package/dist/configs/components/wd-department.d.ts +6 -0
- package/dist/configs/components/wd-department.js +1 -1
- package/dist/configs/components/wd-form-arr.d.ts +4 -0
- package/dist/configs/components/wd-form-detail.d.ts +4 -0
- package/dist/configs/components/wd-form-obj.d.ts +4 -0
- package/dist/configs/components/wd-input-email.d.ts +4 -0
- package/dist/configs/components/wd-input-number.d.ts +4 -0
- package/dist/configs/components/wd-input-phone.d.ts +4 -0
- package/dist/configs/components/wd-input-url.d.ts +4 -0
- package/dist/configs/components/wd-input.d.ts +4 -0
- package/dist/configs/components/wd-location.d.ts +4 -0
- package/dist/configs/components/wd-member.d.ts +4 -0
- package/dist/configs/components/wd-radio.d.ts +4 -0
- package/dist/configs/components/wd-rating.d.ts +4 -0
- package/dist/configs/components/wd-region.d.ts +4 -0
- package/dist/configs/components/wd-rich-text.d.ts +4 -0
- package/dist/configs/components/wd-select-multiple.d.ts +17 -8
- package/dist/configs/components/wd-select-multiple.js +43 -10
- package/dist/configs/components/wd-select.d.ts +17 -8
- package/dist/configs/components/wd-select.js +85 -8
- package/dist/configs/components/wd-switch.d.ts +4 -0
- package/dist/configs/components/wd-tag-select.d.ts +4 -0
- package/dist/configs/components/wd-tag.d.ts +4 -0
- package/dist/configs/components/wd-textarea.d.ts +4 -0
- package/dist/configs/components/wd-time.d.ts +4 -0
- package/dist/configs/components/wd-upload-file.d.ts +4 -0
- package/dist/configs/components/wd-upload-image.d.ts +195 -15
- package/dist/configs/components/wd-upload-image.js +125 -6
- package/dist/configs/index.d.ts +536 -20
- package/dist/configs/type-utils/type-form.d.ts +4 -0
- package/dist/configs/type-utils/type-form.js +4 -0
- package/dist/configs/type-utils/x-runtime-default.d.ts +3 -0
- package/dist/configs/type-utils/x-runtime-default.js +3 -0
- package/dist/configs/utils/field.d.ts +1 -0
- package/dist/configs/utils/field.js +95 -0
- package/dist/style/weda-ui.min.css +1 -1
- package/dist/web/components/form/uploader/index.d.ts +1 -0
- package/dist/web/components/form/uploader/index.js +7 -4
- package/dist/web/components/form/uploader/upload/index.d.ts +26 -0
- package/dist/web/components/form/uploader/upload/index.js +200 -0
- package/dist/web/components/form/uploader/uploader.h5.d.ts +6 -1
- package/dist/web/components/form/uploader/uploader.h5.js +26 -94
- package/dist/web/components/form/uploader/uploader.pc.d.ts +1 -1
- package/dist/web/components/form/uploader/uploader.pc.js +30 -100
- package/dist/web/components/form/uploader/util.d.ts +16 -0
- package/dist/web/components/form/uploader/util.js +106 -5
- package/dist/web/components/form/uploaderFile/uploadFile.h5.js +3 -5
- package/dist/web/components/form/uploaderFile/uploadFile.pc.js +3 -5
- package/dist/web/components/uploaderView/index.js +1 -1
- package/dist/web/components/wd-ad/wd-ad.js +2 -4
- package/dist/web/components/wd-select/relationSelect/relationSelect.js +2 -2
- package/dist/web/components/wd-select/select/index.js +3 -2
- package/dist/web/components/wd-select/select/selectUI.js +3 -3
- package/dist/web/components/wd-select/wd-select.d.ts +2 -0
- package/dist/web/components/wd-select/wd-select.js +9 -3
- package/dist/web/components/wd-select-multiple/wd-select-multiple.d.ts +2 -0
- package/dist/web/components/wd-select-multiple/wd-select-multiple.js +9 -3
- package/dist/web/components/wd-upload-image/wd-upload-image.js +14 -4
- package/package.json +5 -5
- package/dist/web/components/form/uploader/useUploadFile.d.ts +0 -16
- package/dist/web/components/form/uploader/useUploadFile.js +0 -99
|
@@ -52,7 +52,7 @@ const defaultSize = 50;
|
|
|
52
52
|
const defaultPage = 1;
|
|
53
53
|
export function RelationSelect(props) {
|
|
54
54
|
var _a, _b;
|
|
55
|
-
const { placeholder, size, disabled, onChange, value, onSearch, addRelationButton, childRef, dataSourceName, selectFields, selectFieldType, primaryField, setRefreshStatus, mode, onRelationOptionJump, enableRelationOptionJump, listWidth = 700, ignoreCase = true, where, queryCondition, supportManyRelated, sorter, } = props;
|
|
55
|
+
const { placeholder, size, disabled, onChange, value, onSearch, addRelationButton, childRef, dataSourceName, selectFields, selectFieldType, primaryField, setRefreshStatus, mode, onRelationOptionJump, enableRelationOptionJump, listWidth = 700, ignoreCase = true, where, queryCondition, supportManyRelated, sorter, searchable, } = props;
|
|
56
56
|
const selectFieldsLength = selectFieldType === 'custom' ? selectFields === null || selectFields === void 0 ? void 0 : selectFields.length : 0;
|
|
57
57
|
// 设置下拉列表与下拉按钮同宽
|
|
58
58
|
// 以传入为准,未传入,在自定义展示字段少于2个时设置为 true,否则设置为false,宽度设置为700,
|
|
@@ -151,7 +151,7 @@ export function RelationSelect(props) {
|
|
|
151
151
|
searchOptionListWithWhere(filter);
|
|
152
152
|
onSearch(keyword);
|
|
153
153
|
};
|
|
154
|
-
return (_jsx(Select, { ...props, overlayClassName: isRelationSelectOption ? 'wd-relation-select-overlay' : '', searchable:
|
|
154
|
+
return (_jsx(Select, { ...props, overlayClassName: isRelationSelectOption ? 'wd-relation-select-overlay' : '', searchable: searchable, listWidth: listWidth, listHeight: _listHeight, matchButtonWidth: _matchButtonWidth, placeholder: placeholder, appearance: 'button', filter: () => true, size: size, disabled: disabled, autoClearSearchValue: true, options: customOptions, value: value, onChange: onChange, onSearch: searchHandle, bottomTips: isLoading ? _jsx(LoadingTip, {}) : undefined, onScrollBottom: () => {
|
|
155
155
|
if (!isLoading && customOptions.length < total) {
|
|
156
156
|
setQuery((query) => ({
|
|
157
157
|
...query,
|
|
@@ -3,6 +3,7 @@ import { ConfigProvider } from 'tea-component';
|
|
|
3
3
|
import { CustomSelect } from '../relationSelect/index';
|
|
4
4
|
import { SelectUI as Select } from './selectUI';
|
|
5
5
|
export function SelectCom(props) {
|
|
6
|
-
const { isRelation } = props;
|
|
7
|
-
|
|
6
|
+
const { isRelation, filterable = false } = props;
|
|
7
|
+
const filter = filterable ? () => true : undefined;
|
|
8
|
+
return (_jsx(ConfigProvider, { classPrefix: "wedatea2td", children: isRelation ? _jsx(CustomSelect, { ...props }) : _jsx(Select, { ...props, filter: filter }) }));
|
|
8
9
|
}
|
|
@@ -29,7 +29,7 @@ const getSelectedItem = (options = [], value) => {
|
|
|
29
29
|
return options === null || options === void 0 ? void 0 : options.filter((i) => selectedVal.find((j) => j === i.value) !== undefined);
|
|
30
30
|
};
|
|
31
31
|
function SelectH5(props) {
|
|
32
|
-
const { placeholder, name, disabled, footer, options = [], value, onChange, overlayClassName, searchable, bottomTips, onSearch, onOpen, onScrollBottom, mode, readValue, popupContainer, searchPlaceholder, } = props;
|
|
32
|
+
const { placeholder, name, disabled, footer, options = [], value, onChange, overlayClassName, searchable, bottomTips, onSearch, onOpen, onScrollBottom, mode, readValue, popupContainer, searchPlaceholder, filterable, onBlur, onFocus, } = props;
|
|
33
33
|
const isMultiple = mode === 'multiple';
|
|
34
34
|
const customPickerCls = classNames('weda-ui-custom-picker__cloumns', {
|
|
35
35
|
'weda-ui-custom-picker__cloumns--select-multiple': isMultiple,
|
|
@@ -49,7 +49,7 @@ function SelectH5(props) {
|
|
|
49
49
|
return options.filter((i) => String(i === null || i === void 0 ? void 0 : i.label).toLowerCase().includes(searchValue.toLowerCase()));
|
|
50
50
|
};
|
|
51
51
|
// 前端查询
|
|
52
|
-
const customOptions = isSearch && searchValue ? getOptionList() : options;
|
|
52
|
+
const customOptions = isSearch && searchValue && !filterable ? getOptionList() : options;
|
|
53
53
|
const handleZhStart = () => {
|
|
54
54
|
// 判断是否输入中文,则停止搜索
|
|
55
55
|
setIsSearch(false);
|
|
@@ -124,7 +124,7 @@ function SelectH5(props) {
|
|
|
124
124
|
setCurrentSelected(dealSelectedItem(item));
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
return (_jsxs(_Fragment, { children: [_jsx("input", { "data-testid": "form-item-select", className: inputCls, type: "text", name: name, placeholder: placeholder, autoComplete: "off", disabled: disabled, readOnly: true, value: readValue || '', onClick: handleClick }), _jsxs(Modal, { visible: visible, onClose: () => {
|
|
127
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { "data-testid": "form-item-select", className: inputCls, type: "text", name: name, placeholder: placeholder, autoComplete: "off", disabled: disabled, readOnly: true, value: readValue || '', onClick: handleClick, onFocus: onFocus, onBlur: onBlur }), _jsxs(Modal, { visible: visible, onClose: () => {
|
|
128
128
|
if (inputFocus) {
|
|
129
129
|
// 聚焦在搜索框
|
|
130
130
|
setInputFocus(false);
|
|
@@ -20,7 +20,7 @@ import { SelectProvider } from './contexts/selectContext';
|
|
|
20
20
|
*/
|
|
21
21
|
export const WdSelect = forwardRef(function WsSelect(props, ref) {
|
|
22
22
|
const { classRoot = 'select', clearable = X_RUNTIME_DEFAULT.clearable, placeholder, range, format, tipBlock = X_RUNTIME_DEFAULT.tipBlock, where = X_RUNTIME_DEFAULT.where, enumName, primaryField, viewId, dataSourceName, events = emptyObject, ignoreCase = X_RUNTIME_DEFAULT.ignoreCase, staticSearchable = X_RUNTIME_DEFAULT.staticSearchable, enableRelationalSetting = X_RUNTIME_DEFAULT.enableRelationalSetting, enableRelationalRefresh = X_RUNTIME_DEFAULT.enableRelationalRefresh, addRelationButtonText = X_RUNTIME_DEFAULT.addRelationButtonText, enableAddRelationButton = X_RUNTIME_DEFAULT.enableAddRelationButton, enableRelationOptionJump = X_RUNTIME_DEFAULT.enableRelationOptionJump, popupContainer, selectFields: customFields = [], // 自定义展示字段
|
|
23
|
-
selectFieldType = 'primary', searchPlaceholder, } = props;
|
|
23
|
+
selectFieldType = 'primary', searchPlaceholder, searchable = X_RUNTIME_DEFAULT.searchable, filterable = X_RUNTIME_DEFAULT.filterable, } = props;
|
|
24
24
|
const childRef = useRef(null);
|
|
25
25
|
const [options, setOptions] = useSyncValue(range, isObjectEqual);
|
|
26
26
|
const [innerHandle, setInnerHandle] = useState({});
|
|
@@ -54,6 +54,12 @@ export const WdSelect = forwardRef(function WsSelect(props, ref) {
|
|
|
54
54
|
disabled,
|
|
55
55
|
value,
|
|
56
56
|
});
|
|
57
|
+
const onFocus = (e) => {
|
|
58
|
+
events.focus(null, { originEvent: e });
|
|
59
|
+
};
|
|
60
|
+
const onBlur = (e) => {
|
|
61
|
+
events.blur(null, { originEvent: e });
|
|
62
|
+
};
|
|
57
63
|
const isRelation = isFormatWithRelation(format);
|
|
58
64
|
const LabelAdornment = isRelation && (_jsx(RelationalSetting, { size: props.size, refresh: () => {
|
|
59
65
|
var _a;
|
|
@@ -105,11 +111,11 @@ export const WdSelect = forwardRef(function WsSelect(props, ref) {
|
|
|
105
111
|
}, [debouncedTriggerSearchEvent]);
|
|
106
112
|
if (!visible)
|
|
107
113
|
return null;
|
|
108
|
-
return (_jsx(SelectProvider, { options: options, setOptions: setOptions, children: _jsx(WdFormItem, { ...formItemProps, children: _jsxs(_Fragment, { children: [_jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(Select, { ...props, style: undefined, className: undefined, onRelationTagClick: (item) => {
|
|
114
|
+
return (_jsx(SelectProvider, { options: options, setOptions: setOptions, children: _jsx(WdFormItem, { ...formItemProps, children: _jsxs(_Fragment, { children: [_jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(Select, { ...props, onBlur: onBlur, onFocus: onFocus, filterable: filterable, style: undefined, className: undefined, onRelationTagClick: (item) => {
|
|
109
115
|
var _a;
|
|
110
116
|
(_a = delayEvents === null || delayEvents === void 0 ? void 0 : delayEvents.onRelationTagClick) === null || _a === void 0 ? void 0 : _a.call(delayEvents, item);
|
|
111
117
|
}, enableRelationOptionJump: enableRelationOptionJump, onRelationOptionJump: (item) => {
|
|
112
118
|
var _a;
|
|
113
119
|
(_a = delayEvents === null || delayEvents === void 0 ? void 0 : delayEvents.onRelationOptionJump) === null || _a === void 0 ? void 0 : _a.call(delayEvents, item);
|
|
114
|
-
}, selectFieldType: selectFieldType, selectFields: customFields, isRelation: isRelation, addRelationButtonText: addRelationButtonText, enableAddRelationButton: enableAddRelationButton, childRef: childRef, events: delayEvents, labelVisible: false, value: value, enumName: enumName, format: format, placeholder: placeholder, primaryField: primaryField, options: options, size: "full", tipBlock: tipBlock, viewId: viewId, where: where, dataSourceName: dataSourceName, readOnly: readOnly, disabled: disabled, mode: "selector", decorator: null, ignoreCase: ignoreCase, staticSearchable: staticSearchable, onChange: handleChange, onSearch: onSearchValueInput, popupContainer: popupContainer, searchable:
|
|
120
|
+
}, selectFieldType: selectFieldType, selectFields: customFields, isRelation: isRelation, addRelationButtonText: addRelationButtonText, enableAddRelationButton: enableAddRelationButton, childRef: childRef, events: delayEvents, labelVisible: false, value: value, enumName: enumName, format: format, placeholder: placeholder, primaryField: primaryField, options: options, size: "full", tipBlock: tipBlock, viewId: viewId, where: where, dataSourceName: dataSourceName, readOnly: readOnly, disabled: disabled, mode: "selector", decorator: null, ignoreCase: ignoreCase, staticSearchable: staticSearchable, onChange: handleChange, onSearch: onSearchValueInput, popupContainer: popupContainer, searchable: searchable, searchPlaceholder: searchPlaceholder }) }) }), layout === 'horizontal' && LabelAdornment] }) }) }));
|
|
115
121
|
});
|
|
@@ -21,7 +21,7 @@ import { SelectProvider } from '../wd-select/contexts/selectContext';
|
|
|
21
21
|
*/
|
|
22
22
|
export const WdSelectMultiple = forwardRef(function WdSelectMultiple(props, ref) {
|
|
23
23
|
const { classRoot = 'select-multiple', clearable = X_RUNTIME_DEFAULT.clearable, placeholder, range, enumName, format, primaryField, tipBlock = X_RUNTIME_DEFAULT.tipBlock, viewId, dataSourceName, events = emptyObject, ignoreCase = X_RUNTIME_DEFAULT.ignoreCase, staticSearchable = X_RUNTIME_DEFAULT.staticSearchable, where = X_RUNTIME_DEFAULT.where, enableRelationalSetting = X_RUNTIME_DEFAULT.enableRelationalSetting, enableRelationalRefresh = X_RUNTIME_DEFAULT.enableRelationalRefresh, addRelationButtonText = X_RUNTIME_DEFAULT.addRelationButtonText, enableAddRelationButton = X_RUNTIME_DEFAULT.enableAddRelationButton, enableRelationOptionJump = X_RUNTIME_DEFAULT.enableRelationOptionJump, popupContainer, selectFields: customFields = [], // 自定义展示字段
|
|
24
|
-
selectFieldType = 'primary', searchPlaceholder, } = props;
|
|
24
|
+
selectFieldType = 'primary', searchPlaceholder, searchable = X_RUNTIME_DEFAULT.searchable, filterable = X_RUNTIME_DEFAULT.filterable, } = props;
|
|
25
25
|
const childRef = useRef(null);
|
|
26
26
|
const [options, setOptions] = useSyncValue(range, isObjectEqual);
|
|
27
27
|
const [innerHandle, setInnerHandle] = useState({});
|
|
@@ -56,6 +56,12 @@ export const WdSelectMultiple = forwardRef(function WdSelectMultiple(props, ref)
|
|
|
56
56
|
onChange === null || onChange === void 0 ? void 0 : onChange(v);
|
|
57
57
|
(_a = delayEvents === null || delayEvents === void 0 ? void 0 : delayEvents.change) === null || _a === void 0 ? void 0 : _a.call(delayEvents, { value: v, context });
|
|
58
58
|
};
|
|
59
|
+
const onFocus = (e) => {
|
|
60
|
+
events.focus(null, { originEvent: e });
|
|
61
|
+
};
|
|
62
|
+
const onBlur = (e) => {
|
|
63
|
+
events.blur(null, { originEvent: e });
|
|
64
|
+
};
|
|
59
65
|
const isRelation = isFormatWithRelation(format);
|
|
60
66
|
const LabelAdornment = isRelation && (_jsx(RelationalSetting, { size: props.size, refresh: () => {
|
|
61
67
|
var _a;
|
|
@@ -101,11 +107,11 @@ export const WdSelectMultiple = forwardRef(function WdSelectMultiple(props, ref)
|
|
|
101
107
|
}, [debouncedTriggerSearchEvent]);
|
|
102
108
|
if (!visible)
|
|
103
109
|
return null;
|
|
104
|
-
return (_jsx(SelectProvider, { options: options, setOptions: setOptions, children: _jsx(WdFormItem, { ...formItemProps, children: _jsxs(_Fragment, { children: [_jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(SelectMultiple, { ...props, style: undefined, className: undefined, onRelationTagClick: (item) => {
|
|
110
|
+
return (_jsx(SelectProvider, { options: options, setOptions: setOptions, children: _jsx(WdFormItem, { ...formItemProps, children: _jsxs(_Fragment, { children: [_jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(SelectMultiple, { ...props, onBlur: onBlur, onFocus: onFocus, filterable: filterable, style: undefined, className: undefined, onRelationTagClick: (item) => {
|
|
105
111
|
var _a;
|
|
106
112
|
(_a = delayEvents === null || delayEvents === void 0 ? void 0 : delayEvents.onRelationTagClick) === null || _a === void 0 ? void 0 : _a.call(delayEvents, item);
|
|
107
113
|
}, enableRelationOptionJump: enableRelationOptionJump, onRelationOptionJump: (item) => {
|
|
108
114
|
var _a;
|
|
109
115
|
(_a = delayEvents === null || delayEvents === void 0 ? void 0 : delayEvents.onRelationOptionJump) === null || _a === void 0 ? void 0 : _a.call(delayEvents, item);
|
|
110
|
-
}, selectFieldType: selectFieldType, selectFields: customFields, isRelation: isRelation, addRelationButtonText: addRelationButtonText, enableAddRelationButton: enableAddRelationButton, childRef: childRef, events: delayEvents, labelVisible: false, value: value, enumName: enumName, format: format, placeholder: placeholder, primaryField: primaryField, options: options, size: "full", tipBlock: tipBlock, viewId: viewId, dataSourceName: dataSourceName, readOnly: readOnly, disabled: disabled, mode: "multiple", decorator: null, ignoreCase: ignoreCase, staticSearchable: staticSearchable, where: where, onChange: handleChange, onSearch: onSearchValueInput, popupContainer: popupContainer, searchable:
|
|
116
|
+
}, selectFieldType: selectFieldType, selectFields: customFields, isRelation: isRelation, addRelationButtonText: addRelationButtonText, enableAddRelationButton: enableAddRelationButton, childRef: childRef, events: delayEvents, labelVisible: false, value: value, enumName: enumName, format: format, placeholder: placeholder, primaryField: primaryField, options: options, size: "full", tipBlock: tipBlock, viewId: viewId, dataSourceName: dataSourceName, readOnly: readOnly, disabled: disabled, mode: "multiple", decorator: null, ignoreCase: ignoreCase, staticSearchable: staticSearchable, where: where, onChange: handleChange, onSearch: onSearchValueInput, popupContainer: popupContainer, searchable: searchable, searchPlaceholder: searchPlaceholder }) }) }), layout === 'horizontal' && LabelAdornment] }) }) }));
|
|
111
117
|
});
|
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useMemo, useRef } from 'react';
|
|
2
|
+
import { forwardRef, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { useFormInputTrait } from '../../components/form-input-hooks';
|
|
4
4
|
import { WdFormItem } from '../wd-form-item';
|
|
5
5
|
import Uploader from '../form/uploader';
|
|
6
6
|
import { emptyObject } from '../../utils/constant';
|
|
7
7
|
import { convertSingleValue } from '../../utils/tool';
|
|
8
|
+
import { useSetWidgetApi } from '../../utils/widget-api/use-set-widget-api';
|
|
8
9
|
import { X_RUNTIME_DEFAULT } from '../../../configs/type-utils/x-runtime-default';
|
|
9
10
|
import './style';
|
|
11
|
+
import { Upload } from '../form/uploader/upload/index';
|
|
10
12
|
/**
|
|
11
13
|
* 图片上传-标准化
|
|
12
14
|
*/
|
|
13
15
|
export const WdUploadImage = forwardRef(function WdUploadImage(props, ref) {
|
|
14
16
|
const { classRoot = 'upload-image', showShape = X_RUNTIME_DEFAULT.showShape, acceptTypes = X_RUNTIME_DEFAULT.acceptTypes, maxSize = X_RUNTIME_DEFAULT.maxSize, single = X_RUNTIME_DEFAULT.single, maxUploadCount = X_RUNTIME_DEFAULT.maxUploadCount, events = emptyObject, isCompressBeforeUpload = false,
|
|
15
17
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
16
|
-
compressQuality = 70, compressedHeight = 0, compressedWidth = 0, sourceType = 'both', tips, callbacks, } = props;
|
|
18
|
+
compressQuality = 70, compressedHeight = 0, compressedWidth = 0, sourceType = 'both', tips, callbacks, template = 'normal', children, } = props;
|
|
17
19
|
// 强制转换初始值
|
|
18
20
|
const initRef = useRef(false);
|
|
21
|
+
const uploadRef = useRef(null);
|
|
19
22
|
const formValue = useMemo(() => {
|
|
20
23
|
if (initRef.current)
|
|
21
24
|
return props.value;
|
|
22
25
|
initRef.current = true;
|
|
23
26
|
return convertSingleValue(props.value, single);
|
|
24
27
|
}, [props.value, single]);
|
|
25
|
-
const
|
|
28
|
+
const [innerHandle, setInnerHandle] = useState({});
|
|
29
|
+
const [uploadHandle, setUploadHandle] = useState({});
|
|
30
|
+
const traitProps = { ...props, value: formValue, inputRef: ref, setInnerHandle };
|
|
26
31
|
const trait = useFormInputTrait(traitProps);
|
|
27
32
|
const { value, onChange, disabled, readOnly, visible } = trait;
|
|
28
33
|
const formItemProps = {
|
|
@@ -32,7 +37,12 @@ export const WdUploadImage = forwardRef(function WdUploadImage(props, ref) {
|
|
|
32
37
|
readOnly: false,
|
|
33
38
|
size: 'md',
|
|
34
39
|
};
|
|
40
|
+
useSetWidgetApi(() => ({
|
|
41
|
+
...innerHandle,
|
|
42
|
+
...uploadHandle,
|
|
43
|
+
}), [innerHandle, uploadHandle], ref);
|
|
44
|
+
const multiple = !single;
|
|
35
45
|
if (!visible)
|
|
36
46
|
return null;
|
|
37
|
-
return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(Uploader, { events: events, labelVisible: false, acceptTypes: acceptTypes, defaultValue: value, maxSize: maxSize, maxUploadCount: maxUploadCount, single: single, tips: tips, showShape: showShape, readOnly: readOnly, disabled: disabled, decorator: null, onChange: onChange, isCompressBeforeUpload: isCompressBeforeUpload, compressQuality: compressQuality, compressedHeight: compressedHeight, compressedWidth: compressedWidth, sourceType: sourceType, callbacks: callbacks }) }));
|
|
47
|
+
return (_jsx(WdFormItem, { ...formItemProps, children: template === 'custom' ? (_jsx(Upload, { events: events, acceptTypes: acceptTypes, maxSize: maxSize, maxUploadCount: maxUploadCount, readOnly: readOnly, disabled: disabled, isCompressBeforeUpload: isCompressBeforeUpload, compressQuality: compressQuality, compressedHeight: compressedHeight, compressedWidth: compressedWidth, callbacks: callbacks, value: value, multiple: multiple, capture: sourceType === 'camera' ? 'capture' : null, onChange: onChange, ref: uploadRef, setUploadHandle: setUploadHandle, children: children })) : (_jsx(Uploader, { events: events, labelVisible: false, acceptTypes: acceptTypes, defaultValue: value, maxSize: maxSize, maxUploadCount: maxUploadCount, single: single, tips: tips, showShape: showShape, readOnly: readOnly, disabled: disabled, decorator: null, onChange: onChange, isCompressBeforeUpload: isCompressBeforeUpload, compressQuality: compressQuality, compressedHeight: compressedHeight, compressedWidth: compressedWidth, sourceType: sourceType, callbacks: callbacks, setUploadHandle: setUploadHandle })) }));
|
|
38
48
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/weda-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index",
|
|
6
6
|
"miniprogram": "mpdist",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"description": "腾讯云微搭低代码组件库模板",
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@antv/g6": "^4.8.5",
|
|
88
|
-
"@cloudbase/weda-client": "^1.1.
|
|
88
|
+
"@cloudbase/weda-client": "^1.1.27",
|
|
89
89
|
"@codemirror/autocomplete": "^6.16.0",
|
|
90
90
|
"@codemirror/lang-javascript": "^6.2.2",
|
|
91
91
|
"@codemirror/lang-json": "^6.0.1",
|
|
@@ -147,9 +147,9 @@
|
|
|
147
147
|
"@babel/preset-env": "^7.22.15",
|
|
148
148
|
"@babel/preset-react": "^7.22.15",
|
|
149
149
|
"@babel/preset-typescript": "^7.22.15",
|
|
150
|
-
"@cloudbase/cals": "^1.2.
|
|
151
|
-
"@cloudbase/lowcode-cli": "^0.22.
|
|
152
|
-
"@cloudbase/weda-cloud-sdk": "^1.0.
|
|
150
|
+
"@cloudbase/cals": "^1.2.13",
|
|
151
|
+
"@cloudbase/lowcode-cli": "^0.22.2",
|
|
152
|
+
"@cloudbase/weda-cloud-sdk": "^1.0.99",
|
|
153
153
|
"@commitlint/cli": "^16.0.2",
|
|
154
154
|
"@commitlint/config-conventional": "^17.7.0",
|
|
155
155
|
"@craco/craco": "^7.1.0",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const CLASS_PREFIX = "weda-uploader-pc";
|
|
2
|
-
export declare const IMAGE_TYPES: string[];
|
|
3
|
-
interface TempFileProps {
|
|
4
|
-
progress?: number;
|
|
5
|
-
loading?: boolean;
|
|
6
|
-
realUrl?: string;
|
|
7
|
-
tempUrl?: string;
|
|
8
|
-
key?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function useUploader(props: any): {
|
|
11
|
-
tempFile: TempFileProps[];
|
|
12
|
-
uploading: boolean;
|
|
13
|
-
upload: (fileList: any) => Promise<any[]>;
|
|
14
|
-
getTempFile: (allFile?: any[]) => any[];
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { randomStr } from '../../../utils/platform';
|
|
3
|
-
import isObjectEqual from '../../../utils/isObjectEqual';
|
|
4
|
-
import { getBase64, uploadTcbMulti } from './util';
|
|
5
|
-
// 默认组件类前缀
|
|
6
|
-
export const CLASS_PREFIX = 'weda-uploader-pc';
|
|
7
|
-
// 默认图片类型
|
|
8
|
-
export const IMAGE_TYPES = [
|
|
9
|
-
'image/jpg',
|
|
10
|
-
'image/png',
|
|
11
|
-
'image/tif',
|
|
12
|
-
'image/bmp',
|
|
13
|
-
'image/jpeg',
|
|
14
|
-
'image/tiff',
|
|
15
|
-
'image/gif',
|
|
16
|
-
];
|
|
17
|
-
const getInitTempFile = ({ single, value, defaultValue, uploadPath }) => {
|
|
18
|
-
let initialValue = []
|
|
19
|
-
.concat(value ? value : defaultValue)
|
|
20
|
-
.filter((d) => typeof d === 'string' && d !== '');
|
|
21
|
-
if (single) {
|
|
22
|
-
initialValue = initialValue[0] ? [initialValue[0]] : [];
|
|
23
|
-
}
|
|
24
|
-
const tempFile = initialValue.map((i) => ({
|
|
25
|
-
key: randomStr(),
|
|
26
|
-
uploadPath,
|
|
27
|
-
realUrl: i,
|
|
28
|
-
tempUrl: '',
|
|
29
|
-
progress: 100,
|
|
30
|
-
loading: false,
|
|
31
|
-
}));
|
|
32
|
-
return tempFile;
|
|
33
|
-
};
|
|
34
|
-
export function useUploader(props) {
|
|
35
|
-
const { defaultValue, // 需要兼容 cloud:和https: 协议,需要兼容 字符串和字符串数组
|
|
36
|
-
uploadPath = 'weda-uploader', events, single = false, value, // 数据管理后台中,formily使用此字段传默认值
|
|
37
|
-
isCompressBeforeUpload, compressQuality, compressedHeight, compressedWidth, } = props;
|
|
38
|
-
// 上传中
|
|
39
|
-
const [uploading, setUploading] = React.useState(false);
|
|
40
|
-
// 文件列表
|
|
41
|
-
const [tempFile, setTempFile] = React.useState(() => {
|
|
42
|
-
return getInitTempFile(props);
|
|
43
|
-
});
|
|
44
|
-
const defaultValueRef = React.useRef(null);
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
if (isObjectEqual(defaultValueRef.current, defaultValue))
|
|
47
|
-
return;
|
|
48
|
-
const tempFile = getInitTempFile({
|
|
49
|
-
single,
|
|
50
|
-
value,
|
|
51
|
-
defaultValue,
|
|
52
|
-
uploadPath,
|
|
53
|
-
});
|
|
54
|
-
defaultValueRef.current = defaultValue;
|
|
55
|
-
setTempFile(tempFile);
|
|
56
|
-
}, [defaultValue, single, uploadPath, value]);
|
|
57
|
-
// 方法:上传前,判断图片大小、数量是否满足,取消默认组件的上传事件,用自定义的 tcb 上传方法
|
|
58
|
-
const upload = async (fileList) => {
|
|
59
|
-
let tempFiles = fileList.map((i) => ({
|
|
60
|
-
file: i,
|
|
61
|
-
key: randomStr(),
|
|
62
|
-
uploadPath,
|
|
63
|
-
progress: 0,
|
|
64
|
-
loading: true,
|
|
65
|
-
}));
|
|
66
|
-
tempFiles = await getBase64(tempFiles);
|
|
67
|
-
const allTempFile = [...tempFile, ...tempFiles];
|
|
68
|
-
setTempFile(allTempFile);
|
|
69
|
-
setUploading(true);
|
|
70
|
-
const result = await uploadTcbMulti(tempFiles, {
|
|
71
|
-
isCompressBeforeUpload,
|
|
72
|
-
compressedHeight,
|
|
73
|
-
compressedWidth,
|
|
74
|
-
compressQuality,
|
|
75
|
-
onUploadProgress: (item) => {
|
|
76
|
-
setTempFile((allTempFile) => allTempFile.map((i) => (i.key === item.key ? { ...i, ...item } : i)));
|
|
77
|
-
},
|
|
78
|
-
onUploadFinish: (item) => {
|
|
79
|
-
var _a;
|
|
80
|
-
(_a = events === null || events === void 0 ? void 0 : events.success) === null || _a === void 0 ? void 0 : _a.call(events, { value: item.realUrl, file: item.file });
|
|
81
|
-
setUploading(false);
|
|
82
|
-
setTempFile((allTempFile) => allTempFile.map((i) => (i.key === item.key ? { ...i, ...item } : i)));
|
|
83
|
-
},
|
|
84
|
-
onUploadError: (err) => {
|
|
85
|
-
events.error && events.error(err);
|
|
86
|
-
setUploading(false);
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
const allFile = allTempFile.map((i) => result.find((j) => (j === null || j === void 0 ? void 0 : j.key) === (i === null || i === void 0 ? void 0 : i.key)) || i);
|
|
90
|
-
return allFile;
|
|
91
|
-
};
|
|
92
|
-
const getTempFile = (allFile = []) => {
|
|
93
|
-
setTempFile(allFile);
|
|
94
|
-
let value = allFile.map((i) => i === null || i === void 0 ? void 0 : i.realUrl).filter((j) => !!j);
|
|
95
|
-
value = single ? value[0] || '' : value;
|
|
96
|
-
return value;
|
|
97
|
-
};
|
|
98
|
-
return { tempFile, uploading, upload, getTempFile };
|
|
99
|
-
}
|