@yorha2b-lab/autodev 2.1.19 → 2.1.21

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.19",
3
+ "version": "2.1.21",
4
4
  "description": "基于视觉大模型的前端(react+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -189,7 +189,7 @@ const generateSmartImports = (codeStr, hasTabs) => {
189
189
  usedReact.length && `import { ${usedReact.join(', ')} } from 'react'`,
190
190
  `import { request } from '../../utils/request'`,
191
191
  `import { formatQuery } from '../../utils/utils'`,
192
- `import { ${hasTabs ? 'tabs, ' : ''}columns, formItems, modalItems } from './resource'`,
192
+ `import { ${hasTabs ? 'tabs, ' : ''}formItems, modalItems, tableColumns} from './resource'`,
193
193
  ...usedHooks.map(hook => `import { ${hook} } from '../../hooks/${hook}'`),
194
194
  ...usedComps.map(comp => `import { ${comp} } from '../../components/${comp}'`),
195
195
  usedAntd.length && `import { Form, ${usedAntd.join(', ')} } from 'antd'`
@@ -58,8 +58,8 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagi
58
58
  return {
59
59
  total,
60
60
  showSizeChanger: true,
61
- current: search?.pageNo,
62
- pageSize: search?.pageSize,
61
+ current: Number(search?.pageNo),
62
+ pageSize: Number(search?.pageSize),
63
63
  showTotal: (total) => `共 ${total} 条`,
64
64
  ...(typeof pagination === 'object' ? pagination : {})
65
65
  }
@@ -14,7 +14,16 @@
14
14
  {{/if}}
15
15
  {{#if hasPagination}}
16
16
  {{{{raw}}}}
17
- onChange={(pagination, filters, sorter) => setSearch({ ...search , pageNo: pagination.current, pageSize: pagination.pageSize, orderBy: sorter.column ? sorter.field : undefined })}
17
+ onChange={(pagination, filters, sorter) => {
18
+ if (sorter.column) {
19
+ const newSearch = { ...search, pageNo: pagination.current, pageSize: pagination.pageSize, orderBy: sorter.field }
20
+ const params = new URLSearchParams(Object.fromEntries(Object.entries({ ...query, ...newSearch }).filter(([key, value]) => !['', null, undefined].includes(value))))
21
+ window.history.replaceState(null, '', `${window.location.pathname}?${params.toString()}`)
22
+ setSearch(newSearch)
23
+ } else {
24
+ setSearch({ ...search, orderBy: undefined })
25
+ }
26
+ }}
18
27
  {{{{/raw}}}}
19
28
  {{/if}}
20
29
  {{#if hasRowSelection}}
@@ -5,12 +5,12 @@ const query = formatQuery(Object.fromEntries(new URLSearchParams(location.search
5
5
  const { total, columns, loading, dataSource, search, setSearch, setDataSource, refresh } = useTableQuery({
6
6
  api: async params => await request('/api/{{fileName}}', { method: 'POST', body: params }),
7
7
  initialParams: { pageNo: 1, pageSize: 10, ...query },
8
- cols:[],//前端指定列数组
8
+ cols:tableColumns,//前端指定列数组
9
9
  formatResponse: response => {
10
10
  return {
11
11
  data: response?.data ?? [],
12
12
  total: response?.data?.total ?? 0,
13
- columns: [],//可选,解析接口动态列;优先级高于cols
13
+ columns: undefined,//可选,解析接口动态列;优先级高于cols
14
14
  }
15
15
  },
16
16
  })
@@ -15,7 +15,7 @@ export const useTableQuery = ({ api, cols = [], initialParams = {}, formatRespon
15
15
  apiRef.current = api
16
16
  }, [api])
17
17
 
18
- const getColumnSchema = cols => cols.map(col => ({ title: col.title, dataIndex: col.dataIndex })).join('|')
18
+ const getColumnSchema = cols => cols.map(col => `${col.title}-${col.dataIndex}-${col.sortOrder}`).join('|')
19
19
 
20
20
  const fetchData = useCallback(async () => {
21
21
  if (!apiRef.current) return
@@ -43,5 +43,5 @@ export const useTableQuery = ({ api, cols = [], initialParams = {}, formatRespon
43
43
  fetchData()
44
44
  }, [fetchData])
45
45
 
46
- return { total, columns, loading, dataSource, search, setSearch, setDataSource, refresh: fetchData }
46
+ return { total, columns, loading, dataSource, search, setSearch, setLoading, setDataSource, refresh: fetchData }
47
47
  }
@@ -13,6 +13,6 @@ export const {{this.name}} = {{{stringify this.data 50}}}
13
13
  export const formItems = {{{stringify formItemsData 150}}}
14
14
  {{/if}}
15
15
 
16
- export const columns = {{{stringify columnsData 200}}}
16
+ export const tableColumns = {{{stringify columnsData 200}}}
17
17
 
18
18
  export const modalItems = []