@yorha2b-lab/autodev 7.7.4 → 7.7.5

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.4",
3
+ "version": "7.7.5",
4
4
  "description": "基于 AI 视觉与语义协议的前端 (React+Antd) 代码构筑与旧系统重构引擎",
5
5
  "bin": {
6
6
  "bunker": "bin/bunker.js"
@@ -9,11 +9,14 @@ const arrayMoveImmutable = (array, oldIndex, newIndex) => {
9
9
  return newArray
10
10
  }
11
11
 
12
- export const DraggableContainer = ({ props, setDataSource }) => {
12
+ export const DraggableContainer = ({ props, customSave, setDataSource, dataSourceRef }) => {
13
13
 
14
14
  const onSortEnd = ({ oldIndex, newIndex }) => {
15
15
  if (oldIndex !== newIndex) {
16
- setDataSource(prev => arrayMoveImmutable(prev.slice(), oldIndex, newIndex))
16
+ const currentData = dataSourceRef?.current || []
17
+ const sortedDataSource = arrayMoveImmutable(currentData.slice(), oldIndex, newIndex)
18
+ setDataSource(sortedDataSource)
19
+ customSave?.(sortedDataSource)
17
20
  }
18
21
  }
19
22
 
@@ -55,15 +55,18 @@ import { useRef, useMemo, useEffect, useCallback } from 'react'
55
55
  * }}
56
56
  * />
57
57
  */
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
+ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagination, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], draggable = false, scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
59
59
 
60
60
  const tableRef = useRef(null)
61
61
  const hasScrolledRef = useRef(false)
62
+ const dataSourceRef = useRef(dataSource)
63
+ dataSourceRef.current = dataSource
62
64
 
63
65
  /**
64
66
  * @description [权限侦察] 自动扫描列配置。若存在 editType 型号,则激活“骇入模式(编辑模式)”。
65
67
  */
66
68
  const isEditable = useMemo(() => columns.some(col => col.editType), [columns])
69
+ const hasCustomComponents = isEditable || draggable
67
70
 
68
71
  /**
69
72
  * @function handleSave
@@ -73,27 +76,36 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagi
73
76
  * @param {Object} row - 修改后的行片段
74
77
  */
75
78
  const handleSave = useCallback((row) => {
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
- })
79
+ const prev = dataSourceRef.current
80
+ const index = prev.findIndex(item => row[rowKey] === item[rowKey])
81
+ if (index === -1) return
82
+ const item = prev[index]
83
+ const updatedRow = { ...item, ...row }
84
+ const newData = [...prev]
85
+ newData.splice(index, 1, updatedRow)
86
+ setDataSource(newData)
87
+ customSave?.(updatedRow, newData)
84
88
  }, [rowKey, customSave, setDataSource])
85
89
 
86
90
  /**
87
91
  * @constant components
88
92
  * @description [零部件注册] 注入地堡特有的可编辑 Row 和 Cell 单元。
89
93
  */
90
- const components = useMemo(() => ({
91
- body: {
92
- row: EditableRow,
93
- cell: EditableCell,
94
- wrapper: props => <DraggableContainer props={props} setDataSource={setDataSource} />,
94
+ const components = useMemo(() => {
95
+ if (!hasCustomComponents) return undefined
96
+ const c = { body: {} }
97
+ // 1. 只有有编辑列时,才挂载行内编辑单元
98
+ if (isEditable) {
99
+ c.body.row = EditableRow
100
+ c.body.cell = EditableCell
101
+ }
102
+ // 2. 只有开启了拖拽,才挂载拖拽容器
103
+ if (draggable) {
104
+ c.body.wrapper = props => <DraggableContainer props={props} customSave={customSave} setDataSource={setDataSource} dataSourceRef={dataSourceRef} />
95
105
  }
96
- }), [setDataSource])
106
+ return c
107
+ }, [isEditable, draggable, customSave, setDataSource])
108
+
97
109
 
98
110
  /**
99
111
  * @constant mergedColumns
@@ -183,9 +195,9 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagi
183
195
  columns={mergedColumns}
184
196
  dataSource={dataSource}
185
197
  size={size ?? 'middle'}
198
+ components={components}
186
199
  rowSelection={rowSelection}
187
200
  pagination={paginationConfig}
188
- components={isEditable ? components : undefined}
189
201
  // 💡 信号注入:将行监听协议绑定至底层 tr
190
202
  onRow={(record, index) => ({ record, index, ...(typeof lineFormChange === 'function' ? { onValuesChange: lineFormChange } : {}) })}
191
203
  rowClassName={(record, index) => {