Browse Source

Merge remote-tracking branch 'origin/master'

master
zhanglei 2 weeks ago
parent
commit
237c130a38
  1. 1
      frontend_vue.py
  2. 8
      templates/vue/api.ts.j2
  3. 73
      templates/vue/index.vue.j2
  4. 4
      utils.py

1
frontend_vue.py

@ -53,6 +53,7 @@ def generate(table):
ctx = {
"table":table,
"old_table": to_kebab(table),
"entity":entity,
"fields":build_fields(table)
}

8
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);
}
}

73
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 })
</script>
<template>
<div>
<Grid table-title="用户列表">
<template #toolbar-tools>
<button @click="() => gridApi.reload()">刷新</button>
</template>
</Grid>
</div>
<template>
<Grid/>
</template>

4
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:])

Loading…
Cancel
Save