diff --git a/templates/vue/data.ts.j2 b/templates/vue/data.ts.j2 index 7512c1b..ceff274 100644 --- a/templates/vue/data.ts.j2 +++ b/templates/vue/data.ts.j2 @@ -15,7 +15,7 @@ export const columns: VxeGridProps['columns'] = [ field: '{{f.name}}', // 宽度 - width: 150, + width: 150 }, {% endfor %} diff --git a/templates/vue/form.ts.j2 b/templates/vue/form.ts.j2 index 54dd232..3e4bc11 100644 --- a/templates/vue/form.ts.j2 +++ b/templates/vue/form.ts.j2 @@ -16,7 +16,7 @@ export const formSchema: VbenFormSchema[] = [ label: '{{f.comment}}', // 自动组件 - component: '{{f.component}}', + component: '{{f.component}}' }, {% endfor %} diff --git a/templates/vue/index.vue.j2 b/templates/vue/index.vue.j2 index 4251337..23041ae 100644 --- a/templates/vue/index.vue.j2 +++ b/templates/vue/index.vue.j2 @@ -9,56 +9,56 @@ import { columns } from './data'; import { {{entity}}Api } from '#/api/{{entity}}'; +console.log('=== columns 配置 ===', columns) const [Grid, gridApi] = useVbenVxeGrid({ columns, - proxyConfig: { - - ajax: { - - query: async ({ page }) => { - - const res = await {{entity}}Api.page({ - pageNum: page.currentPage, - pageSize: page.pageSize, - }) - const data = res.data - - const result = { - items: data.records, - total: data.total + 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 + } } - - console.log('=== 返回给 VxeTable 的数据 ===', result) - - return result - } - - } - + }, + pagerConfig: { + enabled: true, + }, }, - pagerConfig: { - enabled: true, - }, - } - - const [Grid, gridApi] = useVbenVxeGrid({ - gridOptions, }) - - - - - - gridApi.reload()">刷新 - - - - + - \ No newline at end of file + + + + + gridApi.reload()">刷新 + + + + + diff --git a/templates/vue/router.ts.j2 b/templates/vue/router.ts.j2 index 76da233..3e52059 100644 --- a/templates/vue/router.ts.j2 +++ b/templates/vue/router.ts.j2 @@ -8,7 +8,7 @@ const routes: RouteRecordRaw[] = [ { path: '/{{entity}}', - name: '{{entityComment}}', + name: '{{comment}}模块', meta: { icon: 'ic:baseline-view-in-ar', order: 1000, @@ -18,9 +18,9 @@ const routes: RouteRecordRaw[] = [ children: [ { meta: { - title: "{{entityComment}}列表", + title: "{{comment}}列表", }, - name: '{{entity}}_List', + name: '{{entity}}List', path: '/{{entity}}', component: () => import('#/views/{{entity}}/index.vue'), }, diff --git a/vue-vben-admin/apps/web-antd/src/api/user/user.ts b/vue-vben-admin/apps/web-antd/src/api/user/user.ts index dc07414..ae39635 100644 --- a/vue-vben-admin/apps/web-antd/src/api/user/user.ts +++ b/vue-vben-admin/apps/web-antd/src/api/user/user.ts @@ -1,40 +1,43 @@ +/** + * 自动生成 API + * 负责调用后端接口 + */ + import { requestClient } from '#/api/request'; +import { useAppConfig } from '@vben/hooks'; -export namespace UserApi { +export namespace userApi { - /** - * 分页查询 - */ - export function page(params:any){ - return requestClient.get('/api/user/page',{params}); - } + const applicationConfig = useAppConfig(import.meta.env, import.meta.env.PROD); + console.log('=== 接口域名 ===', applicationConfig.javaURL + '/health-user/page') /** - * 详情 + * 分页查询 */ - export function detail(id:number){ - return requestClient.get('/api/user/'+id); + export function page(params: any) { + return requestClient.post(applicationConfig.javaURL + '/health-user/page', params , + { headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1'} }); } /** - * 新增 + * 获取详情 */ - export function add(data:any){ - return requestClient.post('/api/user',data); + export function get(id: number) { + return requestClient.get(applicationConfig.javaURL + '/health_user/' + id); } /** - * 更新 + * 新增 / 修改 */ - export function update(id:number,data:any){ - return requestClient.put('/api/user/'+id,data); + export function save(data: any) { + return requestClient.post(applicationConfig.javaURL + '/health_user', data); } /** * 删除 */ - export function remove(id:number){ - return requestClient.delete('/api/user/'+id); + export function remove(id: number) { + return requestClient.delete(applicationConfig.javaURL + '/health_user/' + id); } }