@yorha2b-lab/autodev 7.7.1 → 7.7.2
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 +1 -1
- package/src/workshop/react/briefings/raider.js +1 -0
- package/src/workshop/react/standardParts/MyBaseForm.js +1 -1
- package/src/workshop/react/standardParts/MyForm.js +97 -0
- package/src/workshop/react/standardParts/MyModal.js +31 -0
- package/src/workshop/react/standardParts/MyModalForm.js +11 -96
package/package.json
CHANGED
|
@@ -48,6 +48,7 @@ module.exports = `
|
|
|
48
48
|
- daterange: name 必须设为 '字段英文名start,字段英文名end'。
|
|
49
49
|
- 增强属性:
|
|
50
50
|
- 文字单位: 若项末尾有单位(如 元/kg),必须存入 unit 属性。
|
|
51
|
+
- 说明文字: 若表单项下方有灰色说明文字如(必填,不能超过多少字),必须存入help属性。
|
|
51
52
|
- 尾操作: 若项末尾有操作按钮(如 选择、编辑 等操作),必须存入 {renderAction:true,addonAfter:'尾操作名'} 属性。
|
|
52
53
|
- 必填校验: 若图片中 label 前有红色星号,必须加入 rules:[{required:true,message:'xxx不能为空'}]。
|
|
53
54
|
|
|
@@ -95,10 +95,10 @@ export const MyBaseForm = ({ item, form }) => {
|
|
|
95
95
|
// 💡 单兵模式:标准 Form.Item 构筑
|
|
96
96
|
<Form.Item
|
|
97
97
|
label={item.label}
|
|
98
|
-
extra={item.extra}
|
|
99
98
|
tooltip={item.tooltip}
|
|
100
99
|
labelCol={item.labelCol}
|
|
101
100
|
wrapperCol={item.wrapperCol}
|
|
101
|
+
extra={item.extra || item.help}
|
|
102
102
|
required={item.required ?? item.rules?.some(v => v.required)}
|
|
103
103
|
style={{ marginBottom: !item.name ? 0 : undefined, ...item.style }}
|
|
104
104
|
>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { MyBaseForm } from './MyBaseForm'
|
|
2
|
+
import { Row, Col, Form, Button, Collapse } from 'antd'
|
|
3
|
+
|
|
4
|
+
const LAYOUT_PROCESSORS = {
|
|
5
|
+
section: ({ item, renderCore }) => (
|
|
6
|
+
<Col span={item.span ?? 24} style={{ marginBottom: 16 }}>
|
|
7
|
+
<div style={{ fontWeight: 'bold', marginBottom: 12, borderLeft: '4px solid #1890ff', paddingLeft: 8 }}>{item.title}</div>
|
|
8
|
+
<Row gutter={[24, 0]}>
|
|
9
|
+
{renderCore(item.childItems || [])}
|
|
10
|
+
</Row>
|
|
11
|
+
</Col>
|
|
12
|
+
),
|
|
13
|
+
collapse: ({ item, renderCore }) => (
|
|
14
|
+
<Col span={item.span ?? 24} style={{ marginBottom: 16 }}>
|
|
15
|
+
<Collapse defaultActiveKey={['1']}>
|
|
16
|
+
<Collapse.Panel key='1' header={<span style={{ fontWeight: 'bold' }}>{item.title}</span>}>
|
|
17
|
+
<Row gutter={[24, 0]}>
|
|
18
|
+
{renderCore(item.childItems || [])}
|
|
19
|
+
</Row>
|
|
20
|
+
</Collapse.Panel>
|
|
21
|
+
</Collapse>
|
|
22
|
+
</Col>
|
|
23
|
+
),
|
|
24
|
+
default: ({ item, renderCore }) => <Row gutter={[24, 0]}>{renderCore(item.childItems || [])}</Row>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 定义“零部件增强协议”处理器,以后加任何新功能,只需要在这个对象里加一个 Key,不需要动主逻辑!
|
|
28
|
+
const ACTION_PROCESSORS = {
|
|
29
|
+
// 处理尾操作按钮
|
|
30
|
+
addonAfter: (item, { tableConfig, setModalTable, setSelectedTableRows }) => ({
|
|
31
|
+
props: {
|
|
32
|
+
addonAfter: (
|
|
33
|
+
<Button onClick={() => {
|
|
34
|
+
setSelectedTableRows([])
|
|
35
|
+
setModalTable({ visible: true, title: `选择${item.label}`, ...tableConfig[item.name] })
|
|
36
|
+
}}>
|
|
37
|
+
{item.addonAfter}
|
|
38
|
+
</Button>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
// 以后想加个“前缀图标”?直接加在这里:
|
|
43
|
+
// prefix: (item) => ({ props: { prefix: <Icon type={item.prefix} /> } }),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const FormRenderer = ({ form, formItems, tableProps = {} }) => {
|
|
47
|
+
|
|
48
|
+
// 定义核心渲染逻辑,供递归使用
|
|
49
|
+
const renderCore = items => <FormRenderer form={form} formItems={items} tableProps={tableProps} />
|
|
50
|
+
|
|
51
|
+
// 定义单项动作注入逻辑
|
|
52
|
+
const getRenderItemProps = item => {
|
|
53
|
+
if (!item.renderAction) return {}
|
|
54
|
+
const props = {}
|
|
55
|
+
Object.keys(ACTION_PROCESSORS).forEach(key => {
|
|
56
|
+
if (item[key]) {
|
|
57
|
+
Object.assign(props, ACTION_PROCESSORS[key](item, tableProps))
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
return props
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return formItems.map((item, index) => {
|
|
64
|
+
// 情况 A:发现容器型零件 (含有 layoutType)
|
|
65
|
+
if (item.layoutType && LAYOUT_PROCESSORS[item.layoutType]) {
|
|
66
|
+
const Layout = LAYOUT_PROCESSORS[item.layoutType] ?? LAYOUT_PROCESSORS.default
|
|
67
|
+
return (
|
|
68
|
+
<Layout
|
|
69
|
+
item={item}
|
|
70
|
+
key={item.name || index}
|
|
71
|
+
renderCore={renderCore} // 注入渲染能力,让 Layout 自己去 Map
|
|
72
|
+
/>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 情况 B:标准作战零件
|
|
77
|
+
return (
|
|
78
|
+
<Col span={item.span ?? 6} key={item.name || index}>
|
|
79
|
+
<MyBaseForm item={{ ...item, ...getRenderItemProps(item) }} form={form} />
|
|
80
|
+
</Col>
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const MyForm = ({ formItems, externalForm, labelCol, wrapperCol, tableProps, layout = 'horizontal', onValuesChange }) => {
|
|
86
|
+
|
|
87
|
+
const [internalForm] = Form.useForm()
|
|
88
|
+
const form = externalForm || internalForm
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Form form={form} layout={layout} preserve={false} labelCol={labelCol} wrapperCol={wrapperCol} onValuesChange={onValuesChange}>
|
|
92
|
+
<Row gutter={[24, 0]}>
|
|
93
|
+
<FormRenderer form={form} formItems={formItems} tableProps={tableProps} />
|
|
94
|
+
</Row>
|
|
95
|
+
</Form>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Modal } from 'antd'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
export const MyModal = ({ width, title, okText, footer, record, visible, children, handleOk, setModal, cancelText, okButtonProps }) => {
|
|
5
|
+
|
|
6
|
+
const [pending, setPending] = useState(false)
|
|
7
|
+
|
|
8
|
+
const handleCancel = () => setModal({ visible: false })
|
|
9
|
+
|
|
10
|
+
const ctx = { record, pending, handleOk, handleCancel, setModal, setPending }
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Modal
|
|
14
|
+
centered
|
|
15
|
+
title={title}
|
|
16
|
+
width={width}
|
|
17
|
+
open={visible}
|
|
18
|
+
destroyOnClose
|
|
19
|
+
okText={okText}
|
|
20
|
+
onOk={handleOk}
|
|
21
|
+
cancelText={cancelText}
|
|
22
|
+
onCancel={handleCancel}
|
|
23
|
+
confirmLoading={pending}
|
|
24
|
+
okButtonProps={okButtonProps}
|
|
25
|
+
footer={typeof footer === 'function' ? footer(ctx) : footer}
|
|
26
|
+
bodyStyle={{ paddingBottom: 0, maxHeight: '80vh', overflowY: 'auto' }}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</Modal>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -1,97 +1,8 @@
|
|
|
1
1
|
import dayjs from 'dayjs'
|
|
2
|
-
import {
|
|
2
|
+
import { MyForm } from './MyForm'
|
|
3
|
+
import { Form, Modal } from 'antd'
|
|
3
4
|
import { MyModalTable } from './MyModalTable'
|
|
4
5
|
import { useRef, useMemo, useState, useEffect } from 'react'
|
|
5
|
-
import { Row, Col, Form, Modal, Button, Collapse } from 'antd'
|
|
6
|
-
|
|
7
|
-
const LAYOUT_PROCESSORS = {
|
|
8
|
-
section: ({ item, renderCore }) => (
|
|
9
|
-
<Col span={item.span ?? 24} style={{ marginBottom: 16 }}>
|
|
10
|
-
<div style={{ fontWeight: 'bold', marginBottom: 12, borderLeft: '4px solid #1890ff', paddingLeft: 8 }}>{item.title}</div>
|
|
11
|
-
<Row gutter={[24, 0]}>
|
|
12
|
-
{renderCore(item.childItems || [])}
|
|
13
|
-
</Row>
|
|
14
|
-
</Col>
|
|
15
|
-
),
|
|
16
|
-
collapse: ({ item, renderCore }) => (
|
|
17
|
-
<Col span={item.span ?? 24} style={{ marginBottom: 16 }}>
|
|
18
|
-
<Collapse defaultActiveKey={['1']}>
|
|
19
|
-
<Collapse.Panel key='1' header={<span style={{ fontWeight: 'bold' }}>{item.title}</span>}>
|
|
20
|
-
<Row gutter={[24, 0]}>
|
|
21
|
-
{renderCore(item.childItems || [])}
|
|
22
|
-
</Row>
|
|
23
|
-
</Collapse.Panel>
|
|
24
|
-
</Collapse>
|
|
25
|
-
</Col>
|
|
26
|
-
),
|
|
27
|
-
default: ({ item, renderCore }) => <Row gutter={[24, 0]}>{renderCore(item.childItems || [])}</Row>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 定义“零部件增强协议”处理器,以后加任何新功能,只需要在这个对象里加一个 Key,不需要动主逻辑!
|
|
31
|
-
const ACTION_PROCESSORS = {
|
|
32
|
-
// 处理尾操作按钮
|
|
33
|
-
addonAfter: (item, { tableConfig, setModalTable, setSelectedTableRows }) => ({
|
|
34
|
-
props: {
|
|
35
|
-
addonAfter: (
|
|
36
|
-
<Button onClick={() => {
|
|
37
|
-
setSelectedTableRows([])
|
|
38
|
-
setModalTable({ visible: true, title: `选择${item.label}`, ...tableConfig[item.name] })
|
|
39
|
-
}}>
|
|
40
|
-
{item.addonAfter}
|
|
41
|
-
</Button>
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
}),
|
|
45
|
-
// 以后想加个“前缀图标”?直接加在这里:
|
|
46
|
-
// prefix: (item) => ({ props: { prefix: <Icon type={item.prefix} /> } }),
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const FormRenderer = ({ form, formItems, tableConfig, setModalTable, setSelectedTableRows }) => {
|
|
50
|
-
|
|
51
|
-
// 定义核心渲染逻辑,供递归使用
|
|
52
|
-
const renderCore = items => (
|
|
53
|
-
<FormRenderer
|
|
54
|
-
form={form}
|
|
55
|
-
formItems={items}
|
|
56
|
-
tableConfig={tableConfig}
|
|
57
|
-
setModalTable={setModalTable}
|
|
58
|
-
setSelectedTableRows={setSelectedTableRows}
|
|
59
|
-
/>
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
// 定义单项动作注入逻辑
|
|
63
|
-
const getRenderItemProps = item => {
|
|
64
|
-
if (!item.renderAction) return {}
|
|
65
|
-
const props = {}
|
|
66
|
-
Object.keys(ACTION_PROCESSORS).forEach(key => {
|
|
67
|
-
if (item[key]) {
|
|
68
|
-
Object.assign(props, ACTION_PROCESSORS[key](item, { tableConfig, setModalTable, setSelectedTableRows }))
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
return props
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return formItems.map((item, index) => {
|
|
75
|
-
// 情况 A:发现容器型零件 (含有 layoutType)
|
|
76
|
-
if (item.layoutType && LAYOUT_PROCESSORS[item.layoutType]) {
|
|
77
|
-
const Layout = LAYOUT_PROCESSORS[item.layoutType] ?? LAYOUT_PROCESSORS.default
|
|
78
|
-
return (
|
|
79
|
-
<Layout
|
|
80
|
-
item={item}
|
|
81
|
-
key={item.name || index}
|
|
82
|
-
renderCore={renderCore} // 注入渲染能力,让 Layout 自己去 Map
|
|
83
|
-
/>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 情况 B:标准作战零件
|
|
88
|
-
return (
|
|
89
|
-
<Col span={item.span ?? 6} key={item.name || index}>
|
|
90
|
-
<MyBaseForm item={{ ...item, ...getRenderItemProps(item) }} form={form} />
|
|
91
|
-
</Col>
|
|
92
|
-
)
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
6
|
|
|
96
7
|
const flattenFormItems = items => {
|
|
97
8
|
if (!Array.isArray(items)) return []
|
|
@@ -242,11 +153,15 @@ export const MyModalForm = ({ extra, width, title, layout, okText, options, foot
|
|
|
242
153
|
>
|
|
243
154
|
{modalTable.visible && <MyModalTable rowKey={rowKey} {...modalTable} rowSelection={tableRowSelection} onOk={modalTableOk} setModal={setModalTable} />}
|
|
244
155
|
{extra?.header?.(ctx)}
|
|
245
|
-
<
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
156
|
+
<MyForm
|
|
157
|
+
layout={layout}
|
|
158
|
+
externalForm={form}
|
|
159
|
+
labelCol={labelCol}
|
|
160
|
+
formItems={formItems}
|
|
161
|
+
wrapperCol={wrapperCol}
|
|
162
|
+
tableProps={{ tableConfig, setModalTable, setSelectedTableRows }}
|
|
163
|
+
onValuesChange={(changed, all) => onValuesChange?.({ changed, all, form, record })}
|
|
164
|
+
/>
|
|
250
165
|
{extra?.footer?.(ctx)}
|
|
251
166
|
</Modal>
|
|
252
167
|
)
|