@hw-component/form 1.2.4 → 1.2.6

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 (54) hide show
  1. package/.eslintcache +1 -1
  2. package/es/Form/FormItem/hooks.d.ts +2 -2
  3. package/es/Form/config.d.ts +1 -1
  4. package/es/Form/config.js +1 -1
  5. package/es/Form/modal.d.ts +2 -1
  6. package/es/Input/VerificationCodeInput/hooks.d.ts +1 -1
  7. package/es/Input/VerificationCodeInput/index.d.ts +2 -2
  8. package/es/Upload/UrlUpload/hooks.d.ts +2 -0
  9. package/es/Upload/UrlUpload/hooks.js +18 -0
  10. package/es/Upload/UrlUpload/index.d.ts +1 -1
  11. package/es/Upload/UrlUpload/index.js +21 -5
  12. package/es/Upload/hooks/change.d.ts +1 -1
  13. package/es/Upload/hooks/change.js +16 -9
  14. package/es/Upload/hooks/propsMaker.js +5 -2
  15. package/es/Upload/index.js +4 -3
  16. package/es/Upload/modal.d.ts +4 -1
  17. package/es/Upload/util.d.ts +1 -1
  18. package/es/Upload/util.js +3 -0
  19. package/es/index.css +2 -2
  20. package/es/index.d.ts +1 -1
  21. package/lib/Form/FormItem/hooks.d.ts +2 -2
  22. package/lib/Form/config.d.ts +1 -1
  23. package/lib/Form/config.js +1 -1
  24. package/lib/Form/modal.d.ts +2 -1
  25. package/lib/Input/VerificationCodeInput/hooks.d.ts +1 -1
  26. package/lib/Input/VerificationCodeInput/index.d.ts +2 -2
  27. package/lib/Upload/UrlUpload/hooks.d.ts +2 -0
  28. package/lib/Upload/UrlUpload/hooks.js +19 -0
  29. package/lib/Upload/UrlUpload/index.d.ts +1 -1
  30. package/lib/Upload/UrlUpload/index.js +20 -4
  31. package/lib/Upload/hooks/change.d.ts +1 -1
  32. package/lib/Upload/hooks/change.js +16 -9
  33. package/lib/Upload/hooks/propsMaker.js +5 -2
  34. package/lib/Upload/index.js +4 -3
  35. package/lib/Upload/modal.d.ts +4 -1
  36. package/lib/Upload/util.d.ts +1 -1
  37. package/lib/Upload/util.js +3 -0
  38. package/lib/index.css +2 -2
  39. package/lib/index.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/src/components/Form/FormItem/hooks.tsx +4 -3
  42. package/src/components/Form/config.ts +1 -0
  43. package/src/components/Form/index.less +9 -9
  44. package/src/components/Form/modal.ts +4 -2
  45. package/src/components/Input/VerificationCodeInput/hooks.ts +2 -2
  46. package/src/components/Input/VerificationCodeInput/index.tsx +5 -5
  47. package/src/components/Upload/UrlUpload/hooks.ts +13 -0
  48. package/src/components/Upload/UrlUpload/index.tsx +12 -5
  49. package/src/components/Upload/hooks/change.ts +9 -2
  50. package/src/components/Upload/hooks/propsMaker.ts +6 -2
  51. package/src/components/Upload/index.tsx +2 -1
  52. package/src/components/Upload/modal.ts +4 -1
  53. package/src/components/Upload/util.ts +5 -1
  54. package/src/pages/Form/index.tsx +17 -0
@@ -1,10 +1,11 @@
1
1
  import UpFormItem from "./UpFormItem";
2
2
  import RegularFormItem from "./RegularFormItem";
3
- import React, { useMemo } from "react";
3
+ import type React from "react";
4
+ import { useMemo } from "react";
4
5
  import type { HFormInstance, HItemProps } from "../modal";
5
6
  import type { LabelAlignModal } from "../modal";
6
7
  import { useClassName } from "../../hooks";
7
- import {HelperModal} from "../modal";
8
+ import type {HelperModal} from "../modal";
8
9
 
