@hw-component/form 0.0.9-beta-v19 → 0.0.9-beta-v21
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/.eslintcache +1 -0
- package/.idea/hw-component-form.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/es/Select/modal.d.ts +1 -3
- package/lib/Select/modal.d.ts +1 -3
- package/package.json +1 -1
- package/public/index.html +0 -19
- package/scripts/rollup.config.js +0 -90
- package/scripts/webpack.config.js +0 -76
- package/src/Layout.tsx +0 -61
- package/src/app.tsx +0 -33
- package/src/components/Cascader/index.tsx +0 -31
- package/src/components/CheckboxGroup/CheckBox/index.tsx +0 -38
- package/src/components/CheckboxGroup/hooks.ts +0 -105
- package/src/components/CheckboxGroup/index.tsx +0 -85
- package/src/components/CheckboxGroup/modal.ts +0 -17
- package/src/components/DialogForm/DrawerForm/Footer.tsx +0 -20
- package/src/components/DialogForm/DrawerForm/Title.tsx +0 -12
- package/src/components/DialogForm/DrawerForm/index.tsx +0 -110
- package/src/components/DialogForm/ModalForm.tsx +0 -91
- package/src/components/DialogForm/hooks.ts +0 -122
- package/src/components/DialogForm/modal.ts +0 -44
- package/src/components/Form/Context/FormConfigProvider.tsx +0 -38
- package/src/components/Form/Context/index.tsx +0 -14
- package/src/components/Form/FormItem/BasicItem.tsx +0 -95
- package/src/components/Form/FormItem/Helper.tsx +0 -25
- package/src/components/Form/FormItem/RegularFormItem.tsx +0 -13
- package/src/components/Form/FormItem/UpFormItem.tsx +0 -21
- package/src/components/Form/FormItem/hooks.tsx +0 -54
- package/src/components/Form/FormItem/index.tsx +0 -8
- package/src/components/Form/HFormConnect.tsx +0 -74
- package/src/components/Form/InitSet.tsx +0 -10
- package/src/components/Form/Label.tsx +0 -50
- package/src/components/Form/config.ts +0 -58
- package/src/components/Form/hooks/index.ts +0 -114
- package/src/components/Form/hooks/useDefaultRender.tsx +0 -45
- package/src/components/Form/hooks/useHForm.ts +0 -182
- package/src/components/Form/hooks/useInitConfigData.tsx +0 -194
- package/src/components/Form/index.less +0 -54
- package/src/components/Form/index.tsx +0 -113
- package/src/components/Form/modal.ts +0 -206
- package/src/components/Input/ButtonInput.tsx +0 -47
- package/src/components/Input/ColorInput/Picker.tsx +0 -18
- package/src/components/Input/ColorInput/data.ts +0 -102
- package/src/components/Input/ColorInput/index.less +0 -10
- package/src/components/Input/ColorInput/index.tsx +0 -58
- package/src/components/Input/InputNumber.tsx +0 -5
- package/src/components/Input/SelectInput.tsx +0 -75
- package/src/components/Input/TrimInput.tsx +0 -26
- package/src/components/Input/VerificationCodeInput.tsx +0 -74
- package/src/components/Input/defaultConfig.ts +0 -8
- package/src/components/Input/index.tsx +0 -26
- package/src/components/Input/modal.ts +0 -40
- package/src/components/PageHandler/ErrorComponent.tsx +0 -20
- package/src/components/PageHandler/LoadingComponent.tsx +0 -9
- package/src/components/PageHandler/index.tsx +0 -14
- package/src/components/PageHandler/modal.ts +0 -6
- package/src/components/RadioGroup/index.tsx +0 -45
- package/src/components/Select/components/AllSelect.tsx +0 -54
- package/src/components/Select/components/CheckBoxOption.tsx +0 -14
- package/src/components/Select/components/DropdownComponent.tsx +0 -36
- package/src/components/Select/components/NoFindItem.tsx +0 -7
- package/src/components/Select/components/NotFoundContent.tsx +0 -25
- package/src/components/Select/defaultConfig.tsx +0 -23
- package/src/components/Select/hooks/changeHooks.tsx +0 -159
- package/src/components/Select/hooks/norHooks.ts +0 -85
- package/src/components/Select/index.less +0 -22
- package/src/components/Select/index.tsx +0 -126
- package/src/components/Select/modal.ts +0 -38
- package/src/components/Select/utils.ts +0 -18
- package/src/components/Submit/components.tsx +0 -57
- package/src/components/Submit/hooks.ts +0 -31
- package/src/components/Submit/index.tsx +0 -33
- package/src/components/Switch/index.tsx +0 -77
- package/src/components/TDPicker/RangePicker.tsx +0 -109
- package/src/components/TDPicker/TimePicker.tsx +0 -29
- package/src/components/TDPicker/hooks.ts +0 -150
- package/src/components/TDPicker/index.tsx +0 -33
- package/src/components/TDPicker/modal.ts +0 -48
- package/src/components/TextArea/TrimTextArea.tsx +0 -30
- package/src/components/TextArea/index.tsx +0 -8
- package/src/components/Upload/Btn.tsx +0 -24
- package/src/components/Upload/MediaTypeEle/TypeEle.tsx +0 -26
- package/src/components/Upload/MediaTypeEle/index.tsx +0 -34
- package/src/components/Upload/Preview/index.tsx +0 -14
- package/src/components/Upload/UrlUpload/index.tsx +0 -104
- package/src/components/Upload/enums.ts +0 -5
- package/src/components/Upload/hooks/change.ts +0 -79
- package/src/components/Upload/hooks/customRequest.ts +0 -87
- package/src/components/Upload/hooks/propsMaker.ts +0 -20
- package/src/components/Upload/index.tsx +0 -119
- package/src/components/Upload/modal.ts +0 -33
- package/src/components/Upload/util.ts +0 -27
- package/src/components/config.ts +0 -47
- package/src/components/hooks/index.ts +0 -53
- package/src/components/index.tsx +0 -37
- package/src/components/modal.ts +0 -20
- package/src/components/styles/index.less +0 -3
- package/src/components/styles/local.less +0 -1
- package/src/components/typings.d.ts +0 -11
- package/src/index.less +0 -20
- package/src/index.tsx +0 -12
- package/src/pages/Checkbox/index.tsx +0 -14
- package/src/pages/DatePicker/index.tsx +0 -33
- package/src/pages/DrawerForm/index.tsx +0 -145
- package/src/pages/Form/index.tsx +0 -172
- package/src/pages/Input/index.tsx +0 -30
- package/src/pages/ModalForm/index.tsx +0 -191
- package/src/pages/Radio/index.tsx +0 -18
- package/src/pages/Select/index.tsx +0 -63
- package/src/pages/Switch/index.tsx +0 -18
- package/src/pages/Upload/index.tsx +0 -14
- package/src/routes.tsx +0 -80
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Select } from "antd";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { useFilterOption, useOptionReq } from "./hooks/norHooks";
|
|
4
|
-
import { useValueChange } from "./hooks/changeHooks";
|
|
5
|
-
import type { HSelectProps } from "./modal";
|
|
6
|
-
import { defaultModeConfig, defaultSelectConfig } from "./defaultConfig";
|
|
7
|
-
import DropdownComponent from "./components/DropdownComponent";
|
|
8
|
-
import AllSelect from "./components/AllSelect";
|
|
9
|
-
import { useChangeOptions, useMatchConfigProps } from "../hooks";
|
|
10
|
-
import HFormConnect from "../Form/HFormConnect";
|
|
11
|
-
const { Option } = Select;
|
|
12
|
-
|
|
13
|
-
const Index: React.FC<HSelectProps> = ({
|
|
14
|
-
style = { width: "100%" },
|
|
15
|
-
mode,
|
|
16
|
-
options,
|
|
17
|
-
modeConfig = defaultModeConfig,
|
|
18
|
-
value,
|
|
19
|
-
onChange,
|
|
20
|
-
fieldNames: propsFieldNames,
|
|
21
|
-
request,
|
|
22
|
-
manual,
|
|
23
|
-
optionLabelProp = "label",
|
|
24
|
-
filterProvider,
|
|
25
|
-
optionFilterProp = "filterLabel",
|
|
26
|
-
serviceSearch,
|
|
27
|
-
onSearch: propsOnSearch,
|
|
28
|
-
filterOption,
|
|
29
|
-
showSearch,
|
|
30
|
-
labelInValue,
|
|
31
|
-
noMatchItemRender = defaultSelectConfig.noMatchItemRender,
|
|
32
|
-
allSelect,
|
|
33
|
-
addDispatchListener,
|
|
34
|
-
addFormat,
|
|
35
|
-
dispatch,
|
|
36
|
-
...props
|
|
37
|
-
}) => {
|
|
38
|
-
const { icon, render } = modeConfig?.[mode || ""] || {};
|
|
39
|
-
const { fieldNames } = useMatchConfigProps({ fieldNames: propsFieldNames });
|
|
40
|
-
const selfFilterOption = useFilterOption({ filterOption, serviceSearch });
|
|
41
|
-
const {
|
|
42
|
-
run,
|
|
43
|
-
loading,
|
|
44
|
-
data: resultData,
|
|
45
|
-
error,
|
|
46
|
-
onSearch,
|
|
47
|
-
mathShowSearch,
|
|
48
|
-
reload,
|
|
49
|
-
} = useOptionReq({
|
|
50
|
-
options,
|
|
51
|
-
manual,
|
|
52
|
-
fieldNames,
|
|
53
|
-
request,
|
|
54
|
-
serviceSearch,
|
|
55
|
-
showSearch,
|
|
56
|
-
onSearch: propsOnSearch,
|
|
57
|
-
dispatch,
|
|
58
|
-
}); //options
|
|
59
|
-
|
|
60
|
-
const data = useChangeOptions({ options: resultData, fieldNames });
|
|
61
|
-
const { val, change } = useValueChange({
|
|
62
|
-
labelInValue,
|
|
63
|
-
onChange,
|
|
64
|
-
value,
|
|
65
|
-
options: data,
|
|
66
|
-
mode,
|
|
67
|
-
noMatchItemRender,
|
|
68
|
-
fieldNames,
|
|
69
|
-
});
|
|
70
|
-
addDispatchListener?.("reload", reload);
|
|
71
|
-
return (
|
|
72
|
-
<Select
|
|
73
|
-
style={style}
|
|
74
|
-
mode={mode}
|
|
75
|
-
loading={loading}
|
|
76
|
-
value={val}
|
|
77
|
-
onSearch={onSearch}
|
|
78
|
-
onChange={change}
|
|
79
|
-
dropdownRender={(node) => {
|
|
80
|
-
return (
|
|
81
|
-
<DropdownComponent
|
|
82
|
-
loading={loading}
|
|
83
|
-
reload={run}
|
|
84
|
-
error={error}
|
|
85
|
-
options={data}
|
|
86
|
-
>
|
|
87
|
-
<AllSelect
|
|
88
|
-
allSelect={allSelect}
|
|
89
|
-
options={data}
|
|
90
|
-
mode={mode}
|
|
91
|
-
value={val}
|
|
92
|
-
onChange={change}
|
|
93
|
-
>
|
|
94
|
-
{node}
|
|
95
|
-
</AllSelect>
|
|
96
|
-
</DropdownComponent> //全选
|
|
97
|
-
);
|
|
98
|
-
}}
|
|
99
|
-
optionLabelProp={optionLabelProp}
|
|
100
|
-
menuItemSelectedIcon={icon}
|
|
101
|
-
optionFilterProp={optionFilterProp}
|
|
102
|
-
filterOption={selfFilterOption}
|
|
103
|
-
showSearch={mathShowSearch}
|
|
104
|
-
labelInValue={true}
|
|
105
|
-
{...props}
|
|
106
|
-
>
|
|
107
|
-
{data?.map((item) => {
|
|
108
|
-
const { value: optionValue, label } = item;
|
|
109
|
-
const result = filterProvider?.(item) || label;
|
|
110
|
-
const filter = { [optionFilterProp]: result };
|
|
111
|
-
return (
|
|
112
|
-
<Option
|
|
113
|
-
value={optionValue}
|
|
114
|
-
key={optionValue}
|
|
115
|
-
label={label}
|
|
116
|
-
mode={mode}
|
|
117
|
-
{...filter}
|
|
118
|
-
>
|
|
119
|
-
{render ? render(item, val) : label}
|
|
120
|
-
</Option>
|
|
121
|
-
);
|
|
122
|
-
})}
|
|
123
|
-
</Select>
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
export default HFormConnect(Index);
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { SelectProps } from "antd";
|
|
2
|
-
import type React from "react";
|
|
3
|
-
import type { PromiseFnResult } from "../modal";
|
|
4
|
-
import type { argsFn } from "@/components/Form/modal";
|
|
5
|
-
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
|
-
import type { DispatchModal } from "@/components/Form/modal";
|
|
7
|
-
export type OptionType = Record<string, any>;
|
|
8
|
-
export type PartialHSelectProps = Partial<HSelectProps>;
|
|
9
|
-
export type RenderFn = (data: OptionType) => React.ReactNode;
|
|
10
|
-
|
|
11
|
-
interface ModeConfigItem {
|
|
12
|
-
icon?: React.ReactNode | null; //自定义多选时当前选中的条目图标
|
|
13
|
-
render?: (item: OptionType, value: any[]) => React.ReactNode; //options内容
|
|
14
|
-
}
|
|
15
|
-
export interface ModeConfig {
|
|
16
|
-
multiple?: ModeConfigItem;
|
|
17
|
-
tags?: ModeConfigItem;
|
|
18
|
-
}
|
|
19
|
-
export interface HSelectProps
|
|
20
|
-
extends Omit<SelectProps, "options" | "placeholder"> {
|
|
21
|
-
style?: React.CSSProperties;
|
|
22
|
-
request?: PromiseFnResult<any, OptionType[]>;
|
|
23
|
-
manual?: boolean;
|
|
24
|
-
modeConfig?: ModeConfig;
|
|
25
|
-
filterProvider?: (item: any) => string; //筛选字段默认为label
|
|
26
|
-
serviceSearch?: boolean; //服务端搜索
|
|
27
|
-
options?: OptionType[];
|
|
28
|
-
noMatchItemRender?: RenderFn; //没有数据
|
|
29
|
-
allSelect?: boolean; //显示全选
|
|
30
|
-
addDispatchListener?: (key: string, fn: argsFn) => void;
|
|
31
|
-
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
32
|
-
placeholder?: string;
|
|
33
|
-
dispatch?: DispatchModal;
|
|
34
|
-
}
|
|
35
|
-
export interface FilterDataModal {
|
|
36
|
-
value: any;
|
|
37
|
-
index: number;
|
|
38
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const itemOpMaker = (itemOp, fieldNames) => {
|
|
2
|
-
const { label, value: itemVal, ...oItemOp } = itemOp;
|
|
3
|
-
const { label: labelKey = "", value: valKey = "" } = fieldNames;
|
|
4
|
-
return {
|
|
5
|
-
[labelKey]: label,
|
|
6
|
-
[valKey]: itemVal,
|
|
7
|
-
...oItemOp,
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const itemOpProvider = (itemOps, fieldNames) => {
|
|
12
|
-
if (Array.isArray(itemOps)) {
|
|
13
|
-
return itemOps.map((item) => {
|
|
14
|
-
return itemOpMaker(item, fieldNames);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return itemOpMaker(itemOps, fieldNames);
|
|
18
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Button } from "antd";
|
|
2
|
-
import { useFormContext } from "../Form/Context";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import type {
|
|
5
|
-
ISubmitProps,
|
|
6
|
-
SubmitBarExtraType,
|
|
7
|
-
} from "@/components/Submit/index";
|
|
8
|
-
interface ControlFooterProps extends ISubmitProps {
|
|
9
|
-
action: SubmitBarExtraType;
|
|
10
|
-
}
|
|
11
|
-
function ResetBtn({ form, ...props }) {
|
|
12
|
-
return (
|
|
13
|
-
<Button
|
|
14
|
-
{...props}
|
|
15
|
-
onClick={() => {
|
|
16
|
-
form.resetFields();
|
|
17
|
-
}}
|
|
18
|
-
>
|
|
19
|
-
重置
|
|
20
|
-
</Button>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function SubBtn({
|
|
25
|
-
type = "primary",
|
|
26
|
-
form,
|
|
27
|
-
text = "提交",
|
|
28
|
-
loading,
|
|
29
|
-
...props
|
|
30
|
-
}: ISubmitProps) {
|
|
31
|
-
const { loading: formSubLoading = loading } = useFormContext();
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Button
|
|
35
|
-
{...props}
|
|
36
|
-
type={type as any}
|
|
37
|
-
onClick={form.submit}
|
|
38
|
-
loading={formSubLoading}
|
|
39
|
-
>
|
|
40
|
-
{text}
|
|
41
|
-
</Button>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const ControlFooter = ({ action, ...props }: ControlFooterProps) => {
|
|
46
|
-
const { form } = props;
|
|
47
|
-
if (action === "reset") {
|
|
48
|
-
return <ResetBtn {...props} />;
|
|
49
|
-
}
|
|
50
|
-
if (action === "submit") {
|
|
51
|
-
return <SubBtn {...props} />;
|
|
52
|
-
}
|
|
53
|
-
if (typeof action === "string") {
|
|
54
|
-
return <>{action}</>;
|
|
55
|
-
}
|
|
56
|
-
return React.cloneElement(action as any, { form });
|
|
57
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ISubmitProps,
|
|
3
|
-
SubmitBarExtraType,
|
|
4
|
-
} from "@/components/Submit/index";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
|
-
|
|
7
|
-
const getBarComKeyList = (extraList: SubmitBarExtraType[]) => {
|
|
8
|
-
return extraList.map((item, index) => {
|
|
9
|
-
return {
|
|
10
|
-
action: item,
|
|
11
|
-
key: `${index}`,
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useBarSortList = (
|
|
17
|
-
props: Pick<ISubmitProps, "reset" | "extraList">
|
|
18
|
-
) => {
|
|
19
|
-
const { extraList, reset = false } = props;
|
|
20
|
-
const list = useMemo(() => {
|
|
21
|
-
if (!extraList) {
|
|
22
|
-
const defaultList: SubmitBarExtraType[] = reset
|
|
23
|
-
? ["reset", "submit"]
|
|
24
|
-
: ["submit"];
|
|
25
|
-
return getBarComKeyList(defaultList);
|
|
26
|
-
}
|
|
27
|
-
return getBarComKeyList(extraList);
|
|
28
|
-
}, [extraList, reset]);
|
|
29
|
-
|
|
30
|
-
return list;
|
|
31
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Row, Space } from "antd";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import type { ButtonProps, FormInstance } from "antd/es";
|
|
4
|
-
import { useBarSortList } from "./hooks";
|
|
5
|
-
import { ControlFooter } from "./components";
|
|
6
|
-
|
|
7
|
-
export type SubmitBarExtraType = "submit" | "reset" | React.ReactDOM;
|
|
8
|
-
|
|
9
|
-
export interface ISubmitProps extends Omit<ButtonProps, "form"> {
|
|
10
|
-
text?: string;
|
|
11
|
-
form: FormInstance;
|
|
12
|
-
reset?: boolean;
|
|
13
|
-
position?: "start" | "end";
|
|
14
|
-
extraList?: SubmitBarExtraType[];
|
|
15
|
-
}
|
|
16
|
-
export default ({
|
|
17
|
-
position = "start",
|
|
18
|
-
reset,
|
|
19
|
-
extraList,
|
|
20
|
-
...props
|
|
21
|
-
}: ISubmitProps) => {
|
|
22
|
-
const barList = useBarSortList({ reset, extraList });
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Row justify={position} style={{ width: "100%" }}>
|
|
26
|
-
<Space>
|
|
27
|
-
{barList?.map(({ action, key }) => {
|
|
28
|
-
return <ControlFooter {...props} key={key} action={action} />;
|
|
29
|
-
})}
|
|
30
|
-
</Space>
|
|
31
|
-
</Row>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { SwitchProps } from "antd";
|
|
2
|
-
import { Space, Switch } from "antd";
|
|
3
|
-
import React, { useMemo } from "react";
|
|
4
|
-
import { useMatchConfigProps } from "../hooks";
|
|
5
|
-
import type { ValueSwitchMapModal } from "../modal";
|
|
6
|
-
import type { addFormatItemModal } from "../Form/modal";
|
|
7
|
-
import HFormConnect from "../Form/HFormConnect";
|
|
8
|
-
|
|
9
|
-
export interface HSwitchProps extends Omit<SwitchProps, "onChange"> {
|
|
10
|
-
valueMap?: ValueSwitchMapModal;
|
|
11
|
-
value?: any;
|
|
12
|
-
onChange?: (val: any) => void;
|
|
13
|
-
beforeText?: React.ReactNode;
|
|
14
|
-
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
15
|
-
}
|
|
16
|
-
const Index: React.FC<HSwitchProps> = ({
|
|
17
|
-
value,
|
|
18
|
-
onChange,
|
|
19
|
-
valueMap: propsValueSwitchMap,
|
|
20
|
-
children,
|
|
21
|
-
unCheckedChildren = "关闭",
|
|
22
|
-
checkedChildren = "开启",
|
|
23
|
-
beforeText,
|
|
24
|
-
addFormat,
|
|
25
|
-
...props
|
|
26
|
-
}) => {
|
|
27
|
-
const { valueSwitchMap = {} } = useMatchConfigProps({
|
|
28
|
-
valueSwitchMap: propsValueSwitchMap,
|
|
29
|
-
});
|
|
30
|
-
const swChecked = useMemo(() => {
|
|
31
|
-
const { open } = valueSwitchMap;
|
|
32
|
-
return value === open;
|
|
33
|
-
}, [value]);
|
|
34
|
-
const change = (checked) => {
|
|
35
|
-
let subVal = valueSwitchMap.close;
|
|
36
|
-
if (checked) {
|
|
37
|
-
subVal = valueSwitchMap.open;
|
|
38
|
-
}
|
|
39
|
-
onChange?.(subVal);
|
|
40
|
-
};
|
|
41
|
-
addFormat?.({
|
|
42
|
-
float: {
|
|
43
|
-
inputValue: (item, initValue) => {
|
|
44
|
-
const { close } = valueSwitchMap;
|
|
45
|
-
const { name: valueName = "" } = item;
|
|
46
|
-
let val = initValue[valueName];
|
|
47
|
-
if (typeof val === "undefined" || val === null) {
|
|
48
|
-
val = close;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
[valueName]: val,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
outputValue: (item, outputValue) => {
|
|
55
|
-
const { name = "" } = item;
|
|
56
|
-
return {
|
|
57
|
-
[name]: outputValue[name],
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
return (
|
|
63
|
-
<Space>
|
|
64
|
-
{beforeText}
|
|
65
|
-
<Switch
|
|
66
|
-
checked={swChecked}
|
|
67
|
-
checkedChildren={checkedChildren}
|
|
68
|
-
unCheckedChildren={unCheckedChildren}
|
|
69
|
-
onChange={change}
|
|
70
|
-
{...props}
|
|
71
|
-
/>
|
|
72
|
-
<span>{children}</span>
|
|
73
|
-
</Space>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export default HFormConnect(Index);
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { DatePicker } from "antd";
|
|
2
|
-
import type { HRangePickerProps } from "./modal";
|
|
3
|
-
import {
|
|
4
|
-
useGetTimeKey,
|
|
5
|
-
useRangePickerTimeVal,
|
|
6
|
-
useRangeValueProvider,
|
|
7
|
-
} from "./hooks";
|
|
8
|
-
import React, { useMemo } from "react";
|
|
9
|
-
import type { RangePickerProps } from "antd/es/date-picker";
|
|
10
|
-
import { useMatchConfigProps } from "../hooks";
|
|
11
|
-
import type { HItemProps } from "../Form/modal";
|
|
12
|
-
import HFormConnect from "../Form/HFormConnect";
|
|
13
|
-
|
|
14
|
-
const RangePicker = DatePicker.RangePicker as any;
|
|
15
|
-
|
|
16
|
-
const HRangePicker: React.FC<HRangePickerProps> = ({
|
|
17
|
-
value,
|
|
18
|
-
onChange,
|
|
19
|
-
showTime = true,
|
|
20
|
-
format = "X",
|
|
21
|
-
valueMap,
|
|
22
|
-
ranges = true,
|
|
23
|
-
name,
|
|
24
|
-
addFormat,
|
|
25
|
-
disabledDate,
|
|
26
|
-
...props
|
|
27
|
-
}) => {
|
|
28
|
-
const { valueRangePickerValueMap = {}, dateRanges } = useMatchConfigProps({
|
|
29
|
-
valueRangePickerValueMap: valueMap,
|
|
30
|
-
dateRanges: undefined,
|
|
31
|
-
});
|
|
32
|
-
const dateMapKeys = useGetTimeKey({
|
|
33
|
-
valueMap: valueRangePickerValueMap,
|
|
34
|
-
name,
|
|
35
|
-
});
|
|
36
|
-
const paramsProvider = useRangeValueProvider({ valueMap: dateMapKeys });
|
|
37
|
-
const timeVal = useRangePickerTimeVal({
|
|
38
|
-
value,
|
|
39
|
-
format,
|
|
40
|
-
valueMap: dateMapKeys,
|
|
41
|
-
});
|
|
42
|
-
const defaultRanges = useMemo(() => {
|
|
43
|
-
if (!ranges) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
if (ranges === true) {
|
|
47
|
-
return dateRanges;
|
|
48
|
-
}
|
|
49
|
-
return ranges;
|
|
50
|
-
}, [ranges]); //默认
|
|
51
|
-
addFormat?.({
|
|
52
|
-
float: {
|
|
53
|
-
inputValue: (item, initValue) => {
|
|
54
|
-
const { name: valueName = "" } = item;
|
|
55
|
-
const resultObj = {};
|
|
56
|
-
Object.values(dateMapKeys).forEach((key) => {
|
|
57
|
-
if (initValue[key]) {
|
|
58
|
-
resultObj[key] = initValue[key];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const hasKeys = Object.keys(resultObj).length !== 0;
|
|
62
|
-
return {
|
|
63
|
-
[valueName]: hasKeys ? resultObj : null,
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
outputValue: (item, outputValue) => {
|
|
67
|
-
const { name: valueName = "" } = item;
|
|
68
|
-
const { [valueName]: itemVal = {} } = outputValue;
|
|
69
|
-
return {
|
|
70
|
-
...itemVal,
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const change = (val) => {
|
|
77
|
-
if (!format || !val) {
|
|
78
|
-
onChange?.(val);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const subVal = val.map((item) => {
|
|
82
|
-
return item?.format(format) || null;
|
|
83
|
-
});
|
|
84
|
-
onChange?.(paramsProvider(subVal));
|
|
85
|
-
};
|
|
86
|
-
return (
|
|
87
|
-
<RangePicker
|
|
88
|
-
value={timeVal}
|
|
89
|
-
onChange={change}
|
|
90
|
-
showTime={showTime}
|
|
91
|
-
onCalendarChange={change}
|
|
92
|
-
ranges={defaultRanges as RangePickerProps["ranges"]}
|
|
93
|
-
disabledDate={(currentDate) => {
|
|
94
|
-
return !!disabledDate?.(currentDate, timeVal);
|
|
95
|
-
}}
|
|
96
|
-
{...props}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
const Index = HFormConnect(HRangePicker);
|
|
101
|
-
export default {
|
|
102
|
-
Component: Index,
|
|
103
|
-
placeholder: ({ label }: HItemProps) => {
|
|
104
|
-
return [`请选择开始${label}`, `请选择结束${label}`];
|
|
105
|
-
},
|
|
106
|
-
requiredErrMsg: ({ label }: HItemProps) => {
|
|
107
|
-
return `请选择${label}`;
|
|
108
|
-
},
|
|
109
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { TimePicker } from "antd";
|
|
2
|
-
import type { HTimePickerProps } from "./modal";
|
|
3
|
-
import { useTimePickerChange, useTimePickerValue } from "./hooks";
|
|
4
|
-
import HFormConnect from "../Form/HFormConnect";
|
|
5
|
-
|
|
6
|
-
const Index = ({
|
|
7
|
-
value,
|
|
8
|
-
format = "X",
|
|
9
|
-
onChange,
|
|
10
|
-
addFormat,
|
|
11
|
-
disabledDate,
|
|
12
|
-
...props
|
|
13
|
-
}: HTimePickerProps) => {
|
|
14
|
-
addFormat?.({});
|
|
15
|
-
const timeVal = useTimePickerValue({ value, format });
|
|
16
|
-
const change = useTimePickerChange({ value, format, onChange });
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<TimePicker
|
|
20
|
-
value={timeVal}
|
|
21
|
-
onChange={change}
|
|
22
|
-
disabledDate={(currentDate) => {
|
|
23
|
-
return !!disabledDate?.(currentDate, timeVal);
|
|
24
|
-
}}
|
|
25
|
-
{...props}
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
export default HFormConnect(Index);
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from "react";
|
|
2
|
-
import type { Moment, DurationInputArg2 } from "moment";
|
|
3
|
-
import moment from "moment";
|
|
4
|
-
import type { HRangePickerProps } from "./modal";
|
|
5
|
-
import type { DateRangePickerValueMapModal } from "../modal";
|
|
6
|
-
|
|
7
|
-
interface UseTimeValParams {
|
|
8
|
-
value?: any | [any, any];
|
|
9
|
-
format?: string;
|
|
10
|
-
valueMap?: DateRangePickerValueMapModal;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface UseTimePickerValParams {
|
|
14
|
-
value?: any;
|
|
15
|
-
format?: string | DurationInputArg2;
|
|
16
|
-
}
|
|
17
|
-
interface UseTimeChangeParams {
|
|
18
|
-
format?: string;
|
|
19
|
-
onChange?: (time?: Moment | string | number) => void;
|
|
20
|
-
value?: any;
|
|
21
|
-
}
|
|
22
|
-
export const useTimeVal = ({ value, format }: UseTimeValParams) => {
|
|
23
|
-
return useMemo(() => {
|
|
24
|
-
if (!value || !format) {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
return moment(value, format);
|
|
28
|
-
}, [value, format]);
|
|
29
|
-
}; //单个时间
|
|
30
|
-
|
|
31
|
-
export const useGetTimeKey = ({
|
|
32
|
-
valueMap = {},
|
|
33
|
-
name = "",
|
|
34
|
-
}: HRangePickerProps) => {
|
|
35
|
-
const { start, end } = valueMap;
|
|
36
|
-
if (!start || !end) {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
const startKey = typeof start === "string" ? start : start(name);
|
|
40
|
-
const endKey = typeof end === "string" ? end : end(name);
|
|
41
|
-
return {
|
|
42
|
-
start: startKey,
|
|
43
|
-
end: endKey,
|
|
44
|
-
};
|
|
45
|
-
}; //构建格式
|
|
46
|
-
export const useTimeChange = ({ format, onChange }: UseTimeChangeParams) => {
|
|
47
|
-
return useCallback(
|
|
48
|
-
(value) => {
|
|
49
|
-
if (!format) {
|
|
50
|
-
onChange?.(value);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const subVal = value?.format(format);
|
|
54
|
-
onChange?.(subVal);
|
|
55
|
-
},
|
|
56
|
-
[format, onChange]
|
|
57
|
-
);
|
|
58
|
-
}; //时间
|
|
59
|
-
|
|
60
|
-
const formatMap = {
|
|
61
|
-
X: "s",
|
|
62
|
-
x: "ms",
|
|
63
|
-
};
|
|
64
|
-
export const useTimePickerValue = ({
|
|
65
|
-
value,
|
|
66
|
-
format,
|
|
67
|
-
}: UseTimePickerValParams) => {
|
|
68
|
-
return useMemo(() => {
|
|
69
|
-
if (!value || !format) {
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
if (formatMap[format]) {
|
|
73
|
-
const timeStr = moment()
|
|
74
|
-
.startOf("days")
|
|
75
|
-
.add(value, formatMap[format] as DurationInputArg2)
|
|
76
|
-
.format("HH:mm:ss");
|
|
77
|
-
return moment(timeStr, "HH:mm:ss");
|
|
78
|
-
}
|
|
79
|
-
return moment(value, format);
|
|
80
|
-
}, [value, format]);
|
|
81
|
-
}; //区间选择
|
|
82
|
-
|
|
83
|
-
export const useTimePickerChange = ({
|
|
84
|
-
value,
|
|
85
|
-
format,
|
|
86
|
-
onChange,
|
|
87
|
-
}: UseTimeChangeParams) => {
|
|
88
|
-
return useCallback(
|
|
89
|
-
(val) => {
|
|
90
|
-
if (!format || !val) {
|
|
91
|
-
onChange?.(val);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (formatMap[format]) {
|
|
95
|
-
const startTime = moment().startOf("days").format(format) as any;
|
|
96
|
-
const nowTime = val.format(format);
|
|
97
|
-
onChange?.(nowTime - startTime);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const subVal = val?.format(format);
|
|
101
|
-
onChange?.(subVal);
|
|
102
|
-
},
|
|
103
|
-
[format, onChange, value]
|
|
104
|
-
);
|
|
105
|
-
}; //时分秒
|
|
106
|
-
|
|
107
|
-
export const useRangeValueProvider = ({ valueMap = {} }: HRangePickerProps) => {
|
|
108
|
-
return (val: any[]) => {
|
|
109
|
-
const { start, end } = valueMap;
|
|
110
|
-
if (!start || !end) {
|
|
111
|
-
return val;
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
[start as string]: val[0],
|
|
115
|
-
[end as string]: val[1],
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
}; //格式转化
|
|
119
|
-
|
|
120
|
-
export const useRangePickerTimeVal = ({
|
|
121
|
-
value,
|
|
122
|
-
format,
|
|
123
|
-
valueMap = {},
|
|
124
|
-
}: UseTimeValParams) => {
|
|
125
|
-
return useMemo(() => {
|
|
126
|
-
if (!value || !format) {
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
if (!Array.isArray(value)) {
|
|
130
|
-
const { start, end } = valueMap;
|
|
131
|
-
if (!start || !end) {
|
|
132
|
-
console.error("日期value格式错误!");
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const { [start as string]: startTime, [end as string]: endTime } = value;
|
|
136
|
-
if (!startTime && !endTime) {
|
|
137
|
-
return [];
|
|
138
|
-
}
|
|
139
|
-
const startMoment = startTime && moment(startTime, format);
|
|
140
|
-
const endMoment = endTime && moment(endTime, format);
|
|
141
|
-
return [startMoment, endMoment];
|
|
142
|
-
}
|
|
143
|
-
return value.map((item) => {
|
|
144
|
-
if (!item) {
|
|
145
|
-
return item;
|
|
146
|
-
}
|
|
147
|
-
return moment(item, format);
|
|
148
|
-
});
|
|
149
|
-
}, [value, format, valueMap]);
|
|
150
|
-
}; //初始化时间格式转化
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { DatePicker } from "antd";
|
|
2
|
-
import type { HDatePickerProps } from "./modal";
|
|
3
|
-
import { useTimeChange, useTimeVal } from "./hooks";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import HFormConnect from "../Form/HFormConnect";
|
|
6
|
-
const Picker = DatePicker as any;
|
|
7
|
-
const Index: React.FC<HDatePickerProps> = ({
|
|
8
|
-
value,
|
|
9
|
-
onChange,
|
|
10
|
-
showTime = true,
|
|
11
|
-
format = "X",
|
|
12
|
-
disabledDate,
|
|
13
|
-
addFormat,
|
|
14
|
-
style = { width: "100%" },
|
|
15
|
-
...props
|
|
16
|
-
}) => {
|
|
17
|
-
addFormat?.({});
|
|
18
|
-
const timeVal = useTimeVal({ value, format });
|
|
19
|
-
const change = useTimeChange({ format, onChange });
|
|
20
|
-
return (
|
|
21
|
-
<Picker
|
|
22
|
-
value={timeVal}
|
|
23
|
-
onChange={change}
|
|
24
|
-
showTime={showTime}
|
|
25
|
-
style={style}
|
|
26
|
-
disabledDate={(currentDate) => {
|
|
27
|
-
return !!disabledDate?.(currentDate, timeVal);
|
|
28
|
-
}}
|
|
29
|
-
{...props}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
export default HFormConnect(Index);
|