@hw-component/form 1.4.8 → 1.5.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.
@@ -2,7 +2,7 @@ import type { HSelectProps } from "@/components/Select/modal";
2
2
  import { Checkbox, Space } from "antd";
3
3
  import { itemOpProvider } from "../utils";
4
4
  import { useClassName } from "../../hooks";
5
- import React, {useMemo} from "react";
5
+ import React, { useMemo } from "react";
6
6
 
7
7
  interface IProps extends HSelectProps {
8
8
  checked?: boolean;
@@ -23,23 +23,23 @@ const Index: React.FC<IProps> = ({
23
23
  fieldNames = {},
24
24
  children,
25
25
  }) => {
26
- const notDisOption=useMemo(()=>{
27
- return options?.filter((item)=>{
28
- return !item.disabled;
29
- })
30
- },[options]);
26
+ const notDisOption = useMemo(() => {
27
+ return options?.filter((item) => {
28
+ return !item.disabled;
29
+ });
30
+ }, [options]);
31
31
  const opLen = notDisOption?.length || 0;
32
32
  const checked = (value as any[])?.length >= opLen;
33
33
  const classNames = useRootClassName(checked);
34
34
  const optionsClassName = useClassName(classNames);
35
35
  const allCheckBox = useClassName("hw-all-check-box");
36
- const allCheck=()=>{
37
- const allCheckOption=options?.filter((item)=>{
38
- return !item.disabled;
39
- });
40
- const subItemOps=itemOpProvider(allCheckOption,fieldNames);
36
+ const allCheck = () => {
37
+ const allCheckOption = options?.filter((item) => {
38
+ return !item.disabled;
39
+ });
40
+ const subItemOps = itemOpProvider(allCheckOption, fieldNames);
41
41
  onChange?.(allCheckOption, subItemOps);
42
- }
42
+ };
43
43
  const change = () => {
44
44
  if (!checked) {
45
45
  allCheck();
@@ -47,7 +47,7 @@ const Index: React.FC<IProps> = ({
47
47
  }
48
48
  onChange?.([], []);
49
49
  };
50
- if (!allSelect || mode !== "multiple" || serviceSearch||opLen===0) {
50
+ if (!allSelect || mode !== "multiple" || serviceSearch || opLen === 0) {
51
51
  return <>{children}</>;
52
52
  }
53
53
  return (
@@ -3,12 +3,12 @@ import React from "react";
3
3
  interface ICheckBoxOptionProps {
4
4
  label?: React.ReactNode;
5
5
  checked: boolean;
6
- disabled?:boolean;
6
+ disabled?: boolean;
7
7
  }
8
- export default ({ label, checked ,disabled}: ICheckBoxOptionProps) => {
8
+ export default ({ label, checked, disabled }: ICheckBoxOptionProps) => {
9
9
  return (
10
10
  <Space>
11
- <Checkbox checked={checked} disabled={disabled}/>
11
+ <Checkbox checked={checked} disabled={disabled} />
12
12
  {label}
13
13
  </Space>
14
14
  );
@@ -9,10 +9,12 @@ export const defaultModeConfig: HSelectProps["modeConfig"] = {
9
9
  const checkVal = value?.map((itemVal) => {
10
10
  return itemVal.value;
11
11
  });
12
- const {label,disabled,value:itemVal}=item;
12
+ const { label, disabled, value: itemVal } = item;
13
13
  const newVal = checkVal || [];
14
14
  const checked = newVal.indexOf(itemVal) !== -1;
15
- return <CheckBoxOption disabled={disabled} label={label} checked={checked} />;
15
+ return (
16
+ <CheckBoxOption disabled={disabled} label={label} checked={checked} />
17
+ );
16
18
  },
17
19
  },
18
20
  };
@@ -142,11 +142,11 @@ export const useValueChange = (params: PartialHSelectProps) => {
142
142
  onChange(newChangeVal, subItemOps);
143
143
  };
144
144
  useEffect(() => {
145
- if (mode === "tags" ) {
145
+ if (mode === "tags") {
146
146
  setVal(value);
147
147
  return;
148
148
  }
149
- if (value===null||value===undefined){
149
+ if (value === null || value === undefined) {
150
150
  setVal(undefined);
151
151
  return;
152
152
  }
@@ -43,7 +43,7 @@ const Index: React.FC<HSwitchProps> = ({
43
43
  float: {
44
44
  inputValue: (item, initValue) => {
45
45
  const { close } = valueSwitchMap;
46
- const { name: valueName="" } = item;
46
+ const { name: valueName = "" } = item;
47
47
  let val = initValue[valueName];
48
48
  if (typeof val === "undefined" || val === null) {
49
49
  val = close;
@@ -9,13 +9,14 @@ import { message } from "antd";
9
9
  interface SubReqParamsModal {
10
10
  request?: (
11
11
  file: Exclude<BeforeUploadFileType, File | boolean> | RcFile
12
- ) => Promise<{ url: string }>;
12
+ ) => Promise<{ url: string ,thumbUrl?:string}>;
13
13
  file: RcFile;
14
14
  }
15
15
  interface ResultModal {
16
16
  url: string;
17
17
  status: UploadFileStatus;
18
18
  uid?: string;
19
+ thumbUrl?:string;
19
20
  }
20
21
  const subReq = async ({
21
22
  request,
@@ -28,9 +29,10 @@ const subReq = async ({
28
29
  };
29
30
  }
30
31
  try {
31
- const { url } = await request(file);
32
+ const { url ,thumbUrl} = await request(file);
32
33
  return {
33
34
  url,
35
+ thumbUrl,
34
36
  status: "done",
35
37
  };
36
38
  } catch (err: any) {
@@ -42,17 +44,19 @@ const subReq = async ({
42
44
  }
43
45
  };
44
46
  const fileListProvider = (changeFile: ResultModal, files?: UploadFile[]) => {
45
- const { status, url, uid } = changeFile;
47
+ const { status, url, uid,thumbUrl } = changeFile;
46
48
  if (status === "error") {
47
49
  return files?.filter((item) => {
48
50
  return item.uid !== uid;
49
51
  });
50
52
  }
51
53
  return files?.map((item) => {
54
+ const fileDefaultThumbUrl=item.thumbUrl||thumbUrl;
52
55
  const resultUrl = url || item.thumbUrl;
53
56
  if (item.uid === uid) {
54
57
  item.status = status;
55
58
  item.response = { url: resultUrl };
59
+ item.thumbUrl=fileDefaultThumbUrl;
56
60
  return item;
57
61
  }
58
62
  return item;
@@ -75,7 +75,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
75
75
  return {
76
76
  name: itemData,
77
77
  response: {
78
- url:itemData,
78
+ url: itemData,
79
79
  },
80
80
  status: "done",
81
81
  uid: `init-${index}`,
@@ -1,21 +1,28 @@
1
- import {HForm, HFormConfigProvider, HSwitch, useHForm} from "../../components";
1
+ import {
2
+ HForm,
3
+ HFormConfigProvider,
4
+ HSwitch,
5
+ useHForm,
6
+ } from "../../components";
2
7
  import { useState } from "react";
3
- import {Button, DatePicker, Form, Input, Row} from "antd";
4
- const Test2=()=>{
5
- return <Row style={{background:"red"}}>
6
-
7
- </Row>
8
- }
9
- const Test3=({value,onChange})=>{
10
- return <Input value={value.input}
11
- style={{width:100}}
12
- onChange={(e)=>{
13
- onChange({
14
- ...value,
15
- input:e.target.value
16
- })
17
- }}/>
18
- }
8
+ import { Button, DatePicker, Form, Input, Row } from "antd";
9
+ const Test2 = () => {
10
+ return <Row style={{ background: "red" }} />;
11
+ };
12
+ const Test3 = ({ value, onChange }) => {
13
+ return (
14
+ <Input
15
+ value={value.input}
16
+ style={{ width: 100 }}
17
+ onChange={(e) => {
18
+ onChange({
19
+ ...value,
20
+ input: e.target.value,
21
+ });
22
+ }}
23
+ />
24
+ );
25
+ };
19
26
  const formData = (options) => {
20
27
  const op = [
21
28
  {
@@ -28,20 +35,20 @@ const formData = (options) => {
28
35
  },
29
36
  ];
30
37
  return [
31
- {
32
- label: "12321",
33
- className: "3",
34
- name:"min",
35
- type:"inputNumberGroup",
36
- itemProps:{
37
- addonAfter:<Test3/>
38
- },
38
+ {
39
+ label: "12321",
40
+ className: "3",
41
+ name: "inputNumberGroup",
42
+ type: "inputNumberGroup",
43
+ itemProps: {
44
+ addonAfter: <Test3 />,
39
45
  },
46
+ },
40
47
  {
41
48
  label: "测试12312",
42
49
  className: "hdjd",
43
- type: "colorInput",
44
- name:"test",
50
+ type: "colorInput",
51
+ name: "test",
45
52
  },
46
53
  ];
47
54
  };
@@ -49,7 +56,6 @@ function Ttta({ form }) {
49
56
  return (
50
57
  <div
51
58
  onClick={() => {
52
- console.log("form", form);
53
59
  form.setFieldsValue({ switch: 1 });
54
60
  }}
55
61
  >
@@ -94,13 +100,18 @@ export default () => {
94
100
  form={form}
95
101
  labelAlign={"right"}
96
102
  onFinish={(value) => {
97
- console.log(value);
103
+ console.log(value, "fff");
98
104
  }}
99
105
  onValuesChange={(val) => {
100
106
  console.log(val, "onValuesChange");
101
107
  }}
102
108
  initialValues={{
103
109
  file: "https://img0.baidu.com/it/u=530540642,263790536&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=667",
110
+ min: 1,
111
+ max: 2,
112
+ inputNumberGroup: {
113
+ input: "xxxxxxx",
114
+ },
104
115
  }}
105
116
  request={(params) => {
106
117
  return new Promise<any>((resolve) => {
@@ -113,19 +124,19 @@ export default () => {
113
124
  </HFormConfigProvider>
114
125
  <div
115
126
  onClick={async () => {
116
- const result=await form.validateFields();
117
- console.log(result);
127
+ const result = await form.validateFields();
128
+ console.log(result);
118
129
  }}
119
130
  >
120
131
  点我
121
132
  </div>
122
- <div
123
- onClick={async () => {
124
- form.submit()
125
- }}
126
- >
127
- 提交
128
- </div>
133
+ <div
134
+ onClick={() => {
135
+ form.submit();
136
+ }}
137
+ >
138
+ 提交
139
+ </div>
129
140
  <div
130
141
  onClick={() => {
131
142
  form.resetFields();
@@ -2,14 +2,15 @@ import { Button } from "antd";
2
2
  import {
3
3
  HModalForm,
4
4
  useHDialogForm,
5
- HFormConfigProvider, HUrlUpload,
5
+ HFormConfigProvider,
6
+ HUrlUpload,
6
7
  } from "../../components";
7
8
  import { useState } from "react";
8
9
  import { ShowParamsModal } from "@/components/DialogForm/modal";
9
10
 
10
- const Test=(props)=>{
11
- return <HUrlUpload {...props}/>
12
- }
11
+ const Test = (props) => {
12
+ return <HUrlUpload {...props} />;
13
+ };
13
14
  const data = [
14
15
  {
15
16
  label: "输入框",
@@ -109,9 +110,9 @@ const data = [
109
110
  {
110
111
  label: "地址文件",
111
112
  name: "urlUpload",
112
- render:()=>{
113
- return <Test/>
114
- }
113
+ render: () => {
114
+ return <Test />;
115
+ },
115
116
  },
116
117
  {
117
118
  label: "下拉框",
@@ -154,9 +155,9 @@ export default () => {
154
155
  params: {
155
156
  name: num,
156
157
  },
157
- initialValues:{
158
- urlUpload:"ffff"
159
- }
158
+ initialValues: {
159
+ urlUpload: "ffff",
160
+ },
160
161
  });
161
162
  }}
162
163
  >
@@ -14,7 +14,7 @@ export default () => {
14
14
  <HSelect
15
15
  fieldNames={{ label: "name", value: "value" }}
16
16
  options={[
17
- { name: "测试1", value: 10, userId: 112321,disabled:true },
17
+ { name: "测试1", value: 10, userId: 112321, disabled: true },
18
18
  { name: "测试2", value: 20, userId: 112321 },
19
19
  ]}
20
20
  placeholder="多选"
@@ -6,9 +6,21 @@ import { MediaTypeEnum } from "../../components/Upload/enums";
6
6
  export default () => {
7
7
  const [files, setFiles] = useState([]);
8
8
  const [files1, setFiles1] = useState([]);
9
+ console.log(files)
9
10
  return (
10
11
  <Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
11
- <HUpload value={files} onChange={setFiles} multiple={true} maxCount={3} />
12
+ <HUpload exFiles={null}
13
+ value={files}
14
+ request={()=>{
15
+ return {
16
+ url:"https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641",
17
+ thumbUrl:"https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641"
18
+ }
19
+ }}
20
+ onChange={setFiles}
21
+ multiple={true}
22
+ maxCount={3}
23
+ maxSize={Number.MAX_SAFE_INTEGER}/>
12
24
  <HUrlUpload
13
25
  value={files1}
14
26
  mediaType={MediaTypeEnum.file}