@yorha2b-lab/autodev 2.1.11 → 2.1.13

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": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "description": "基于视觉大模型的前端(react+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -14,7 +14,7 @@ export const EditableRow = ({ index, ...props }) => {
14
14
  )
15
15
  }
16
16
 
17
- export const EditableCell = ({ title, record, editable, children, dataIndex, handleSave, rules = [], options = [], editType = 'text', ...restProps }) => {
17
+ export const EditableCell = ({ title, record, editable, children, dataIndex, placeholder, handleSave, rules = [], options = [], editType = 'text', ...restProps }) => {
18
18
 
19
19
  const inputRef = useRef(null)
20
20
  const form = useContext(EditableContext)
@@ -48,10 +48,10 @@ export const EditableCell = ({ title, record, editable, children, dataIndex, han
48
48
 
49
49
  switch (editType) {
50
50
  case 'number':
51
- inputNode = <InputNumber ref={inputRef} onPressEnter={save} onBlur={save} />
51
+ inputNode = <InputNumber ref={inputRef} onPressEnter={save} onBlur={save} placeholder={placeholder ?? title} />
52
52
  break
53
53
  case 'select':
54
- inputNode = <Select ref={inputRef} options={options} onBlur={save} />
54
+ inputNode = <Select ref={inputRef} options={options} onBlur={save} placeholder={placeholder ?? title} />
55
55
  break;
56
56
  case 'checkbox':
57
57
  inputNode = (
@@ -66,7 +66,7 @@ export const EditableCell = ({ title, record, editable, children, dataIndex, han
66
66
  )
67
67
  break;
68
68
  default:
69
- inputNode = <Input ref={inputRef} onPressEnter={save} onBlur={save} />
69
+ inputNode = <Input ref={inputRef} onPressEnter={save} onBlur={save} placeholder={placeholder ?? title} />
70
70
  }
71
71
 
72
72
  return (
@@ -9,14 +9,36 @@ const components = {
9
9
  }
10
10
  }
11
11
 
12
- export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination, rowClassName, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, ...restProps }) => {
13
-
12
+ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagination, rowClassName, customSave, setDataSource, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, ...restProps }) => {
14
13
 
15
14
  const tableRef = useRef(null)
16
15
  const hasScrolledRef = useRef(false)
17
16
 
18
17
  const isEditable = useMemo(() => columns.some(col => col.editType), [columns])
19
18
 
19
+ const handleSave = row => {
20
+ const newData = [...dataSource]
21
+ const index = newData.findIndex(item => row[rowKey] === item[rowKey])
22
+ const item = newData[index]
23
+ newData.splice(index, 1, { ...item, ...row })
24
+ setDataSource(newData)
25
+ customSave?.({ ...item, ...row })
26
+ }
27
+
28
+ const paginationConfig = useMemo(() => {
29
+
30
+ if (!pagination) return false
31
+
32
+ return {
33
+ total,
34
+ showSizeChanger: true,
35
+ current: search?.pageNo,
36
+ pageSize: search?.pageSize,
37
+ showTotal: (total) => `共 ${total} 条`,
38
+ ...pagination
39
+ }
40
+ }, [total, search, pagination])
41
+
20
42
  const mergedColumns = useMemo(() => {
21
43
  return columns.map(col => {
22
44
  if (!col.editType) {
@@ -26,17 +48,18 @@ export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination,
26
48
  ...col,
27
49
  onCell: (record) => ({
28
50
  record,
51
+ handleSave,
29
52
  title: col.title,
30
53
  rules: col.rules,
31
- handleSave: onSave,
32
54
  options: col.options,
33
55
  editType: col.editType,
34
56
  editable: !!col.editType,
35
57
  dataIndex: col.dataIndex,
58
+ placeholder: col.placeholder
36
59
  }),
37
60
  }
38
61
  })
39
- }, [columns, onSave])
62
+ }, [columns])
40
63
 
41
64
  useEffect(() => {
42
65
  if (!autoScroll || !dataSource?.length || query?.rowIndex === undefined) return
@@ -65,9 +88,9 @@ export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination,
65
88
  onChange={onChange}
66
89
  columns={mergedColumns}
67
90
  dataSource={dataSource}
68
- pagination={pagination}
69
91
  size={size ?? 'middle'}
70
92
  rowSelection={rowSelection}
93
+ pagination={paginationConfig}
71
94
  components={isEditable ? components : undefined}
72
95
  rowClassName={(record, index) => {
73
96
  const externalClass = typeof rowClassName === 'function' ? rowClassName(record, index) : rowClassName
@@ -11,7 +11,6 @@
11
11
  {{/if}}
12
12
  {{#if hasPagination}}
13
13
  {{{{raw}}}}
14
- pagination={{ total, showSizeChanger: true, current: search.pageNo, pageSize: search.pageSize }}
15
14
  onChange={(pagination, filters, sorter) => setSearch({ ...search , pageNo: pagination.current, pageSize: pagination.pageSize, orderBy: sorter.column ? sorter.field : undefined })}
16
15
  {{{{/raw}}}}
17
16
  {{/if}}