@hw-component/form 1.11.0 → 1.11.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.
Files changed (41) hide show
  1. package/.eslintcache +1 -1
  2. package/es/Form/config.d.ts +3 -2
  3. package/es/Form/config.js +3 -1
  4. package/es/Input/SelectInput.js +0 -1
  5. package/es/TDPicker/RangePicker.js +18 -3
  6. package/es/TDPicker/modal.d.ts +1 -1
  7. package/es/Upload/ImgCropUpload.d.ts +3 -0
  8. package/es/Upload/ImgCropUpload.js +71 -0
  9. package/es/Upload/MediaTypeEle/index.js +2 -1
  10. package/es/Upload/hooks/change.js +0 -1
  11. package/es/Upload/util.js +0 -2
  12. package/es/index.d.ts +2 -1
  13. package/es/index.js +2 -1
  14. package/lib/Form/config.d.ts +3 -2
  15. package/lib/Form/config.js +3 -1
  16. package/lib/Input/SelectInput.js +0 -1
  17. package/lib/TDPicker/RangePicker.js +17 -2
  18. package/lib/TDPicker/modal.d.ts +1 -1
  19. package/lib/Upload/ImgCropUpload.d.ts +3 -0
  20. package/lib/Upload/ImgCropUpload.js +74 -0
  21. package/lib/Upload/MediaTypeEle/index.js +2 -1
  22. package/lib/Upload/hooks/change.js +0 -1
  23. package/lib/Upload/util.js +0 -2
  24. package/lib/index.d.ts +2 -1
  25. package/lib/index.js +2 -0
  26. package/package.json +3 -2
  27. package/src/components/Form/config.ts +3 -0
  28. package/src/components/Form/hooks/useHForm.ts +12 -12
  29. package/src/components/Input/SelectInput.tsx +0 -1
  30. package/src/components/InputGroup/index.tsx +1 -2
  31. package/src/components/Select/index.tsx +4 -4
  32. package/src/components/TDPicker/RangePicker.tsx +15 -4
  33. package/src/components/TDPicker/modal.ts +1 -1
  34. package/src/components/Upload/ImgCropUpload.tsx +50 -0
  35. package/src/components/Upload/MediaTypeEle/index.tsx +1 -1
  36. package/src/components/Upload/hooks/change.ts +0 -1
  37. package/src/components/Upload/hooks/customRequest.ts +0 -1
  38. package/src/components/Upload/util.ts +0 -2
  39. package/src/components/index.tsx +2 -0
  40. package/src/pages/DatePicker/index.tsx +2 -1
  41. package/src/pages/Form/index.tsx +26 -3
@@ -5,7 +5,7 @@ import {
5
5
  useRangePickerTimeVal,
6
6
  useRangeValueProvider,
7
7
  } from "./hooks";
8
- import React, { useMemo } from "react";
8
+ import React, {useMemo, useState} from "react";
9
9
  import type { RangePickerProps } from "antd/es/date-picker";
10
10
  import { useMatchConfigProps } from "../hooks";
11
11
  import type { HItemProps } from "../Form/modal";
@@ -15,6 +15,8 @@ import InputGroup from "../InputGroup";
15
15
 
16
16
  const RangePicker = DatePicker.RangePicker as any;
17
17
 
18
+ type RangeValue = (Moment|null) [];
19
+
18
20
  const PickerContent: React.ForwardRefRenderFunction<
19
21
  HRangePickerPropsRef,
20
22
  HRangePickerProps
@@ -38,6 +40,7 @@ const PickerContent: React.ForwardRefRenderFunction<
38
40
  valueRangePickerValueMap: valueMap,
39
41
  dateRanges: undefined,
40
42
  });
43
+ const [dates, setDates] = useState<RangeValue>([null,null]);
41
44
  const dateMapKeys = useGetTimeKey({
42
45
  valueMap: valueRangePickerValueMap,
43
46
  name,
@@ -102,6 +105,13 @@ const PickerContent: React.ForwardRefRenderFunction<
102
105
  });
103
106
  onChange?.(paramsProvider(subVal));
104
107
  };
