@cloudbase/weda-ui 3.24.0 → 3.25.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/dataView.js +1 -0
- package/dist/configs/components/listView.js +1 -0
- package/dist/configs/components/wd-button.js +2 -1
- package/dist/configs/components/wd-form-arr.js +4 -1
- package/dist/configs/components/wd-select-multiple.js +1 -0
- package/dist/configs/components/wd-select.js +1 -0
- package/dist/configs/components/wd-table.js +1 -0
- package/dist/configs/components/wd-text.js +2 -2
- package/dist/configs/type-utils/type-form.js +6 -4
- package/dist/configs/utils/field.d.ts +1 -0
- package/dist/configs/utils/field.js +151 -0
- package/dist/style/index.css +6 -0
- package/dist/style/index.scss +1 -1
- package/dist/style/weda-ui.min.css +2 -2
- package/dist/web/components/form-input-hooks/index.js +12 -4
- package/dist/web/components/formdetail/index.js +1 -0
- package/dist/web/components/table/ExportFileModalByApi/index.js +24 -13
- package/dist/web/components/wd-button/wd-button.js +5 -5
- package/dist/web/components/wd-form/hoc/form-container-decorator.js +7 -2
- package/dist/web/components/wd-form/hooks/use-remote-value.js +0 -1
- package/dist/web/components/wd-form-item/wd-form-item.js +9 -11
- package/dist/web/components/wd-table/components/FieldRender/index.js +1 -0
- package/dist/web/components/wd-table/components/FilterFieldsPanel/index.js +2 -2
- package/dist/web/components/wd-table/components/Table/index.d.ts +1 -2
- package/dist/web/components/wd-table/components/Table/index.js +26 -13
- package/dist/web/components/wd-table/components/index.d.ts +2 -1
- package/dist/web/components/wd-table/components/index.js +1 -1
- package/dist/web/components/wd-table/hooks/useTableData.js +15 -6
- package/dist/web/components/wd-table/table-with-form.d.ts +9 -0
- package/dist/web/components/wd-table/table-with-form.js +46 -0
- package/dist/web/components/wd-table/wd-table.d.ts +19 -4
- package/dist/web/components/wd-table/wd-table.js +21 -30
- package/dist/web/utils/hooks/useCanPreview.js +1 -1
- package/package.json +4 -3
|
@@ -20,11 +20,11 @@ import { useFormField } from '../wd-form/contexts/form-field-context';
|
|
|
20
20
|
import { useFormFieldObj } from '../wd-form/contexts/form-field-obj-context';
|
|
21
21
|
import { errorHandler } from '../../utils/error';
|
|
22
22
|
const logger = debug('wd-form-item');
|
|
23
|
-
const SET_VALUE_DEBOUNCE_TIMEOUT = 250;
|
|
24
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
24
|
export function useParentForm(widgetIgnored) {
|
|
26
25
|
return useFormWidget();
|
|
27
26
|
}
|
|
27
|
+
const regex = /^[a-zA-Z_$][\w$]*(?:\[\d+\])*(?:\.[a-zA-Z_$][\w$]*(?:\[\d+\])*)*$/;
|
|
28
28
|
// 转换路径
|
|
29
29
|
const convertPathToArray = (path) => {
|
|
30
30
|
return path
|
|
@@ -46,7 +46,11 @@ export function useFormInputTrait(inputParams) {
|
|
|
46
46
|
const formFieldObjsContext = useFormFieldObj();
|
|
47
47
|
const [isChange, setIsChange] = useState(false);
|
|
48
48
|
const name = useMemo(() => {
|
|
49
|
-
if (isNil(_name)
|
|
49
|
+
if (isNil(_name)) {
|
|
50
|
+
console.warn(`组件 ${$widget.id} 表单key(表单输入类组件 name 属性)没设置或为空串的时候不受表单容器控制`);
|
|
51
|
+
return ''; // 或者 return null; 根据你的后续逻辑决定
|
|
52
|
+
}
|
|
53
|
+
if (typeof _name === 'string' && _name.length === 0) {
|
|
50
54
|
// name 没设置或为空串的时候不受表单容器控制
|
|
51
55
|
console.warn(`组件 ${$widget.id} 表单key(表单输入类组件 name 属性)没设置或为空串的时候不受表单容器控制`);
|
|
52
56
|
}
|
|
@@ -55,10 +59,14 @@ export function useFormInputTrait(inputParams) {
|
|
|
55
59
|
}, [$widget.id, _name]);
|
|
56
60
|
// namePath 用于标识表单项的属性路径,用于容器通过lodash.set/get管理表单项的值
|
|
57
61
|
const namePath = useMemo(() => {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!name) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
58
66
|
if (formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.isChildField) {
|
|
59
|
-
return formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.namePath.concat(name);
|
|
67
|
+
return ((_a = formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.namePath) !== null && _a !== void 0 ? _a : []).concat(name);
|
|
60
68
|
}
|
|
61
|
-
else if (
|
|
69
|
+
else if (regex.test(name)) {
|
|
62
70
|
// 兼容 formDetail 中 的 name 写法
|
|
63
71
|
return convertPathToArray(name);
|
|
64
72
|
}
|
|
@@ -167,6 +167,7 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
167
167
|
if (isWdFormDetail) {
|
|
168
168
|
data = initialValues;
|
|
169
169
|
}
|
|
170
|
+
data = data.map((i, index) => ({ ...i, _id: index }));
|
|
170
171
|
setContextData(data);
|
|
171
172
|
(_a = events === null || events === void 0 ? void 0 : events.onDataChange) === null || _a === void 0 ? void 0 : _a.call(events, {
|
|
172
173
|
data,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
3
3
|
import { Modal, Radio, Form, Table, Checkbox, Icon, List, Status, Bubble, Tooltip } from 'tea-component';
|
|
4
4
|
import { useImportingStatus } from '../hooks/useImportingStatus';
|
|
5
5
|
import { callWedaApi } from '../../../utils/tcb';
|
|
@@ -15,20 +15,31 @@ export function ExportFileModalByApi({ onCancel, visible, fields, selectedKeysLi
|
|
|
15
15
|
const [status, setStatus] = useState(null);
|
|
16
16
|
const [fileId, setFileIds] = useState(null);
|
|
17
17
|
const { fileImportStatus, fileImportErrorMessage } = useImportingStatus(fileId, dbName, 'export');
|
|
18
|
-
const exportFields =
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const exportFields = useMemo(() => {
|
|
19
|
+
const resultArray = [];
|
|
20
|
+
selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys.forEach((item) => {
|
|
21
|
+
const field = tableColumns === null || tableColumns === void 0 ? void 0 : tableColumns.find((columns) => {
|
|
22
|
+
if (columns === null || columns === void 0 ? void 0 : columns.isRelated) {
|
|
23
|
+
return (columns === null || columns === void 0 ? void 0 : columns.slotKey) === item;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return (columns === null || columns === void 0 ? void 0 : columns.fieldKey) === item;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
resultArray.push({
|
|
30
|
+
FieldId: (field === null || field === void 0 ? void 0 : field.isRelated) ? `@${field === null || field === void 0 ? void 0 : field.fieldKey}.${field === null || field === void 0 ? void 0 : field.relatedField}` : item,
|
|
31
|
+
ColumnName: item === '_id' ? '数据标识' : field === null || field === void 0 ? void 0 : field.header,
|
|
32
|
+
});
|
|
33
|
+
const hasRelationId = resultArray.some((item) => item.FieldId === `@${field === null || field === void 0 ? void 0 : field.fieldKey}._id`);
|
|
34
|
+
if (!!exportIdentity.length && (field === null || field === void 0 ? void 0 : field.isRelated) && !hasRelationId) {
|
|
35
|
+
resultArray.push({
|
|
36
|
+
FieldId: `@${field === null || field === void 0 ? void 0 : field.fieldKey}._id`,
|
|
37
|
+
ColumnName: `关联关系【${field === null || field === void 0 ? void 0 : field.fieldKey}】数据标识`,
|
|
38
|
+
});
|
|
25
39
|
}
|
|
26
40
|
});
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
ColumnName: item === '_id' ? '数据标识' : field === null || field === void 0 ? void 0 : field.header,
|
|
30
|
-
};
|
|
31
|
-
});
|
|
41
|
+
return resultArray;
|
|
42
|
+
}, [selectedKeys, tableColumns, exportIdentity]);
|
|
32
43
|
const handleExport = async () => {
|
|
33
44
|
try {
|
|
34
45
|
setStep('isExporting');
|
|
@@ -70,14 +70,14 @@ export const WdButton = forwardRef(function WdButton(props, ref) {
|
|
|
70
70
|
case 'reset':
|
|
71
71
|
// 调用父级表单容器的重置
|
|
72
72
|
parentForm = getParentForm($widget);
|
|
73
|
-
if (parentForm.reset) {
|
|
74
|
-
parentForm
|
|
73
|
+
if ((parentForm === null || parentForm === void 0 ? void 0 : parentForm.reset) && typeof (parentForm === null || parentForm === void 0 ? void 0 : parentForm.reset) === 'function') {
|
|
74
|
+
parentForm.reset();
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
// 老逻辑兼容
|
|
78
78
|
parentForm = getParentForm($node);
|
|
79
|
-
if (parentForm.reset) {
|
|
80
|
-
parentForm
|
|
79
|
+
if ((parentForm === null || parentForm === void 0 ? void 0 : parentForm.reset) && typeof (parentForm === null || parentForm === void 0 ? void 0 : parentForm.reset) === 'function') {
|
|
80
|
+
parentForm.reset();
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
break;
|
|
@@ -111,5 +111,5 @@ export const WdButton = forwardRef(function WdButton(props, ref) {
|
|
|
111
111
|
openType,
|
|
112
112
|
};
|
|
113
113
|
}, [text, theme, variant, size, block, disabled, formType, openType]);
|
|
114
|
-
return (_jsxs("button", { className: classNames(classes, className), disabled: disabled, type: formType, style: style, id: id, ...propsStartWithOn, onClick: onClick, children: [iconPosition === 'before' && iconType === 'text-with-icon' && _jsx(Icon, {}), iconType === 'icon-only' ?
|
|
114
|
+
return (_jsxs("button", { className: classNames(classes, className), disabled: disabled, type: formType, style: style, id: id, ...propsStartWithOn, onClick: onClick, children: [iconPosition === 'before' && iconType === 'text-with-icon' && _jsx(Icon, {}), iconType === 'icon-only' ? _jsx(Icon, {}) : _jsx("span", { className: `${classPrefix}-btn__text`, children: textToString(text) }), iconPosition === 'after' && iconType === 'text-with-icon' && _jsx(Icon, {})] }));
|
|
115
115
|
});
|
|
@@ -6,6 +6,7 @@ import { deepClone } from '../../../utils/tool';
|
|
|
6
6
|
import isObjectEqual from '../../../utils/isObjectEqual';
|
|
7
7
|
import { emptyObject, emptyArray, NOT_EXISTED_VALUE } from '../../../utils/constant';
|
|
8
8
|
import { FormFieldProvider, useFormField } from '../contexts/form-field-context';
|
|
9
|
+
import { useFormFieldObj } from '../contexts/form-field-obj-context';
|
|
9
10
|
/**
|
|
10
11
|
* 表单容器装饰器高阶组件
|
|
11
12
|
* 用于包装组件,提供表单容器上下文
|
|
@@ -17,6 +18,7 @@ export function withFormContainer(Component) {
|
|
|
17
18
|
var _a;
|
|
18
19
|
const { ...componentProps } = props;
|
|
19
20
|
const formField = useFormField();
|
|
21
|
+
const formFieldObjsContext = useFormFieldObj();
|
|
20
22
|
const _formFieldValues = (_a = props.initialValues) !== null && _a !== void 0 ? _a : props.value;
|
|
21
23
|
const [formFieldsValue, setFormFieldsValue] = useState(_formFieldValues !== null && _formFieldValues !== void 0 ? _formFieldValues : ((props === null || props === void 0 ? void 0 : props.objType) === 'arr' ? emptyArray : emptyObject));
|
|
22
24
|
const [isReadyToCalculate, setIsReadyToCalculate] = useState(true);
|
|
@@ -49,8 +51,11 @@ export function withFormContainer(Component) {
|
|
|
49
51
|
return _formData;
|
|
50
52
|
});
|
|
51
53
|
}, []);
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
+
// 顶层没有表单容器,则组件自己管理值
|
|
55
|
+
// 非table组件,直接渲染原始组件,值交给顶层表单容器管理
|
|
56
|
+
// 在表单容器内,table组件,如果结合嵌套组件使用,则将组件值交给顶层表单容器管理,否则自己管理
|
|
57
|
+
const shouldUseProvider = formField ? !formFieldObjsContext && (props === null || props === void 0 ? void 0 : props.componentType) === 'table' : true;
|
|
58
|
+
if (!shouldUseProvider) {
|
|
54
59
|
return _jsx(Component, { ...props, ref: ref, isInformContainer: true });
|
|
55
60
|
}
|
|
56
61
|
return (_jsx(FormFieldProvider, { setFieldValue: setFieldValue, getFieldValue: getFieldValue, isInformContainer: true, formFieldsValue: formFieldsValue, setFormFieldsValue: setFormFieldsValue, isReadyToCalculate: isReadyToCalculate, setIsReadyToCalculate: setIsReadyToCalculate, children: _jsx(Component, { ...componentProps, formFieldsValue: formFieldsValue, ref: ref }) }));
|
|
@@ -17,24 +17,21 @@ const Label = React.memo(function Label({ labelCls, labelStyle, itemWrap, inputI
|
|
|
17
17
|
const Item = React.memo(function Item({ itemWrap, testId, controlWrapCls, readOnly, before, after, readValue, readBeforeAfter, format, value, children, }) {
|
|
18
18
|
return (_jsx("div", { className: `${itemWrap}__control`, "data-testid": testId, children: _jsx("div", { className: controlWrapCls, children: _jsx(WdFormItemReadOnly, { readOnly: readOnly, readValue: readValue, version: "wd", before: before, after: after, readBeforeAfter: readBeforeAfter, format: format, value: value, children: children }) }) }));
|
|
19
19
|
});
|
|
20
|
-
const
|
|
21
|
-
const { mode, labelProps, itemProps, children } = props || {};
|
|
20
|
+
const LabelContainerComp = React.memo(function LabelContainer(props) {
|
|
21
|
+
const { isH5, isRoot, labelVisible, mode, labelProps, itemProps, children } = props || {};
|
|
22
22
|
const cardRef = React.createRef();
|
|
23
23
|
const [iconName, setIconName] = useState('chevronup');
|
|
24
24
|
const headerSlot = (_jsxs(_Fragment, { children: [_jsx(WdIcon, { name: iconName, events: {
|
|
25
25
|
tap: () => {
|
|
26
26
|
setIconName(iconName === 'chevrondown' ? 'chevronup' : 'chevrondown');
|
|
27
27
|
},
|
|
28
|
-
} }), _jsx(Label, { ...labelProps })] }));
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
} }), (labelVisible || (!isH5 && isRoot)) && _jsx(Label, { ...labelProps })] }));
|
|
29
|
+
const showLabel = isRoot && labelVisible;
|
|
30
|
+
if (mode === 'custom' || mode === 'table' || mode === 'web-table') {
|
|
31
|
+
return (_jsxs(_Fragment, { children: [showLabel && _jsx(Label, { ...labelProps }), _jsx(Item, { ...itemProps, children: children }), ' '] }));
|
|
31
32
|
}
|
|
32
33
|
const contentSlot = _jsx(Item, { ...itemProps, children: children });
|
|
33
|
-
return (_jsx(WdCard, { ref: cardRef, className: iconName === 'chevrondown' ? 'wd-card-content__hidden' : '', showContent: true, headerSlot: headerSlot, contentSlot: contentSlot, events: { tap: () => { } } }));
|
|
34
|
-
});
|
|
35
|
-
const LabelContainerComp = React.memo(function LabelContainerComp({ isRoot, isH5, mode, labelProps, itemProps, children, }) {
|
|
36
|
-
const showLabel = isRoot && !isH5;
|
|
37
|
-
return (_jsxs(_Fragment, { children: [showLabel && _jsx(Label, { ...labelProps }), _jsx(LabelContainer, { isRoot: isRoot, labelProps: labelProps, itemProps: itemProps, mode: mode, children: children })] }));
|
|
34
|
+
return (_jsxs(_Fragment, { children: [showLabel && !isH5 && _jsx(Label, { ...labelProps }), ' ', _jsx(WdCard, { ref: cardRef, className: iconName === 'chevrondown' ? 'wd-card-content__hidden' : '', showContent: true, headerSlot: headerSlot, contentSlot: contentSlot, events: { tap: () => { } } })] }));
|
|
38
35
|
});
|
|
39
36
|
/**
|
|
40
37
|
* 表单项包裹,包括标题、文本提示、校验
|
|
@@ -152,5 +149,6 @@ export const WdFormItem = React.memo(function WdFormItem(props) {
|
|
|
152
149
|
};
|
|
153
150
|
if (!visible)
|
|
154
151
|
return null;
|
|
155
|
-
|
|
152
|
+
const labelClass = classNames({ [`${itemWrap}`]: true, [`${itemWrap}__vertical`]: hasLabelContainer && isH5 });
|
|
153
|
+
return (_jsxs("div", { className: cls, id: isRoot ? id : null, style: style, children: [_jsx("div", { className: labelClass, children: hasLabelContainer ? (_jsx(LabelContainerComp, { isRoot: isRoot, isH5: isH5, mode: props === null || props === void 0 ? void 0 : props.mode, labelProps: labelProps, itemProps: itemProps, labelVisible: labelVisible, children: children })) : (_jsxs(_Fragment, { children: [labelVisible && _jsx(Label, { ...labelProps }), _jsx(Item, { ...itemProps, children: children })] })) }), Message, Help] }));
|
|
156
154
|
});
|
|
@@ -989,6 +989,7 @@ export const getTableColumns = ({ fields, columnSets, slots, fixedFront, fixedEn
|
|
|
989
989
|
key: (i === null || i === void 0 ? void 0 : i.slotKey) || (i === null || i === void 0 ? void 0 : i.key),
|
|
990
990
|
// 此字段为colum 绑定字段的key值,业务场景使用次字段
|
|
991
991
|
fieldKey: i === null || i === void 0 ? void 0 : i.key,
|
|
992
|
+
shouldCellUpdate: (prevRow, nextRow) => prevRow[i === null || i === void 0 ? void 0 : i.key] !== nextRow[i === null || i === void 0 ? void 0 : i.key],
|
|
992
993
|
}));
|
|
993
994
|
};
|
|
994
995
|
export const mapColumKey = (columnSets) => {
|
|
@@ -8,7 +8,7 @@ import { FilterFieldItem } from './FilterFieldItem';
|
|
|
8
8
|
import { arrayInputType } from './Fields';
|
|
9
9
|
import { filterFieldsGenerate } from './filterFieldsGenerate';
|
|
10
10
|
import { WdButton } from '../../../wd-button';
|
|
11
|
-
import { usePlatform } from '../../../../utils/platform';
|
|
11
|
+
import { usePlatform, textToString } from '../../../../utils/platform';
|
|
12
12
|
import { useSetWidgetApi } from '../../../../utils/widget-api/use-set-widget-api';
|
|
13
13
|
// 正则元字符添加转义符
|
|
14
14
|
const escapeRegExp = (string) => {
|
|
@@ -151,7 +151,7 @@ export const FilterFieldsPanel = forwardRef(function Comp(props, ref) {
|
|
|
151
151
|
searchValues.push(searchItem);
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
|
-
searchItem.val = (_c = i.value) === null || _c === void 0 ? void 0 : _c.trim();
|
|
154
|
+
searchItem.val = (_c = textToString(i.value)) === null || _c === void 0 ? void 0 : _c.trim();
|
|
155
155
|
searchValues.push(searchItem);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
interface BaseTableComProps {
|
|
2
|
+
export interface BaseTableComProps {
|
|
3
3
|
events?: any;
|
|
4
4
|
recordKey?: string;
|
|
5
5
|
className?: any;
|
|
@@ -40,4 +40,3 @@ interface BaseTableComProps {
|
|
|
40
40
|
}
|
|
41
41
|
export declare const BaseTableCom: ({ events, recordKey, className, columns, setColumns, records, sortColumns, sort, onSelectChange, selectedKeys, rowColor, isError, errorObj, isLoading, queryParams, total, onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageIndex, rowClick, cellClick, currentSize, isNoDataSourceBind, isH5, emptyText: _emptyText, __innerSlot, bottomTip, enableBottomTipSlot, rowDisabled, componentId, }: BaseTableComProps) => JSX.Element;
|
|
42
42
|
export declare const BaseTable: React.MemoExoticComponent<({ events, recordKey, className, columns, setColumns, records, sortColumns, sort, onSelectChange, selectedKeys, rowColor, isError, errorObj, isLoading, queryParams, total, onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageIndex, rowClick, cellClick, currentSize, isNoDataSourceBind, isH5, emptyText: _emptyText, __innerSlot, bottomTip, enableBottomTipSlot, rowDisabled, componentId, }: BaseTableComProps) => JSX.Element>;
|
|
43
|
-
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/* eslint max-lines: [error,
|
|
3
|
-
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
/* eslint max-lines: [error, 380] */
|
|
3
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
4
4
|
import { Table, StatusTip, ConfigProvider } from 'tea-component';
|
|
5
|
-
import { useResizeObserver } from '@react-hookz/web';
|
|
5
|
+
import { useResizeObserver, useDebouncedCallback } from '@react-hookz/web';
|
|
6
6
|
import { errorHandler } from '../../../../utils/error';
|
|
7
7
|
import { useConfig } from '../../../../utils/config-context';
|
|
8
8
|
const { sortable, radioable, selectable, injectable, pageable, autotip, scrollable, columnsResizable } = Table.addons;
|
|
@@ -17,6 +17,8 @@ const miniPageSize = 10;
|
|
|
17
17
|
// h5 端表格高度
|
|
18
18
|
const tableHeight = { sm: 500, md: 580, lg: 880 };
|
|
19
19
|
const tableHeaderHeight = 51;
|
|
20
|
+
// 默认防抖延迟时间(毫秒)
|
|
21
|
+
const DEFAULT_DEBOUNCE_DELAY = 200;
|
|
20
22
|
const renderStatus = ({ isH5, status, isNoDataSourceBind, _emptyText, errorObj, __innerSlot }) => {
|
|
21
23
|
var _a, _b;
|
|
22
24
|
const text = {
|
|
@@ -32,14 +34,13 @@ const renderStatus = ({ isH5, status, isNoDataSourceBind, _emptyText, errorObj,
|
|
|
32
34
|
return (_jsx(StatusContent, { emptyText: text[`${status}`], component: "table", icon: status, errorObj: errorObj, isH5: isH5 }));
|
|
33
35
|
};
|
|
34
36
|
// eslint-disable-next-line complexity
|
|
35
|
-
export const BaseTableCom = ({ events, recordKey, className, columns, setColumns, records, sortColumns, sort, onSelectChange, selectedKeys, rowColor, isError, errorObj, isLoading, queryParams, total = defaultTotal,
|
|
36
|
-
// refreshTable,
|
|
37
|
-
onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageIndex, rowClick, cellClick, currentSize, isNoDataSourceBind, isH5, emptyText: _emptyText, __innerSlot = (_jsx(_Fragment, {})), bottomTip, enableBottomTipSlot = false, rowDisabled, componentId, }) => {
|
|
37
|
+
export const BaseTableCom = ({ events, recordKey, className, columns, setColumns, records, sortColumns, sort, onSelectChange, selectedKeys, rowColor, isError, errorObj, isLoading, queryParams, total = defaultTotal, onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageIndex, rowClick, cellClick, currentSize, isNoDataSourceBind, isH5, emptyText: _emptyText, __innerSlot = (_jsx(_Fragment, {})), bottomTip, enableBottomTipSlot = false, rowDisabled, componentId, }) => {
|
|
38
38
|
var _a;
|
|
39
39
|
const tableRef = useRef(null);
|
|
40
40
|
const { classPrefix } = useConfig();
|
|
41
41
|
// 是否展示全局loading
|
|
42
42
|
const isShowLoading = isH5 ? (queryParams === null || queryParams === void 0 ? void 0 : queryParams.pageIndex) === pageIndexSpan && isLoading : isLoading;
|
|
43
|
+
const [h5Loading, setH5Loading] = useState(false);
|
|
43
44
|
// table状态样式
|
|
44
45
|
const showStatus = isShowLoading || isError || !(records === null || records === void 0 ? void 0 : records.length);
|
|
45
46
|
const classes = {
|
|
@@ -110,17 +111,29 @@ onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageI
|
|
|
110
111
|
// 支撑分页的最大高度
|
|
111
112
|
const tableDomHeight = (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight;
|
|
112
113
|
// 支持表格滚动,高度超过 500 开始显示滚动条
|
|
114
|
+
const fetchData = useDebouncedCallback(() => {
|
|
115
|
+
if (!isLoading && (records === null || records === void 0 ? void 0 : records.length) < total && isH5 && Number.isFinite(total)) {
|
|
116
|
+
const newPageIndex = queryParams.pageIndex + pageIndexSpan;
|
|
117
|
+
onQueryChange({ pageIndex: newPageIndex });
|
|
118
|
+
if (events === null || events === void 0 ? void 0 : events.onPagingChange) {
|
|
119
|
+
events.onPagingChange({
|
|
120
|
+
pageIndex: newPageIndex,
|
|
121
|
+
pageSize: queryParams.pageSize || defaultPageSize,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, [isLoading, records === null || records === void 0 ? void 0 : records.length, total, isH5, queryParams.pageIndex], DEFAULT_DEBOUNCE_DELAY);
|
|
113
126
|
if (isH5) {
|
|
114
127
|
tableAddons.push(scrollable({
|
|
115
128
|
maxHeight: tableDomHeight - tableHeaderHeight,
|
|
116
129
|
onScrollBottom: () => {
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
130
|
+
if ((records === null || records === void 0 ? void 0 : records.length) < total && isH5) {
|
|
131
|
+
setH5Loading(true);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
setH5Loading(false);
|
|
123
135
|
}
|
|
136
|
+
fetchData();
|
|
124
137
|
},
|
|
125
138
|
}));
|
|
126
139
|
}
|
|
@@ -153,7 +166,7 @@ onQueryChange, enablePagination, columnSelectType, defaultPageSize, defaultPageI
|
|
|
153
166
|
targetColumnKey: (columns === null || columns === void 0 ? void 0 : columns.length) && columnSelectType === 'radio' ? 'weda_radio' : undefined,
|
|
154
167
|
}));
|
|
155
168
|
}
|
|
156
|
-
const showLoadingBottomTip = isLoading
|
|
169
|
+
const showLoadingBottomTip = (isLoading || h5Loading) && records.length > 0;
|
|
157
170
|
const showAllDataBottomTip = (records === null || records === void 0 ? void 0 : records.length) === total && !isLoading && (records === null || records === void 0 ? void 0 : records.length) > miniPageSize;
|
|
158
171
|
const bottomTipCompRender = () => {
|
|
159
172
|
const shouldShowBottomTip = enableBottomTipSlot && !showStatus;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pagination } from './Pagination';
|
|
2
|
-
import { BaseTable as Table } from './Table';
|
|
2
|
+
import { BaseTable as Table, BaseTableComProps } from './Table';
|
|
3
3
|
import { SearchBox } from './SearchBox';
|
|
4
4
|
import { ExportFileModal, exportHandle, exportHandleByApi } from './ExportFileModalByApi';
|
|
5
5
|
import { ImportFileModal, importHandleByApi } from './ImportFileModalByApi';
|
|
@@ -8,3 +8,4 @@ import { deleteRecord } from './deleteModal';
|
|
|
8
8
|
import { FilterFieldsPanel } from './FilterFieldsPanel';
|
|
9
9
|
import { ToolBar } from './ToolBar';
|
|
10
10
|
export { Pagination, Table, SearchBox, ExportFileModal, ImportFileModal, InOrOutRecordModal, deleteRecord, importHandleByApi, exportHandle, exportHandleByApi, FilterFieldsPanel, ToolBar, };
|
|
11
|
+
export type { BaseTableComProps };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Pagination } from './Pagination';
|
|
2
2
|
import { BaseTable as Table } from './Table';
|
|
3
3
|
import { SearchBox } from './SearchBox';
|
|
4
|
-
import { ExportFileModal, exportHandle, exportHandleByApi
|
|
4
|
+
import { ExportFileModal, exportHandle, exportHandleByApi } from './ExportFileModalByApi';
|
|
5
5
|
import { ImportFileModal, importHandleByApi } from './ImportFileModalByApi';
|
|
6
6
|
import { InOrOutRecordModal } from './InOrOutRecordModal';
|
|
7
7
|
import { deleteRecord } from './deleteModal';
|
|
@@ -28,22 +28,31 @@ export const useTableData = ({ dataSourceAPI, connectorMethod, query, events, is
|
|
|
28
28
|
canCallQuerySuccess = false;
|
|
29
29
|
if (Object.keys(select).length !== 0) {
|
|
30
30
|
canCallQuerySuccess = true;
|
|
31
|
-
|
|
32
|
-
data
|
|
31
|
+
const result = await dataSourceAPI.getRecordListV2(query, { swr });
|
|
32
|
+
data = {
|
|
33
|
+
...data,
|
|
34
|
+
total: result.total,
|
|
35
|
+
records: result.records || [],
|
|
36
|
+
};
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
else {
|
|
36
40
|
// 不是新添加的表格,用旧方法查询
|
|
37
|
-
|
|
38
|
-
data
|
|
41
|
+
const result = await dataSourceAPI.getRecordList(query, { swr });
|
|
42
|
+
data = {
|
|
43
|
+
...data,
|
|
44
|
+
total: result.total,
|
|
45
|
+
records: result.records || [],
|
|
46
|
+
};
|
|
39
47
|
}
|
|
40
48
|
setIsError(false);
|
|
41
49
|
}
|
|
42
50
|
else if (connectorMethod === null || connectorMethod === void 0 ? void 0 : connectorMethod.name) {
|
|
43
51
|
data = await dataSourceAPI.getConnect(connectorMethod === null || connectorMethod === void 0 ? void 0 : connectorMethod.name, query, swr);
|
|
44
52
|
}
|
|
45
|
-
//
|
|
46
|
-
|
|
53
|
+
// 分页器查询时合并多次请求结果再赋值表格
|
|
54
|
+
// H5端是滚动加载更多,不合并请求
|
|
55
|
+
if (fetchVersion !== fetchRef.current.version && !isH5)
|
|
47
56
|
return;
|
|
48
57
|
const records = (data === null || data === void 0 ? void 0 : data.records) || [];
|
|
49
58
|
setTotal(data === null || data === void 0 ? void 0 : data.total);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BaseTableComProps } from './components';
|
|
3
|
+
export interface TableWithFormProps extends BaseTableComProps {
|
|
4
|
+
isInformContainer?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const TableWithForm: React.ForwardRefExoticComponent<Pick<{
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
initialValues?: any;
|
|
9
|
+
}, string | number> & React.RefAttributes<unknown>>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { forwardRef, useMemo, useState } from 'react';
|
|
3
|
+
import { useDeepCompareEffect } from '@react-hookz/web';
|
|
4
|
+
import { Table } from './components';
|
|
5
|
+
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
6
|
+
import { withFormContainer } from '../wd-form/hoc/form-container-decorator';
|
|
7
|
+
import { useFormField } from '../wd-form/contexts/form-field-context';
|
|
8
|
+
import { useFormFieldObj } from '../wd-form/contexts/form-field-obj-context';
|
|
9
|
+
import { useSetWidgetApi } from '../../utils/widget-api/use-set-widget-api';
|
|
10
|
+
import isObjectEqual from '../../utils/isObjectEqual';
|
|
11
|
+
export const TableWithForm = withFormContainer(React.memo(forwardRef(function TableComp(tableProps, ref) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { records = [] } = tableProps;
|
|
14
|
+
const formField = useFormField();
|
|
15
|
+
const { formFieldsValue = [], setFieldValue, setFormFieldsValue, getFieldValue } = formField || {};
|
|
16
|
+
const formFieldObjsContext = useFormFieldObj();
|
|
17
|
+
const [columns, setColumns] = useState(tableProps.columns);
|
|
18
|
+
const isEditorMode = (_b = (_a = window.$w) === null || _a === void 0 ? void 0 : _a.wedaContext) === null || _b === void 0 ? void 0 : _b.isEditorMode;
|
|
19
|
+
const parentNamePath = tableProps.isInformContainer && (formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.isChildField) ? formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.namePath : null;
|
|
20
|
+
const tableValue = useMemo(() => {
|
|
21
|
+
return parentNamePath && getFieldValue ? getFieldValue({ namePath: parentNamePath }) : formFieldsValue;
|
|
22
|
+
}, [formFieldsValue, getFieldValue, parentNamePath]);
|
|
23
|
+
useDeepCompareEffect(() => {
|
|
24
|
+
if (!isObjectEqual(tableProps.columns, columns, true)) {
|
|
25
|
+
setColumns(tableProps.columns);
|
|
26
|
+
}
|
|
27
|
+
}, [tableProps.columns]);
|
|
28
|
+
useDeepCompareEffect(() => {
|
|
29
|
+
// records变化时,同步更新value
|
|
30
|
+
const value = [...records];
|
|
31
|
+
const parentNamePath = tableProps.isInformContainer && (formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.isChildField) ? formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.namePath : null;
|
|
32
|
+
if (setFieldValue && parentNamePath && !isObjectEqual(tableValue, value)) {
|
|
33
|
+
// 情况1: 在表单容器内且是子字段,通过父路径设置值
|
|
34
|
+
setFieldValue({ namePath: parentNamePath, value });
|
|
35
|
+
}
|
|
36
|
+
else if (setFormFieldsValue && !isObjectEqual(tableValue, value)) {
|
|
37
|
+
// 情况2: 不在表单容器内,或者是表单容器但非子字段,直接设置表单值
|
|
38
|
+
setFormFieldsValue(value);
|
|
39
|
+
}
|
|
40
|
+
}, [formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.namePath, records, tableProps.isInformContainer, formFieldObjsContext === null || formFieldObjsContext === void 0 ? void 0 : formFieldObjsContext.isChildField]);
|
|
41
|
+
useSetWidgetApi(() => ({
|
|
42
|
+
value: tableValue,
|
|
43
|
+
}), [tableValue], ref);
|
|
44
|
+
// 非编辑模式缓存columns
|
|
45
|
+
return _jsx(Table, { ...tableProps, columns: isEditorMode ? tableProps.columns : columns });
|
|
46
|
+
})));
|
|
@@ -10,10 +10,7 @@ export declare const GlobalButton: React.NamedExoticComponent<{
|
|
|
10
10
|
classPrefix: string;
|
|
11
11
|
slots: any;
|
|
12
12
|
}>;
|
|
13
|
-
export declare const WdTable: React.ForwardRefExoticComponent<
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
initialValues?: any;
|
|
16
|
-
}, string | number> & React.RefAttributes<unknown>>;
|
|
13
|
+
export declare const WdTable: React.ForwardRefExoticComponent<WdTableProps & React.RefAttributes<TCompRef>>;
|
|
17
14
|
export interface WdTableProps extends CommonPropsType, DataType {
|
|
18
15
|
isMock?: boolean;
|
|
19
16
|
multipleSelect: boolean;
|
|
@@ -22,3 +19,21 @@ export interface WdTableProps extends CommonPropsType, DataType {
|
|
|
22
19
|
__innerSlot?: React.ReactNode;
|
|
23
20
|
initialValues?: [];
|
|
24
21
|
}
|
|
22
|
+
type TCompRef = {
|
|
23
|
+
import: () => void;
|
|
24
|
+
exportOptionalMode: () => void;
|
|
25
|
+
export: () => void;
|
|
26
|
+
deleteSelected: () => void;
|
|
27
|
+
refresh: () => void;
|
|
28
|
+
refreshKeepPage: () => void;
|
|
29
|
+
deleteOne: (params: {
|
|
30
|
+
id: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
openOperationDialog: () => void;
|
|
33
|
+
records?: any[];
|
|
34
|
+
total: number;
|
|
35
|
+
pageNo: number;
|
|
36
|
+
pageSize: number;
|
|
37
|
+
selectedRecords: any[];
|
|
38
|
+
};
|
|
39
|
+
export {};
|