@yorha2b-lab/autodev 2.1.10 → 2.1.12

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.10",
3
+ "version": "2.1.12",
4
4
  "description": "基于视觉大模型的前端(react+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -114,7 +114,7 @@ const matrixEffect = async (duration = 1500) => {
114
114
  ]
115
115
 
116
116
  const endTime = Date.now() + duration
117
- const isLegendary = currentTotal >= 2000
117
+ const isLegendary = currentTotal >= 3000
118
118
  const width = process.stdout.columns || 80
119
119
 
120
120
  if (isLegendary) {
@@ -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 (
@@ -11,12 +11,36 @@ const components = {
11
11
 
12
12
  export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination, rowClassName, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, ...restProps }) => {
13
13
 
14
+ const { total, search, customSave, setDataSource } = restProps
14
15
 
15
16
  const tableRef = useRef(null)
16
17
  const hasScrolledRef = useRef(false)
17
18
 
18
19
  const isEditable = useMemo(() => columns.some(col => col.editType), [columns])
19
20
 
21
+ const handleSave = row => {
22
+ const newData = [...dataSource]
23
+ const index = newData.findIndex(item => row[rowKey] === item[rowKey])
24
+ const item = newData[index]
25
+ newData.splice(index, 1, { ...item, ...row })
26
+ setDataSource(newData)
27
+ customSave?.({ ...item, ...row })
28
+ }
29
+
30
+ const paginationConfig = useMemo(() => {
31
+
32
+ if (!pagination) return false
33
+
34
+ return {
35
+ total,
36
+ showSizeChanger: true,
37
+ current: search?.pageNo,
38
+ pageSize: search?.pageSize,
39
+ showTotal: (total) => `共 ${total} 条`,
40
+ ...pagination
41
+ }
42
+ }, [total, search, pagination])
43
+
20
44
  const mergedColumns = useMemo(() => {
21
45
  return columns.map(col => {
22
46
  if (!col.editType) {
@@ -26,17 +50,18 @@ export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination,
26
50
  ...col,
27
51
  onCell: (record) => ({
28
52
  record,
53
+ handleSave,
29
54
  title: col.title,
30
55
  rules: col.rules,
31
- handleSave: onSave,
32
56
  options: col.options,
33
57
  editType: col.editType,
34
58
  editable: !!col.editType,
35
59
  dataIndex: col.dataIndex,
60
+ placeholder: col.placeholder
36
61
  }),
37
62
  }
38
63
  })
39
- }, [columns, onSave])
64
+ }, [columns])
40
65
 
41
66
  useEffect(() => {
42
67
  if (!autoScroll || !dataSource?.length || query?.rowIndex === undefined) return
@@ -65,9 +90,9 @@ export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination,
65
90
  onChange={onChange}
66
91
  columns={mergedColumns}
67
92
  dataSource={dataSource}
68
- pagination={pagination}
69
93
  size={size ?? 'middle'}
70
94
  rowSelection={rowSelection}
95
+ pagination={paginationConfig}
71
96
  components={isEditable ? components : undefined}
72
97
  rowClassName={(record, index) => {
73
98
  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}}