kts-components-document-access-point 1.4.4 → 1.4.7

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 (123) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +4 -4
  3. package/.prettierignore +7 -7
  4. package/.prettierrc +11 -11
  5. package/.umirc.ts +11 -11
  6. package/README.md +3 -3
  7. package/dist/index.esm.js +13 -12
  8. package/dist/index.js +13 -12
  9. package/docs/index.md +3 -3
  10. package/index.html +12 -12
  11. package/package.json +56 -56
  12. package/src/DocumentWhiteList/___demo___/base/index.tsx +7 -7
  13. package/src/DocumentWhiteList/___demo___/setService/index.tsx +23 -23
  14. package/src/DocumentWhiteList/control/actions/addblack/index.ts +14 -14
  15. package/src/DocumentWhiteList/control/actions/addwhite/index.ts +14 -14
  16. package/src/DocumentWhiteList/control/actions/blacklist/index.ts +22 -22
  17. package/src/DocumentWhiteList/control/actions/checkclient/index.ts +14 -14
  18. package/src/DocumentWhiteList/control/actions/demo/index.ts +4 -4
  19. package/src/DocumentWhiteList/control/actions/didilist/index.ts +18 -18
  20. package/src/DocumentWhiteList/control/actions/enableblacklist/index.ts +17 -17
  21. package/src/DocumentWhiteList/control/actions/enablelist/index.ts +18 -18
  22. package/src/DocumentWhiteList/control/actions/enablewhitelist/index.ts +17 -17
  23. package/src/DocumentWhiteList/control/actions/getmode/index.ts +14 -14
  24. package/src/DocumentWhiteList/control/actions/setmode/index.ts +14 -14
  25. package/src/DocumentWhiteList/control/actions/synclist/index.ts +19 -19
  26. package/src/DocumentWhiteList/control/actions/whitelist/index.ts +22 -22
  27. package/src/DocumentWhiteList/control/index.tsx +42 -42
  28. package/src/DocumentWhiteList/control/state/index.ts +47 -47
  29. package/src/DocumentWhiteList/index.md +5 -5
  30. package/src/DocumentWhiteList/index.tsx +40 -40
  31. package/src/DocumentWhiteList/interface/index.ts +30 -30
  32. package/src/DocumentWhiteList/ui/clientmodal/index.tsx +190 -190
  33. package/src/DocumentWhiteList/ui/main/black.tsx +126 -132
  34. package/src/DocumentWhiteList/ui/main/index.tsx +49 -49
  35. package/src/DocumentWhiteList/ui/main/switchmode.tsx +52 -52
  36. package/src/DocumentWhiteList/ui/main/white.tsx +119 -120
  37. package/src/DocumentWhiteList/ui/pageheader/BlackHeader.tsx +143 -143
  38. package/src/DocumentWhiteList/ui/pageheader/WhiteHeader.tsx +152 -152
  39. package/src/DocumentWhiteList/ui/pageui/index.tsx +64 -64
  40. package/src/DocumentWhiteList/ui/whitemodal/index.tsx +146 -146
  41. package/src/DocumentWhiteList/util/ConfigEnum.ts +8 -8
  42. package/src/DocumentsCont/___demo___/base/index.tsx +7 -7
  43. package/src/DocumentsCont/___demo___/setService/index.tsx +25 -25
  44. package/src/DocumentsCont/index.md +9 -9
  45. package/src/DocumentsCont/index.tsx +54 -51
  46. package/src/DocumentsDemo/Controller/index.tsx +14 -14
  47. package/src/DocumentsDemo/Controller/whitelist.ts +22 -22
  48. package/src/DocumentsDemo/Text.tsx +22 -22
  49. package/src/DocumentsDemo/___demo___/base/index.tsx +7 -7
  50. package/src/DocumentsDemo/index.md +6 -6
  51. package/src/DocumentsDemo/index.tsx +38 -38
  52. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/IProperties/index.ts +69 -69
  53. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/IRules/index.ts +18 -18
  54. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/ISchema/index.ts +14 -14
  55. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/PropertyTableState/index.ts +12 -12
  56. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/RuleState/index.ts +336 -336
  57. package/src/DocumentsEdit/DocumentsEditController/DocumentsEditControllerState/index.ts +51 -51
  58. package/src/DocumentsEdit/DocumentsEditController/actions/addProperties/index.ts +37 -37
  59. package/src/DocumentsEdit/DocumentsEditController/actions/delProperties/index.ts +48 -48
  60. package/src/DocumentsEdit/DocumentsEditController/actions/editProperties/index.ts +93 -93
  61. package/src/DocumentsEdit/DocumentsEditController/index.tsx +21 -21
  62. package/src/DocumentsEdit/___demo___/conventional/index.tsx +10 -10
  63. package/src/DocumentsEdit/___demo___/monitor/index.tsx +1421 -1421
  64. package/src/DocumentsEdit/___demo___/readOnly/index.tsx +16 -16
  65. package/src/DocumentsEdit/constant/propertyColumns/index.tsx +65 -65
  66. package/src/DocumentsEdit/index.less +45 -45
  67. package/src/DocumentsEdit/index.md +10 -10
  68. package/src/DocumentsEdit/index.tsx +117 -117
  69. package/src/DocumentsEdit/tools/index.ts +88 -88
  70. package/src/DocumentsEdit/ui/AddPropertyButton/index.tsx +238 -238
  71. package/src/DocumentsEdit/ui/Breadcrumb/index.tsx +51 -51
  72. package/src/DocumentsEdit/ui/EditProperty/index.tsx +290 -290
  73. package/src/DocumentsEdit/ui/EditRule/index.tsx +156 -156
  74. package/src/DocumentsEdit/ui/EditRule/ui/AddRuleButton/index.tsx +49 -49
  75. package/src/DocumentsEdit/ui/EditRule/ui/DelRuleButton/index.tsx +31 -31
  76. package/src/DocumentsEdit/ui/EditRule/ui/RuleForm/fn/algorithmFormComponent/index.tsx +142 -142
  77. package/src/DocumentsEdit/ui/EditRule/ui/RuleForm/index.tsx +154 -154
  78. package/src/DocumentsEdit/ui/PropertyTable/hooks/useTableProps/index.less +4 -4
  79. package/src/DocumentsEdit/ui/PropertyTable/hooks/useTableProps/index.tsx +70 -70
  80. package/src/DocumentsEdit/ui/PropertyTable/hooks/useTableProps/ui/AddChildPropertyButton/index.tsx +34 -34
  81. package/src/DocumentsEdit/ui/PropertyTable/hooks/useTableProps/ui/AddRuleButton/index.tsx +64 -64
  82. package/src/DocumentsEdit/ui/PropertyTable/hooks/useTableProps/ui/EditPropertyButton/index.tsx +31 -31
  83. package/src/DocumentsEdit/ui/PropertyTable/index.less +19 -19
  84. package/src/DocumentsEdit/ui/PropertyTable/index.tsx +18 -18
  85. package/src/DocumentsEdit/ui/RefPropertyButton/index.tsx +121 -121
  86. package/src/DocumentsList/DocumentsListController/DocumentsListControllerState/index.ts +55 -55
  87. package/src/DocumentsList/DocumentsListController/actions/demo/index.ts +4 -4
  88. package/src/DocumentsList/DocumentsListController/actions/typelist/index.ts +15 -15
  89. package/src/DocumentsList/DocumentsListController/index.tsx +16 -16
  90. package/src/DocumentsList/___demo___/list/index.tsx +4 -4
  91. package/src/DocumentsList/index.less +22 -22
  92. package/src/DocumentsList/index.md +3 -3
  93. package/src/DocumentsList/index.tsx +46 -46
  94. package/src/DocumentsList/ui/ModalComfirm/index.tsx +94 -92
  95. package/src/DocumentsList/ui/PageHeader/SendHeader.tsx +230 -230
  96. package/src/DocumentsList/ui/PageHeader/index.tsx +325 -325
  97. package/src/DocumentsList/ui/PageUI/index.tsx +65 -65
  98. package/src/DocumentsList/ui/RuleTable/index.tsx +163 -163
  99. package/src/DocumentsList/ui/sendlist/index.tsx +151 -151
  100. package/src/DocumentsList/util/ConfigEnum.ts +11 -11
  101. package/src/DocumentsRule/control/actions/batchsend/index.ts +13 -13
  102. package/src/DocumentsRule/control/actions/configsave/index.ts +14 -14
  103. package/src/DocumentsRule/control/actions/configupdate/index.ts +13 -13
  104. package/src/DocumentsRule/control/actions/getconfigbyid/index.ts +14 -14
  105. package/src/DocumentsRule/control/actions/getrecordbyid/index.ts +14 -14
  106. package/src/DocumentsRule/control/actions/gettemplate/index.ts +15 -15
  107. package/src/DocumentsRule/control/actions/listbysubjectid/index.ts +13 -13
  108. package/src/DocumentsRule/control/actions/typelist/index.ts +13 -13
  109. package/src/DocumentsRule/control/index.tsx +30 -30
  110. package/src/DocumentsRule/control/state/index.ts +42 -42
  111. package/src/DocumentsRule/index.md +1 -1
  112. package/src/DocumentsRule/index.tsx +25 -25
  113. package/src/DocumentsRule/interface/index.ts +28 -28
  114. package/src/DocumentsRule/ui/main/index.tsx +362 -362
  115. package/src/DocumentsService/index.ts +18 -18
  116. package/src/index.ts +9 -9
  117. package/tsconfig.json +29 -29
  118. package/typings.d.ts +3 -3
  119. package/docs-dist/404.html +0 -38
  120. package/docs-dist/index.html +0 -38
  121. package/docs-dist/static/icon.050945f2.svg +0 -1
  122. package/docs-dist/umi.css +0 -11
  123. package/docs-dist/umi.js +0 -1
