@hw-component/form 1.8.1 → 1.8.3

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.
@@ -1,15 +1,13 @@
1
1
  @import "../styles/local.less";
2
2
  @all-input-group: ~"@{ant-prefix}-hw-input-group";
3
3
 
4
- .@{all-input-group} {
5
- .@{all-input-group}-disabled {
6
- background-color: #f5f5f5;
7
- }
8
- }
9
4
  .@{all-input-group} {
10
5
  display: flex !important;
11
6
  width: 100%;
12
7
  color: rgba(0, 0, 0, 0.25);
8
+ .@{all-input-group}-disabled {
9
+ background-color: #f5f5f5;
10
+ }
13
11
  .@{all-input-group}-body {
14
12
  position: relative;
15
13
  display: flex !important;
@@ -44,7 +42,7 @@
44
42
  display: flex;
45
43
  align-items: center;
46
44
  padding: 0 4px;
47
- color:rgba(0, 0, 0, 0.25);
45
+ color: rgba(0, 0, 0, 0.25);
48
46
  }
49
47
  .@{all-input-group}-one {
50
48
  flex: 1;
@@ -13,26 +13,27 @@ export const useValueChange = (params: PartialHSelectProps) => {
13
13
  fieldNames = {},
14
14
  } = params;
15
15
  const [val, setVal] = useState<any>();
16
- const labelInValueItemMaker=(changeVal)=>{
17
- const {value:fieldValue="value",label:fieldLabel="label"}=fieldNames;
18
- const {label:changeLabel,value:changeValue,...oVal}=changeVal;
19
- return {
20
- [fieldValue]:changeValue,
21
- [fieldLabel]:changeLabel,
22
- ...oVal
16
+ const labelInValueItemMaker = (changeVal) => {
17
+ const { value: fieldValue = "value", label: fieldLabel = "label" } =
18
+ fieldNames;
19
+ const { label: changeLabel, value: changeValue, ...oVal } = changeVal;
20
+ return {
21
+ [fieldValue]: changeValue,
22
+ [fieldLabel]: changeLabel,
23
+ ...oVal,
24
+ };
25
+ };
26
+ const labelInValueMaker = (changeVal) => {
27
+ if (!changeVal) {
28
+ return undefined;
29
+ }
30
+ if (!Array.isArray(changeVal)) {
31
+ return labelInValueItemMaker(changeVal);
23
32
  }
24
- }
25
- const labelInValueMaker=(changeVal)=>{
26
- if (!changeVal){
27
- return undefined;
28
- }
29
- if (!Array.isArray(changeVal)){
30
- return labelInValueItemMaker(changeVal)
31
- }
32
- return changeVal.map((item)=>{
33
- return labelInValueItemMaker(item)
34
- })
35
- }
33
+ return changeVal.map((item) => {
34
+ return labelInValueItemMaker(item);
35
+ });
36
+ };
36
37
  const change = (changeVal, itemOps) => {
37
38
  if (!onChange) {
38
39
  setVal(changeVal);
@@ -44,11 +45,11 @@ export const useValueChange = (params: PartialHSelectProps) => {
44
45
  }
45
46
  const subItemOps = itemOpProvider(itemOps, fieldNames);
46
47
  if (labelInValue) {
47
- onChange(labelInValueMaker(changeVal),itemOps);
48
+ onChange(labelInValueMaker(changeVal), itemOps);
48
49
  return;
49
50
  }
50
51
  let newChangeVal = changeVal.value;
51
- if (Array.isArray(changeVal)&&!labelInValue) {
52
+ if (Array.isArray(changeVal) && !labelInValue) {
52
53
  newChangeVal = changeVal.map((item) => {
53
54
  return item.value;
54
55
  });
@@ -60,7 +61,7 @@ export const useValueChange = (params: PartialHSelectProps) => {
60
61
  setVal(undefined);
61
62
  return;
62
63
  }
63
- if (mode === "tags"||labelInValue) {
64
+ if (mode === "tags" || labelInValue) {
64
65
  setVal(value);
65
66
  return;
66
67
  }
@@ -73,13 +74,14 @@ export const useValueChange = (params: PartialHSelectProps) => {
73
74
  }, [value, options, mode]);
74
75
  const itemMaker = (item) => {
75
76
  const { value: itemVal, label, noMatch } = item;
76
- const {value:fieldValue="value",label:fieldLabel="label"}=fieldNames;
77
- if (labelInValue){
78
- const {[fieldValue]:changeVal,[fieldLabel]:changeLable}=item;
79
- return {
80
- value:changeVal,
81
- label: changeLable
82
- };
77
+ const { value: fieldValue = "value", label: fieldLabel = "label" } =
78
+ fieldNames;
79
+ if (labelInValue) {
80
+ const { [fieldValue]: changeVal, [fieldLabel]: changeLable } = item;
81
+ return {
82
+ value: changeVal,
83
+ label: changeLable,
84
+ };
83
85
  }
84
86
  if (noMatch) {
85
87
  return {
@@ -100,7 +100,7 @@ const useOptionsRequest = ({
100
100
  }
101
101
  );
102
102
  const run = (requestParams = {}, type = "init") => {
103
- if (loading&&type!=="init") {
103
+ if (loading && type !== "init") {
104
104
  return;
105
105
  }
106
106
  listRun(requestParams, type);
@@ -3,7 +3,7 @@ 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
- import { useEffect, useRef, useState } from "react";
6
+ import { useRef, useState } from "react";
7
7
  import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
8
  import { useDefaultExFiles } from "./hooks";
9
9
  const { Text } = Typography;
@@ -1,6 +1,9 @@
1
1
  import moment from "moment";
2
2
  import type { IFormConfigContextProps } from "./Form/modal";
3
3
  import { fileToBase64 } from "./Upload/util";
4
+ const rangeStartDay=(day:number)=>{
5
+ return moment().subtract(day, "days").startOf("days")
6
+ }
4
7
  export const baseConfig: IFormConfigContextProps = {
5
8
  fieldNames: {
6
9
  label: "label",
@@ -23,9 +26,15 @@ export const baseConfig: IFormConfigContextProps = {
23
26
  },
24
27
  },
25
28
  dateRanges: {
26
- 最近三天: [moment().subtract(2, "days").startOf("days"), moment()],
27
- 最近七天: [moment().subtract(6, "days").startOf("days"), moment()],
28
- 最近三十天: [moment().subtract(29, "days").startOf("days"), moment()],
29
+ 最近三天: ()=>{
30
+ return [rangeStartDay(2), moment()]
31
+ },
32
+ 最近七天: ()=>{
33
+ return [rangeStartDay(6),moment()]
34
+ },
35
+ 最近三十天:()=>{
36
+ return [rangeStartDay(29), moment()]
37
+ },
29
38
  },
30
39
  uploadProps: {
31
40
  exFiles: ["JPG", "PNG", "JPEG", "GIF"],
@@ -6,7 +6,7 @@ export { default as useHForm } from "./Form/hooks/useHForm";
6
6
  export { useHDialogForm } from "./DialogForm/hooks";
7
7
  export { default as HFormConnect } from "./Form/HFormConnect";
8
8
  export { default as HFormConfigProvider } from "./Form/Context/FormConfigProvider";
9
- export {default as HBasicForm} from './Form/Basic';
9
+ export { default as HBasicForm } from "./Form/Basic";
10
10
 
11
11
  import ModalForm from "./DialogForm/ModalForm";
12
12
  import DrawerForm from "./DialogForm/DrawerForm";
@@ -1,102 +1,79 @@
1
1
  import {
2
- HBasicForm,
3
- HForm,
4
- HFormConfigProvider,
5
- HSwitch,
6
- useHForm,
7
- HSelect
2
+ HBasicForm,
3
+ HForm,
4
+ HFormConfigProvider,
5
+ HSwitch,
6
+ useHForm,
7
+ HSelect,
8
8
  } from "../../components";
9
9
  import { useState } from "react";
10
- import {Button, DatePicker, Form, Input, Row, Space} from "antd";
10
+ import { Button, DatePicker, Form, Input, Row, Space } from "antd";
11
11
  const Test2 = () => {
12
12
  return <Row style={{ background: "red" }} />;
13
13
  };
14
- const Test3 = ({ value={}, onChange }) => {
15
- const {fs,end}=value;
16
- return <Space>
17
- <HSelect
18
- options={[{value:"1321",key:1}]}
19
- value={fs}
20
- allowClear
21
- onChange={()=>{
22
- onChange?.({})
23
- }}
24
- />
25
- <HSelect options={[{value:"112",key:2}]}
26
- allowClear
27
- value={end}
28
- onChange={(val)=>{
29
- onChange?.({
30
- ...value,
31
- end:val
32
- })
33
- }}
34
- />
14
+ const Test3 = ({ value = {}, onChange }) => {
15
+ const { fs, end } = value;
16
+ return (
17
+ <Space>
18
+ <HSelect
19
+ options={[{ value: "1321", key: 1 }]}
20
+ value={fs}
21
+ allowClear
22
+ onChange={() => {
23
+ onChange?.({});
24
+ }}
25
+ />
26
+ <HSelect
27
+ options={[{ value: "112", key: 2 }]}
28
+ allowClear
29
+ value={end}
30
+ onChange={(val) => {
31
+ onChange?.({
32
+ ...value,
33
+ end: val,
34
+ });
35
+ }}
36
+ />
35
37
  </Space>
38
+ );
36
39
  };
37
- const TestItem=()=>{
38
- return <Form.Item name="name1">
39
- <Test3/>
40
+ const TestItem = () => {
41
+ return (
42
+ <Form.Item name="name1">
43
+ <Test3 />
40
44
  </Form.Item>
41
- }
42
- const Test3Item=()=>{
43
- return <Form.List name="users">
44
- {(fields, { add, remove }) => (
45
+ );
46
+ };
47
+ const Test3Item = () => {
48
+ return (
49
+ <Form.List name="users">
50
+ {(fields, { add, remove }) => (
45
51
  <>
46
- {fields.map(({ key, name, ...restField }) => (
47
- <Form.Item
48
- {...restField}
49
- name={name}
50
- key={key}
51
- >
52
- <Test3/>
53
- </Form.Item>
54
- ))}
55
- <Form.Item>
56
- <Button type="dashed" onClick={() => add({})} block>
57
- Add field
58
- </Button>
52
+ {fields.map(({ key, name, ...restField }) => (
53
+ <Form.Item {...restField} name={name} key={key}>
54
+ <Test3 />
59
55
  </Form.Item>
56
+ ))}
57
+ <Form.Item>
58
+ <Button type="dashed" onClick={() => add({})} block>
59
+ Add field
60
+ </Button>
61
+ </Form.Item>
60
62
  </>
61
- )}
62
-
63
- </Form.List>
64
- }
63
+ )}
64
+ </Form.List>
65
+ );
66
+ };
65
67
  const formData = (options) => {
66
68
  return [
67
69
  {
68
- render:()=>{
69
- return <HBasicForm
70
- configData={[
71
- {
72
- label: "下拉123",
73
- className: "xiala",
74
- render:()=>{
75
- return <TestItem/>
76
- }
77
- },
78
- ]}/>
79
- }
70
+ name:"name",
71
+ label:"输入框"
80
72
  },
81
73
  {
82
- label: '会员标签',
83
- hover: '添加新的会员标签后会覆盖用户原有的会员标签类型',
84
- nameKey: 'userTags',
85
- style: {
86
- marginBottom: 0,
87
- },
88
- render:()=>{
89
- return <HBasicForm
90
- configData={[
91
- {
92
- label: "333",
93
- className: "xiala",
94
- render:()=>{
95
- return <Test3Item/>
96
- }
97
- },
98
- ]}/>
99
- }
74
+ name:"url",
75
+ type:"urlUpload",
76
+ label:"文本"
100
77
  },
101
78
  ];
102
79
  };
@@ -140,6 +117,7 @@ export default () => {
140
117
  <HForm
141
118
  configData={formData(options)}
142
119
  labelWidth={300}
120
+ dismissOnPressEnter={false}
143
121
  form={form}
144
122
  labelAlign={"left"}
145
123
  onFinish={(value) => {
@@ -149,7 +127,7 @@ export default () => {
149
127
  console.log(val, "onValuesChange");
150
128
  }}
151
129
  initialValues={{
152
- name1:{}
130
+ name1: {},
153
131
  }}
154
132
  request={(params) => {
155
133
  return new Promise<any>((resolve) => {
@@ -26,11 +26,13 @@ export default () => {
26
26
  return Promise.resolve({ code: 200 });
27
27
  }}
28
28
  />
29
- <HInputNumberGroup
30
- inputNumberProps={[{
31
- min:Number.MIN_SAFE_INTEGER
32
- }]}
33
- />
29
+ <HInputNumberGroup
30
+ inputNumberProps={[
31
+ {
32
+ min: Number.MIN_SAFE_INTEGER,
33
+ },
34
+ ]}
35
+ />
34
36
  </Space>
35
37
  );
36
38
  };
@@ -1,8 +1,8 @@
1
1
  import { HSelect } from "../../components";
2
- import { Space ,Select} from "antd";
2
+ import { Space, Select } from "antd";
3
3
  import { useState } from "react";
4
4
  export default () => {
5
- const [selectVal, setSelectVal] = useState([{name:"11",id:-100}]);
5
+ const [selectVal, setSelectVal] = useState([{ name: "11", id: -100 }]);
6
6
  return (
7
7
  <Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
8
8
  <HSelect
@@ -11,12 +11,12 @@ export default () => {
11
11
  allowClear={true}
12
12
  labelInValue
13
13
  fieldNames={{
14
- label:"name",
15
- value:"id"
14
+ label: "name",
15
+ value: "id",
16
16
  }}
17
17
  value={selectVal}
18
- onChange={(val,item)=>{
19
- setSelectVal(val)
18
+ onChange={(val, item) => {
19
+ setSelectVal(val);
20
20
  }}
21
21
  request={async (params) => {
22
22
  const { page, size } = params;
@@ -24,15 +24,19 @@ export default () => {
24
24
  for (let i = 0; i < 100; i += 1) {
25
25
  op.push({ name: `第${page}页第${i}条`, id: i + page });
26
26
  }
27
- return Promise.resolve({
28
- page,
29
- size: 100,
30
- total: 1000,
31
- data: op,
32
- })
27
+ return Promise.resolve({
28
+ page,
29
+ size: 100,
30
+ total: 1000,
31
+ data: op,
32
+ });
33
33
  }}
34
34
  isList
35
35
  />
36
+ <HSelect
37
+ value={1}
38
+ options={null}
39
+ />
36
40
  </Space>
37
41
  );
38
42
  };
@@ -24,13 +24,12 @@ export default () => {
24
24
  maxCount={3}
25
25
  maxSize={Number.MAX_SAFE_INTEGER}
26
26
  />
27
- <HUrlUpload
27
+ <HUpload
28
28
  value={files1}
29
29
  mediaType={MediaTypeEnum.file}
30
30
  showUploadList={{
31
31
  showPreviewIcon: false,
32
32
  }}
33
- exFiles={["TXT", "EXE"]}
34
33
  onChange={setFiles1}
35
34
  />
36
35
  </Space>