@yorha2b-lab/autodev 7.8.0 → 7.8.1
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/bin/bunker.js +1 -1
- package/package.json +1 -1
- package/src/constitution/inspector.js +1 -0
- package/src/units/striker.js +1 -1
- package/src/workshop/react/blueprint/molds/MySearchForm.hbs +1 -1
- package/src/workshop/react/blueprint/molds/handleBlock.hbs +3 -4
- package/src/workshop/react/blueprint/molds/stateBlock.hbs +2 -0
- package/src/workshop/react/extensions/useTableQuery.js +4 -14
- package/src/workshop/react/standardParts/DraggableContainer.js +5 -1
- package/src/workshop/react/standardParts/EditableCell.js +8 -4
- package/src/workshop/react/standardParts/MyBaseForm.js +3 -3
- package/src/workshop/react/standardParts/MyDescription.js +3 -3
- package/src/workshop/react/standardParts/MyForm.js +9 -5
- package/src/workshop/react/standardParts/MyModalForm.js +1 -1
- package/src/workshop/react/standardParts/MyModalTable.js +2 -2
- package/src/workshop/react/standardParts/MyPopoverTable.js +1 -0
- package/src/workshop/react/standardParts/MySearchForm.js +3 -3
- package/src/workshop/react/standardParts/MyTable.js +32 -28
- package/src/workshop/react/standardParts/index.js +64 -23
package/bin/bunker.js
CHANGED
|
@@ -53,7 +53,7 @@ program
|
|
|
53
53
|
]
|
|
54
54
|
}
|
|
55
55
|
Object.entries(outpost).forEach(([type, items]) => items.forEach(quartermaster[type]))
|
|
56
|
-
const bunkerCmd = chalk.yellow(`
|
|
56
|
+
const bunkerCmd = chalk.yellow(`"bunker": "bunker boot"`)
|
|
57
57
|
console.log(chalk.cyan(dialog.bunker.initComplete(bunkerCmd)))
|
|
58
58
|
})
|
|
59
59
|
|
package/package.json
CHANGED
package/src/units/striker.js
CHANGED
|
@@ -80,10 +80,10 @@ module.exports = {
|
|
|
80
80
|
pod042.success(spinner, dialog.pod042.assemblyComplete(fileName, (endTime - startTime) / 1000))
|
|
81
81
|
|
|
82
82
|
if (fs.existsSync(mission.input)) {
|
|
83
|
-
fs.unlinkSync(mission.input)
|
|
84
83
|
const cwdUtilsDir = path.join(process.cwd(), utilsDir)
|
|
85
84
|
if (!fs.existsSync(cwdUtilsDir)) fs.mkdirSync(cwdUtilsDir, { recursive: true })
|
|
86
85
|
fs.writeFileSync(path.join(cwdUtilsDir, 'menus.js'), `export const menus = ${contextStringify({ context: logistics.supporter.getExistingMenus(pagesDir), maxLength: 50 })}`)
|
|
86
|
+
fs.unlinkSync(mission.input)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<MySearchForm form={form}
|
|
1
|
+
<MySearchForm form={form} loading={loading} formItems={ {{formItems}} } initialParams={initialParams} initialValues={query} setSearch={setSearch} />
|
|
@@ -71,17 +71,16 @@ const showImg = (record, dataIndex) => {
|
|
|
71
71
|
|
|
72
72
|
{{/if}}
|
|
73
73
|
|
|
74
|
-
let fetching = false
|
|
75
74
|
const modalSubmit = async params => {
|
|
75
|
+
if (fetchingRef.current) return
|
|
76
76
|
const requestMap={
|
|
77
77
|
{{#each operations}}
|
|
78
78
|
{{this.action}}:()=> {{this.request}},
|
|
79
79
|
{{/each}}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
fetching = true
|
|
81
|
+
fetchingRef.current = true
|
|
83
82
|
const response = await requestMap[modal.type]?.()
|
|
84
|
-
|
|
83
|
+
fetchingRef.current = false
|
|
85
84
|
if({{{responseSuccess}}}){
|
|
86
85
|
setModal({ visible: false })
|
|
87
86
|
refresh()
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useRef, useState, useEffect, useCallback } from 'react'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const getColumnSchema = cols => cols.map(col => `${col.title}-${col.dataIndex}-${col.sortOrder}`).join('|')
|
|
4
|
+
|
|
5
|
+
export const useTableQuery = ({ api, cols = [], initialParams = {}, formatResponse }) => {
|
|
4
6
|
|
|
5
7
|
const [total, setTotal] = useState(0)
|
|
6
8
|
const [columns, setColumns] = useState(cols)
|
|
@@ -10,7 +12,6 @@ export const useTableQuery = ({ api, cols = [], initialParams = {}, formatRespon
|
|
|
10
12
|
|
|
11
13
|
const apiRef = useRef(api)
|
|
12
14
|
const fetchIdRef = useRef(0)
|
|
13
|
-
const lastFilterRef = useRef('')
|
|
14
15
|
const formatResponseRef = useRef(formatResponse)
|
|
15
16
|
|
|
16
17
|
useEffect(() => {
|
|
@@ -21,19 +22,8 @@ export const useTableQuery = ({ api, cols = [], initialParams = {}, formatRespon
|
|
|
21
22
|
formatResponseRef.current = formatResponse
|
|
22
23
|
}, [formatResponse])
|
|
23
24
|
|
|
24
|
-
const getColumnSchema = cols => cols.map(col => `${col.title}-${col.dataIndex}-${col.sortOrder}`).join('|')
|
|
25
|
-
|
|
26
25
|
const fetchData = useCallback(async () => {
|
|
27
26
|
if (!apiRef.current) return
|
|
28
|
-
|
|
29
|
-
if (isLocalPaging) {
|
|
30
|
-
const currentFilter = JSON.stringify(Object.fromEntries(Object.entries(search).filter(([k]) => !['pageNo', 'pageSize'].includes(k))))
|
|
31
|
-
if (lastFilterRef.current === currentFilter && dataSource.length > 0) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
lastFilterRef.current = currentFilter
|
|
35
|
-
}
|
|
36
|
-
|
|
37
27
|
setLoading(true)
|
|
38
28
|
const currentFetchId = ++fetchIdRef.current
|
|
39
29
|
try {
|
|
@@ -57,7 +47,7 @@ export const useTableQuery = ({ api, cols = [], initialParams = {}, formatRespon
|
|
|
57
47
|
setLoading(false)
|
|
58
48
|
}
|
|
59
49
|
}
|
|
60
|
-
}, [search
|
|
50
|
+
}, [search])
|
|
61
51
|
|
|
62
52
|
useEffect(() => {
|
|
63
53
|
fetchData()
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { TableContext } from './MyTable'
|
|
1
3
|
import { SortableContainer } from 'react-sortable-hoc'
|
|
2
4
|
|
|
3
5
|
const SortableBody = SortableContainer(props => <tbody {...props} />)
|
|
@@ -9,7 +11,9 @@ const arrayMoveImmutable = (array, oldIndex, newIndex) => {
|
|
|
9
11
|
return newArray
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export const DraggableContainer =
|
|
14
|
+
export const DraggableContainer = props => {
|
|
15
|
+
|
|
16
|
+
const { customSave, setDataSource, dataSourceRef } = useContext(TableContext)
|
|
13
17
|
|
|
14
18
|
const onSortEnd = ({ oldIndex, newIndex }) => {
|
|
15
19
|
if (oldIndex !== newIndex) {
|
|
@@ -12,11 +12,15 @@ export const EditableRow = ({ index, record, columns, draggable, ...props }) =>
|
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
if (record) {
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const extra = {}
|
|
16
|
+
columns.forEach(col => {
|
|
17
|
+
if (col.dataIndex in record && col.mode) {
|
|
18
|
+
extra[col.dataIndex] = record[col.dataIndex]?.toString()?.split(',') || []
|
|
19
|
+
}
|
|
20
|
+
})
|
|
17
21
|
form.setFieldsValue({ ...record, ...extra })
|
|
18
22
|
}
|
|
19
|
-
}, [record])
|
|
23
|
+
}, [record, columns, form])
|
|
20
24
|
|
|
21
25
|
return (
|
|
22
26
|
<Form form={form} component={false} onValuesChange={(changedValue, allValue) => props?.onValuesChange?.({ changedValue, allValue, form })}>
|
|
@@ -59,7 +63,7 @@ export const EditableCell = ({ mode, title, record, rowKey, editMode, editable,
|
|
|
59
63
|
try {
|
|
60
64
|
const values = await form.validateFields()
|
|
61
65
|
if (mode) {
|
|
62
|
-
values[dataIndex] = values[dataIndex]
|
|
66
|
+
values[dataIndex] = values[dataIndex]?.join(',')
|
|
63
67
|
}
|
|
64
68
|
if (!defaultEdit) {
|
|
65
69
|
toggleEdit()
|
|
@@ -10,7 +10,7 @@ const getValueFromEvent = e => {
|
|
|
10
10
|
return e?.fileList
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const renderFormContent = ({ item, prefixName = [] }) => {
|
|
13
|
+
const renderFormContent = ({ item, form, prefixName = [] }) => {
|
|
14
14
|
|
|
15
15
|
if (!item.name) {
|
|
16
16
|
return <span dangerouslySetInnerHTML={{ __html: item.value }} />
|
|
@@ -20,7 +20,7 @@ const renderFormContent = ({ item, prefixName = [] }) => {
|
|
|
20
20
|
|
|
21
21
|
const inputNode = (
|
|
22
22
|
<Form.Item noStyle name={namePath} rules={item.rules} dependencies={item.dependencies} initialValue={item.value} {...(['upload', 'ossUpload'].includes(item.type) ? { getValueFromEvent, valuePropName: 'fileList' } : { valuePropName: item.valuePropName })}>
|
|
23
|
-
{formNode({ item })}
|
|
23
|
+
{formNode({ item, form })}
|
|
24
24
|
</Form.Item>
|
|
25
25
|
)
|
|
26
26
|
|
|
@@ -60,7 +60,7 @@ export const MyBaseForm = ({ item, form }) => {
|
|
|
60
60
|
required={item.required ?? item.rules?.some(v => v.required)}
|
|
61
61
|
style={{ marginBottom: !item.name ? 0 : undefined, ...item.style }}
|
|
62
62
|
>
|
|
63
|
-
{item.render ? (typeof item.render === 'function' ? item.render(item, form) : item.render) : renderFormContent({ item })}
|
|
63
|
+
{item.render ? (typeof item.render === 'function' ? item.render(item, form) : item.render) : renderFormContent({ item, form })}
|
|
64
64
|
</Form.Item>
|
|
65
65
|
)
|
|
66
66
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Form, Descriptions } from 'antd'
|
|
2
2
|
import { MyBaseForm } from './MyBaseForm'
|
|
3
3
|
|
|
4
|
-
export const MyDescription = ({ title, column, layout = 'vertical', descriptions, form: externalForm, onValuesChange }) => {
|
|
4
|
+
export const MyDescription = ({ title, column, layout = 'vertical', labelStyle, contentStyle, descriptions, form: externalForm, onValuesChange }) => {
|
|
5
5
|
|
|
6
6
|
const [internalForm] = Form.useForm()
|
|
7
7
|
const form = externalForm || internalForm
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
10
|
<Form form={form} preserve={false} component={false} onValuesChange={onValuesChange}>
|
|
11
|
-
<Descriptions title={title} column={column} layout={layout}>
|
|
11
|
+
<Descriptions title={title} column={column} layout={layout} labelStyle={labelStyle} contentStyle={contentStyle}>
|
|
12
12
|
{descriptions.map(item => (
|
|
13
|
-
<Descriptions.Item key={item.label} label={item.name ? undefined : item.label}>
|
|
13
|
+
<Descriptions.Item key={item.label} span={item.span ?? 1} label={item.name ? undefined : item.label}>
|
|
14
14
|
{item.name ? <MyBaseForm item={item} form={form} /> : item.value}
|
|
15
15
|
</Descriptions.Item>))}
|
|
16
16
|
</Descriptions>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import dayjs from 'dayjs'
|
|
2
2
|
import { MyBaseForm } from './MyBaseForm'
|
|
3
3
|
import { flattenFormItems } from '../utils/utils'
|
|
4
|
-
import { useContext, createContext } from 'react'
|
|
5
4
|
import { Row, Col, Form, Button, Collapse } from 'antd'
|
|
5
|
+
import { useEffect, useContext, createContext } from 'react'
|
|
6
6
|
|
|
7
7
|
const FormContext = createContext({})
|
|
8
8
|
|
|
@@ -30,12 +30,16 @@ const LAYOUT_PROCESSORS = {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const ACTION_PROCESSORS = {
|
|
33
|
-
addonAfter: (item, { tableConfig, setModalTable, setSelectedTableRows }) => ({
|
|
33
|
+
addonAfter: (item, { customClick, tableConfig = {}, setModalTable, setSelectedTableRows }) => ({
|
|
34
34
|
props: {
|
|
35
35
|
addonAfter: (
|
|
36
36
|
<Button onClick={() => {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (typeof customClick === 'function') {
|
|
38
|
+
customClick()
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
setSelectedTableRows?.([])
|
|
42
|
+
setModalTable?.({ visible: true, title: `选择${item.label}`, ...tableConfig[item.name] })
|
|
39
43
|
}}>
|
|
40
44
|
{item.addonAfter}
|
|
41
45
|
</Button>
|
|
@@ -109,7 +113,7 @@ export const MyForm = ({ record, formItems = [], externalForm, labelCol, wrapper
|
|
|
109
113
|
initialData[key] = dayjs(value)
|
|
110
114
|
}
|
|
111
115
|
} else if ((config?.type === 'select' && config.mode) || config?.type === 'checkbox') {
|
|
112
|
-
initialData[key] = Array.isArray(value) ? value : value
|
|
116
|
+
initialData[key] = Array.isArray(value) ? value : value?.split(config.separator ?? ',')
|
|
113
117
|
} else {
|
|
114
118
|
initialData[key] = value
|
|
115
119
|
}
|
|
@@ -48,7 +48,7 @@ export const MyModalForm = ({ extra, width, title, layout, okText, options, foot
|
|
|
48
48
|
const tableRowSelection = useMemo(() => ({
|
|
49
49
|
selectedRowKeys: selectedTableRows.map(row => row[rowKey]),
|
|
50
50
|
onChange: (selectedRowKeys, selectedRows) => setSelectedTableRows(selectedRows),
|
|
51
|
-
}), [rowKey,
|
|
51
|
+
}), [rowKey, selectedTableRows])
|
|
52
52
|
|
|
53
53
|
const ctx = { form, record, pending, handleOk, handleCancel, setModal }
|
|
54
54
|
|
|
@@ -11,9 +11,9 @@ export const MyModalTable = ({ api, onOk, title, width, footer, visible, operate
|
|
|
11
11
|
|
|
12
12
|
const { total, loading, columns, dataSource, search, refresh, setLoading, setSearch, setDataSource } = useTableQuery({ api, cols: modalColumns, initialParams, formatResponse, isLocalPaging })
|
|
13
13
|
|
|
14
|
-
const handleSearch = values => setSearch({ ...
|
|
14
|
+
const handleSearch = values => setSearch(prev => ({ ...prev, ...values, pageNo: 1 }))
|
|
15
15
|
|
|
16
|
-
const handleTableChange = (pagination, filters, sorter) => setSearch({ ...
|
|
16
|
+
const handleTableChange = (pagination, filters, sorter) => setSearch(prev => ({ ...prev, pageNo: pagination.current, pageSize: pagination.pageSize, orderBy: sorter.column ? sorter.field : undefined }))
|
|
17
17
|
|
|
18
18
|
const handleOk = async () => {
|
|
19
19
|
if (onOk) {
|
|
@@ -4,7 +4,7 @@ import { useMemo, useState, useEffect } from 'react'
|
|
|
4
4
|
import { Row, Col, Form, Button, Space } from 'antd'
|
|
5
5
|
import { SearchOutlined, RedoOutlined } from '@ant-design/icons'
|
|
6
6
|
|
|
7
|
-
export const MySearchForm = ({ form, extra,
|
|
7
|
+
export const MySearchForm = ({ form, extra, options, loading, labelCol, setSearch, formItems, showLimit = 7, initialValues = {}, initialParams = {}, customReset, customFinish, renderAction, onValuesChange, syncUrlParams = true, defaultPageSize = 10 }) => {
|
|
8
8
|
|
|
9
9
|
const [limit, setLimit] = useState(showLimit)
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ export const MySearchForm = ({ form, extra, search, options, loading, labelCol,
|
|
|
26
26
|
if (customReset) {
|
|
27
27
|
customReset()
|
|
28
28
|
} else {
|
|
29
|
-
setSearch({ pageNo: 1, pageSize:
|
|
29
|
+
setSearch(prev => ({ pageNo: 1, pageSize: prev.pageSize ?? defaultPageSize, ...initialParams }))
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -54,7 +54,7 @@ export const MySearchForm = ({ form, extra, search, options, loading, labelCol,
|
|
|
54
54
|
if (customFinish) {
|
|
55
55
|
customFinish(formattedValues)
|
|
56
56
|
} else {
|
|
57
|
-
setSearch({ ...
|
|
57
|
+
setSearch(prev => ({ ...prev, ...formattedValues, pageNo: 1 }))
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Table, Space } from 'antd'
|
|
2
2
|
import { DraggableContainer } from './DraggableContainer'
|
|
3
3
|
import { EditableRow, EditableCell } from './EditableCell'
|
|
4
|
-
import { useRef, useMemo, useEffect, useCallback } from 'react'
|
|
4
|
+
import { useRef, useMemo, useEffect, useCallback, createContext } from 'react'
|
|
5
|
+
|
|
6
|
+
export const TableContext = createContext(null)
|
|
5
7
|
|
|
6
8
|
export const MyTable = ({ size, query, total, search, options, autoScroll, onChange, editingKey, setSearch, pagination, editRender = {}, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', editMode = 'cellEdit', loading = false, dataSource = [], draggable = false, scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
|
|
7
9
|
|
|
@@ -33,10 +35,10 @@ export const MyTable = ({ size, query, total, search, options, autoScroll, onCha
|
|
|
33
35
|
c.body.cell = EditableCell
|
|
34
36
|
}
|
|
35
37
|
if (draggable) {
|
|
36
|
-
c.body.wrapper =
|
|
38
|
+
c.body.wrapper = DraggableContainer
|
|
37
39
|
}
|
|
38
40
|
return c
|
|
39
|
-
}, [isEditable, draggable
|
|
41
|
+
}, [isEditable, draggable])
|
|
40
42
|
|
|
41
43
|
const mergedColumns = useMemo(() => {
|
|
42
44
|
return columns.map(col => {
|
|
@@ -48,7 +50,7 @@ export const MyTable = ({ size, query, total, search, options, autoScroll, onCha
|
|
|
48
50
|
currentCol = {
|
|
49
51
|
...currentCol,
|
|
50
52
|
filterSearch: true,
|
|
51
|
-
onFilter: (value, record) => col.
|
|
53
|
+
...(col.remote ? {} : { onFilter: (value, record) => col.customFilter({ value, record, dataIndex: col.dataIndex }) }),
|
|
52
54
|
filterDropdown: ({ close, confirm, selectedKeys, clearFilters, setSelectedKeys }) => (
|
|
53
55
|
<Space direction='vertical' style={{ padding: 12 }}>
|
|
54
56
|
{col.customFilterDropdown({ dataIndex: col.dataIndex, selectedKeys, setSelectedKeys })}
|
|
@@ -89,7 +91,7 @@ export const MyTable = ({ size, query, total, search, options, autoScroll, onCha
|
|
|
89
91
|
}),
|
|
90
92
|
}
|
|
91
93
|
})
|
|
92
|
-
}, [columns, options,
|
|
94
|
+
}, [rowKey, columns, options, editMode, setSearch, editingKey, editRender, renderAction, handleSave])
|
|
93
95
|
|
|
94
96
|
const paginationConfig = useMemo(() => {
|
|
95
97
|
|
|
@@ -100,8 +102,8 @@ export const MyTable = ({ size, query, total, search, options, autoScroll, onCha
|
|
|
100
102
|
showSizeChanger: true,
|
|
101
103
|
showTotal: (total) => `共 ${total} 条`,
|
|
102
104
|
...(isLocalPaging ? {} : {
|
|
103
|
-
current: Number(search?.pageNo),
|
|
104
|
-
pageSize: Number(search?.pageSize),
|
|
105
|
+
current: Number(search?.pageNo ?? 1),
|
|
106
|
+
pageSize: Number(search?.pageSize ?? 10),
|
|
105
107
|
}),
|
|
106
108
|
...(typeof pagination === 'object' ? pagination : {})
|
|
107
109
|
}
|
|
@@ -126,27 +128,29 @@ export const MyTable = ({ size, query, total, search, options, autoScroll, onCha
|
|
|
126
128
|
|
|
127
129
|
return (
|
|
128
130
|
<div ref={tableRef}>
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
131
|
+
<TableContext.Provider value={{ customSave, setDataSource, dataSourceRef }}>
|
|
132
|
+
<Table
|
|
133
|
+
{...restProps}
|
|
134
|
+
rowKey={rowKey}
|
|
135
|
+
scroll={scroll}
|
|
136
|
+
loading={loading}
|
|
137
|
+
onChange={onChange}
|
|
138
|
+
columns={mergedColumns}
|
|
139
|
+
dataSource={dataSource}
|
|
140
|
+
size={size ?? 'middle'}
|
|
141
|
+
components={components}
|
|
142
|
+
rowSelection={rowSelection}
|
|
143
|
+
pagination={paginationConfig}
|
|
144
|
+
onRow={(record, index) => ({ record, index, draggable, columns: mergedColumns, ...(typeof lineFormChange === 'function' ? { onValuesChange: lineFormChange } : {}) })}
|
|
145
|
+
rowClassName={(record, index) => {
|
|
146
|
+
const externalClass = typeof rowClassName === 'function' ? rowClassName(record, index) : rowClassName
|
|
147
|
+
const classes = [externalClass]
|
|
148
|
+
if (isEditable) classes.push('editable-row')
|
|
149
|
+
if (autoScroll && query?.rowIndex === index) classes.push('search-highlight-row')
|
|
150
|
+
return classes.filter(Boolean).join(' ')
|
|
151
|
+
}}
|
|
152
|
+
/>
|
|
153
|
+
</TableContext.Provider>
|
|
150
154
|
</div>
|
|
151
155
|
)
|
|
152
156
|
}
|
|
@@ -1,17 +1,68 @@
|
|
|
1
|
+
import { Fragment } from 'react'
|
|
1
2
|
import { MyBaseForm } from './MyBaseForm'
|
|
2
3
|
import { AliyunOSSUpload } from './AliyunOSSUpload'
|
|
3
|
-
import { Tree,
|
|
4
|
+
import { Tree, Radio, Input, Upload, Select, Cascader, Checkbox, DatePicker, InputNumber, TreeSelect, AutoComplete } from 'antd'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const componentDict = {
|
|
7
|
+
date: { Component: DatePicker },
|
|
8
|
+
number: { Component: InputNumber },
|
|
9
|
+
ossUpload: { Component: AliyunOSSUpload },
|
|
10
|
+
default: {
|
|
11
|
+
Component: Input,
|
|
12
|
+
props: () => ({ allowClear: true })
|
|
13
|
+
},
|
|
14
|
+
daterange: {
|
|
15
|
+
Component: DatePicker.RangePicker,
|
|
16
|
+
props: () => ({ placeholder: undefined })
|
|
17
|
+
},
|
|
18
|
+
textarea: {
|
|
19
|
+
Component: Input.TextArea,
|
|
20
|
+
props: () => ({ autoSize: { minRows: 4 } })
|
|
21
|
+
},
|
|
22
|
+
upload: {
|
|
23
|
+
Component: Upload,
|
|
24
|
+
props: ({ item }) => ({ ...item.uploadProps })
|
|
25
|
+
},
|
|
26
|
+
auto: {
|
|
27
|
+
Component: AutoComplete,
|
|
28
|
+
props: ({ item }) => ({ options: item.options })
|
|
29
|
+
},
|
|
30
|
+
checkbox: {
|
|
31
|
+
Component: Checkbox.Group,
|
|
32
|
+
props: ({ item }) => ({ options: item.options })
|
|
33
|
+
},
|
|
34
|
+
radio: {
|
|
35
|
+
Component: Radio.Group,
|
|
36
|
+
props: ({ item }) => ({ options: item.options })
|
|
37
|
+
},
|
|
38
|
+
treeSelect: {
|
|
39
|
+
Component: TreeSelect,
|
|
40
|
+
props: ({ item }) => ({ treeData: item.options })
|
|
41
|
+
},
|
|
42
|
+
tree: {
|
|
43
|
+
Component: Tree,
|
|
44
|
+
props: ({ item }) => ({ checkable: true, treeData: item.options })
|
|
45
|
+
},
|
|
46
|
+
cascader: {
|
|
47
|
+
Component: Cascader,
|
|
48
|
+
props: ({ item }) => ({ allowClear: true, showSearch: true, options: item.options })
|
|
49
|
+
},
|
|
50
|
+
select: {
|
|
51
|
+
Component: Select,
|
|
52
|
+
props: ({ item }) => ({ allowClear: true, showSearch: true, mode: item.mode, options: item.options, optionFilterProp: 'label' })
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const formNode = ({ item, form }) => {
|
|
6
57
|
|
|
7
58
|
if (item.type === 'group' && Array.isArray(item.groups)) {
|
|
8
59
|
return (
|
|
9
60
|
<Input.Group compact style={{ width: item.width ?? '100%', display: 'flex', ...item.style }}>
|
|
10
61
|
{item.groups.map((subItem, ind) => (
|
|
11
|
-
<
|
|
12
|
-
<div style={{ flex: 1, minWidth: 0, marginRight: 8 }}><MyBaseForm item={subItem}
|
|
62
|
+
<Fragment key={subItem.name}>
|
|
63
|
+
<div style={{ flex: 1, minWidth: 0, marginRight: 8 }}><MyBaseForm item={subItem} form={form} /></div>
|
|
13
64
|
{ind < item.groups.length - 1 && <span style={{ color: '#888', whiteSpace: 'nowrap', marginRight: 8 }}>{item.separator}</span>}
|
|
14
|
-
</
|
|
65
|
+
</Fragment>
|
|
15
66
|
))}
|
|
16
67
|
</Input.Group>
|
|
17
68
|
)
|
|
@@ -21,25 +72,15 @@ export const formNode = ({ item }) => {
|
|
|
21
72
|
disabled: item.readOnly,
|
|
22
73
|
style: { width: item.width ?? '100%' },
|
|
23
74
|
placeholder: item.placeholder ?? `请${['select', 'cascader', 'date'].includes(item.type) ? '选择' : '输入'}`,
|
|
24
|
-
...item.props
|
|
25
75
|
}
|
|
26
76
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
default: <Input allowClear {...commonProps} />,
|
|
31
|
-
ossUpload: <AliyunOSSUpload {...commonProps} />,
|
|
32
|
-
auto: <AutoComplete options={item.options} {...commonProps} />,
|
|
33
|
-
radio: <Radio.Group options={item.options} {...commonProps} />,
|
|
34
|
-
tree: <Tree checkable treeData={item.options} {...commonProps} />,
|
|
35
|
-
treeSelect: <TreeSelect treeData={item.options} {...commonProps} />,
|
|
36
|
-
checkbox: <Checkbox.Group options={item.options} {...commonProps} />,
|
|
37
|
-
textarea: <Input.TextArea autoSize={{ minRows: 4 }} {...commonProps} />,
|
|
38
|
-
daterange: <DatePicker.RangePicker {...commonProps} placeholder={undefined} />,
|
|
39
|
-
cascader: <Cascader showSearch allowClear options={item.options} {...commonProps} />,
|
|
40
|
-
upload: <Upload {...item.uploadProps} {...commonProps}>{item.content ?? '上传文件'}</Upload>,
|
|
41
|
-
select: <Select allowClear showSearch mode={item.mode} options={item.options} optionFilterProp='label' {...commonProps} />,
|
|
42
|
-
}
|
|
77
|
+
const config = componentDict[item.type] ?? componentDict.default
|
|
78
|
+
const Component = config.Component
|
|
79
|
+
const specialProps = config.props?.({ item, form }) ?? {}
|
|
43
80
|
|
|
44
|
-
return
|
|
81
|
+
return (
|
|
82
|
+
<Component {...commonProps} {...specialProps} {...item.props}>
|
|
83
|
+
{item.type === 'upload' && (item.content ?? '上传文件')}
|
|
84
|
+
</Component>
|
|
85
|
+
)
|
|
45
86
|
}
|