9
10
  export const useFormItemDomControl = ({
10
11
  shouldUpdate,
@@ -54,6 +55,6 @@ export const usePositionClassName = (position: LabelAlignModal) => {
54
55
  return useClassName(className);
55
56
  };
56
57
 
57
- export const useFormItemLabel=(form:HFormInstance,label?:React.ReactNode|HelperModal,)=>{
58
+ export const useFormItemLabel=(form: HFormInstance,label?: React.ReactNode|HelperModal,)=>{
58
59
  return typeof label==="function"?label(form):label;
59
60
  }
@@ -27,6 +27,7 @@ export const placeholderConfig = {
27
27
  "buttonInput",
28
28
  "verificationCodeInput",
29
29
  "trimInput",
30
+ 'urlUpload'
30
31
  ],
31
32
  selectType: ["select", "datePicker", "timePicker", "colorInput"],
32
33
  };
@@ -17,12 +17,12 @@
17
17
  .@{ant-prefix}-hw-form-item-colon {
18
18
  text-align: left;
19
19
  }
20
- .@{ant-prefix}-hw-form-item-required{
20
+ .@{ant-prefix}-hw-form-item-required {
21
21
  position: absolute;
22
22
  left: -10px;
23
- top: 0px;
23
+ top: 0;
24
24
  }
25
- .@{ant-prefix}-hw-form-label-item{
25
+ .@{ant-prefix}-hw-form-label-item {
26
26
  position: relative;
27
27
  }
28
28
  }
@@ -52,12 +52,12 @@
52
52
  .@{ant-prefix}-hw-form-item-colon {
53
53
  text-align: left;
54
54
  }
55
- .@{ant-prefix}-hw-form-item-required{
55
+ .@{ant-prefix}-hw-form-item-required {
56
56
  position: absolute;
57
57
  left: -10px;
58
- top: 0px;
58
+ top: 0;
59
59
  }
60
- .@{ant-prefix}-hw-form-label-item{
60
+ .@{ant-prefix}-hw-form-label-item {
61
61
  position: relative;
62
62
  }
63
63
  .@{ant-prefix}-form-item-label > label {
@@ -65,7 +65,7 @@
65
65
  }
66
66
  }
67
67
 
68
- .@{ant-prefix}-hw-form-item-no-required{
68
+ .@{ant-prefix}-hw-form-item-no-required {
69
69
  display: none;
70
70
  }
71
71
  .@{ant-prefix}-hw-form-item-required:before {
@@ -78,8 +78,8 @@
78
78
  content: "*";
79
79
  margin-right: 4px;
80
80
  }
81
- .@{ant-prefix}-hw-form-form-item{
82
- .@{ant-prefix}-form-item-label{
81
+ .@{ant-prefix}-hw-form-form-item {
82
+ .@{ant-prefix}-form-item-label {
83
83
  overflow:visible
84
84
  }
85
85
  }
@@ -34,6 +34,7 @@ import type { ForwardedRef } from "react";
34
34
  import type { DataFnProvider } from "../modal";
35
35
  import type { ColProps } from "antd/lib/grid/col";
36
36
  import type { Gutter } from "antd/lib/grid/row";
37
+ import type {IUrlUploadProps} from "../Upload/modal";
37
38
 
38
39
  type RenderFun = (
39
40
  props: HItemProps,
@@ -54,7 +55,8 @@ export type ItemPropsType =
54
55
  | HTimePickerProps
55
56
  | TextAreaProps
56
57
  | IUpLoadProps
57
- | CascaderProps<any>;
58
+ | CascaderProps<any>
59
+ | IUrlUploadProps
58
60
 
59
61
  export interface HoverModal {
60
62
  text?: string;
@@ -93,7 +95,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"|"l
93
95
  itemSpan?: ColProps;
94
96
  hideLabel?: boolean;
95
97
  labelAlign?: LabelAlignModal;
96
- label?:React.ReactNode|HelperModal;
98
+ label?: React.ReactNode|HelperModal;
97
99
  }
98
100
  export interface HFormProps<T = any, R = any>
99
101
  extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
@@ -1,7 +1,7 @@
1
- import {ButtonProps} from "./index";
1
+ import type {ButtonProps} from "./index";
2
2
  import {useEffect, useState} from "react";
3
3
 
4
- export const useDis=(buttonProps:ButtonProps)=>{
4
+ export const useDis=(buttonProps: ButtonProps)=>{
5
5
  const {disabled}=buttonProps;
6
6
  const [btnDis,setBtnDis]=useState<boolean|undefined>(!!disabled);
7
7
  const [countdown, setCountdown] = useState<number>(0);
@@ -2,21 +2,21 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ButtonInput from "../ButtonInput";
3
3
  import { useRequest } from "ahooks";
4
4
  import type { HFormInstance } from "../../Form/modal";
5
- import {HButtonInputProps} from "../modal";
5
+ import type {HButtonInputProps} from "../modal";
6
6
  import HFormConnect from "../../Form/HFormConnect";
7
- import {argsFn} from "../../Form/modal";
7
+ import type {argsFn} from "../../Form/modal";
8
8
  import {useDis} from "./hooks";
9
9
 
10
- type disabledFn=(data:any)=>boolean;
10
+ type disabledFn=(data: any) => boolean;
11
11
  export interface ButtonProps extends Omit<HButtonInputProps["buttonProps"],"disabled">{
12
- disabled?:boolean|disabledFn;
12
+ disabled?: boolean|disabledFn;
13
13
  }
14
14
 
15
15
  export interface HVerificationCodeInputProps extends Omit<HButtonInputProps, "form"|"buttonProps"> {
16
16
  request?: (value: any) => Promise<any>;
17
17
  form?: HFormInstance;
18
18
  addDispatchListener?: (key: string, fn: argsFn) => void;
19
- buttonProps?:ButtonProps;
19
+ buttonProps?: ButtonProps;
20
20
  }
21
21
  const Index= ({
22
22
  value,
@@ -0,0 +1,13 @@
1
+ import type {IUrlUploadProps} from "../modal";
2
+ import {MediaTypeEnum} from '../enums';
3
+
4
+ const defaultExFiles={
5
+ [MediaTypeEnum.video]:["MP4"],
6
+ [MediaTypeEnum.audio]:["MP3"],
7
+ }
8
+ export const useDefaultExFiles=({mediaType=MediaTypeEnum.img,exFiles}: IUrlUploadProps)=>{
9
+ if (exFiles||exFiles===null){
10
+ return exFiles;
11
+ };
12
+ return defaultExFiles[mediaType]
13
+ }
@@ -1,11 +1,12 @@
1
- import { message, Space } from "antd";
1
+ import { message, Space ,Typography} from "antd";
2
2
  import Input from "antd/es/input/Input";
3
3
  import Upload from "../index";
4
4
  import type { IUploadRefModal, IUrlUploadProps } from "../modal";
5
5
  import TypeEle from "../MediaTypeEle/TypeEle";
6
6
  import { useRef, useState } from "react";
7
7
  import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
-
8
+ import {useDefaultExFiles} from "./hooks";
9
+ const {Text}=Typography;
9
10
  const mkSubFileList = (fileList: UploadFile[], maxCount = 1) => {
10
11
  const len = fileList.length;
11
12
  if (len > maxCount) {
@@ -19,9 +20,13 @@ const Index = ({
19
20
  value = [],
20
21
  onChange,
21
22
  mediaType,
23
+ inputHelper,
24
+ style={},
25
+ exFiles,
22
26
  ...props
23
27
  }: IUrlUploadProps) => {
24
- const { maxCount } = props;
28
+ const { maxCount} = props;
29
+ const defaultExFiles: string[]|null=useDefaultExFiles({mediaType,exFiles});
25
30
  const [url, setUrl] = useState("");
26
31
  const [load, setLoad] = useState<boolean>(false);
27
32
  const ref = useRef<IUploadRefModal | null>(null);
@@ -76,8 +81,9 @@ const Index = ({
76
81
  setUrl("");
77
82
  setLoad(false);
78
83
  };
84
+ const upProps={exFiles:defaultExFiles,...props};
79
85
  return (
80
- <Space direction={"vertical"} style={{ width: "100%" }} size={"middle"}>
86
+ <Space direction={"vertical"} style={{width:"100%",...style}} size={"middle"}>
81
87
  <Input
82
88
  placeholder={placeholder}
83
89
  onBlur={onBlur}
@@ -87,7 +93,8 @@ const Index = ({
87
93
  setUrl(e.target.value);
88
94
  }}
89
95
  />
90
- <Upload {...props} ref={ref} value={value} onChange={onChange} />
96
+ {inputHelper&&<Text type={"secondary"}>{inputHelper}</Text>}
97
+ <Upload {...upProps} ref={ref} value={value} onChange={onChange} />
91
98
  {load && (
92
99
  <div style={{ display: "none" }}>
93
100
  <TypeEle
@@ -14,7 +14,7 @@ const checkFile = (item: UploadFile, oldFile: UploadFile[] = []) => {
14
14
  const matchFile = (
15
15
  newFile: UploadFile[],
16
16
  oldFile: UploadFile[] = [],
17
- exFiles?: string[],
17
+ exFiles?: string[]|null,
18
18
  maxSize?: number
19
19
  ) => {
20
20
  const newResultFileList: UploadFile[] = [];
@@ -50,6 +50,7 @@ export const useChange = ({
50
50
  request,
51
51
  exFiles,
52
52
  maxSize,
53
+ thumbUrl
53
54
  }: IUpLoadProps) => {
54
55
  const customRequest = useCustomRequest({ request, onChange, value });
55
56
 
@@ -67,7 +68,13 @@ export const useChange = ({
67
68
  if (errList.length) {
68
69
  message.error(errList[0].message);
69
70
  }
70
- onChange?.(newFileList);
71
+ const changeFile=newFileList?.map((item)=>{
72
+ return {
73
+ thumbUrl,
74
+ ...item
75
+ }
76
+ });
77
+ onChange?.(changeFile);
71
78
  customRequest(addFile);
72
79
  },
73
80
  { manual: true, debounceInterval: 100 }
@@ -5,7 +5,6 @@ export const useProps = ({ request, exFiles, maxSize }: IUpLoadProps) => {
5
5
  const configUploadProps = useFormConfigContext("uploadProps");
6
6
  const inputProps = {
7
7
  request,
8
- exFiles,
9
8
  maxSize,
10
9
  };
11
10
  const keys = Object.keys(inputProps);
@@ -16,5 +15,10 @@ export const useProps = ({ request, exFiles, maxSize }: IUpLoadProps) => {
16
15
  return;
17
16
  }
18
17
  });
19
- return resultProps;
18
+ const defaultExFiles=exFiles===undefined?resultProps.exFiles:exFiles;
19
+ console.log(defaultExFiles)
20
+ return {
21
+ ...resultProps,
22
+ exFiles:defaultExFiles
23
+ };
20
24
  };
@@ -20,6 +20,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
20
20
  request,
21
21
  maxSize,
22
22
  addFormat,
23
+ thumbUrl,
23
24
  ...props
24
25
  },
25
26
  ref
@@ -31,6 +32,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
31
32
  value,
32
33
  maxCount,
33
34
  onChange,
35
+ thumbUrl
34
36
  });
35
37
  useImperativeHandle(ref, () => {
36
38
  return {
@@ -90,7 +92,6 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
90
92
  },
91
93
  },
92
94
  });
93
- console.log(onPreview, "onPreview");
94
95
  return (
95
96
  <div style={contentStyle}>
96
97
  <Upload
@@ -4,9 +4,10 @@ import type { BeforeUploadFileType, RcFile } from "rc-upload/lib/interface";
4
4
  import type { UploadChangeParam } from "antd/lib/upload/interface";
5
5
  import type { MediaTypeEnum } from "@/components/Upload/enums";
6
6
  import type { addFormatItemModal } from "@/components/Form/modal";
7
+ import type React from "react";
7
8
 
8
9
  export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
9
- exFiles?: string[];
10
+ exFiles?: string[]|null;
10
11
  request?: (
11
12
  file: Exclude<BeforeUploadFileType, File | boolean> | RcFile
12
13
  ) => Promise<{ url: string }>;
@@ -16,6 +17,7 @@ export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
16
17
  maxRowNum?: number;
17
18
  maxSize?: number;
18
19
  addFormat?: (config: Record<string, addFormatItemModal>) => void;
20
+ thumbUrl?: string;
19
21
  }
20
22
  export interface IMediaTypeEleProps {
21
23
  file?: UploadFile;
@@ -30,4 +32,5 @@ export interface IUploadRefModal {
30
32
  export interface IUrlUploadProps extends IUpLoadProps {
31
33
  placeholder?: string;
32
34
  mediaType?: MediaTypeEnum;
35
+ inputHelper?: React.ReactNode
33
36
  }
@@ -6,13 +6,17 @@ export const getFileExt = (file: UploadFile): string => {
6
6
  return name.substring(index + 1).toUpperCase();
7
7
  };
8
8
 
9
- export const checkFileType = (file: UploadFile, exFiles: string[] = []) => {
9
+ export const checkFileType = (file: UploadFile, exFiles: string[]|null = []) => {
10
+ if (!exFiles){
11
+ return true;
12
+ }
10
13
  const exName: string = getFileExt(file);
11
14
  return exFiles.indexOf(exName) !== -1;
12
15
  };
13
16
 
14
17
  export const checkFileSize = (file: UploadFile, maxSize = 0) => {
15
18
  const { size = 0 } = file;
19
+
16
20
  return size <= maxSize;
17
21
  };
18
22
 
@@ -2,6 +2,7 @@ import { HForm, HFormConfigProvider, useHForm } from "../../components";
2
2
  import { Button, Form, Input } from "antd";
3
3
  import React from "react";
4
4
  import {useRequest} from "ahooks";
5
+ import {MediaTypeEnum} from "../../components/Upload/enums";
5
6
 
6
7
  const formData = () => {
7
8
  return [
@@ -109,6 +110,22 @@ const formData = () => {
109
110
  manual:false
110
111
  },
111
112
  },
113
+ {
114
+ type: "urlUpload",
115
+ name:"urlUpload",
116
+ label:"测试",
117
+ helper:"123123",
118
+ itemProps: {
119
+ inputHelper:"fff",
120
+ style:{
121
+ width:368
122
+ },
123
+ exFiles:null,
124
+ mediaType:MediaTypeEnum.video,
125
+ maxSize:Number.MAX_SAFE_INTEGER,
126
+ thumbUrl:"https://inews.gtimg.com/om_bt/OHyQqgC_5oi4Vm0tlH49XvJzqNBHo2Zryxx5F_be5N2cIAA/1000"
127
+ }
128
+ },
112
129
  ];
113
130
  };
114
131
  function Ttta({ form }) {