@@ -1,88 +1,88 @@
1
- import IProperties, { FormatType, PropertiesType } from "../DocumentsEditController/DocumentsEditControllerState/IProperties";
2
-
3
- /** 初始化 form type */
4
- export function initType(editProperties: IProperties) {
5
- if (!!editProperties.items) editProperties = editProperties.items;
6
- if (editProperties.format === 'date') return 'string|date';
7
- if (editProperties.format === 'date-time') return 'string|date-time';
8
- if (editProperties.format === "time") return 'string|time';
9
- return editProperties.type;
10
- }
11
-
12
- /** form type => 属性的 type */
13
- export function getType(v: string): PropertiesType {
14
- if (v === 'string|date') return 'string';
15
- if (v === 'string|time') return 'string';
16
- if (v === 'string|date-time') return 'string';
17
- return v as PropertiesType;
18
- }
19
-
20
- /** form type => 属性的 type 的中文 */
21
- export function getTypeName(v: string) {
22
- switch (v) {
23
- case 'string|date':
24
- return '日期(YYYY-MM-DD)'
25
- case 'string|date-time':
26
- return '日期-时间(YYYY-MM-DD hh:mm:ss)'
27
- case 'string|time':
28
- return '时间(hh:mm:ss)'
29
- case 'string':
30
- return '文本'
31
- case 'object':
32
- return '复合类型'
33
- case 'integer':
34
- return '数字(整数)'
35
- case 'number':
36
- return '数字(小数)'
37
- case 'boolean':
38
- return '布尔(是/否)'
39
- default:
40
- return '未知'
41
- }
42
- }
43
-
44
- /** form type => 属性的 type */
45
- export function getFormat(v: string): FormatType | undefined {
46
- if (v === 'string|date') return 'date';
47
- if (v === 'string|time') return 'time';
48
- if (v === 'string|date-time') return 'date-time';
49
- return undefined;
50
- }
51
-
52
- /** form => 属性的 Items */
53
- export function getItems(values: any) {
54
- if (values.isArray) {
55
- return {
56
- $id: `#/definitions/${values.$name}/items`,
57
- $count: 0,
58
- $name: values.$name,
59
- $createTime: new Date().getTime(),
60
- title: values.title,
61
- type: getType(values.type),
62
- format: getFormat(values.type),
63
- properties: values.properties,
64
- }
65
- } else {
66
- return undefined;
67
- }
68
- }
69
-
70
- /** 删除 属性的 properties */
71
- export function delProperties(editProperties: IProperties, definitions: { [key: string]: IProperties }) {
72
- if (!editProperties.properties) return;
73
-
74
- Object.entries(editProperties.properties)
75
- .filter(e => {
76
- definitions[e[0]].$count--;
77
- if (definitions[e[0]].$count <= 0) delPropertiesOneself(definitions[e[0]].$name, definitions);
78
- })
79
-
80
- delete editProperties.properties;
81
- }
82
-
83
- /** 删除 属性 自己 */
84
- export function delPropertiesOneself($name: string, definitions: { [key: string]: IProperties }) {
85
- delProperties(definitions[$name], definitions);
86
- delete definitions[$name];
87
- }
88
-
1
+ import IProperties, { FormatType, PropertiesType } from "../DocumentsEditController/DocumentsEditControllerState/IProperties";
2
+
3
+ /** 初始化 form type */
4
+ export function initType(editProperties: IProperties) {
5
+ if (!!editProperties.items) editProperties = editProperties.items;
6
+ if (editProperties.format === 'date') return 'string|date';
7
+ if (editProperties.format === 'date-time') return 'string|date-time';
8
+ if (editProperties.format === "time") return 'string|time';
9
+ return editProperties.type;
10
+ }
11
+
12
+ /** form type => 属性的 type */
13
+ export function getType(v: string): PropertiesType {
14
+ if (v === 'string|date') return 'string';
15
+ if (v === 'string|time') return 'string';
16
+ if (v === 'string|date-time') return 'string';
17
+ return v as PropertiesType;
18
+ }
19
+
20
+ /** form type => 属性的 type 的中文 */
21
+ export function getTypeName(v: string) {
22
+ switch (v) {
23
+ case 'string|date':
24
+ return '日期(YYYY-MM-DD)'
25
+ case 'string|date-time':
26
+ return '日期-时间(YYYY-MM-DD hh:mm:ss)'
27
+ case 'string|time':
28
+ return '时间(hh:mm:ss)'
29
+ case 'string':
30
+ return '文本'
31
+ case 'object':
32
+ return '复合类型'
33
+ case 'integer':
34
+ return '数字(整数)'
35
+ case 'number':
36
+ return '数字(小数)'
37
+ case 'boolean':
38
+ return '布尔(是/否)'
39
+ default:
40
+ return '未知'
41
+ }
42
+ }
43
+
44
+ /** form type => 属性的 type */
45
+ export function getFormat(v: string): FormatType | undefined {
46
+ if (v === 'string|date') return 'date';
47
+ if (v === 'string|time') return 'time';
48
+ if (v === 'string|date-time') return 'date-time';
49
+ return undefined;
50
+ }
51
+
52
+ /** form => 属性的 Items */
53
+ export function getItems(values: any) {
54
+ if (values.isArray) {
55
+ return {
56
+ $id: `#/definitions/${values.$name}/items`,
57
+ $count: 0,
58
+ $name: values.$name,
59
+ $createTime: new Date().getTime(),
60
+ title: values.title,
61
+ type: getType(values.type),
62
+ format: getFormat(values.type),
63
+ properties: values.properties,
64
+ }
65
+ } else {
66
+ return undefined;
67
+ }
68
+ }
69
+
70
+ /** 删除 属性的 properties */
71
+ export function delProperties(editProperties: IProperties, definitions: { [key: string]: IProperties }) {
72
+ if (!editProperties.properties) return;
73
+
74
+ Object.entries(editProperties.properties)
75
+ .filter(e => {
76
+ definitions[e[0]].$count--;
77
+ if (definitions[e[0]].$count <= 0) delPropertiesOneself(definitions[e[0]].$name, definitions);
78
+ })
79
+
80
+ delete editProperties.properties;
81
+ }
82
+
83
+ /** 删除 属性 自己 */
84
+ export function delPropertiesOneself($name: string, definitions: { [key: string]: IProperties }) {
85
+ delProperties(definitions[$name], definitions);
86
+ delete definitions[$name];
87
+ }
88
+
@@ -1,239 +1,239 @@
1
- import React from 'react';
2
- import { v4 as uuidv4 } from 'uuid';
3
- import {
4
- Button,
5
- Drawer,
6
- Space,
7
- Form,
8
- Input,
9
- Radio,
10
- Switch,
11
- FormInstance,
12
- Select,
13
- Divider
14
- } from 'kts-components-antd-x4';
15
- import DocumentsEdit from '../../';
16
- import * as tools from '../../tools';
17
- import IProperties from '../../DocumentsEditController/DocumentsEditControllerState/IProperties';
18
-
19
- const { Option } = Select;
20
- const { TextArea } = Input;
21
-
22
- export default () => {
23
-
24
- const controller = DocumentsEdit.useDocumentsEditController();
25
-
26
- /** 当前正在处理的属性 */
27
- const current = controller.useMemo(s => s.propertyTableState.current, []);
28
-
29
- /** 只读模式 */
30
- const readOnly = controller.useMemo(s => s.readOnly, []);
31
-
32
- const [visible, setVisible] = React.useState(false);
33
-
34
- const onOpen = React.useCallback(() => { setVisible(true) }, []);
35
-
36
- const onClose = React.useCallback(() => { setVisible(false) }, []);
37
-
38
- const [form] = Form.useForm();
39
-
40
- /** 点击了提交 */
41
- const onSubmit = React.useCallback(async () => {
42
- try {
43
- const values = await form.validateFields();
44
- const name = uuidv4();
45
- const properties: IProperties = {
46
- $id: `#/definitions/${name}`,
47
- $count: 1,
48
- $name: name,
49
- $createTime: new Date().getTime(),
50
- title: values.title,
51
- type: values.isArray ? 'array' : tools.getType(values.type),
52
- format: values.isArray ? undefined : tools.getFormat(values.type),
53
- items: tools.getItems({ ...values, $name: name }),
54
- description: values.description,
55
- rules: values.isArray ? [{
56
- _index: 0,
57
- name: '数组容量校验(Min)',
58
- checkType: 'control',
59
- message: `数组长度不得小于${values.exclusiveMinItems ? "等于" : ""}${values.minItems}`,
60
- algorithm: 'array-0',
61
- minItems: values.minItems ? parseInt(values.minItems) : undefined,
62
- exclusiveMinItems: values.exclusiveMinItems,
63
- }, {
64
- _index: 0,
65
- name: '数组容量校验(Max)',
66
- checkType: 'control',
67
- message: `数组长度不得大于${values.exclusiveMaxItems ? "等于" : ""}${values.maxItems}`,
68
- algorithm: 'array-1',
69
- maxItems: values.maxItems ? parseInt(values.maxItems) : undefined,
70
- exclusiveMaxItems: values.exclusiveMaxItems,
71
- }] : undefined,
72
- }
73
- controller.addProperties({ current, properties, values });
74
- onClose();
75
- } catch (error) {
76
- }
77
- }, [current, controller])
78
-
79
- return (
80
- <>
81
- {readOnly === false && <Button onClick={onOpen} >新增字段</Button>}
82
- <Drawer
83
- title="新增字段"
84
- placement="right"
85
- width={500}
86
- onClose={onClose}
87
- visible={visible}
88
- destroyOnClose={true}
89
- footer={
90
- <Space>
91
- <Button onClick={onSubmit} type="primary" >确定</Button>
92
- <Button onClick={onClose} >取消</Button>
93
- </Space>
94
- }
95
- >
96
- <DrawerBody form={form} />
97
- </Drawer>
98
- </>
99
- );
100
- };
101
-
102
- const DrawerBody = (props: { form: FormInstance<any> }) => {
103
-
104
- const controller = DocumentsEdit.useDocumentsEditController();
105
-
106
- React.useEffect(() => () => { props.form.resetFields() }, []);
107
-
108
- // 是否数组
109
- const [isArray, setIsArray] = React.useState(false);
110
-
111
- const definitions = controller.useMemo(s => s.propertyTableState.current?.properties ?? {}, [])
112
-
113
- return (
114
- <Form
115
- labelCol={{ span: 8 }}
116
- wrapperCol={{ span: 16 }}
117
- form={props.form}
118
- layout="horizontal"
119
- >
120
- <Form.Item
121
- name="$name"
122
- label="字段名"
123
- rules={[
124
- { required: true, message: '请输入字段名' },
125
- { pattern: /^([a-z]|[A-Z]|_)\w*$/, message: '只能英文、数字、下划线,并且英文、下划线开头' },
126
- { max: 50, message: '只能输入50个字符' },
127
- {
128
- validator(_, value: string) {
129
- if (!value) return Promise.resolve();
130
- if (value.length > 20) return Promise.resolve();
131
- if (definitions[value]) {
132
- return Promise.reject(new Error('字段名已被使用'));
133
- } else {
134
- return Promise.resolve();
135
- }
136
- }
137
- }
138
- ]}
139
- >
140
- <Input placeholder="请输入字段名" />
141
- </Form.Item>
142
- <Form.Item
143
- name="title"
144
- label="显示名称"
145
- rules={[
146
- { required: true, message: '请输入显示名称' },
147
- { max: 20, message: '只能输入20个字符' },
148
- ]}
149
- >
150
- <Input placeholder="请输入显示名称" />
151
- </Form.Item>
152
- <Form.Item
153
- name="isArray"
154
- label="是否数组"
155
- initialValue={false}
156
- >
157
- <Radio.Group onChange={e => { setIsArray(e.target.value) }} >
158
- <Radio value={false}>单值</Radio>
159
- <Radio value={true}>数组</Radio>
160
- </Radio.Group>
161
- </Form.Item>
162
-
163
- {
164
- isArray && <>
165
- <Divider />
166
- <Form.Item
167
- name="minItems"
168
- label="最少项"
169
- rules={[
170
- { pattern: /(^[1-9]\d*$)|^[0]$/, message: '支持不超过20位的正整数' },
171
- { max: 20, message: '支持不超过20位的正整数' },
172
- ]}
173
- >
174
- <Input placeholder="请输入最少项" />
175
- </Form.Item>
176
- <Form.Item
177
- name="maxItems"
178
- label="最多项"
179
- rules={[
180
- { pattern: /(^[1-9]\d*$)|^[0]$/, message: '支持不超过20位的正整数' },
181
- { max: 20, message: '支持不超过20位的正整数' },
182
- ]}
183
- >
184
- <Input placeholder="请输入最多项" />
185
- </Form.Item>
186
- <Form.Item
187
- name="exclusiveMinItems"
188
- label="排除最少项"
189
- valuePropName="checked"
190
- >
191
- <Switch />
192
- </Form.Item>
193
- <Form.Item
194
- name="exclusiveMaxItems"
195
- label="排除最多项"
196
- valuePropName="checked"
197
- >
198
- <Switch />
199
- </Form.Item>
200
- <Divider />
201
- </>
202
- }
203
-
204
- <Form.Item
205
- name="required"
206
- label="是否必填"
207
- valuePropName="checked"
208
- initialValue={true}
209
- >
210
- <Switch />
211
- </Form.Item>
212
- <Form.Item
213
- name="type"
214
- label="类型"
215
- initialValue="string"
216
- >
217
- <Select>
218
- <Option key="00" value="string">{tools.getTypeName('string')}</Option>
219
- <Option key="01" value="string|date">{tools.getTypeName('string|date')}</Option>
220
- <Option key="02" value="string|time">{tools.getTypeName('string|time')}</Option>
221
- <Option key="03" value="string|date-time">{tools.getTypeName('string|date-time')}</Option>
222
- <Option key="04" value="boolean">{tools.getTypeName('boolean')}</Option>
223
- <Option key="05" value="integer">{tools.getTypeName('integer')}</Option>
224
- <Option key="06" value="number">{tools.getTypeName('number')}</Option>
225
- <Option key="07" value="object">{tools.getTypeName('object')}</Option>
226
- </Select>
227
- </Form.Item>
228
- <Form.Item
229
- name="description"
230
- label="描述"
231
- rules={[
232
- { max: 50, message: '只能输入50个字符' }
233
- ]}
234
- >
235
- <TextArea autoSize placeholder="请输入描述" />
236
- </Form.Item>
237
- </Form>
238
- )
1
+ import React from 'react';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import {
4
+ Button,
5
+ Drawer,
6
+ Space,
7
+ Form,
8
+ Input,
9
+ Radio,
10
+ Switch,
11
+ FormInstance,
12
+ Select,
13
+ Divider
14
+ } from 'kts-components-antd-x4';
15
+ import DocumentsEdit from '../../';
16
+ import * as tools from '../../tools';
17
+ import IProperties from '../../DocumentsEditController/DocumentsEditControllerState/IProperties';
18
+
19
+ const { Option } = Select;
20
+ const { TextArea } = Input;
21
+
22
+ export default () => {
23
+
24
+ const controller = DocumentsEdit.useDocumentsEditController();
25
+
26
+ /** 当前正在处理的属性 */
27
+ const current = controller.useMemo(s => s.propertyTableState.current, []);
28
+
29
+ /** 只读模式 */
30
+ const readOnly = controller.useMemo(s => s.readOnly, []);
31
+
32
+ const [visible, setVisible] = React.useState(false);
33
+
34
+ const onOpen = React.useCallback(() => { setVisible(true) }, []);
35
+
36
+ const onClose = React.useCallback(() => { setVisible(false) }, []);
37
+
38
+ const [form] = Form.useForm();
39
+
40
+ /** 点击了提交 */
41
+ const onSubmit = React.useCallback(async () => {
42
+ try {
43
+ const values = await form.validateFields();
44
+ const name = uuidv4();
45
+ const properties: IProperties = {
46
+ $id: `#/definitions/${name}`,
47
+ $count: 1,
48
+ $name: name,
49
+ $createTime: new Date().getTime(),
50
+ title: values.title,
51
+ type: values.isArray ? 'array' : tools.getType(values.type),
52
+ format: values.isArray ? undefined : tools.getFormat(values.type),
53
+ items: tools.getItems({ ...values, $name: name }),
54
+ description: values.description,
55
+ rules: values.isArray ? [{
56
+ _index: 0,
57
+ name: '数组容量校验(Min)',
58
+ checkType: 'control',
59
+ message: `数组长度不得小于${values.exclusiveMinItems ? "等于" : ""}${values.minItems}`,
60
+ algorithm: 'array-0',
61
+ minItems: values.minItems ? parseInt(values.minItems) : undefined,
62
+ exclusiveMinItems: values.exclusiveMinItems,
63
+ }, {
64
+ _index: 0,
65
+ name: '数组容量校验(Max)',
66
+ checkType: 'control',
67
+ message: `数组长度不得大于${values.exclusiveMaxItems ? "等于" : ""}${values.maxItems}`,
68
+ algorithm: 'array-1',
69
+ maxItems: values.maxItems ? parseInt(values.maxItems) : undefined,
70
+ exclusiveMaxItems: values.exclusiveMaxItems,
71
+ }] : undefined,
72
+ }
73
+ controller.addProperties({ current, properties, values });
74
+ onClose();
75
+ } catch (error) {
76
+ }
77
+ }, [current, controller])
78
+
79
+ return (
80
+ <>
81
+ {readOnly === false && <Button onClick={onOpen} >新增字段</Button>}
82
+ <Drawer
83
+ title="新增字段"
84
+ placement="right"
85
+ width={500}
86
+ onClose={onClose}
87
+ visible={visible}
88
+ destroyOnClose={true}
89
+ footer={
90
+ <Space>
91
+ <Button onClick={onSubmit} type="primary" >确定</Button>
92
+ <Button onClick={onClose} >取消</Button>
93
+ </Space>
94
+ }
95
+ >
96
+ <DrawerBody form={form} />
97
+ </Drawer>
98
+ </>
99
+ );
100
+ };
101
+
102
+ const DrawerBody = (props: { form: FormInstance<any> }) => {
103
+
104
+ const controller = DocumentsEdit.useDocumentsEditController();
105
+
106
+ React.useEffect(() => () => { props.form.resetFields() }, []);
107
+
108
+ // 是否数组
109
+ const [isArray, setIsArray] = React.useState(false);
110
+
111
+ const definitions = controller.useMemo(s => s.propertyTableState.current?.properties ?? {}, [])
112
+
113
+ return (
114
+ <Form
115
+ labelCol={{ span: 8 }}
116
+ wrapperCol={{ span: 16 }}
117
+ form={props.form}
118
+ layout="horizontal"
119
+ >
120
+ <Form.Item
121
+ name="$name"
122
+ label="字段名"
123
+ rules={[
124
+ { required: true, message: '请输入字段名' },
125
+ { pattern: /^([a-z]|[A-Z]|_)\w*$/, message: '只能英文、数字、下划线,并且英文、下划线开头' },
126
+ { max: 50, message: '只能输入50个字符' },
127
+ {
128
+ validator(_, value: string) {
129
+ if (!value) return Promise.resolve();
130
+ if (value.length > 20) return Promise.resolve();
131
+ if (definitions[value]) {
132
+ return Promise.reject(new Error('字段名已被使用'));
133
+ } else {
134
+ return Promise.resolve();
135
+ }
136
+ }
137
+ }
138
+ ]}
139
+ >
140
+ <Input placeholder="请输入字段名" />
141
+ </Form.Item>
142
+ <Form.Item
143
+ name="title"
144
+ label="显示名称"
145
+ rules={[
146
+ { required: true, message: '请输入显示名称' },
147
+ { max: 20, message: '只能输入20个字符' },
148
+ ]}
149
+ >
150
+ <Input placeholder="请输入显示名称" />
151
+ </Form.Item>
152
+ <Form.Item
153
+ name="isArray"
154
+ label="是否数组"
155
+ initialValue={false}
156
+ >
157
+ <Radio.Group onChange={e => { setIsArray(e.target.value) }} >
158
+ <Radio value={false}>单值</Radio>
159
+ <Radio value={true}>数组</Radio>
160
+ </Radio.Group>
161
+ </Form.Item>
162
+
163
+ {
164
+ isArray && <>
165
+ <Divider />
166
+ <Form.Item
167
+ name="minItems"
168
+ label="最少项"
169
+ rules={[
170
+ { pattern: /(^[1-9]\d*$)|^[0]$/, message: '支持不超过20位的正整数' },
171
+ { max: 20, message: '支持不超过20位的正整数' },
172
+ ]}
173
+ >
174
+ <Input placeholder="请输入最少项" />
175
+ </Form.Item>
176
+ <Form.Item
177
+ name="maxItems"
178
+ label="最多项"
179
+ rules={[
180
+ { pattern: /(^[1-9]\d*$)|^[0]$/, message: '支持不超过20位的正整数' },
181
+ { max: 20, message: '支持不超过20位的正整数' },
182
+ ]}
183
+ >
184
+ <Input placeholder="请输入最多项" />
185
+ </Form.Item>
186
+ <Form.Item
187
+ name="exclusiveMinItems"
188
+ label="排除最少项"
189
+ valuePropName="checked"
190
+ >
191
+ <Switch />
192
+ </Form.Item>
193
+ <Form.Item
194
+ name="exclusiveMaxItems"
195
+ label="排除最多项"
196
+ valuePropName="checked"
197
+ >
198
+ <Switch />
199
+ </Form.Item>
200
+ <Divider />
201
+ </>
202
+ }
203
+
204
+ <Form.Item
205
+ name="required"
206
+ label="是否必填"
207
+ valuePropName="checked"
208
+ initialValue={true}
209
+ >
210
+ <Switch />
211
+ </Form.Item>
212
+ <Form.Item
213
+ name="type"
214
+ label="类型"
215
+ initialValue="string"
216
+ >
217
+ <Select>
218
+ <Option key="00" value="string">{tools.getTypeName('string')}</Option>
219
+ <Option key="01" value="string|date">{tools.getTypeName('string|date')}</Option>
220
+ <Option key="02" value="string|time">{tools.getTypeName('string|time')}</Option>
221
+ <Option key="03" value="string|date-time">{tools.getTypeName('string|date-time')}</Option>
222
+ <Option key="04" value="boolean">{tools.getTypeName('boolean')}</Option>
223
+ <Option key="05" value="integer">{tools.getTypeName('integer')}</Option>
224
+ <Option key="06" value="number">{tools.getTypeName('number')}</Option>
225
+ <Option key="07" value="object">{tools.getTypeName('object')}</Option>
226
+ </Select>
227
+ </Form.Item>
228
+ <Form.Item
229
+ name="description"
230
+ label="描述"
231
+ rules={[
232
+ { max: 50, message: '只能输入50个字符' }
233
+ ]}
234
+ >
235
+ <TextArea autoSize placeholder="请输入描述" />
236
+ </Form.Item>
237
+ </Form>
238
+ )
239
239
  }