108
+ const onOpenChange = (open: boolean) => {
109
+ if (open) {
110
+ setDates(timeVal);
111
+ } else {
112
+ setDates([null,null]);
113
+ }
114
+ };
105
115
  return (
106
116
  <RangePicker
107
117
  value={timeVal}
@@ -109,10 +119,11 @@ const PickerContent: React.ForwardRefRenderFunction<
109
119
  style={{ width: "100%", ...style }}
110
120
  onChange={change}
111
121
  showTime={showTime}
112
- onCalendarChange={change}
122
+ onCalendarChange={val => setDates(val)}
123
+ onOpenChange={onOpenChange}
113
124
  ranges={defaultRanges as RangePickerProps["ranges"]}
114
125
  disabledDate={(currentDate) => {
115
- return !!disabledDate?.(currentDate, timeVal);
126
+ return !!disabledDate?.(currentDate, dates);
116
127
  }}
117
128
  {...props}
118
129
  />
@@ -126,7 +137,7 @@ const HRangePicker: React.ForwardRefRenderFunction<
126
137
  > = (props, ref) => {
127
138
  return (
128
139
  <InputGroup {...props}>
129
- <Content ref={ref} />
140
+ <Content ref={ref}/>
130
141
  </InputGroup>
131
142
  );
132
143
  };
@@ -38,7 +38,7 @@ export interface HRangePickerProps
38
38
  valueMap?: DateRangePickerValueMapModal;
39
39
  ranges?: RangePickerProps["ranges"] | boolean;
40
40
  addFormat?: (config: Record<string, addFormatItemModal>) => void;
41
- disabledDate?: DisabledDateFnModal<Moment[] | undefined>;
41
+ disabledDate?: DisabledDateFnModal<(Moment|null) []>;
42
42
  }
43
43
 
44
44
  export interface HTimePickerProps
@@ -0,0 +1,50 @@
1
+ import ImgCrop from 'antd-img-crop';
2
+ import {message, Upload} from "antd";
3
+ import Btn from "./Btn";
4
+ import React, {useState} from "react";
5
+ import type {IUpLoadProps} from "./modal";
6
+ import {checkFileType} from "./util";
7
+ import Preview, {type IPreviewProps} from "./Preview";
8
+
9
+ export default ({value,onChange,maxCount=1,exFiles=["PNG","JPEG","JPG","GIF"]}:IUpLoadProps)=>{
10
+ const [previewModal, setPreviewModal] = useState<IPreviewProps>({});
11
+ const change=({file,fileList})=>{
12
+ if (!checkFileType(file, exFiles)) {
13
+ return message.error(new Error("文件格式错误!"));
14
+ }
15
+ if (maxCount===1){
16
+ onChange?.([file]);
17
+ return ;
18
+ }
19
+ onChange?.(fileList);
20
+ }
21
+ const { visible, file: previewFile } = previewModal;
22
+ const preview = (file) => {
23
+ setPreviewModal({
24
+ visible: true,
25
+ file,
26
+ });
27
+ };
28
+ return <>
29
+ <ImgCrop rotate>
30
+ <Upload
31
+ customRequest={({onSuccess})=>{
32
+ onSuccess?.({});
33
+ }}
34
+ fileList={value}
35
+ listType="picture-card"
36
+ onChange={change}
37
+ onPreview={preview}
38
+ >
39
+ <Btn value={value} maxCount={maxCount} listType="picture-card"/>
40
+ </Upload>
41
+ </ImgCrop>
42
+ <Preview
43
+ visible={visible}
44
+ file={previewFile}
45
+ onCancel={() => {
46
+ setPreviewModal({});
47
+ }}
48
+ />
49
+ </>
50
+ }
@@ -28,7 +28,7 @@ export default ({ file, onReady, onError }: IMediaTypeEleProps) => {
28
28
  onError={onError}
29
29
  onReady={onReady}
30
30
  mediaType={mediaType}
31
- url={file.response.url}
31
+ url={file.response?.url||file.thumbUrl}
32
32
  />
33
33
  );
34
34
  };
@@ -24,7 +24,6 @@ const matchFile = (
24
24
  return errList.push(new Error("超出限制大小!"));
25
25
  }
26
26
  if (!checkFileType(item, exFiles)) {
27
- console.log(item, "item");
28
27
  return errList.push(new Error("文件格式错误!"));
29
28
  }
