diff --git a/frontend_vue.py b/frontend_vue.py index b6ab6da..065a664 100644 --- a/frontend_vue.py +++ b/frontend_vue.py @@ -53,6 +53,7 @@ def generate(table): ctx = { "table":table, + "old_table": to_kebab(table), "entity":entity, "fields":build_fields(table) } diff --git a/templates/vue/api.ts.j2 b/templates/vue/api.ts.j2 index 7b5ea03..5b8356a 100644 --- a/templates/vue/api.ts.j2 +++ b/templates/vue/api.ts.j2 @@ -15,28 +15,28 @@ export namespace {{entity}}Api { * 分页查询 */ export function page(params: any) { - return requestClient.post(applicationConfig.javaURL+'/{{table}}/page', { params }); + return requestClient.post(applicationConfig.javaURL+'/{{old_table}}/page', params,{ headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1'}}); } /** * 获取详情 */ export function get(id: number) { - return requestClient.get(applicationConfig.javaURL+'/{{table}}/' + id); + return requestClient.get(applicationConfig.javaURL+'/{{old_table}}/' + id); } /** * 新增 / 修改 */ export function save(data: any) { - return requestClient.post(applicationConfig.javaURL+'/{{table}}', data); + return requestClient.post(applicationConfig.javaURL+'/{{old_table}}', data); } /** * 删除 */ export function remove(id: number) { - return requestClient.delete(applicationConfig.javaURL+'/{{table}}/' + id); + return requestClient.delete(applicationConfig.javaURL+'/{{old_table}}/' + id); } } \ No newline at end of file diff --git a/templates/vue/index.vue.j2 b/templates/vue/index.vue.j2 index 23041ae..0731cfe 100644 --- a/templates/vue/index.vue.j2 +++ b/templates/vue/index.vue.j2 @@ -8,57 +8,44 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { columns } from './data'; import { {{entity}}Api } from '#/api/{{entity}}'; - -console.log('=== columns 配置 ===', columns) -const [Grid, gridApi] = useVbenVxeGrid({ - +const gridOptions = { columns, - - gridOptions: { - proxyConfig: { - ajax: { - query: async ({ page }) => { - try { - console.log('=== 请求参数 ===', page) - - const res = await userApi.page({ - pageNum: page?.currentPage || 1, - pageSize: page?.pageSize || 10, - }) - - console.log('=== API 返回的数据 ===', res) - const data = res.error?.result || res.result || res - const result = { - items: data.records, - total: data.total - } - console.log('=== 转换后的数据 ===', result) - return result - - } catch (error) { - console.error('查询用户列表失败:', error) - throw error + proxyConfig: { + ajax: { + query: async ({ page }) => { + try { + const res = await userApi.page({ + pageNum: page?.currentPage || 1, + pageSize: page?.pageSize || 10, + }) + + const data = res.error?.result || res.result || res + + return { + items: data.records || [], + total: data.total || 0 } + + } catch (error) { + console.error('查询用户列表失败:', error) + throw error } } }, - pagerConfig: { - enabled: true, - }, + response: { + result: 'items', + total: 'total' + } }, -}) - - + pagerConfig: { + enabled: true, + }, +} +const [Grid, gridApi] = useVbenVxeGrid({ gridOptions }) - + \ No newline at end of file diff --git a/utils.py b/utils.py index e08dcf5..1bc45e7 100644 --- a/utils.py +++ b/utils.py @@ -2,6 +2,10 @@ import argparse import re from copy import deepcopy +def to_kebab(name): + parts = name.split("_") + return "-".join(parts) + def to_camel(name): parts = name.split("_") return parts[0] + "".join(p.capitalize() for p in parts[1:])