@zat-design/sisyphus-react 4.5.0 → 4.5.2
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/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProDrawerForm/components/ProDrawer/index.js +58 -86
- package/es/ProDrawerForm/components/ProModal/index.js +44 -20
- package/es/ProDrawerForm/hooks/useConfirmClose.js +70 -0
- package/es/ProDrawerForm/index.js +7 -11
- package/es/ProDrawerForm/utils/index.js +36 -0
- package/es/ProEditTable/components/RcTable/BaseTable.js +10 -0
- package/es/ProEditTable/components/Summary/index.js +3 -2
- package/es/ProEditTable/utils/tools.js +1 -1
- package/es/ProEnum/index.js +6 -3
- package/es/ProForm/components/combination/FormList/components/ActionButton.js +7 -6
- package/es/ProForm/components/combination/FormList/components/ToolbarButton.js +4 -3
- package/es/ProForm/components/combination/ProModalSelect/index.js +7 -2
- package/es/ProForm/components/combination/ProModalSelect/utils/mergeSelectedRows.js +26 -0
- package/es/ProForm/components/render/RenderFields.js +3 -1
- package/es/ProForm/hooks/useWatch.js +8 -10
- package/es/ProLayout/components/ProHeader/index.js +28 -15
- package/es/ProSelect/index.js +77 -178
- package/es/ProSelect/utils/index.js +174 -0
- package/es/ProTree/components/ProTreeSelect/index.js +41 -14
- package/es/ProTree/components/ProTreeSelect/style/index.less +13 -4
- package/es/ProTree/style/index.less +20 -9
- package/es/ProTree/utils.js +26 -0
- package/es/ProTreeModal/style/index.less +1 -1
- package/es/ProUpload/components/DragRender.js +2 -1
- package/es/ProUpload/index.js +1 -1
- package/es/ProViewer/propsType.js +3 -1
- package/es/index.js +10 -0
- package/package.json +7 -13
- package/es/FormsProvider/index.d.ts +0 -18
- package/es/ProAction/components/CheckModalContent/index.d.ts +0 -8
- package/es/ProAction/index.d.ts +0 -7
- package/es/ProAction/propsType.d.ts +0 -45
- package/es/ProConfigProvider/index.d.ts +0 -9
- package/es/ProConfigProvider/propsType.d.ts +0 -78
- package/es/ProDownload/index.d.ts +0 -6
- package/es/ProDownload/propsType.d.ts +0 -71
- package/es/ProDownload/utils.d.ts +0 -60
- package/es/ProDrawerForm/components/ProDrawer/index.d.ts +0 -7
- package/es/ProDrawerForm/components/ProModal/index.d.ts +0 -7
- package/es/ProDrawerForm/components/index.d.ts +0 -2
- package/es/ProDrawerForm/index.d.ts +0 -6
- package/es/ProDrawerForm/propsType.d.ts +0 -100
- package/es/ProDrawerForm/utils/index.d.ts +0 -6
- package/es/ProEditLabel/components/RenderProForm.d.ts +0 -4
- package/es/ProEditLabel/index.d.ts +0 -4
- package/es/ProEditLabel/propsType.d.ts +0 -163
- package/es/ProEditLabel/utils/index.d.ts +0 -7
- package/es/ProEditTable/components/ActionButton/index.d.ts +0 -2
- package/es/ProEditTable/components/RcTable/BaseTable.d.ts +0 -6
- package/es/ProEditTable/components/RcTable/DraggableTable.d.ts +0 -7
- package/es/ProEditTable/components/RcTable/index.d.ts +0 -4
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.d.ts +0 -4
- package/es/ProEditTable/components/RenderField/index.d.ts +0 -3
- package/es/ProEditTable/components/RenderField/propsType.d.ts +0 -30
- package/es/ProEditTable/components/RenderField/tools.d.ts +0 -22
- package/es/ProEditTable/components/RenderToolbar/index.d.ts +0 -2
- package/es/ProEditTable/components/Summary/index.d.ts +0 -12
- package/es/ProEditTable/components/Validator/index.d.ts +0 -19
- package/es/ProEditTable/components/index.d.ts +0 -5
- package/es/ProEditTable/index.d.ts +0 -4
- package/es/ProEditTable/propsType.d.ts +0 -437
- package/es/ProEditTable/utils/config.d.ts +0 -25
- package/es/ProEditTable/utils/diffOriginal.d.ts +0 -22
- package/es/ProEditTable/utils/getDefaultProps.d.ts +0 -1
- package/es/ProEditTable/utils/index.d.ts +0 -23
- package/es/ProEditTable/utils/tools.d.ts +0 -128
- package/es/ProEditTable/utils/transform.d.ts +0 -13
- package/es/ProEditTable/utils/useEditTableError.d.ts +0 -7
- package/es/ProEditTable/utils/useShouldUpdateForTable.d.ts +0 -16
- package/es/ProEditTable/utils/validateAll.d.ts +0 -89
- package/es/ProEnum/components/Group.d.ts +0 -10
- package/es/ProEnum/components/Tag.d.ts +0 -7
- package/es/ProEnum/hooks/useEnum.d.ts +0 -29
- package/es/ProEnum/hooks/useEnumRequest.d.ts +0 -4
- package/es/ProEnum/hooks/useFrequentEnumRequest.d.ts +0 -14
- package/es/ProEnum/index.d.ts +0 -10
- package/es/ProEnum/propsType.d.ts +0 -310
- package/es/ProEnum/utils/eventCenter.d.ts +0 -1
- package/es/ProEnum/utils/frequentEnum.d.ts +0 -39
- package/es/ProEnum/utils/getEnum.d.ts +0 -47
- package/es/ProEnum/utils/getEnumLabel.d.ts +0 -2
- package/es/ProEnum/utils/index.d.ts +0 -84
- package/es/ProForm/components/Container.d.ts +0 -9
- package/es/ProForm/components/FormFooter/index.d.ts +0 -5
- package/es/ProForm/components/FormFooter/propsType.d.ts +0 -22
- package/es/ProForm/components/base/Checkbox/index.d.ts +0 -14
- package/es/ProForm/components/base/DatePicker/index.d.ts +0 -11
- package/es/ProForm/components/base/Input/index.d.ts +0 -3
- package/es/ProForm/components/base/Input/propsType.d.ts +0 -21
- package/es/ProForm/components/base/InputNumber/index.d.ts +0 -11
- package/es/ProForm/components/base/Radio/index.d.ts +0 -15
- package/es/ProForm/components/base/RangePicker/index.d.ts +0 -19
- package/es/ProForm/components/base/RangePicker/useDateRange.d.ts +0 -15
- package/es/ProForm/components/base/Select/index.d.ts +0 -11
- package/es/ProForm/components/base/Switch/index.d.ts +0 -10
- package/es/ProForm/components/base/SwitchCheckbox/index.d.ts +0 -10
- package/es/ProForm/components/base/TextArea/index.d.ts +0 -11
- package/es/ProForm/components/base/TimePicker/index.d.ts +0 -13
- package/es/ProForm/components/combination/Container/index.d.ts +0 -4
- package/es/ProForm/components/combination/Container/propsType.d.ts +0 -13
- package/es/ProForm/components/combination/FormList/components/ActionButton.d.ts +0 -24
- package/es/ProForm/components/combination/FormList/components/BlockFields.d.ts +0 -23
- package/es/ProForm/components/combination/FormList/components/Empty.d.ts +0 -13
- package/es/ProForm/components/combination/FormList/components/LineFields.d.ts +0 -20
- package/es/ProForm/components/combination/FormList/components/ToolbarButton.d.ts +0 -12
- package/es/ProForm/components/combination/FormList/index.d.ts +0 -4
- package/es/ProForm/components/combination/FormList/propsType.d.ts +0 -69
- package/es/ProForm/components/combination/FormList/utils.d.ts +0 -18
- package/es/ProForm/components/combination/Group/component/AddonWrapper/index.d.ts +0 -9
- package/es/ProForm/components/combination/Group/component/ComRender.d.ts +0 -28
- package/es/ProForm/components/combination/Group/component/FlexibleGroup.d.ts +0 -10
- package/es/ProForm/components/combination/Group/hooks/index.d.ts +0 -34
- package/es/ProForm/components/combination/Group/index.d.ts +0 -9
- package/es/ProForm/components/combination/Group/propsType.d.ts +0 -99
- package/es/ProForm/components/combination/Group/utils/index.d.ts +0 -154
- package/es/ProForm/components/combination/ProCascader/index.d.ts +0 -4
- package/es/ProForm/components/combination/ProCascader/propsType.d.ts +0 -48
- package/es/ProForm/components/combination/ProCascader/utils/index.d.ts +0 -14
- package/es/ProForm/components/combination/ProModalSelect/hooks/useRequestList.d.ts +0 -33
- package/es/ProForm/components/combination/ProModalSelect/index.d.ts +0 -4
- package/es/ProForm/components/combination/ProModalSelect/propsType.d.ts +0 -106
- package/es/ProForm/components/combination/ProModalSelect/utils/index.d.ts +0 -1
- package/es/ProForm/components/combination/ProNumberRange/index.d.ts +0 -4
- package/es/ProForm/components/combination/ProNumberRange/propsType.d.ts +0 -85
- package/es/ProForm/components/combination/ProRangeLimit/index.d.ts +0 -4
- package/es/ProForm/components/combination/ProRangeLimit/propsType.d.ts +0 -23
- package/es/ProForm/components/combination/ProTimeLimit/hooks/useControlled.d.ts +0 -9
- package/es/ProForm/components/combination/ProTimeLimit/index.d.ts +0 -33
- package/es/ProForm/components/index.d.ts +0 -29
- package/es/ProForm/components/render/ChangedWrapper.d.ts +0 -17
- package/es/ProForm/components/render/ConfirmWrapper.d.ts +0 -10
- package/es/ProForm/components/render/CustomComponentViewWrapper.d.ts +0 -30
- package/es/ProForm/components/render/Render.d.ts +0 -4
- package/es/ProForm/components/render/RenderFields.d.ts +0 -26
- package/es/ProForm/components/render/propsType.d.ts +0 -279
- package/es/ProForm/hooks/useControlled.d.ts +0 -1
- package/es/ProForm/hooks/useDeepCompareMemo.d.ts +0 -2
- package/es/ProForm/hooks/useFieldProps.d.ts +0 -4
- package/es/ProForm/hooks/useForm.d.ts +0 -8
- package/es/ProForm/hooks/useRules.d.ts +0 -16
- package/es/ProForm/hooks/useShouldUpdate.d.ts +0 -31
- package/es/ProForm/hooks/useWatch.d.ts +0 -22
- package/es/ProForm/index.d.ts +0 -6
- package/es/ProForm/propsType.d.ts +0 -143
- package/es/ProForm/utils/buildFormItemProps.d.ts +0 -25
- package/es/ProForm/utils/diffOriginal.d.ts +0 -10
- package/es/ProForm/utils/getDefaultProps.d.ts +0 -1
- package/es/ProForm/utils/index.d.ts +0 -109
- package/es/ProForm/utils/processDependencies.d.ts +0 -29
- package/es/ProForm/utils/reactiveValues.d.ts +0 -34
- package/es/ProForm/utils/rulesCreator.d.ts +0 -7
- package/es/ProForm/utils/transformNames.d.ts +0 -10
- package/es/ProForm/utils/transformValue.d.ts +0 -6
- package/es/ProForm/utils/valueType.d.ts +0 -70
- package/es/ProIcon/config/index.d.ts +0 -19
- package/es/ProIcon/index.d.ts +0 -4
- package/es/ProIcon/propsTypes.d.ts +0 -175
- package/es/ProIcon/utils/index.d.ts +0 -6
- package/es/ProLayout/components/Layout/Header/index.d.ts +0 -4
- package/es/ProLayout/components/Layout/Menu/FoldMenu/index.d.ts +0 -3
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.d.ts +0 -3
- package/es/ProLayout/components/Layout/Menu/OpenMenu/propsType.d.ts +0 -15
- package/es/ProLayout/components/Layout/Menu/SideMenu/index.d.ts +0 -3
- package/es/ProLayout/components/Layout/Menu/index.d.ts +0 -4
- package/es/ProLayout/components/Layout/Notice/index.d.ts +0 -4
- package/es/ProLayout/components/Layout/index.d.ts +0 -3
- package/es/ProLayout/components/ProCollapse/PropTypes.d.ts +0 -98
- package/es/ProLayout/components/ProCollapse/index.d.ts +0 -3
- package/es/ProLayout/components/ProFooter/PropTypes.d.ts +0 -27
- package/es/ProLayout/components/ProFooter/index.d.ts +0 -4
- package/es/ProLayout/components/ProHeader/PropTypes.d.ts +0 -206
- package/es/ProLayout/components/ProHeader/components/Copy/index.d.ts +0 -4
- package/es/ProLayout/components/ProHeader/components/ProBackBtn/index.d.ts +0 -9
- package/es/ProLayout/components/ProHeader/components/ProBackBtn/propsType.d.ts +0 -4
- package/es/ProLayout/components/ProHeader/components/index.d.ts +0 -2
- package/es/ProLayout/components/ProHeader/index.d.ts +0 -4
- package/es/ProLayout/components/ProHeader/utils/index.d.ts +0 -5
- package/es/ProLayout/components/TabsManager/components/TabContextMenu.d.ts +0 -7
- package/es/ProLayout/components/TabsManager/components/TabItem.d.ts +0 -26
- package/es/ProLayout/components/TabsManager/components/TabsContext.d.ts +0 -6
- package/es/ProLayout/components/TabsManager/components/TabsHeader.d.ts +0 -10
- package/es/ProLayout/components/TabsManager/hooks/useActiveTab.d.ts +0 -6
- package/es/ProLayout/components/TabsManager/hooks/useIframeRoute.d.ts +0 -25
- package/es/ProLayout/components/TabsManager/hooks/useProLayoutTabs.d.ts +0 -18
- package/es/ProLayout/components/TabsManager/hooks/useTabsCache.d.ts +0 -31
- package/es/ProLayout/components/TabsManager/hooks/useTabsState.d.ts +0 -5
- package/es/ProLayout/components/TabsManager/index.d.ts +0 -7
- package/es/ProLayout/components/TabsManager/propTypes.d.ts +0 -89
- package/es/ProLayout/components/TabsManager/utils/index.d.ts +0 -47
- package/es/ProLayout/components/index.d.ts +0 -3
- package/es/ProLayout/index.d.ts +0 -20
- package/es/ProLayout/propTypes.d.ts +0 -533
- package/es/ProLayout/utils/index.d.ts +0 -43
- package/es/ProSelect/components/AdaptiveTooltip.d.ts +0 -4
- package/es/ProSelect/index.d.ts +0 -5
- package/es/ProSelect/propsType.d.ts +0 -160
- package/es/ProSelect/utils/index.d.ts +0 -4
- package/es/ProStep/components/Anchor/index.d.ts +0 -4
- package/es/ProStep/components/Item/index.d.ts +0 -3
- package/es/ProStep/components/LazyLoad/index.d.ts +0 -19
- package/es/ProStep/components/Listener/index.d.ts +0 -4
- package/es/ProStep/components/Step/index.d.ts +0 -5
- package/es/ProStep/index.d.ts +0 -11
- package/es/ProStep/propsType.d.ts +0 -224
- package/es/ProStep/utils/index.d.ts +0 -22
- package/es/ProStepTab/index.d.ts +0 -22
- package/es/ProStepTab/propsType.d.ts +0 -114
- package/es/ProTable/components/EditableCell/EditIcon.d.ts +0 -6
- package/es/ProTable/components/EditableCell/index.d.ts +0 -4
- package/es/ProTable/components/EditableCell/propsType.d.ts +0 -24
- package/es/ProTable/components/FormatColumn/index.d.ts +0 -22
- package/es/ProTable/components/FormatColumn/propsType.d.ts +0 -29
- package/es/ProTable/components/RcTable/components/BaseTable/index.d.ts +0 -3
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/index.d.ts +0 -18
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/utils/index.d.ts +0 -8
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/utils/propsType.d.ts +0 -61
- package/es/ProTable/components/RcTable/components/DraggableTable/index.d.ts +0 -3
- package/es/ProTable/components/RcTable/index.d.ts +0 -4
- package/es/ProTable/components/RenderColumn/index.d.ts +0 -22
- package/es/ProTable/components/RenderEmptyText/index.d.ts +0 -3
- package/es/ProTable/components/RenderFooter/index.d.ts +0 -2
- package/es/ProTable/components/RenderSummary/index.d.ts +0 -3
- package/es/ProTable/components/RenderTableHeader/index.d.ts +0 -2
- package/es/ProTable/components/RenderTabs/index.d.ts +0 -4
- package/es/ProTable/components/TableResizable/index.d.ts +0 -13
- package/es/ProTable/components/TooltipTitle/index.d.ts +0 -11
- package/es/ProTable/components/index.d.ts +0 -31
- package/es/ProTable/hooks/useAntdTable.d.ts +0 -7
- package/es/ProTable/index.d.ts +0 -17
- package/es/ProTable/propsType.d.ts +0 -792
- package/es/ProTable/utils/columnStorage.d.ts +0 -35
- package/es/ProTable/utils/index.d.ts +0 -52
- package/es/ProTabs/components/Card/index.d.ts +0 -3
- package/es/ProTabs/components/index.d.ts +0 -1
- package/es/ProTabs/index.d.ts +0 -4
- package/es/ProTabs/propType.d.ts +0 -94
- package/es/ProThemeTools/component/ProTools/index.d.ts +0 -3
- package/es/ProThemeTools/component/index.d.ts +0 -1
- package/es/ProThemeTools/context/ThemeContext.d.ts +0 -43
- package/es/ProThemeTools/index.d.ts +0 -9
- package/es/ProThemeTools/propsType.d.ts +0 -170
- package/es/ProThemeTools/utils/index.d.ts +0 -51
- package/es/ProTooltip/index.d.ts +0 -3
- package/es/ProTooltip/propsType.d.ts +0 -57
- package/es/ProTree/components/AdaptiveTooltip.d.ts +0 -4
- package/es/ProTree/components/CloseIcon.d.ts +0 -2
- package/es/ProTree/components/List.d.ts +0 -17
- package/es/ProTree/components/ProTree.d.ts +0 -3
- package/es/ProTree/components/ProTreeSelect/index.d.ts +0 -5
- package/es/ProTree/components/ProTreeSelect/propsType.d.ts +0 -439
- package/es/ProTree/components/SearchTitle.d.ts +0 -11
- package/es/ProTree/components/Tree.d.ts +0 -27
- package/es/ProTree/components/index.d.ts +0 -4
- package/es/ProTree/index.d.ts +0 -3
- package/es/ProTree/propsType.d.ts +0 -812
- package/es/ProTree/utils.d.ts +0 -52
- package/es/ProTreeModal/components/Cascader.d.ts +0 -14
- package/es/ProTreeModal/components/CloseIcon.d.ts +0 -2
- package/es/ProTreeModal/components/List.d.ts +0 -21
- package/es/ProTreeModal/components/SearchTitle.d.ts +0 -7
- package/es/ProTreeModal/components/SortableItem.d.ts +0 -12
- package/es/ProTreeModal/components/Tree.d.ts +0 -25
- package/es/ProTreeModal/components/Trigger.d.ts +0 -21
- package/es/ProTreeModal/components/index.d.ts +0 -6
- package/es/ProTreeModal/index.d.ts +0 -4
- package/es/ProTreeModal/propsType.d.ts +0 -298
- package/es/ProTreeModal/utils.d.ts +0 -39
- package/es/ProUpload/components/ButtonRender.d.ts +0 -20
- package/es/ProUpload/components/DragRender.d.ts +0 -21
- package/es/ProUpload/components/DraggableUploadListItem.d.ts +0 -2
- package/es/ProUpload/components/Example.d.ts +0 -10
- package/es/ProUpload/components/FileItem.d.ts +0 -33
- package/es/ProUpload/components/ImageRender.d.ts +0 -19
- package/es/ProUpload/index.d.ts +0 -4
- package/es/ProUpload/propsType.d.ts +0 -264
- package/es/ProUpload/uitls.d.ts +0 -3
- package/es/ProUtils/utils/index.d.ts +0 -6
- package/es/ProViewer/index.d.ts +0 -4
- package/es/ProViewer/propsType.d.ts +0 -35
- package/es/ProWaterMark/index.d.ts +0 -4
- package/es/ProWaterMark/propsType.d.ts +0 -6
- package/es/hooks/useDraggableRow.d.ts +0 -34
- package/es/index.d.ts +0 -47
- package/es/locale/en_US.d.ts +0 -176
- package/es/locale/index.d.ts +0 -15
- package/es/locale/zh_CN.d.ts +0 -176
- package/es/tokens.d.ts +0 -83
- package/es/utils/index.d.ts +0 -20
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import _cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
import _isEqual from "lodash/isEqual";
|
|
1
3
|
import _debounce from "lodash/debounce";
|
|
2
4
|
import warning from 'rc-util/lib/warning';
|
|
3
5
|
import { useState, useEffect, useRef, useMemo } from 'react';
|
|
4
|
-
import isEqual from 'lodash/isEqual';
|
|
5
|
-
import cloneDeep from 'lodash/cloneDeep';
|
|
6
6
|
import { toArray } from "../utils";
|
|
7
7
|
|
|
8
8
|
// 从一个对象或Form值中获取特定路径的值
|
|
@@ -79,10 +79,8 @@ const useWatchWarning = process.env.NODE_ENV !== 'production' ? dependencies =>
|
|
|
79
79
|
function useWatch(dependencies, form, wait) {
|
|
80
80
|
const isSelector = typeof dependencies === 'function';
|
|
81
81
|
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
useWatchWarning(dependencies);
|
|
85
|
-
}
|
|
82
|
+
// 无条件调用,内部按 isSelector 决定是否真正执行警告逻辑,保证 Hook 顺序稳定
|
|
83
|
+
useWatchWarning(dependencies);
|
|
86
84
|
|
|
87
85
|
// 获取表单实例
|
|
88
86
|
const formInstance = form;
|
|
@@ -134,8 +132,8 @@ function useWatch(dependencies, form, wait) {
|
|
|
134
132
|
if (wait) {
|
|
135
133
|
return _debounce(value => {
|
|
136
134
|
// 只在值真正变化时才更新状态
|
|
137
|
-
if (!
|
|
138
|
-
prevStateRef.current =
|
|
135
|
+
if (!_isEqual(prevStateRef.current, value)) {
|
|
136
|
+
prevStateRef.current = _cloneDeep(value);
|
|
139
137
|
setState(value);
|
|
140
138
|
}
|
|
141
139
|
}, wait);
|
|
@@ -143,8 +141,8 @@ function useWatch(dependencies, form, wait) {
|
|
|
143
141
|
|
|
144
142
|
// 非防抖版本
|
|
145
143
|
return value => {
|
|
146
|
-
if (!
|
|
147
|
-
prevStateRef.current =
|
|
144
|
+
if (!_isEqual(prevStateRef.current, value)) {
|
|
145
|
+
prevStateRef.current = _cloneDeep(value);
|
|
148
146
|
setState(value);
|
|
149
147
|
}
|
|
150
148
|
};
|
|
@@ -18,6 +18,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
18
18
|
const {
|
|
19
19
|
formatAmount
|
|
20
20
|
} = tools;
|
|
21
|
+
const toKeyPart = value => {
|
|
22
|
+
if (value == null || value === '') return undefined;
|
|
23
|
+
if (typeof value === 'string' || typeof value === 'number') return String(value);
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
const getDescribeColumnKey = (item, index) => toKeyPart(item.label) ?? toKeyPart(item.value) ?? `describe-${index}`;
|
|
27
|
+
const getDescribeValueKey = (item, parentKey, index) => toKeyPart(item.link) ?? toKeyPart(item.value) ?? `${parentKey}-value-${index}`;
|
|
28
|
+
const getTagKey = (tagItem, parentKey, index) => toKeyPart(tagItem) ?? `${parentKey}-tag-${index}`;
|
|
29
|
+
const getSubDescribeKey = (item, index) => toKeyPart(item.label) ?? toKeyPart(item.code) ?? `sub-describe-${index}`;
|
|
21
30
|
const ProHeader = props => {
|
|
22
31
|
const {
|
|
23
32
|
breadcrumbColumns,
|
|
@@ -93,6 +102,7 @@ const ProHeader = props => {
|
|
|
93
102
|
items = [],
|
|
94
103
|
width
|
|
95
104
|
} = item;
|
|
105
|
+
const describeItemKey = getDescribeColumnKey(item, index);
|
|
96
106
|
// show为false直接隐藏¸
|
|
97
107
|
if (show === false || !show) {
|
|
98
108
|
return null;
|
|
@@ -102,11 +112,11 @@ const ProHeader = props => {
|
|
|
102
112
|
if (Array.isArray(params?.tag) && params?.tag.length) {
|
|
103
113
|
return /*#__PURE__*/_jsx(Space, {
|
|
104
114
|
size: 4,
|
|
105
|
-
children: params.tag.map((tagItem,
|
|
115
|
+
children: params.tag.map((tagItem, tagIndex) => {
|
|
106
116
|
return /*#__PURE__*/_jsx("div", {
|
|
107
117
|
className: "pro-header-tag",
|
|
108
118
|
children: tagItem
|
|
109
|
-
},
|
|
119
|
+
}, getTagKey(tagItem, describeItemKey, tagIndex));
|
|
110
120
|
})
|
|
111
121
|
});
|
|
112
122
|
}
|
|
@@ -145,10 +155,10 @@ const ProHeader = props => {
|
|
|
145
155
|
'pro-header-describe-items': true,
|
|
146
156
|
'pro-header-describe-items-more': items.length >= 2
|
|
147
157
|
}),
|
|
148
|
-
children: [items?.length > 3 ? `共${items?.length}个,` : null, items.map((item,
|
|
158
|
+
children: [items?.length > 3 ? `共${items?.length}个,` : null, items.map((item, itemIndex) => {
|
|
149
159
|
return /*#__PURE__*/_jsxs("span", {
|
|
150
|
-
children: [valueRender(item), items?.length !==
|
|
151
|
-
},
|
|
160
|
+
children: [valueRender(item), items?.length !== itemIndex + 1 ? ' 、' : null]
|
|
161
|
+
}, getDescribeValueKey(item, describeItemKey, itemIndex));
|
|
152
162
|
}), itemsHidden ? /*#__PURE__*/_jsx("span", {
|
|
153
163
|
className: "pro-header-describe-items-omit",
|
|
154
164
|
children: "..."
|
|
@@ -156,11 +166,11 @@ const ProHeader = props => {
|
|
|
156
166
|
});
|
|
157
167
|
if (itemsHidden) {
|
|
158
168
|
const tipResult = /*#__PURE__*/_jsx(_Fragment, {
|
|
159
|
-
children: items.map((item,
|
|
169
|
+
children: items.map((item, itemIndex) => {
|
|
160
170
|
return /*#__PURE__*/_jsx("p", {
|
|
161
171
|
className: "pro-header-describe-items-tip-value",
|
|
162
172
|
children: valueRender(item)
|
|
163
|
-
},
|
|
173
|
+
}, getDescribeValueKey(item, describeItemKey, itemIndex));
|
|
164
174
|
})
|
|
165
175
|
});
|
|
166
176
|
return /*#__PURE__*/_jsx(Tooltip, {
|
|
@@ -200,7 +210,7 @@ const ProHeader = props => {
|
|
|
200
210
|
})
|
|
201
211
|
})]
|
|
202
212
|
})
|
|
203
|
-
},
|
|
213
|
+
}, describeItemKey);
|
|
204
214
|
})
|
|
205
215
|
});
|
|
206
216
|
};
|
|
@@ -269,10 +279,11 @@ const ProHeader = props => {
|
|
|
269
279
|
orientation: "vertical"
|
|
270
280
|
}),
|
|
271
281
|
children: actionRender.map((item, index) => {
|
|
282
|
+
const actionKey = ( /*#__PURE__*/React.isValidElement(item) && item.key != null ? String(item.key) : undefined) ?? toKeyPart(item?.type) ?? `action-${index}`;
|
|
272
283
|
if (_isFunction(item?.type)) {
|
|
273
284
|
return /*#__PURE__*/_jsx("div", {
|
|
274
285
|
children: item
|
|
275
|
-
},
|
|
286
|
+
}, actionKey);
|
|
276
287
|
}
|
|
277
288
|
// 判断第一层dom节点为空
|
|
278
289
|
if (item?.type && !item?.props?.children) {
|
|
@@ -280,7 +291,7 @@ const ProHeader = props => {
|
|
|
280
291
|
}
|
|
281
292
|
return /*#__PURE__*/_jsx("div", {
|
|
282
293
|
children: item
|
|
283
|
-
},
|
|
294
|
+
}, actionKey);
|
|
284
295
|
})
|
|
285
296
|
});
|
|
286
297
|
}
|
|
@@ -303,15 +314,16 @@ const ProHeader = props => {
|
|
|
303
314
|
show = true,
|
|
304
315
|
tag
|
|
305
316
|
} = item;
|
|
317
|
+
const breadcrumbItemKey = toKeyPart(value) ?? `breadcrumb-${index}`;
|
|
306
318
|
const tagRender = () => {
|
|
307
319
|
if (Array.isArray(tag) && tag.length) {
|
|
308
320
|
return /*#__PURE__*/_jsx(Space, {
|
|
309
321
|
size: 8,
|
|
310
|
-
children: tag.map((tagItem,
|
|
322
|
+
children: tag.map((tagItem, tagIndex) => {
|
|
311
323
|
return /*#__PURE__*/_jsx("div", {
|
|
312
324
|
className: "pro-header-tag",
|
|
313
325
|
children: tagItem
|
|
314
|
-
},
|
|
326
|
+
}, getTagKey(tagItem, breadcrumbItemKey, tagIndex));
|
|
315
327
|
})
|
|
316
328
|
});
|
|
317
329
|
}
|
|
@@ -330,7 +342,7 @@ const ProHeader = props => {
|
|
|
330
342
|
return null;
|
|
331
343
|
}
|
|
332
344
|
return {
|
|
333
|
-
key:
|
|
345
|
+
key: breadcrumbItemKey,
|
|
334
346
|
title: /*#__PURE__*/_jsxs(Space, {
|
|
335
347
|
size: 4,
|
|
336
348
|
children: [value, " ", tagRender()]
|
|
@@ -362,6 +374,7 @@ const ProHeader = props => {
|
|
|
362
374
|
width,
|
|
363
375
|
tag
|
|
364
376
|
} = item;
|
|
377
|
+
const infoItemKey = (type && toKeyPart(value) ? `${type}-${toKeyPart(value)}` : undefined) ?? toKeyPart(value) ?? `info-${index}`;
|
|
365
378
|
// show或者值不存在为false直接隐藏¸
|
|
366
379
|
if (!show || !value) {
|
|
367
380
|
return '';
|
|
@@ -419,7 +432,7 @@ const ProHeader = props => {
|
|
|
419
432
|
hidden: ['version', 'tag'].includes(type) && !val
|
|
420
433
|
}),
|
|
421
434
|
children: type === 'copy' ? valueRender('copy') : valueRender()
|
|
422
|
-
},
|
|
435
|
+
}, infoItemKey);
|
|
423
436
|
})
|
|
424
437
|
});
|
|
425
438
|
};
|
|
@@ -513,7 +526,7 @@ const ProHeader = props => {
|
|
|
513
526
|
children: _subDescribeColumns.map((item, index) => {
|
|
514
527
|
return /*#__PURE__*/_jsx("li", {
|
|
515
528
|
children: subDescribeRender(item)
|
|
516
|
-
}, index);
|
|
529
|
+
}, getSubDescribeKey(item, index));
|
|
517
530
|
})
|
|
518
531
|
}), /*#__PURE__*/_jsx("div", {
|
|
519
532
|
className: "pro-header-fold",
|
package/es/ProSelect/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _isNumber from "lodash/isNumber";
|
|
2
2
|
import _omit from "lodash/omit";
|
|
3
|
-
import _isString from "lodash/isString";
|
|
4
3
|
import _isObject from "lodash/isObject";
|
|
5
4
|
import _isFunction from "lodash/isFunction";
|
|
6
5
|
import { useDeepCompareEffect, useRequest as useRequestFunc } from 'ahooks';
|
|
@@ -11,22 +10,8 @@ import Container from "../ProForm/components/Container";
|
|
|
11
10
|
import AdaptiveTooltip from "./components/AdaptiveTooltip";
|
|
12
11
|
import { ProForm } from '..';
|
|
13
12
|
import locale from "../locale";
|
|
14
|
-
import { getSelectList } from "./utils";
|
|
15
|
-
|
|
16
|
-
/** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
|
|
13
|
+
import { getSelectList, flattenOptions, findValueObject, defaultFilterOption as defaultFilterOptionFn, getInnerRecord, buildSelectOptions, resolveChangeOption, computeChangeValue, computeTransformValue } from "./utils";
|
|
17
14
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
-
function flattenOptions(list) {
|
|
19
|
-
if (!Array.isArray(list) || !list.length) return [];
|
|
20
|
-
const out = [];
|
|
21
|
-
list.forEach(item => {
|
|
22
|
-
if (Array.isArray(item.options)) {
|
|
23
|
-
out.push(...item.options);
|
|
24
|
-
} else {
|
|
25
|
-
out.push(item);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
15
|
export const ProSelect = (props, ref) => {
|
|
31
16
|
const {
|
|
32
17
|
fieldNames: proSelectFieldNames = {},
|
|
@@ -122,18 +107,10 @@ export const ProSelect = (props, ref) => {
|
|
|
122
107
|
fetchFunctionRef.current = fetchFunction;
|
|
123
108
|
}, [fetchFunction]);
|
|
124
109
|
const cacheList = useRequest?.options?.cacheKey ? successTransformDataHandle(fetchFunction?.data) : [];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
input.forEach(i => {
|
|
130
|
-
const res = flatOptions.find(item => item[code] === i);
|
|
131
|
-
if (res) resArr.push(res);
|
|
132
|
-
});
|
|
133
|
-
return resArr;
|
|
134
|
-
}
|
|
135
|
-
return flatOptions.find(item => item[code] === input);
|
|
136
|
-
};
|
|
110
|
+
|
|
111
|
+
// 展平结果仅随 selectList 变化;滚动重挂载/无关 rerender 时复用,避免重复展平
|
|
112
|
+
const flatOptions = useMemo(() => flattenOptions(selectList), [selectList]);
|
|
113
|
+
const getValueObject = input => findValueObject(flatOptions, code, input);
|
|
137
114
|
useImperativeHandle(ref, () => ({
|
|
138
115
|
getValueObject,
|
|
139
116
|
useRequestRef: fetchFunction
|
|
@@ -203,53 +180,29 @@ export const ProSelect = (props, ref) => {
|
|
|
203
180
|
if (!flatOptions.length) {
|
|
204
181
|
return viewEmpty;
|
|
205
182
|
}
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
if (labelInValue) {
|
|
209
|
-
return item[code] === v[code];
|
|
210
|
-
}
|
|
211
|
-
return item[code] === v;
|
|
212
|
-
});
|
|
213
|
-
if (option) {
|
|
214
|
-
return selectProps.showCodeName ? `${option[code]}-${option[label]}` : option?.[label];
|
|
215
|
-
}
|
|
216
|
-
return '-';
|
|
217
|
-
});
|
|
218
|
-
const record = value.map(v => {
|
|
219
|
-
return flatOptions.find(item => {
|
|
220
|
-
if (labelInValue) {
|
|
221
|
-
return item[code] === v[code];
|
|
222
|
-
}
|
|
223
|
-
return item[code] === v;
|
|
224
|
-
});
|
|
225
|
-
}).filter(v => !!v);
|
|
183
|
+
const findOption = v => flatOptions.find(item => labelInValue ? item[code] === v[code] : item[code] === v);
|
|
184
|
+
const record = value.map(findOption).filter(v => !!v);
|
|
226
185
|
|
|
227
|
-
// 自定义option时,默认取optionRender的值
|
|
228
|
-
|
|
229
|
-
if (!record.length) {
|
|
230
|
-
return viewEmpty;
|
|
231
|
-
}
|
|
232
|
-
const arr = [];
|
|
233
|
-
record.forEach(item => {
|
|
234
|
-
arr.push(props.optionRender(item));
|
|
235
|
-
});
|
|
186
|
+
// 自定义 option 时,默认取 optionRender 的值
|
|
187
|
+
if (_isFunction(props.optionRender) && record.length) {
|
|
236
188
|
return /*#__PURE__*/_jsx(Space, {
|
|
237
189
|
orientation: "vertical",
|
|
238
190
|
size: 4,
|
|
239
|
-
children:
|
|
240
|
-
children: item
|
|
241
|
-
}, item))
|
|
191
|
+
children: record.map(item => /*#__PURE__*/_jsx(React.Fragment, {
|
|
192
|
+
children: props.optionRender(item)
|
|
193
|
+
}, item[code]))
|
|
242
194
|
});
|
|
243
|
-
}
|
|
244
|
-
|
|
195
|
+
}
|
|
196
|
+
const labelList = value.map(v => {
|
|
197
|
+
const option = findOption(v);
|
|
198
|
+
if (!option) return '-';
|
|
199
|
+
return selectProps.showCodeName ? `${option[code]}-${option[label]}` : option?.[label];
|
|
200
|
+
});
|
|
201
|
+
return labelList?.join('、');
|
|
245
202
|
};
|
|
246
203
|
|
|
247
204
|
// 必须在早期 return 之前声明,确保每次渲染 hooks 调用数量一致(React Rules of Hooks)
|
|
248
|
-
const defaultFilterOption = useCallback(
|
|
249
|
-
if (option?.value == null) return false;
|
|
250
|
-
const optionLabel = option?.searchText ?? option?.title ?? option?.label;
|
|
251
|
-
return String(optionLabel ?? '').toLowerCase().includes(input.toLowerCase());
|
|
252
|
-
}, []);
|
|
205
|
+
const defaultFilterOption = useCallback(defaultFilterOptionFn, []);
|
|
253
206
|
const mergedShowSearch = useMemo(() => {
|
|
254
207
|
const defaultConfig = {
|
|
255
208
|
enabled: true,
|
|
@@ -283,6 +236,29 @@ export const ProSelect = (props, ref) => {
|
|
|
283
236
|
}
|
|
284
237
|
return defaultConfig;
|
|
285
238
|
}, [_onSearch, defaultFilterOption, selectProps.showSearch]);
|
|
239
|
+
let newSelectList = selectList;
|
|
240
|
+
if (otherProps?.listName && filterInList) {
|
|
241
|
+
newSelectList = getSelectList({
|
|
242
|
+
otherProps,
|
|
243
|
+
value,
|
|
244
|
+
dataSource: selectList,
|
|
245
|
+
labelInValue,
|
|
246
|
+
fieldNames,
|
|
247
|
+
mode: selectProps.mode
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// antd Select 的 options 仅随数据源/字段映射/展示配置变化;滚动重挂载与无关 rerender 时复用,
|
|
252
|
+
// 避免每次渲染全量重建 option 对象(落在虚拟表格挂载热路径上)。
|
|
253
|
+
// 依赖用 buildSelectOptions 实际消费的原始值(code/label/showCodeName/OptionRender),
|
|
254
|
+
// 而非每次新建的函数引用,避免缓存失效。
|
|
255
|
+
// 必须在 isView 早期 return 之前声明,确保每次渲染 hooks 调用数量一致(React Rules of Hooks)。
|
|
256
|
+
const selectOptions = useMemo(() => buildSelectOptions(newSelectList, {
|
|
257
|
+
code,
|
|
258
|
+
label,
|
|
259
|
+
showCodeName: selectProps.showCodeName,
|
|
260
|
+
optionRender: OptionRender
|
|
261
|
+
}), [newSelectList, code, label, selectProps.showCodeName, OptionRender]);
|
|
286
262
|
if (isView || props.isView) {
|
|
287
263
|
if (Array.isArray(value)) {
|
|
288
264
|
// 如果设置了maxTagCount且超出数量,需要截断显示
|
|
@@ -337,32 +313,6 @@ export const ProSelect = (props, ref) => {
|
|
|
337
313
|
return props.children;
|
|
338
314
|
};
|
|
339
315
|
const isReactElement = element => /*#__PURE__*/isValidElement(element);
|
|
340
|
-
const getInnerRecord = option => {
|
|
341
|
-
if (!option) return undefined;
|
|
342
|
-
if (option.record) return option.record;
|
|
343
|
-
if (option.data?.record) return option.data.record;
|
|
344
|
-
return undefined;
|
|
345
|
-
};
|
|
346
|
-
const getOptionText = item => {
|
|
347
|
-
if (OptionRender) {
|
|
348
|
-
const rendered = OptionRender(item);
|
|
349
|
-
return _isString(rendered) ? rendered : String(item[label] ?? '');
|
|
350
|
-
}
|
|
351
|
-
const text = selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label];
|
|
352
|
-
return _isString(text) ? text : String(text ?? '');
|
|
353
|
-
};
|
|
354
|
-
const buildOptionItem = (item, index) => {
|
|
355
|
-
const text = getOptionText(item);
|
|
356
|
-
return {
|
|
357
|
-
key: item[code] != null ? `${item[code]}-${index}` : `option-${index}`,
|
|
358
|
-
label: text,
|
|
359
|
-
value: item[code] != null ? item[code] : undefined,
|
|
360
|
-
disabled: !!item.disabled,
|
|
361
|
-
title: text,
|
|
362
|
-
searchText: text,
|
|
363
|
-
record: item
|
|
364
|
-
};
|
|
365
|
-
};
|
|
366
316
|
const selectOptionRender = option => {
|
|
367
317
|
const currentRecord = option?.data?.record || option?.record;
|
|
368
318
|
const text = option?.data?.searchText ?? option?.data?.title ?? option?.label ?? '';
|
|
@@ -381,93 +331,42 @@ export const ProSelect = (props, ref) => {
|
|
|
381
331
|
})
|
|
382
332
|
});
|
|
383
333
|
};
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
Object.assign(item, currentRecord);
|
|
396
|
-
}
|
|
397
|
-
delete item.record;
|
|
398
|
-
delete item.children;
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
if (labelInValue) {
|
|
402
|
-
onChange?.(getChangeValue ? getChangeValue(getValueObject(value)) : getValueObject(value), option);
|
|
403
|
-
} else {
|
|
404
|
-
onChange?.(getChangeValue ? getChangeValue(value) : value, option);
|
|
405
|
-
}
|
|
406
|
-
} else if (!selectProps.mode && labelInValue) {
|
|
407
|
-
onChange(getChangeValue ? getChangeValue(getValueObject(value)) : getValueObject(value), option);
|
|
408
|
-
} else {
|
|
409
|
-
onChange?.(getChangeValue ? getChangeValue(value) : value, getInnerRecord(_option));
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 处理 labelInValue 模式下值的回填
|
|
415
|
-
* @returns
|
|
416
|
-
*/
|
|
417
|
-
const transformValue = () => {
|
|
418
|
-
if (labelInValue && !selectProps.mode) {
|
|
419
|
-
if (!_isObject(value)) {
|
|
420
|
-
return undefined;
|
|
421
|
-
}
|
|
422
|
-
return value?.[code] || value?.value;
|
|
423
|
-
}
|
|
424
|
-
if (labelInValue && selectProps.mode) {
|
|
425
|
-
// 对传入的值做一些基础判断
|
|
426
|
-
if (!Array.isArray(value)) {
|
|
427
|
-
return [];
|
|
428
|
-
}
|
|
429
|
-
return value.map(item => item?.[code]);
|
|
430
|
-
}
|
|
431
|
-
// Handling Jialuo's Extreme Demands
|
|
432
|
-
if (selectProps.mode && value === null) {
|
|
433
|
-
return undefined;
|
|
434
|
-
}
|
|
435
|
-
// 只有当 dataSource 只有一个值时才默认回填(只返回值,不进行状态更新)
|
|
436
|
-
if (defaultOne && !value && !isDefaultOne && selectList?.length === 1) {
|
|
437
|
-
const option = flatOptions[0];
|
|
438
|
-
// selectList 可能是异步回来的值
|
|
439
|
-
if (option) {
|
|
440
|
-
return option?.[code];
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
// 修复空字符placeholder不显示
|
|
444
|
-
if (value === '') {
|
|
445
|
-
return undefined;
|
|
334
|
+
const mode = selectProps.mode;
|
|
335
|
+
const handleChange = (value, rawOption) => {
|
|
336
|
+
// 仅多选、或单选 labelInValue 需要加工 option;其余直接取原始节点上的 record
|
|
337
|
+
if (mode !== 'multiple' && !(labelInValue && !mode)) {
|
|
338
|
+
onChange?.(computeChangeValue(value, {
|
|
339
|
+
mode,
|
|
340
|
+
getChangeValue,
|
|
341
|
+
flatOptions,
|
|
342
|
+
code
|
|
343
|
+
}), getInnerRecord(rawOption));
|
|
344
|
+
return;
|
|
446
345
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
otherProps,
|
|
453
|
-
value,
|
|
454
|
-
dataSource: selectList,
|
|
455
|
-
labelInValue,
|
|
456
|
-
fieldNames,
|
|
457
|
-
mode: selectProps.mode
|
|
346
|
+
// labelInValue 下,option/其首层子节点是 React 节点时取挂载的 record
|
|
347
|
+
const isReactNode = labelInValue && (isReactElement(rawOption) || isReactElement(rawOption?.children));
|
|
348
|
+
const option = resolveChangeOption(rawOption, {
|
|
349
|
+
mode,
|
|
350
|
+
isReactNode
|
|
458
351
|
});
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
352
|
+
onChange?.(computeChangeValue(value, {
|
|
353
|
+
labelInValue,
|
|
354
|
+
mode,
|
|
355
|
+
getChangeValue,
|
|
356
|
+
flatOptions,
|
|
357
|
+
code
|
|
358
|
+
}), option);
|
|
359
|
+
};
|
|
360
|
+
const transformValue = () => computeTransformValue({
|
|
361
|
+
value,
|
|
362
|
+
labelInValue,
|
|
363
|
+
mode,
|
|
364
|
+
defaultOne,
|
|
365
|
+
isDefaultOne,
|
|
366
|
+
selectList,
|
|
367
|
+
flatOptions,
|
|
368
|
+
code
|
|
369
|
+
});
|
|
471
370
|
return /*#__PURE__*/_jsx("div", {
|
|
472
371
|
style: props.style,
|
|
473
372
|
className: "pro-select",
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _difference from "lodash/difference";
|
|
2
|
+
import _isString from "lodash/isString";
|
|
3
|
+
import _isObject from "lodash/isObject";
|
|
2
4
|
import _isNumber from "lodash/isNumber";
|
|
3
5
|
/* eslint-disable no-restricted-syntax */
|
|
4
6
|
/**
|
|
@@ -109,4 +111,176 @@ export const getSelectList = ({
|
|
|
109
111
|
fieldNames,
|
|
110
112
|
mode
|
|
111
113
|
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
|
|
117
|
+
export const flattenOptions = list => {
|
|
118
|
+
if (!Array.isArray(list) || !list.length) return [];
|
|
119
|
+
const out = [];
|
|
120
|
+
list.forEach(item => {
|
|
121
|
+
if (Array.isArray(item.options)) {
|
|
122
|
+
out.push(...item.options);
|
|
123
|
+
} else {
|
|
124
|
+
out.push(item);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return out;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 根据 code 在扁平选项中查找对应的数据对象
|
|
132
|
+
* @param flatOptions 扁平选项列表
|
|
133
|
+
* @param code 值字段名
|
|
134
|
+
* @param input 单个值或值数组
|
|
135
|
+
*/
|
|
136
|
+
export const findValueObject = (flatOptions, code, input) => {
|
|
137
|
+
if (Array.isArray(input) && input.length) {
|
|
138
|
+
return input.map(i => flatOptions.find(item => item[code] === i)).filter(item => !!item);
|
|
139
|
+
}
|
|
140
|
+
return flatOptions.find(item => item[code] === input);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** 默认搜索过滤:在 searchText/title/label 中做大小写不敏感的包含匹配 */
|
|
144
|
+
export const defaultFilterOption = (input, option) => {
|
|
145
|
+
if (option?.value == null) return false;
|
|
146
|
+
const optionLabel = option?.searchText ?? option?.title ?? option?.label;
|
|
147
|
+
return String(optionLabel ?? '').toLowerCase().includes(input.toLowerCase());
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** 取选项上挂载的原始 record(兼容 option.record / option.data.record) */
|
|
151
|
+
export const getInnerRecord = option => {
|
|
152
|
+
if (!option) return undefined;
|
|
153
|
+
if (option.record) return option.record;
|
|
154
|
+
if (option.data?.record) return option.data.record;
|
|
155
|
+
return undefined;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 计算单个选项的展示文本
|
|
160
|
+
* @param optionRender 自定义渲染函数,返回字符串时直接使用
|
|
161
|
+
* @param showCodeName 是否以 code-label 形式展示
|
|
162
|
+
*/
|
|
163
|
+
export const getOptionText = ({
|
|
164
|
+
item,
|
|
165
|
+
optionRender,
|
|
166
|
+
showCodeName,
|
|
167
|
+
code,
|
|
168
|
+
label
|
|
169
|
+
}) => {
|
|
170
|
+
if (optionRender) {
|
|
171
|
+
const rendered = optionRender(item);
|
|
172
|
+
return _isString(rendered) ? rendered : String(item[label] ?? '');
|
|
173
|
+
}
|
|
174
|
+
const text = showCodeName ? `${item[code]}-${item[label]}` : item[label];
|
|
175
|
+
return _isString(text) ? text : String(text ?? '');
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** 构建单个 antd Select option 对象 */
|
|
179
|
+
export const buildOptionItem = (item, index, config) => {
|
|
180
|
+
const text = getOptionText({
|
|
181
|
+
item,
|
|
182
|
+
...config
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
key: item[config.code] != null ? `${item[config.code]}-${index}` : `option-${index}`,
|
|
186
|
+
label: text,
|
|
187
|
+
value: item[config.code] != null ? item[config.code] : undefined,
|
|
188
|
+
disabled: !!item.disabled,
|
|
189
|
+
title: text,
|
|
190
|
+
searchText: text,
|
|
191
|
+
record: item
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 构建 antd Select 的 options(支持分组)
|
|
197
|
+
* @param list 当前数据源(可能含 options 分组项)
|
|
198
|
+
*/
|
|
199
|
+
export const buildSelectOptions = (list, config) => {
|
|
200
|
+
if (!Array.isArray(list)) {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
return list.map((item, index) => {
|
|
204
|
+
const groupOptions = item.options;
|
|
205
|
+
if (Array.isArray(groupOptions)) {
|
|
206
|
+
return {
|
|
207
|
+
key: item[config.label] ?? `group-${index}`,
|
|
208
|
+
label: item[config.label],
|
|
209
|
+
options: groupOptions.map((opt, optIndex) => buildOptionItem(opt, optIndex, config))
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return buildOptionItem(item, index, config);
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* labelInValue 模式下解析 onChange 回调拿到的 option:
|
|
218
|
+
* 多选模式下将 record 合并进每项并清理临时字段,单选直接透传
|
|
219
|
+
*/
|
|
220
|
+
export const resolveChangeOption = (rawOption, {
|
|
221
|
+
mode,
|
|
222
|
+
isReactNode
|
|
223
|
+
}) => {
|
|
224
|
+
let option = rawOption;
|
|
225
|
+
if (isReactNode) {
|
|
226
|
+
option = getInnerRecord(rawOption);
|
|
227
|
+
}
|
|
228
|
+
if (mode === 'multiple' && Array.isArray(option)) {
|
|
229
|
+
option.forEach(item => {
|
|
230
|
+
const currentRecord = getInnerRecord(item);
|
|
231
|
+
if (currentRecord) {
|
|
232
|
+
Object.assign(item, currentRecord);
|
|
233
|
+
}
|
|
234
|
+
delete item.record;
|
|
235
|
+
delete item.children;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return option;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 计算 onChange 第一个参数(值):根据 labelInValue/getChangeValue 决定透传原始值还是值对象
|
|
243
|
+
*/
|
|
244
|
+
export const computeChangeValue = (value, {
|
|
245
|
+
labelInValue,
|
|
246
|
+
mode,
|
|
247
|
+
getChangeValue,
|
|
248
|
+
flatOptions,
|
|
249
|
+
code
|
|
250
|
+
}) => {
|
|
251
|
+
const useValueObject = labelInValue && (mode === 'multiple' || !mode);
|
|
252
|
+
const resolved = useValueObject ? findValueObject(flatOptions, code, value) : value;
|
|
253
|
+
return getChangeValue ? getChangeValue(resolved) : resolved;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 处理 labelInValue 模式及 defaultOne 下值的回填(只返回值,不触发状态更新)
|
|
258
|
+
*/
|
|
259
|
+
export const computeTransformValue = ({
|
|
260
|
+
value,
|
|
261
|
+
labelInValue,
|
|
262
|
+
mode,
|
|
263
|
+
defaultOne,
|
|
264
|
+
isDefaultOne,
|
|
265
|
+
selectList,
|
|
266
|
+
flatOptions,
|
|
267
|
+
code
|
|
268
|
+
}) => {
|
|
269
|
+
if (labelInValue && !mode) {
|
|
270
|
+
if (!_isObject(value)) return undefined;
|
|
271
|
+
return value?.[code] || value?.value;
|
|
272
|
+
}
|
|
273
|
+
if (labelInValue && mode) {
|
|
274
|
+
if (!Array.isArray(value)) return [];
|
|
275
|
+
return value.map(item => item?.[code]);
|
|
276
|
+
}
|
|
277
|
+
// 兼容多选下显式传 null 的极端场景
|
|
278
|
+
if (mode && value === null) return undefined;
|
|
279
|
+
// 仅当 dataSource 只有一项时默认回填
|
|
280
|
+
if (defaultOne && !value && !isDefaultOne && selectList?.length === 1) {
|
|
281
|
+
return flatOptions[0]?.[code];
|
|
282
|
+
}
|
|
283
|
+
// 修复空字符 placeholder 不显示
|
|
284
|
+
if (value === '') return undefined;
|
|
285
|
+
return value;
|
|
112
286
|
};
|