30
29
  if (checkFile(item, oldFile)) {
@@ -4,7 +4,6 @@ import type { RcFile } from "antd/lib/upload";
4
4
  import { useEffect, useMemo } from "react";
5
5
  import type { UploadFileStatus } from "antd/es/upload/interface";
6
6
  import { message } from "antd";
7
- import { useRequest } from "ahooks";
8
7
 
9
8
  interface SubReqParamsModal {
10
9
  request?: IUpLoadProps["request"];
@@ -3,7 +3,6 @@ import type { UploadFile } from "antd/es/upload/interface";
3
3
  export const getFileExt = (file: UploadFile): string => {
4
4
  const { name } = file;
5
5
  const index = name.lastIndexOf(".");
6
- console.log(index, name, file);
7
6
  return name.substring(index + 1).toUpperCase();
8
7
  };
9
8
 
@@ -11,7 +10,6 @@ export const checkFileType = (
11
10
  file: UploadFile,
12
11
  exFiles: string[] | null = []
13
12
  ) => {
14
- console.log(file);
15
13
  if (!exFiles) {
16
14
  return true;
17
15
  }
@@ -12,6 +12,8 @@ export { default as HInputGroup } from "./InputGroup";
12
12
  import ModalForm from "./DialogForm/ModalForm";
13
13
  import DrawerForm from "./DialogForm/DrawerForm";
14
14
  export const HSelect = FormConfig.select;
15
+ export const HImgCropUpload = FormConfig.imgCropUpload;
16
+
15
17
  export const HInput = FormConfig.input;
16
18
  export const HRichEditor = FormConfig.richEditor;
17
19
 
@@ -26,7 +26,8 @@ export default () => {
26
26
  />
27
27
  <HRangePicker
28
28
  value={timeVal}
29
- addonBefore="你好"
29
+ allowEmpty={[true, false]}
30
+ addonBefore="你好1"
30
31
  valueMap={{ start: "start1", end: "end2" }}
31
32
  onChange={(val) => {
32
33
  console.log(val);
@@ -6,9 +6,11 @@ import {
6
6
  HBasicForm,
7
7
  HRangePicker,
8
8
  HSelectInput,
9
+ HUpload
9
10
  } from "../../components";
10
11
  import { useEffect, useState } from "react";
11
12
  import { Button, Col, Form, Input, Row, Space } from "antd";
13
+ import ImgCrop from 'antd-img-crop';
12
14
 
13
15
  const Test3 = ({ value = {}, onChange }) => {
14
16
  const { fs, end } = value;
@@ -143,6 +145,25 @@ const TestItem1 = ({ value, onChange }) => {
143
145
  );
144
146
  };
145
147
 
148
+ const HeaderImg=({ value=[], onChange }) => {
149
+ console.log(value);
150
+ return (
151
+ <ImgCrop rotate>
152
+ <HUpload
153
+ value={value}
154
+ request={null}
155
+ onChange={(info)=>{
156
+ console.log(info,"info")
157
+ onChange(info.fileList)
158
+ }}
159
+
160
+ >
161
+ 天际
162
+ </HUpload>
163
+ </ImgCrop>
164
+ );
165
+ };
166
+
146
167
  export default () => {
147
168
  const form = useHForm();
148
169
  const [id, setId] = useState(1);
@@ -226,7 +247,9 @@ export default () => {
226
247
  label: "你好啊",
227
248
  type: "rangePicker",
228
249
  hover: ["123123213", "22222"],
229
- rules:[{required: true, message: "Please input your password!", }],
250
+ rules: [
251
+ { required: true, message: "Please input your password!" },
252
+ ],
230
253
  itemProps: {
231
254
  valueMap: {
232
255
  start: "start",
@@ -237,14 +260,14 @@ export default () => {
237
260
  {
238
261
  name: "num1",
239
262
  label: "必填",
240
- rules:[{required: true, message: "Please input your password!", }],
263
+ type:"imgCropUpload",
241
264
  dependencies: ["num"],
242
265
  },
243
266
  ]}
244
267
  dismissOnPressEnter={false}
245
268
  form={form}
246
269
  initialValues={{
247
- num1:"23123"
270
+
248
271
  }}
249
272
  labelAlign={"top"}
250
273
  onValuesChange={(val) => {