lu-lowcode-package-form 0.8.3 → 0.8.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lu-lowcode-package-form",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@testing-library/jest-dom": "^5.17.0",
package/src/App.jsx CHANGED
@@ -21,7 +21,7 @@ const treeData = [
21
21
 
22
22
  function App() {
23
23
  const formRef = React.createRef();
24
- const [cols, setCols] = React.useState(1);
24
+ const [cols, setCols] = React.useState(3);
25
25
 
26
26
  const getFormFields = () => {
27
27
  console.log("formRef?.current", formRef)
@@ -30,6 +30,9 @@ function App() {
30
30
  }
31
31
  const setFormFields = () => {
32
32
  formRef?.current?.formRef?.setFieldsValue({
33
+ select1:"1",
34
+ select2:"[\"1\",\"2\"]",
35
+ switch:"1",
33
36
  datetime: "2021-12-12",
34
37
  datetime2: "2021-12-12",
35
38
  datetime3: "2021-12-12",
@@ -39,7 +42,7 @@ function App() {
39
42
  })
40
43
  }
41
44
  const handleCols = () => {
42
- setCols(cols + 1)
45
+ setCols(cols - 1)
43
46
  }
44
47
  return (
45
48
 
@@ -51,6 +54,8 @@ function App() {
51
54
  <div className='fw-[960px] frounded fbg-slate-100 fflex fflex-col fitems-center fpb-10'>
52
55
  <FormContainerWrapper cols={cols} className="" ref={formRef} >
53
56
  <Field.Input label="分组名" __id="title" />
57
+ <Field.SingleSelect mode="single" label="测试单选" __id="select1" options={[{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }]}></Field.SingleSelect>
58
+ <Field.MultipleSelect mode="multiple" label="测多选" __id="select2" options={[{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }]}></Field.MultipleSelect>
54
59
  <Field.TreeSelect label="分组名" __id="title11"></Field.TreeSelect>
55
60
  <Field.Switch label="开关" __id="switch"></Field.Switch>
56
61
  <Field.CodeMachine label="角色编号" prompt="" __id="code" />
@@ -1,4 +1,4 @@
1
1
  export { default as TreeSelect } from './tree-select.jsx';
2
- export { Select, WithSingleSelect,WithMultipleSelect } from './select.jsx';
2
+ export { Select, WithSingleSelect,WithMultipleSelect , MultipleSelect, SingleSelect} from './select.jsx';
3
3
 
4
4
 
@@ -36,6 +36,32 @@ const Select = ({ request, option_label = "label", option_value = "id", disabled
36
36
  )
37
37
  }
38
38
 
39
+ const SingleSelect = ({ ...props }) => {
40
+ return (
41
+ <Select {...props} mode="single" />
42
+ )
43
+ }
44
+
45
+ const MultipleSelect = ({ onChange, value, ...props }) => {
46
+ const [nValue, setNValue] = React.useState([])
47
+
48
+ useEffect(()=>{
49
+ if (typeof value === "string") {
50
+ try {
51
+ value = JSON.parse(value)
52
+ onChange(value)
53
+ } catch (error) {
54
+
55
+ }
56
+ }
57
+
58
+ setNValue(value)
59
+ },[value])
60
+
61
+ return (
62
+ <Select {...props} onChange={onChange} mode="multiple" value={nValue} />
63
+ )
64
+ }
39
65
  /**
40
66
  * 关联单选组件
41
67
  * @param {*}
@@ -95,4 +121,4 @@ const WithMultipleSelect = ({ onChange, value, ...props }) => {
95
121
  )
96
122
  }
97
123
 
98
- export { WithSingleSelect, WithMultipleSelect, Select };
124
+ export { WithSingleSelect, WithMultipleSelect, MultipleSelect, SingleSelect, Select };
@@ -1,15 +1,24 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { Switch as OriginalSwitch } from 'antd';
3
3
  import { BaseWrapper } from "../base.jsx"
4
- const Switch = ({defaultValue ,...props}) => {
5
- defaultValue = defaultValue || false;
6
- useEffect(() => {
7
- props.onChange(defaultValue);
4
+ const Switch = ({value, ...props}) => {
8
5
 
9
- }, [defaultValue]);
6
+ const [nValue, setNValue] = React.useState(false)
7
+ useEffect(()=>{
8
+ let tem_value = false
9
+ if( typeof value === "boolean" )
10
+ tem_value = value
11
+ else if (typeof value === "string")
12
+ tem_value =value == "1" || value == "true"
13
+ else if (typeof value == "number")
14
+ tem_value = value == 1
15
+ setNValue(tem_value)
16
+ // 格式化form表单获取到的值
17
+ props?.onChange(tem_value)
18
+ },[value])
10
19
  return (
11
20
  <BaseWrapper {...props}>
12
- <OriginalSwitch {...props} />
21
+ <OriginalSwitch {...props} value={nValue} />
13
22
  </BaseWrapper>
14
23
  );
15
24
  }
@@ -1,6 +1,6 @@
1
1
  import { Input, TextArea, Password, Search ,CodeMachine} from './field/input/index.jsx'
2
2
  import '../App.css';
3
- import { TreeSelect, Select, WithSingleSelect,WithMultipleSelect } from './field/select/index.jsx'
3
+ import { TreeSelect, Select, WithSingleSelect,WithMultipleSelect, SingleSelect, MultipleSelect } from './field/select/index.jsx'
4
4
  import Custom from './field/custom/index.jsx'
5
5
  import { FormContainer, FormContainerWrapper,LayoutFormRow,LayoutFormGroupTitle } from './form-container/index.jsx'
6
6
  import { Checkbox ,CheckboxTree, CheckboxGroup } from './field/checkbox/index.jsx'
@@ -17,6 +17,8 @@ const Field = {
17
17
  Select,
18
18
  WithSingleSelect,
19
19
  WithMultipleSelect,
20
+ SingleSelect,
21
+ MultipleSelect,
20
22
  CodeMachine,
21
23
  Checkbox,
22
24
  CheckboxTree,
@@ -33,8 +35,8 @@ const Layout = {
33
35
  FormGroupTitle: LayoutFormGroupTitle
34
36
  }
35
37
  export { FormContainer, Field ,FormContainerWrapper,Layout }
36
- // import { default as OptionSetter} from './setter/optionsetter'
37
- // const Setter = {
38
- // OptionSetter
39
- // }
40
- // export { Setter }
38
+ import { default as OptionSetter} from './setter/optionsetter'
39
+ const Setter = {
40
+ OptionSetter
41
+ }
42
+ export { Setter }