@hw-component/form 0.0.9-beta-v21 → 1.0.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/es/DialogForm/modal.d.ts +4 -3
- package/lib/DialogForm/modal.d.ts +4 -3
- package/package.json +1 -1
- package/src/Layout.tsx +61 -0
- package/src/app.tsx +33 -0
- package/src/components/Cascader/index.tsx +31 -0
- package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
- package/src/components/CheckboxGroup/hooks.ts +105 -0
- package/src/components/CheckboxGroup/index.tsx +85 -0
- package/src/components/CheckboxGroup/modal.ts +17 -0
- package/src/components/DialogForm/DrawerForm/Footer.tsx +20 -0
- package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
- package/src/components/DialogForm/DrawerForm/index.tsx +110 -0
- package/src/components/DialogForm/ModalForm.tsx +91 -0
- package/src/components/DialogForm/hooks.ts +122 -0
- package/src/components/DialogForm/modal.ts +45 -0
- package/src/components/Form/Context/FormConfigProvider.tsx +38 -0
- package/src/components/Form/Context/index.tsx +14 -0
- package/src/components/Form/FormItem/BasicItem.tsx +95 -0
- package/src/components/Form/FormItem/Helper.tsx +25 -0
- package/src/components/Form/FormItem/RegularFormItem.tsx +13 -0
- package/src/components/Form/FormItem/UpFormItem.tsx +21 -0
- package/src/components/Form/FormItem/hooks.tsx +54 -0
- package/src/components/Form/FormItem/index.tsx +8 -0
- package/src/components/Form/HFormConnect.tsx +74 -0
- package/src/components/Form/InitSet.tsx +10 -0
- package/src/components/Form/Label.tsx +50 -0
- package/src/components/Form/config.ts +58 -0
- package/src/components/Form/hooks/index.ts +114 -0
- package/src/components/Form/hooks/useDefaultRender.tsx +45 -0
- package/src/components/Form/hooks/useHForm.ts +182 -0
- package/src/components/Form/hooks/useInitConfigData.tsx +194 -0
- package/src/components/Form/index.less +54 -0
- package/src/components/Form/index.tsx +113 -0
- package/src/components/Form/modal.ts +206 -0
- package/src/components/Input/ButtonInput.tsx +47 -0
- package/src/components/Input/ColorInput/Picker.tsx +18 -0
- package/src/components/Input/ColorInput/data.ts +102 -0
- package/src/components/Input/ColorInput/index.less +10 -0
- package/src/components/Input/ColorInput/index.tsx +58 -0
- package/src/components/Input/InputNumber.tsx +5 -0
- package/src/components/Input/SelectInput.tsx +75 -0
- package/src/components/Input/TrimInput.tsx +26 -0
- package/src/components/Input/VerificationCodeInput.tsx +74 -0
- package/src/components/Input/defaultConfig.ts +8 -0
- package/src/components/Input/index.tsx +26 -0
- package/src/components/Input/modal.ts +40 -0
- package/src/components/PageHandler/ErrorComponent.tsx +20 -0
- package/src/components/PageHandler/LoadingComponent.tsx +9 -0
- package/src/components/PageHandler/index.tsx +14 -0
- package/src/components/PageHandler/modal.ts +6 -0
- package/src/components/RadioGroup/index.tsx +45 -0
- package/src/components/Select/components/AllSelect.tsx +54 -0
- package/src/components/Select/components/CheckBoxOption.tsx +14 -0
- package/src/components/Select/components/DropdownComponent.tsx +36 -0
- package/src/components/Select/components/NoFindItem.tsx +7 -0
- package/src/components/Select/components/NotFoundContent.tsx +25 -0
- package/src/components/Select/defaultConfig.tsx +23 -0
- package/src/components/Select/hooks/changeHooks.tsx +159 -0
- package/src/components/Select/hooks/norHooks.ts +85 -0
- package/src/components/Select/index.less +22 -0
- package/src/components/Select/index.tsx +126 -0
- package/src/components/Select/modal.ts +36 -0
- package/src/components/Select/utils.ts +18 -0
- package/src/components/Submit/components.tsx +57 -0
- package/src/components/Submit/hooks.ts +31 -0
- package/src/components/Submit/index.tsx +33 -0
- package/src/components/Switch/index.tsx +77 -0
- package/src/components/TDPicker/RangePicker.tsx +109 -0
- package/src/components/TDPicker/TimePicker.tsx +29 -0
- package/src/components/TDPicker/hooks.ts +150 -0
- package/src/components/TDPicker/index.tsx +33 -0
- package/src/components/TDPicker/modal.ts +48 -0
- package/src/components/TextArea/TrimTextArea.tsx +30 -0
- package/src/components/TextArea/index.tsx +8 -0
- package/src/components/Upload/Btn.tsx +24 -0
- package/src/components/Upload/MediaTypeEle/TypeEle.tsx +26 -0
- package/src/components/Upload/MediaTypeEle/index.tsx +34 -0
- package/src/components/Upload/Preview/index.tsx +14 -0
- package/src/components/Upload/UrlUpload/index.tsx +104 -0
- package/src/components/Upload/enums.ts +5 -0
- package/src/components/Upload/hooks/change.ts +79 -0
- package/src/components/Upload/hooks/customRequest.ts +87 -0
- package/src/components/Upload/hooks/propsMaker.ts +20 -0
- package/src/components/Upload/index.tsx +119 -0
- package/src/components/Upload/modal.ts +33 -0
- package/src/components/Upload/util.ts +27 -0
- package/src/components/config.ts +47 -0
- package/src/components/hooks/index.ts +53 -0
- package/src/components/index.tsx +37 -0
- package/src/components/modal.ts +20 -0
- package/src/components/styles/index.less +3 -0
- package/src/components/styles/local.less +1 -0
- package/src/components/typings.d.ts +11 -0
- package/src/index.less +20 -0
- package/src/index.tsx +12 -0
- package/src/pages/Checkbox/index.tsx +14 -0
- package/src/pages/DatePicker/index.tsx +33 -0
- package/src/pages/DrawerForm/index.tsx +145 -0
- package/src/pages/Form/index.tsx +172 -0
- package/src/pages/Input/index.tsx +30 -0
- package/src/pages/ModalForm/index.tsx +195 -0
- package/src/pages/Radio/index.tsx +18 -0
- package/src/pages/Select/index.tsx +63 -0
- package/src/pages/Switch/index.tsx +18 -0
- package/src/pages/Upload/index.tsx +14 -0
- package/src/routes.tsx +80 -0
- package/.husky/pre-commit +0 -4
- package/.idea/hw-component-form.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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);
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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);
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
}; //初始化时间格式转化
|
|
@@ -0,0 +1,33 @@
|
|
|
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);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RangePickerProps } from "antd/es/date-picker";
|
|
2
|
+
import type { SharedTimeProps } from "rc-picker/lib/panels/TimePanel";
|
|
3
|
+
import type { Moment } from "moment";
|
|
4
|
+
import type { DatePickerProps } from "antd";
|
|
5
|
+
import type { TimePickerProps } from "antd";
|
|
6
|
+
import type { DurationInputArg2 } from "moment";
|
|
7
|
+
import type { DateRangePickerValueMapModal } from "../modal";
|
|
8
|
+
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
9
|
+
interface DisabledDateFnModal<T = Moment | undefined> {
|
|
10
|
+
(currentDate: Moment, value: T): boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface HDatePickerProps
|
|
14
|
+
extends Omit<
|
|
15
|
+
DatePickerProps,
|
|
16
|
+
"onChange" | "format" | "ranges" | "disabledDate"
|
|
17
|
+
> {
|
|
18
|
+
onChange?: (time?: Moment | string | number) => void;
|
|
19
|
+
format?: string;
|
|
20
|
+
showTime?: boolean | SharedTimeProps<Moment>;
|
|
21
|
+
disabledDate?: DisabledDateFnModal;
|
|
22
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface HRangePickerProps
|
|
25
|
+
extends Omit<
|
|
26
|
+
RangePickerProps,
|
|
27
|
+
"onChange" | "format" | "ranges" | "value" | "disabledDate"
|
|
28
|
+
> {
|
|
29
|
+
value?: [any, any] | Record<string, any>;
|
|
30
|
+
onChange?: (val: any) => void;
|
|
31
|
+
showTime?: boolean | { defaultValue?: Moment[] };
|
|
32
|
+
format?: string;
|
|
33
|
+
valueMap?: DateRangePickerValueMapModal;
|
|
34
|
+
ranges?: RangePickerProps["ranges"] | boolean;
|
|
35
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
36
|
+
disabledDate?: DisabledDateFnModal<Moment[] | undefined>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface HTimePickerProps
|
|
40
|
+
extends Omit<
|
|
41
|
+
TimePickerProps,
|
|
42
|
+
"onChange" | "format" | "ranges" | "disabledDate"
|
|
43
|
+
> {
|
|
44
|
+
onChange?: (time?: Moment | string | number) => void;
|
|
45
|
+
format?: DurationInputArg2 | string;
|
|
46
|
+
disabledDate?: DisabledDateFnModal;
|
|
47
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import TextArea from "./index";
|
|
2
|
+
import type { TextAreaProps } from "antd/es/input";
|
|
3
|
+
import type { addFormatItemModal } from "../Form/modal";
|
|
4
|
+
import HFormConnect from "../Form/HFormConnect";
|
|
5
|
+
|
|
6
|
+
interface TrimTextAreaProps extends TextAreaProps {
|
|
7
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
8
|
+
}
|
|
9
|
+
const Index = ({ addFormat, ...props }: TrimTextAreaProps) => {
|
|
10
|
+
addFormat?.({
|
|
11
|
+
float: {
|
|
12
|
+
inputValue: (item, initValue) => {
|
|
13
|
+
const { name: valueName = "" } = item;
|
|
14
|
+
return {
|
|
15
|
+
[valueName]: initValue[valueName],
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
outputValue: (item, outputValue) => {
|
|
19
|
+
const { name = "" } = item;
|
|
20
|
+
const { [name]: itemVal } = outputValue;
|
|
21
|
+
return {
|
|
22
|
+
[name]: itemVal?.trim(),
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return <TextArea {...props} />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default HFormConnect(Index);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PlusOutlined, UploadOutlined } from "@ant-design/icons";
|
|
2
|
+
import type { IUpLoadProps } from "./modal";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { Button } from "antd";
|
|
5
|
+
|
|
6
|
+
export default ({ value, maxCount = 1, listType }: IUpLoadProps) => {
|
|
7
|
+
const len = value?.length || 0;
|
|
8
|
+
const text = useMemo(() => {
|
|
9
|
+
if (len === maxCount) {
|
|
10
|
+
return "更新";
|
|
11
|
+
}
|
|
12
|
+
return "上传";
|
|
13
|
+
}, [len, maxCount]);
|
|
14
|
+
|
|
15
|
+
if (listType === "picture-card") {
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<PlusOutlined />
|
|
19
|
+
<div style={{ marginTop: 8 }}>{text}</div>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return <Button icon={<UploadOutlined />}>{text}</Button>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MediaTypeEnum } from "../enums";
|
|
2
|
+
|
|
3
|
+
interface TypeEleProps {
|
|
4
|
+
mediaType?: MediaTypeEnum;
|
|
5
|
+
url?: string;
|
|
6
|
+
onReady?: VoidFunction;
|
|
7
|
+
onError?: VoidFunction;
|
|
8
|
+
}
|
|
9
|
+
export default ({ mediaType, url, onReady, onError }: TypeEleProps) => {
|
|
10
|
+
if (mediaType === MediaTypeEnum.video) {
|
|
11
|
+
return (
|
|
12
|
+
<video autoPlay width="100%" controls onPlay={onReady} onError={onError}>
|
|
13
|
+
<source src={url} />
|
|
14
|
+
</video>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (mediaType === MediaTypeEnum.audio) {
|
|
19
|
+
return (
|
|
20
|
+
<audio autoPlay controls onPlay={onReady} onError={onError}>
|
|
21
|
+
<source src={url} />
|
|
22
|
+
</audio>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return <img src={url} width="100%" onLoad={onReady} onError={onError} />;
|
|
26
|
+
};
|