@cloudbase/weda-ui 3.1.3 → 3.1.7
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/carousel.json +2 -2
- package/dist/configs/components/chart/bar.json +3 -0
- package/dist/configs/components/chart/line.json +3 -0
- package/dist/configs/components/chart/pie.json +3 -0
- package/dist/configs/components/form/checkbox.json +1 -0
- package/dist/configs/components/form/form.json +39 -15
- package/dist/configs/components/form/richText.json +17 -9
- package/dist/configs/components/form/select.json +1 -0
- package/dist/web/components/chart/common/core/eChartBar.js +3 -1
- package/dist/web/components/chart/common/core/eChartLine.js +3 -1
- package/dist/web/components/form/checkbox/index.js +1 -1
- package/dist/web/components/form/form/index.css +4 -0
- package/dist/web/components/form/form/index.d.ts +21 -2
- package/dist/web/components/form/form/index.js +90 -16
- package/dist/web/components/form/location/common/mapChoose.js +93 -35
- package/dist/web/components/form/select/dropdown-select/ui.d.ts +15 -0
- package/dist/web/components/form/select/dropdown-select/ui.js +55 -0
- package/dist/web/components/form/select/h5.d.ts +1 -1
- package/dist/web/components/form/select/h5.js +54 -152
- package/dist/web/components/form/select/index.d.ts +1 -1
- package/dist/web/components/form/select/index.js +33 -96
- package/dist/web/components/form/select/use-options.d.ts +26 -0
- package/dist/web/components/form/select/use-options.js +103 -0
- package/dist/web/components/form/uploader/index.css +10 -3
- package/dist/web/components/form/uploader/uploader.h5.d.ts +1 -1
- package/dist/web/components/form/uploader/uploader.h5.js +18 -19
- package/dist/web/components/form/uploader/uploader.pc.js +6 -3
- package/dist/web/components/richText/index.css +20 -6
- package/dist/web/components/richText/index.d.ts +2 -3
- package/dist/web/components/richText/index.js +119 -65
- package/dist/web/components/richText/richtext.module.css +5 -0
- package/dist/web/utils/tcb.d.ts +5 -1
- package/dist/web/utils/tcb.js +26 -3
- package/dist/web/utils/use-cloud-id-temp-url.d.ts +1 -0
- package/dist/web/utils/use-cloud-id-temp-url.js +13 -0
- package/package.json +41 -37
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { ConfigProvider, Select as TeaSelect, } from 'tea-component';
|
|
3
|
+
import classNames from '../../../../utils/classnames';
|
|
4
|
+
import { noop } from '../../../../utils/constant';
|
|
5
|
+
import { useSyncValue } from '../../../../utils/useSyncValue';
|
|
6
|
+
import weui from '../../../../utils/weui';
|
|
7
|
+
export function PureSelectPc(props) {
|
|
8
|
+
const { size, onChange = noop, disabled, placeholder } = props;
|
|
9
|
+
const [value, setValue] = useSyncValue(props.value);
|
|
10
|
+
const options = useMemo(() => {
|
|
11
|
+
var _a;
|
|
12
|
+
return ((_a = props.options) !== null && _a !== void 0 ? _a : []).map((opt) => ({
|
|
13
|
+
text: opt.label,
|
|
14
|
+
value: opt.value,
|
|
15
|
+
}));
|
|
16
|
+
}, [props.options]);
|
|
17
|
+
return (React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
|
|
18
|
+
React.createElement("div", { "data-testid": "form-select" },
|
|
19
|
+
React.createElement(TeaSelect, { matchButtonWidth: true, size: size, onChange: (v) => {
|
|
20
|
+
onChange(v);
|
|
21
|
+
setValue(v);
|
|
22
|
+
}, disabled: disabled, value: value, type: "simulate", appearance: "button", placeholder: placeholder, options: options }))));
|
|
23
|
+
}
|
|
24
|
+
export function PureSelectH5(props) {
|
|
25
|
+
const { placeholder, name, disabled, onChange = noop, options, layout, className, } = props;
|
|
26
|
+
const [value, setValue] = useSyncValue(props.value);
|
|
27
|
+
const subCls = classNames({
|
|
28
|
+
'weui-cell': true,
|
|
29
|
+
'weui-cell_active': true,
|
|
30
|
+
'weui-cell_form': true,
|
|
31
|
+
'weui-flex__item': layout !== 'vertical',
|
|
32
|
+
'weui-cell_disabled': disabled,
|
|
33
|
+
});
|
|
34
|
+
const onClick = () => {
|
|
35
|
+
weui.picker(options, {
|
|
36
|
+
id: String(Date.now()),
|
|
37
|
+
defaultValue: [value || options[0].value],
|
|
38
|
+
onConfirm(result) {
|
|
39
|
+
const item = result[0];
|
|
40
|
+
setValue(item.value);
|
|
41
|
+
onChange(item.value);
|
|
42
|
+
},
|
|
43
|
+
className,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const currentLabel = useMemo(() => {
|
|
47
|
+
const currentOpt = options.find((opt) => opt.value === value);
|
|
48
|
+
if (!currentOpt)
|
|
49
|
+
return '';
|
|
50
|
+
return currentOpt.label;
|
|
51
|
+
}, [options, value]);
|
|
52
|
+
return (React.createElement("div", { className: subCls },
|
|
53
|
+
React.createElement("div", { className: "weui-cell__bd weui-flex" },
|
|
54
|
+
React.createElement("input", { onClick: onClick, className: "weui-input", type: "select", name: name, placeholder: placeholder, value: currentLabel, disabled: disabled, autoComplete: 'off', readOnly: true, "data-testid": "form-item-select" }))));
|
|
55
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PropsType } from './index';
|
|
3
|
-
export default function Select({ events, name, placeholder, layout, mode, dateMode, disabled, range, where, primaryField,
|
|
3
|
+
export default function Select({ events, name, placeholder, layout, mode, dateMode, disabled, range, where, primaryField, enumName, dataSourceName, viewId, format, defaultValue, startDate, endDate, defaultDate, startTime, endTime, defaultTime, defaultRegion, defaultMutiRegion, separator, regionType, onChange, }: PropsType): JSX.Element;
|
|
4
4
|
export declare function decodeIsoDatetime(isoStringOrTimesnap: any, type: any, dateMode?: string): any;
|
|
5
5
|
/**
|
|
6
6
|
* 根据时间模式,构造 new Date()的传参格式单个日期和时间组件值
|
|
@@ -5,35 +5,32 @@ import isObjectEqual from '../../../utils/isObjectEqual';
|
|
|
5
5
|
import { regionPicker, getRegionTree, getAreaCode } from './region/index';
|
|
6
6
|
import { defaultProps, moment } from './index';
|
|
7
7
|
import { timePicker, yearPicker, monthPicker } from './time';
|
|
8
|
-
import { callDataSource, callWedaApi } from '../../../utils/tcb';
|
|
9
|
-
import destr from 'destr';
|
|
10
8
|
import { emptyObject } from '../../../utils/constant';
|
|
11
|
-
import {
|
|
9
|
+
import { PureSelectH5 } from './dropdown-select/ui';
|
|
10
|
+
import { useOptions } from './use-options';
|
|
12
11
|
export default function Select({
|
|
13
12
|
// 系统属性
|
|
14
13
|
events = emptyObject,
|
|
15
14
|
// 组件属性
|
|
16
15
|
name, placeholder, layout, mode, dateMode = 'day', disabled = false,
|
|
17
16
|
// selector mode
|
|
18
|
-
range = defaultProps.range, where, primaryField,
|
|
17
|
+
range = defaultProps.range, where, primaryField, enumName, dataSourceName, viewId, format, defaultValue,
|
|
19
18
|
// date mode
|
|
20
19
|
startDate, endDate, defaultDate,
|
|
21
20
|
// time mode
|
|
22
21
|
startTime, endTime, defaultTime,
|
|
23
22
|
// region mode
|
|
24
|
-
defaultRegion, defaultMutiRegion,
|
|
23
|
+
defaultRegion, defaultMutiRegion, separator, regionType, onChange, }) {
|
|
25
24
|
var _a;
|
|
26
25
|
const [date, setDate] = React.useState(decodeIsoDatetime(defaultDate, 'date', dateMode));
|
|
27
26
|
const [time, setTime] = React.useState(decodeIsoDatetime(defaultTime, 'time'));
|
|
28
27
|
const [regioDepth, setRegionDepth] = React.useState(3);
|
|
29
28
|
const [regionData, setRegionData] = React.useState([]);
|
|
30
29
|
const [regionTree, setRegionTree] = React.useState([]);
|
|
30
|
+
const [typeRegion, setTypeRegion] = React.useState(regionType);
|
|
31
31
|
const [region, setRegion] = React.useState(defaultRegion);
|
|
32
32
|
const [mutiRegion, setMutiRegion] = React.useState([]);
|
|
33
|
-
const [typeRegion, setTypeRegion] = React.useState(regionType);
|
|
34
33
|
const [selectedValue, setSelectedValue] = React.useState(defaultValue);
|
|
35
|
-
const [option, setOption] = React.useState([{ label: '', value: '' }]);
|
|
36
|
-
const [records, setRecords] = React.useState([]);
|
|
37
34
|
// 两次默认值不同, 需要刷新
|
|
38
35
|
const prevDefaultRef = React.useRef({});
|
|
39
36
|
React.useEffect(() => {
|
|
@@ -95,7 +92,7 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
95
92
|
(_a = events === null || events === void 0 ? void 0 : events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: defaultMutiRegion, result: changeValue });
|
|
96
93
|
}
|
|
97
94
|
};
|
|
98
|
-
|
|
95
|
+
React.useEffect(() => {
|
|
99
96
|
if (mode == 'region' || mode == 'mutiRegion') {
|
|
100
97
|
if (regionData.length < 1) {
|
|
101
98
|
getAreaCode().then((value) => {
|
|
@@ -130,97 +127,6 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
130
127
|
}
|
|
131
128
|
}
|
|
132
129
|
}, [regionType, mode, regionData]);
|
|
133
|
-
React.useEffect(() => {
|
|
134
|
-
// tcb过滤参数
|
|
135
|
-
const whereEffected = [].concat(getWhereList(where));
|
|
136
|
-
if ((format === 'father-son' || format === 'related') &&
|
|
137
|
-
dataSourceName &&
|
|
138
|
-
viewId) {
|
|
139
|
-
fetchData({
|
|
140
|
-
dataSourceName: dataSourceName,
|
|
141
|
-
viewId: viewId,
|
|
142
|
-
methodName: 'wedaGetRecords',
|
|
143
|
-
params: whereEffected,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}, [where]);
|
|
147
|
-
// 获取数据列表中主列字段,将其作为选项
|
|
148
|
-
React.useEffect(() => {
|
|
149
|
-
var _a;
|
|
150
|
-
if (primaryField) {
|
|
151
|
-
if (records && records.length !== 0) {
|
|
152
|
-
const option = records.map((item) => {
|
|
153
|
-
return {
|
|
154
|
-
label: item[primaryField] || item._id,
|
|
155
|
-
value: item._id,
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
setOption(option);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
setOption([{ label: '', value: '' }]);
|
|
162
|
-
setSelectedValue('');
|
|
163
|
-
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: '' });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}, [records]);
|
|
167
|
-
// 获取数据列表
|
|
168
|
-
const fetchData = async (param) => {
|
|
169
|
-
let pageNo = 1;
|
|
170
|
-
const pageSize = 200;
|
|
171
|
-
let records = [];
|
|
172
|
-
let total = 99999;
|
|
173
|
-
for (let index = 0; index < Math.floor(total / pageSize) + 1; index++) {
|
|
174
|
-
const data = await callDataSource({
|
|
175
|
-
dataSourceName: param.dataSourceName,
|
|
176
|
-
viewId: param.viewId,
|
|
177
|
-
methodName: param.methodName,
|
|
178
|
-
params: {
|
|
179
|
-
where: param.params,
|
|
180
|
-
pageNo: pageNo,
|
|
181
|
-
pageSize: pageSize,
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
pageNo = pageNo + 1;
|
|
185
|
-
if (data === null || data === void 0 ? void 0 : data.records) {
|
|
186
|
-
total = (data === null || data === void 0 ? void 0 : data.total) || 0;
|
|
187
|
-
records = records.concat(data === null || data === void 0 ? void 0 : data.records);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (records) {
|
|
191
|
-
setRecords(records);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
React.useEffect(() => {
|
|
195
|
-
// 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
|
|
196
|
-
if (format === 'x-enum' && enumName) {
|
|
197
|
-
fetchEnumData({ OptNameList: [enumName], PageIndex: 1, PageSize: 10 });
|
|
198
|
-
}
|
|
199
|
-
}, [enumName]);
|
|
200
|
-
// 获取自定义选项集
|
|
201
|
-
const fetchEnumData = async (param) => {
|
|
202
|
-
var _a, _b;
|
|
203
|
-
const data = await callWedaApi({
|
|
204
|
-
action: 'DescribeGeneralOptionsDetailList',
|
|
205
|
-
data: param,
|
|
206
|
-
});
|
|
207
|
-
const config = (_b = destr((_a = data === null || data === void 0 ? void 0 : data.Items[0]) === null || _a === void 0 ? void 0 : _a.Config)) !== null && _b !== void 0 ? _b : [];
|
|
208
|
-
const enumOption = config.map((item) => {
|
|
209
|
-
return {
|
|
210
|
-
label: item.value,
|
|
211
|
-
value: item.key,
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
setOption(enumOption);
|
|
215
|
-
};
|
|
216
|
-
const isFlex = layout !== 'vertical';
|
|
217
|
-
const subCls = classNames({
|
|
218
|
-
'weui-cell': true,
|
|
219
|
-
'weui-cell_active': true,
|
|
220
|
-
'weui-cell_form': true,
|
|
221
|
-
'weui-flex__item': isFlex,
|
|
222
|
-
'weui-cell_disabled': disabled,
|
|
223
|
-
});
|
|
224
130
|
const onDateclick = function () {
|
|
225
131
|
const options = {
|
|
226
132
|
className: 'weda-ui weda-picker',
|
|
@@ -274,48 +180,20 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
274
180
|
},
|
|
275
181
|
});
|
|
276
182
|
};
|
|
277
|
-
const onSelect = function () {
|
|
278
|
-
if (format === 'father-son' ||
|
|
279
|
-
format === 'related' ||
|
|
280
|
-
format === 'x-enum') {
|
|
281
|
-
weui.picker(option, {
|
|
282
|
-
id: String(Date.now()),
|
|
283
|
-
defaultValue: [selectedValue || option[0].value],
|
|
284
|
-
onConfirm(result) {
|
|
285
|
-
var _a;
|
|
286
|
-
const item = result[0];
|
|
287
|
-
setSelectedValue(item === null || item === void 0 ? void 0 : item.value);
|
|
288
|
-
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: item === null || item === void 0 ? void 0 : item.value });
|
|
289
|
-
},
|
|
290
|
-
className: 'weda-ui weda-picker',
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
weui.picker(range, {
|
|
295
|
-
id: String(Date.now()),
|
|
296
|
-
defaultValue: [selectedValue || range[0].value],
|
|
297
|
-
onConfirm(result) {
|
|
298
|
-
var _a;
|
|
299
|
-
const item = result[0];
|
|
300
|
-
setSelectedValue(item === null || item === void 0 ? void 0 : item.value);
|
|
301
|
-
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: item === null || item === void 0 ? void 0 : item.value });
|
|
302
|
-
},
|
|
303
|
-
className: 'weda-ui weda-picker',
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
183
|
let regionTimer;
|
|
308
184
|
const momentClick = async () => {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
185
|
+
const cb = () => {
|
|
186
|
+
clearTimeout(regionTimer);
|
|
187
|
+
if (regionTree.length > 0) {
|
|
188
|
+
onRegionClick();
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
setTimeout(cb, 200);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
regionTimer = setTimeout(cb, 200);
|
|
316
195
|
};
|
|
317
196
|
const onRegionClick = function () {
|
|
318
|
-
clearInterval(regionTimer);
|
|
319
197
|
let defaultValue = [];
|
|
320
198
|
if (mode == 'region') {
|
|
321
199
|
defaultRegion && defaultRegion.length <= 0
|
|
@@ -365,10 +243,6 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
365
243
|
onTimeClick();
|
|
366
244
|
break;
|
|
367
245
|
}
|
|
368
|
-
case 'selector': {
|
|
369
|
-
onSelect();
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
246
|
case 'region': {
|
|
373
247
|
momentClick();
|
|
374
248
|
break;
|
|
@@ -383,16 +257,9 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
383
257
|
}
|
|
384
258
|
};
|
|
385
259
|
const result = React.useMemo(() => {
|
|
386
|
-
var _a
|
|
260
|
+
var _a;
|
|
387
261
|
let selectLabel = '';
|
|
388
|
-
|
|
389
|
-
format === 'related' ||
|
|
390
|
-
format === 'x-enum') {
|
|
391
|
-
selectLabel = (_a = (option !== null && option !== void 0 ? option : []).find((item) => item.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label;
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
selectLabel = (_b = (range !== null && range !== void 0 ? range : []).find((item) => item.value === selectedValue)) === null || _b === void 0 ? void 0 : _b.label;
|
|
395
|
-
}
|
|
262
|
+
selectLabel = (_a = (range !== null && range !== void 0 ? range : []).find((item) => item.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label;
|
|
396
263
|
return {
|
|
397
264
|
selector: selectLabel,
|
|
398
265
|
date: date,
|
|
@@ -400,7 +267,42 @@ defaultRegion, defaultMutiRegion, regionType, separator, onChange, }) {
|
|
|
400
267
|
region: (region || []).join(separator),
|
|
401
268
|
mutiRegion: mutiRegion,
|
|
402
269
|
};
|
|
403
|
-
}, [range, selectedValue, date, time, region, separator, mutiRegion
|
|
270
|
+
}, [range, selectedValue, date, time, region, separator, mutiRegion]);
|
|
271
|
+
const subCls = classNames({
|
|
272
|
+
'weui-cell': true,
|
|
273
|
+
'weui-cell_active': true,
|
|
274
|
+
'weui-cell_form': true,
|
|
275
|
+
'weui-flex__item': layout !== 'vertical',
|
|
276
|
+
'weui-cell_disabled': disabled,
|
|
277
|
+
});
|
|
278
|
+
let params = {
|
|
279
|
+
controlledValue: range,
|
|
280
|
+
};
|
|
281
|
+
if (format === 'father-son' || format === 'related') {
|
|
282
|
+
params = {
|
|
283
|
+
format,
|
|
284
|
+
dataSourceName,
|
|
285
|
+
viewId,
|
|
286
|
+
where,
|
|
287
|
+
primaryField,
|
|
288
|
+
controlledValue: range,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
else if (format === 'x-enum') {
|
|
292
|
+
params = {
|
|
293
|
+
format,
|
|
294
|
+
enumName,
|
|
295
|
+
controlledValue: range,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const [options] = useOptions(params);
|
|
299
|
+
if (mode === 'selector') {
|
|
300
|
+
return (React.createElement(PureSelectH5, { className: "weda-ui weda-picker", name: name, value: selectedValue, placeholder: placeholder, disabled: disabled, options: options, onChange: (value) => {
|
|
301
|
+
var _a;
|
|
302
|
+
setSelectedValue(value);
|
|
303
|
+
(_a = events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value });
|
|
304
|
+
} }));
|
|
305
|
+
}
|
|
404
306
|
return (React.createElement("div", { className: subCls },
|
|
405
307
|
React.createElement("div", { className: "weui-cell__bd weui-flex" },
|
|
406
308
|
React.createElement("input", { onClick: onClick, className: "weui-input", type: "select", name: name, placeholder: placeholder, value: (_a = result[mode]) !== null && _a !== void 0 ? _a : '', disabled: disabled, autoComplete: 'off', readOnly: true, "data-testid": "form-item-select" }))));
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as _moment from 'moment';
|
|
3
|
-
import { usePlatform
|
|
3
|
+
import { usePlatform } from '../../../utils/platform';
|
|
4
4
|
import SelectH5, { decodeIsoDatetime } from './h5';
|
|
5
5
|
import classNames from '../../../utils/classnames';
|
|
6
|
-
import {
|
|
6
|
+
import { DatePicker, TimePicker, Cascader, ConfigProvider, } from 'tea-component';
|
|
7
7
|
import isObjectEqual from '../../../utils/isObjectEqual';
|
|
8
|
-
import { getRegionTree, getAreaCode } from './region';
|
|
9
8
|
import { renderDecorator } from '../renderDecorator';
|
|
10
9
|
import YearPicker from './year';
|
|
11
|
-
import { callDataSource, callWedaApi } from '../../../utils/tcb';
|
|
12
|
-
import destr from 'destr';
|
|
13
10
|
import { emptyObject } from '../../../utils/constant';
|
|
11
|
+
import { PureSelectPc } from './dropdown-select/ui';
|
|
12
|
+
import { useOptions } from './use-options';
|
|
13
|
+
import { getRegionTree, getAreaCode } from './region';
|
|
14
14
|
// @ts-ignore TODO: fix 与plugin构建阶段效果不同
|
|
15
15
|
export const moment = (typeof _moment === 'function' ? _moment : _moment.default);
|
|
16
16
|
export default function Select(props) {
|
|
@@ -70,91 +70,27 @@ function SelectPc({ where, dataSourceName, viewId, format, primaryField, enumNam
|
|
|
70
70
|
const [region, setRegion] = React.useState(defaultRegion || undefined);
|
|
71
71
|
const [mutiRegion, setMutiRegion] = React.useState(defaultMutiRegion != null ? defaultMutiRegion.split(',') : []);
|
|
72
72
|
const [selectedValue, setSelectedValue] = React.useState(defaultValue);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
React.useEffect(() => {
|
|
76
|
-
// 筛选参数
|
|
77
|
-
const whereEffected = [].concat(getWhereList(where));
|
|
78
|
-
if ((format === 'father-son' || format === 'related') &&
|
|
79
|
-
dataSourceName &&
|
|
80
|
-
viewId) {
|
|
81
|
-
fetchData({
|
|
82
|
-
dataSourceName: dataSourceName,
|
|
83
|
-
viewId: viewId,
|
|
84
|
-
methodName: 'wedaGetRecords',
|
|
85
|
-
params: whereEffected,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}, [where]);
|
|
89
|
-
// 获取数据列表中主列字段,将其作为选项
|
|
90
|
-
React.useEffect(() => {
|
|
91
|
-
var _a;
|
|
92
|
-
if (primaryField) {
|
|
93
|
-
if (records && records.length !== 0) {
|
|
94
|
-
const option = records.map((item) => {
|
|
95
|
-
return {
|
|
96
|
-
label: item[primaryField] || item._id,
|
|
97
|
-
value: item._id,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
setOption(option);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
setOption([{ label: '', value: '' }]);
|
|
104
|
-
setSelectedValue('');
|
|
105
|
-
(_a = events === null || events === void 0 ? void 0 : events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value: '' });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, [records]);
|
|
109
|
-
// 获取数据源列表
|
|
110
|
-
const fetchData = async (param) => {
|
|
111
|
-
let pageNo = 1;
|
|
112
|
-
const pageSize = 200;
|
|
113
|
-
let records = [];
|
|
114
|
-
let total = 99999;
|
|
115
|
-
for (let index = 0; index < Math.floor(total / pageSize) + 1; index++) {
|
|
116
|
-
const data = await callDataSource({
|
|
117
|
-
dataSourceName: param.dataSourceName,
|
|
118
|
-
viewId: param.viewId,
|
|
119
|
-
methodName: param.methodName,
|
|
120
|
-
params: {
|
|
121
|
-
pageNo: pageNo,
|
|
122
|
-
pageSize: pageSize,
|
|
123
|
-
where: param.params,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
pageNo = pageNo + 1;
|
|
127
|
-
if (data === null || data === void 0 ? void 0 : data.records) {
|
|
128
|
-
total = (data === null || data === void 0 ? void 0 : data.total) || 0;
|
|
129
|
-
records = records.concat(data === null || data === void 0 ? void 0 : data.records);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (records) {
|
|
133
|
-
setRecords(records);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
React.useEffect(() => {
|
|
137
|
-
// 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
|
|
138
|
-
if (format === 'x-enum' && enumName) {
|
|
139
|
-
fetchEnumData({ OptNameList: [enumName], PageIndex: 1, PageSize: 10 });
|
|
140
|
-
}
|
|
141
|
-
}, [enumName]);
|
|
142
|
-
// 获取自定义选项集
|
|
143
|
-
const fetchEnumData = async (param) => {
|
|
144
|
-
var _a, _b, _c;
|
|
145
|
-
const data = await callWedaApi({
|
|
146
|
-
action: 'DescribeGeneralOptionsDetailList',
|
|
147
|
-
data: param,
|
|
148
|
-
});
|
|
149
|
-
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 : [];
|
|
150
|
-
const enumOption = config.map((item) => {
|
|
151
|
-
return {
|
|
152
|
-
label: item.value,
|
|
153
|
-
value: item.key,
|
|
154
|
-
};
|
|
155
|
-
});
|
|
156
|
-
setOption(enumOption);
|
|
73
|
+
let params = {
|
|
74
|
+
controlledValue: range,
|
|
157
75
|
};
|
|
76
|
+
if (format === 'father-son' || format === 'related') {
|
|
77
|
+
params = {
|
|
78
|
+
format,
|
|
79
|
+
dataSourceName,
|
|
80
|
+
viewId,
|
|
81
|
+
where,
|
|
82
|
+
primaryField,
|
|
83
|
+
controlledValue: range,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (format === 'x-enum') {
|
|
87
|
+
params = {
|
|
88
|
+
format,
|
|
89
|
+
enumName,
|
|
90
|
+
controlledValue: range,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const [options] = useOptions(params);
|
|
158
94
|
React.useEffect(() => {
|
|
159
95
|
var _a, _b, _c, _d, _e;
|
|
160
96
|
let hasChange = false;
|
|
@@ -181,6 +117,7 @@ function SelectPc({ where, dataSourceName, viewId, format, primaryField, enumNam
|
|
|
181
117
|
}
|
|
182
118
|
if (hasChange) {
|
|
183
119
|
prevDefaultRef.current = {
|
|
120
|
+
defaultValue,
|
|
184
121
|
defaultDate,
|
|
185
122
|
defaultTime,
|
|
186
123
|
defaultRegion,
|
|
@@ -188,7 +125,7 @@ function SelectPc({ where, dataSourceName, viewId, format, primaryField, enumNam
|
|
|
188
125
|
};
|
|
189
126
|
}
|
|
190
127
|
});
|
|
191
|
-
|
|
128
|
+
React.useEffect(() => {
|
|
192
129
|
if (mode == 'region' || mode == 'mutiRegion') {
|
|
193
130
|
if (regionData.length < 1) {
|
|
194
131
|
getAreaCode().then((value) => {
|
|
@@ -237,12 +174,12 @@ function SelectPc({ where, dataSourceName, viewId, format, primaryField, enumNam
|
|
|
237
174
|
const createDropdown = () => {
|
|
238
175
|
switch (mode) {
|
|
239
176
|
case 'selector':
|
|
240
|
-
return (React.createElement(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
177
|
+
return (React.createElement(PureSelectPc, { size: size, onChange: (value) => {
|
|
178
|
+
var _a;
|
|
179
|
+
onChange && onChange(value);
|
|
180
|
+
(_a = events === null || events === void 0 ? void 0 : events.change) === null || _a === void 0 ? void 0 : _a.call(events, { value });
|
|
181
|
+
setSelectedValue(value);
|
|
182
|
+
}, value: selectedValue, placeholder: placeholder, options: options }));
|
|
246
183
|
case 'date': {
|
|
247
184
|
const now = moment();
|
|
248
185
|
const start = startDate
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare type OptionItem = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
declare type IRelationFetchOptions = {
|
|
6
|
+
format: 'father-son' | 'related';
|
|
7
|
+
viewId: string;
|
|
8
|
+
dataSourceName: string;
|
|
9
|
+
where: unknown;
|
|
10
|
+
primaryField: string;
|
|
11
|
+
controlledValue: OptionItem[];
|
|
12
|
+
};
|
|
13
|
+
declare type IEnumFetchOptions = {
|
|
14
|
+
format: 'x-enum';
|
|
15
|
+
enumName: string;
|
|
16
|
+
controlledValue: OptionItem[];
|
|
17
|
+
};
|
|
18
|
+
export declare type IUseoptionsParams = (IRelationFetchOptions | IEnumFetchOptions | {
|
|
19
|
+
format?: string;
|
|
20
|
+
controlledValue: OptionItem[];
|
|
21
|
+
}) & {
|
|
22
|
+
callWedaApi?: (params: any) => Promise<any> | any;
|
|
23
|
+
callDataSource?: (params: any) => Promise<any>;
|
|
24
|
+
};
|
|
25
|
+
export declare function useOptions(params: IUseoptionsParams): [options: OptionItem[]];
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useAsync, useDeepCompareEffect } from '@react-hookz/web';
|
|
2
|
+
import destr from 'destr';
|
|
3
|
+
import { useCallback, useEffect } from 'react';
|
|
4
|
+
import { getWhereList } from '../../../utils/platform';
|
|
5
|
+
import { callDataSource as tcbCallDataSource, callWedaApi as tcbCallWedaApi, } from '../../../utils/tcb';
|
|
6
|
+
import { useSyncValue } from '../../../utils/useSyncValue';
|
|
7
|
+
const formatNeedDataFetch = ['father-son', 'related', 'x-enum'];
|
|
8
|
+
export function useOptions(params) {
|
|
9
|
+
const { format, controlledValue, callDataSource = tcbCallDataSource, callWedaApi = tcbCallWedaApi, ...restOptions } = params;
|
|
10
|
+
// 获取自定义选项集
|
|
11
|
+
const fetchEnumData = useCallback(async (param) => {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const data = await callWedaApi({
|
|
14
|
+
action: 'DescribeGeneralOptionsDetailList',
|
|
15
|
+
data: param,
|
|
16
|
+
});
|
|
17
|
+
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 : [];
|
|
18
|
+
const enumOption = config.map((item) => {
|
|
19
|
+
return {
|
|
20
|
+
label: item.value,
|
|
21
|
+
value: item.key,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return enumOption;
|
|
25
|
+
}, [callWedaApi]);
|
|
26
|
+
const fetchData = useCallback(async (param) => {
|
|
27
|
+
let pageNo = 1;
|
|
28
|
+
const pageSize = 200;
|
|
29
|
+
let records = [];
|
|
30
|
+
let total = 99999;
|
|
31
|
+
for (let index = 0; index < Math.floor(total / pageSize) + 1; index++) {
|
|
32
|
+
const data = await callDataSource({
|
|
33
|
+
dataSourceName: param.dataSourceName,
|
|
34
|
+
viewId: param.viewId,
|
|
35
|
+
methodName: param.methodName,
|
|
36
|
+
params: {
|
|
37
|
+
pageNo: pageNo,
|
|
38
|
+
pageSize: pageSize,
|
|
39
|
+
where: param.params,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
pageNo = pageNo + 1;
|
|
43
|
+
if (data === null || data === void 0 ? void 0 : data.records) {
|
|
44
|
+
total = (data === null || data === void 0 ? void 0 : data.total) || 0;
|
|
45
|
+
records = records.concat(data === null || data === void 0 ? void 0 : data.records);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return records;
|
|
49
|
+
}, [callDataSource]);
|
|
50
|
+
const [options, setOptions] = useSyncValue(controlledValue);
|
|
51
|
+
const [state, actions] = useAsync(async () => {
|
|
52
|
+
if (format === 'father-son' || format === 'related') {
|
|
53
|
+
const { dataSourceName, viewId, where, primaryField } = restOptions;
|
|
54
|
+
const whereEffected = [].concat(getWhereList(where));
|
|
55
|
+
const results = await fetchData({
|
|
56
|
+
dataSourceName,
|
|
57
|
+
viewId,
|
|
58
|
+
methodName: 'wedaGetRecords',
|
|
59
|
+
params: whereEffected,
|
|
60
|
+
});
|
|
61
|
+
if (primaryField) {
|
|
62
|
+
if (results && results.length !== 0) {
|
|
63
|
+
const option = results.map((item) => {
|
|
64
|
+
return {
|
|
65
|
+
label: item[primaryField] || item._id,
|
|
66
|
+
value: item._id,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return option;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// 留一个空的weui才正常
|
|
73
|
+
return [{ label: '', value: '' }];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return results.map((opt) => ({
|
|
77
|
+
label: opt._id,
|
|
78
|
+
value: opt._id,
|
|
79
|
+
})); // 兜底 正常来说一定有primaryField
|
|
80
|
+
}
|
|
81
|
+
if (format === 'x-enum') {
|
|
82
|
+
// 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
|
|
83
|
+
const { enumName } = restOptions;
|
|
84
|
+
return fetchEnumData({
|
|
85
|
+
OptNameList: [enumName],
|
|
86
|
+
PageIndex: 1,
|
|
87
|
+
PageSize: 10,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}, []);
|
|
91
|
+
useDeepCompareEffect(() => {
|
|
92
|
+
if (formatNeedDataFetch.includes(format)) {
|
|
93
|
+
actions.execute();
|
|
94
|
+
}
|
|
95
|
+
// @ts-ignore not check
|
|
96
|
+
}, [format, restOptions.enumName, restOptions.where]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (state.status === 'success') {
|
|
99
|
+
setOptions(state.result);
|
|
100
|
+
}
|
|
101
|
+
}, [state, state.status]);
|
|
102
|
+
return [options];
|
|
103
|
+
}
|