@yorha2b-lab/autodev 7.7.1 → 7.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "7.7.1",
3
+ "version": "7.7.3",
4
4
  "description": "基于 AI 视觉与语义协议的前端 (React+Antd) 代码构筑与旧系统重构引擎",
5
5
  "bin": {
6
6
  "bunker": "bin/bunker.js"
@@ -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
 
@@ -0,0 +1,21 @@
1
+ import { SortableContainer } from 'react-sortable-hoc'
2
+
3
+ const SortableBody = SortableContainer(props => <tbody {...props} />)
4
+
5
+ const arrayMoveImmutable = (array, oldIndex, newIndex) => {
6
+ const newArray = [...array]
7
+ const [item] = newArray.splice(oldIndex, 1)
8
+ newArray.splice(newIndex, 0, item)
9
+ return newArray
10
+ }
11
+
12
+ export const DraggableContainer = ({ props, setDataSource }) => {
13
+
14
+ const onSortEnd = ({ oldIndex, newIndex }) => {
15
+ if (oldIndex !== newIndex) {
16
+ setDataSource(prev => arrayMoveImmutable(prev.slice(), oldIndex, newIndex))
17
+ }
18
+ }
19
+
20
+ return <SortableBody useDragHandle disableAutoscroll helperClass='row-dragging' onSortEnd={onSortEnd} {...props} />
21
+ }
@@ -1,3 +1,4 @@
1
+ import { SortableElement } from 'react-sortable-hoc'
1
2
  import { Form, Input, InputNumber, Select, Checkbox } from 'antd'
2
3
  import React, { useRef, useState, useEffect, useContext } from 'react'
3
4
 
@@ -7,6 +8,8 @@ import React, { useRef, useState, useEffect, useContext } from 'react'
7
8
  */
8
9
  const EditableContext = React.createContext(null)
9
10
 
11
+ const SortableItem = SortableElement((props) => <tr {...props} />)
12
+
10
13
  /**
11
14
  * @component EditableRow
12
15
  * @description [地堡战术行容器] 每一行都是一个独立的逻辑闭环。
@@ -33,7 +36,7 @@ export const EditableRow = ({ index, record, ...props }) => {
33
36
  return (
34
37
  <Form form={form} component={false} onValuesChange={(changedValue, allValue) => props?.onValuesChange?.({ changedValue, allValue, form })}>
35
38
  <EditableContext.Provider value={form}>
36
- <tr {...props} />
39
+ <SortableItem index={index} {...props} />
37
40
  </EditableContext.Provider>
38
41
  </Form>
39
42
  )
@@ -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} scrollToFirstError={{ behavior: 'smooth', block: 'center' }}>
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 { MyBaseForm } from './MyBaseForm'
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
- <Form form={form} layout={layout} preserve={false} labelCol={labelCol} wrapperCol={wrapperCol} onValuesChange={(changed, all) => onValuesChange?.({ changed, all, form, record })}>
246
- <Row gutter={[24, 0]}>
247
- <FormRenderer form={form} formItems={formItems} tableConfig={tableConfig} setModalTable={setModalTable} setSelectedTableRows={setSelectedTableRows} />
248
- </Row>
249
- </Form>
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
  )
@@ -1,4 +1,5 @@
1
- import { Space, Table } from 'antd'
1
+ import { Table } from 'antd'
2
+ import { DraggableContainer } from './DraggableContainer'
2
3
  import { EditableRow, EditableCell } from './EditableCell'
3
4
  import { useRef, useMemo, useEffect, useCallback } from 'react'
4
5
 
@@ -54,12 +55,10 @@ import { useRef, useMemo, useEffect, useCallback } from 'react'
54
55
  * }}
55
56
  * />
56
57
  */
57
- export const MyTable = ({ size, query, total, search, autoScroll, onChange, setSearch, pagination, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
58
+ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagination, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
58
59
 
59
60
  const tableRef = useRef(null)
60
61
  const hasScrolledRef = useRef(false)
61
- const dataSourceRef = useRef(dataSource)
62
- dataSourceRef.current = dataSource
63
62
 
64
63
  /**
65
64
  * @description [权限侦察] 自动扫描列配置。若存在 editType 型号,则激活“骇入模式(编辑模式)”。
@@ -69,18 +68,19 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
69
68
  /**
70
69
  * @function handleSave
71
70
  * @description [原子级物理封存] 执行数据更新协议。
71
+ * 采用函数式状态更新(prev => ...)以彻底消除闭航陷阱(Stale Closure),确保数据高频修改时的绝对准确。
72
+ *
72
73
  * @param {Object} row - 修改后的行片段
73
74
  */
74
75
  const handleSave = useCallback((row) => {
75
- const prev = dataSourceRef.current
76
- const index = prev.findIndex(item => row[rowKey] === item[rowKey])
77
- if (index === -1) return
78
- const item = prev[index]
79
- const updatedRow = { ...item, ...row }
80
- const newData = [...prev]
81
- newData.splice(index, 1, updatedRow)
82
- setDataSource(newData)
83
- customSave?.(updatedRow, newData)
76
+ setDataSource(prev => {
77
+ const newData = [...prev]
78
+ const index = newData.findIndex(item => row[rowKey] === item[rowKey])
79
+ const item = newData[index]
80
+ newData.splice(index, 1, { ...item, ...row })
81
+ customSave?.({ ...item, ...row }, newData)
82
+ return newData
83
+ })
84
84
  }, [rowKey, customSave, setDataSource])
85
85
 
86
86
  /**
@@ -91,8 +91,9 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
91
91
  body: {
92
92
  row: EditableRow,
93
93
  cell: EditableCell,
94
+ wrapper: props => <DraggableContainer props={props} setDataSource={setDataSource} />,
94
95
  }
95
- }), [])
96
+ }), [setDataSource])
96
97
 
97
98
  /**
98
99
  * @constant mergedColumns
@@ -102,37 +103,10 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
102
103
  const mergedColumns = useMemo(() => {
103
104
  return columns.map(col => {
104
105
  if (!col.editType) {
105
- let currentCol = { ...col }
106
106
  if (col.renderAction && renderAction?.[col.dataIndex]) {
107
- currentCol.render = renderAction[col.dataIndex]
108
- }
109
- if (col.search) {
110
- currentCol = {
111
- ...currentCol,
112
- filterSearch: true,
113
- onFilter: (value, record) => col.remote ? undefined : col.customFilter({ value, record, dataIndex: col.dataIndex }),
114
- filterDropdown: ({ close, confirm, selectedKeys, clearFilters, setSelectedKeys }) => (
115
- <Space direction='vertical' style={{ padding: 12 }}>
116
- {col.customFilterDropdown({ dataIndex: col.dataIndex, selectedKeys, setSelectedKeys })}
117
- <div style={{ display: 'flex' }}>
118
- <a style={{ marginLeft: 'auto', marginRight: 8 }} onClick={() => {
119
- if (col.remote) {
120
- setSearch(prev => ({ ...prev, pageNo: 1, [col.dataIndex]: col.formatFilter?.(selectedKeys) ?? selectedKeys?.toString() }))
121
- }
122
- confirm()
123
- }}>确定</a>
124
- <a onClick={() => {
125
- if (col.remote) {
126
- setSearch(prev => ({ ...prev, pageNo: 1, [col.dataIndex]: undefined }))
127
- }
128
- clearFilters()
129
- }}>重置</a>
130
- </div>
131
- </Space>
132
- ),
133
- }
107
+ return { ...col, render: renderAction[col.dataIndex] }
134
108
  }
135
- return currentCol
109
+ return col
136
110
  }
137
111
  return {
138
112
  ...col,
@@ -141,7 +115,6 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
141
115
  handleSave,
142
116
  title: col.title,
143
117
  rules: col.rules,
144
- extra: col.extra,
145
118
  options: col.options,
146
119
  editType: col.editType,
147
120
  dataIndex: col.dataIndex,
@@ -174,7 +147,7 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
174
147
  }),
175
148
  ...(typeof pagination === 'object' ? pagination : {})
176
149
  }
177
- }, [total, search, pagination])
150
+ }, [total, search, pagination, isLocalPaging])
178
151
 
179
152
  /**
180
153
  * @description [视觉追踪协议] 当检测到 query.rowIndex 信号时,执行“物理重定向”。