fix: codegen demo

dev
xingyu4j 2025-09-12 16:14:16 +08:00
parent 5f5fb9e544
commit 2c5557aa30
13 changed files with 127 additions and 130 deletions

View File

@ -1,5 +1,4 @@
<script lang="ts" setup>
import type { OnActionClickParams } from '#/adapter/vxe-table';
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
import { nextTick, watch } from 'vue';
@ -8,7 +7,7 @@ import { Plus } from '@vben/icons';
import { ElButton, ElInput } from 'element-plus';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/inner';
import { $t } from '#/locales';
@ -18,22 +17,9 @@ const props = defineProps<{
studentId?: number; //
}>();
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<Demo03StudentApi.Demo03Course>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useDemo03CourseGridEditColumns(onActionClick),
columns: useDemo03CourseGridEditColumns(),
border: true,
showOverflow: true,
autoResize: true,
@ -51,14 +37,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
/** 添加学生课程 */
const onAdd = async () => {
async function handleAdd() {
await gridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
};
}
/** 删除学生课程 */
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
async function handleDelete(row: Demo03StudentApi.Demo03Course) {
await gridApi.grid.remove(row);
};
}
/** 提供获取表格数据的方法供父组件调用 */
defineExpose({
@ -101,13 +87,29 @@ watch(
<template #score="{ row }">
<ElInput v-model="row.score" />
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.delete'),
type: 'danger',
icon: ACTION_ICON.DELETE,
auth: ['infra:demo03-student:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
<div class="-mt-4 flex justify-center">
<ElButton
:icon="Plus"
type="primary"
plain
@click="onAdd"
@click="handleAdd"
v-access:code="['infra:demo03-student:create']"
>
{{ $t('ui.actionTitle.create', ['学生课程']) }}

View File

@ -61,8 +61,8 @@ const [Modal, modalApi] = useVbenModal({
//
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Student;
//
data.demo03Courses = demo03CourseFormRef.value?.getData();
data.demo03Grade = await demo03GradeFormRef.value?.getValues();
data.demo03courses = demo03CourseFormRef.value?.getData();
data.demo03grade = await demo03GradeFormRef.value?.getValues();
try {
await (formData.value?.id
? updateDemo03Student(data)

View File

@ -1,5 +1,4 @@
<script lang="ts" setup>
import type { OnActionClickParams } from '#/adapter/vxe-table';
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
import { nextTick, watch } from 'vue';
@ -8,7 +7,7 @@ import { Plus } from '@vben/icons';
import { ElButton, ElInput } from 'element-plus';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/normal';
import { $t } from '#/locales';
@ -18,22 +17,9 @@ const props = defineProps<{
studentId?: number; //
}>();
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<Demo03StudentApi.Demo03Course>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useDemo03CourseGridEditColumns(onActionClick),
columns: useDemo03CourseGridEditColumns(),
border: true,
showOverflow: true,
autoResize: true,
@ -51,14 +37,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
/** 添加学生课程 */
const onAdd = async () => {
async function handleAdd() {
await gridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
};
}
/** 删除学生课程 */
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
async function handleDelete(row: Demo03StudentApi.Demo03Course) {
await gridApi.grid.remove(row);
};
}
/** 提供获取表格数据的方法供父组件调用 */
defineExpose({
@ -101,13 +87,29 @@ watch(
<template #score="{ row }">
<ElInput v-model="row.score" />
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.delete'),
type: 'danger',
icon: ACTION_ICON.DELETE,
auth: ['infra:demo03-student:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
<div class="-mt-4 flex justify-center">
<ElButton
:icon="Plus"
type="primary"
plain
@click="onAdd"
@click="handleAdd"
v-access:code="['infra:demo03-student:create']"
>
{{ $t('ui.actionTitle.create', ['学生课程']) }}

View File

@ -61,8 +61,8 @@ const [Modal, modalApi] = useVbenModal({
//
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Student;
//
data.demo03Courses = demo03CourseFormRef.value?.getData();
data.demo03Grade = await demo03GradeFormRef.value?.getValues();
data.demo03courses = demo03CourseFormRef.value?.getData();
data.demo03grade = await demo03GradeFormRef.value?.getValues();
try {
await (formData.value?.id
? updateDemo03Student(data)

View File

@ -7,6 +7,7 @@ import { Page, useVbenModal } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Download, Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import {
cloneDeep,
downloadFileFromBlobPart,
@ -36,8 +37,6 @@ import {
} from '#/api/infra/demo/demo01';
import { ContentWrap } from '#/components/content-wrap';
import { DictTag } from '#/components/dict-tag';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo01ContactForm from './modules/form.vue';
@ -57,7 +56,7 @@ const queryFormRef = ref(); // 搜索的表单
const exportLoading = ref(false); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
const params = cloneDeep(queryParams) as any;
@ -70,19 +69,19 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Demo01ContactForm,
@ -140,7 +139,7 @@ function handleRowCheckboxChange({
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
try {
exportLoading.value = true;
const data = await exportDemo01Contact(queryParams);
@ -214,7 +213,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="示例联系人">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -232,7 +231,7 @@ onMounted(() => {
type="primary"
class="ml-2"
:loading="exportLoading"
@click="onExport"
@click="handleExport"
v-access:code="['infra:demo01-contact:export']"
>
{{ $t('ui.actionTitle.export') }}
@ -247,7 +246,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -5,6 +5,7 @@ import { h, onMounted, reactive, ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { Download, Plus } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import {
cloneDeep,
downloadFileFromBlobPart,
@ -29,8 +30,6 @@ import {
getDemo02CategoryList,
} from '#/api/infra/demo/demo02';
import { ContentWrap } from '#/components/content-wrap';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo02CategoryForm from './modules/form.vue';
@ -47,7 +46,7 @@ const queryFormRef = ref(); // 搜索的表单
const exportLoading = ref(false); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
const params = cloneDeep(queryParams) as any;
@ -58,18 +57,18 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Demo02CategoryForm,
@ -107,7 +106,7 @@ async function handleDelete(row: Demo02CategoryApi.Demo02Category) {
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
try {
exportLoading.value = true;
const data = await exportDemo02Category(queryParams);
@ -179,7 +178,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="示例分类">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -200,12 +199,12 @@ onMounted(() => {
type="primary"
class="ml-2"
:loading="exportLoading"
@click="onExport"
@click="handleExport"
v-access:code="['infra:demo02-category:export']"
>
{{ $t('ui.actionTitle.export') }}
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -7,6 +7,7 @@ import { Page, useVbenModal } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Download, Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import {
cloneDeep,
downloadFileFromBlobPart,
@ -38,8 +39,6 @@ import {
} from '#/api/infra/demo/demo03/erp';
import { ContentWrap } from '#/components/content-wrap';
import { DictTag } from '#/components/dict-tag';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo03CourseList from './modules/demo03-course-list.vue';
@ -69,7 +68,7 @@ const queryFormRef = ref(); // 搜索的表单
const exportLoading = ref(false); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
const params = cloneDeep(queryParams) as any;
@ -82,19 +81,19 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Demo03StudentForm,
@ -152,7 +151,7 @@ function handleRowCheckboxChange({
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
try {
exportLoading.value = true;
const data = await exportDemo03Student(queryParams);
@ -226,7 +225,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="学生">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -244,7 +243,7 @@ onMounted(() => {
type="primary"
class="ml-2"
:loading="exportLoading"
@click="onExport"
@click="handleExport"
v-access:code="['infra:demo03-student:export']"
>
{{ $t('ui.actionTitle.export') }}
@ -259,7 +258,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -5,6 +5,7 @@ import { h, nextTick, onMounted, reactive, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import { cloneDeep, formatDateTime, isEmpty } from '@vben/utils';
import {
@ -25,8 +26,6 @@ import {
getDemo03CoursePage,
} from '#/api/infra/demo/demo03/erp';
import { ContentWrap } from '#/components/content-wrap';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo03CourseForm from './demo03-course-form.vue';
@ -108,18 +107,18 @@ const queryParams = reactive({
});
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
if (!props.studentId) {
@ -136,7 +135,7 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
@ -214,7 +213,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="学生">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -237,7 +236,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -5,6 +5,7 @@ import { h, nextTick, onMounted, reactive, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import { cloneDeep, formatDateTime, isEmpty } from '@vben/utils';
import {
@ -25,8 +26,6 @@ import {
getDemo03GradePage,
} from '#/api/infra/demo/demo03/erp';
import { ContentWrap } from '#/components/content-wrap';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo03GradeForm from './demo03-grade-form.vue';
@ -108,18 +107,18 @@ const queryParams = reactive({
});
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
if (!props.studentId) {
@ -136,7 +135,7 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
@ -214,7 +213,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="学生">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -237,7 +236,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -7,6 +7,7 @@ import { Page, useVbenModal } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Download, Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import {
cloneDeep,
downloadFileFromBlobPart,
@ -38,8 +39,6 @@ import {
} from '#/api/infra/demo/demo03/inner';
import { ContentWrap } from '#/components/content-wrap';
import { DictTag } from '#/components/dict-tag';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo03CourseList from './modules/demo03-course-list.vue';
@ -65,7 +64,7 @@ const queryFormRef = ref(); // 搜索的表单
const exportLoading = ref(false); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
const params = cloneDeep(queryParams) as any;
@ -78,19 +77,19 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Demo03StudentForm,
@ -148,7 +147,7 @@ function handleRowCheckboxChange({
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
try {
exportLoading.value = true;
const data = await exportDemo03Student(queryParams);
@ -222,7 +221,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="学生">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -240,7 +239,7 @@ onMounted(() => {
type="primary"
class="ml-2"
:loading="exportLoading"
@click="onExport"
@click="handleExport"
v-access:code="['infra:demo03-student:export']"
>
{{ $t('ui.actionTitle.export') }}
@ -255,7 +254,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"

View File

@ -16,7 +16,7 @@ const props = defineProps<{
const loading = ref(true); //
const list = ref<Demo03StudentApi.Demo03Course[]>([]); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
if (!props.studentId) {
@ -26,7 +26,7 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(

View File

@ -16,7 +16,7 @@ const props = defineProps<{
const loading = ref(true); //
const list = ref<Demo03StudentApi.Demo03Grade[]>([]); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
if (!props.studentId) {
@ -26,7 +26,7 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(

View File

@ -7,6 +7,7 @@ import { Page, useVbenModal } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Download, Plus, Trash2 } from '@vben/icons';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import {
cloneDeep,
downloadFileFromBlobPart,
@ -36,8 +37,6 @@ import {
} from '#/api/infra/demo/demo03/normal';
import { ContentWrap } from '#/components/content-wrap';
import { DictTag } from '#/components/dict-tag';
import { TableToolbar } from '#/components/table-toolbar';
import { useTableToolbar } from '#/hooks';
import { $t } from '#/locales';
import Demo03StudentForm from './modules/form.vue';
@ -58,7 +57,7 @@ const queryFormRef = ref(); // 搜索的表单
const exportLoading = ref(false); //
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
const params = cloneDeep(queryParams) as any;
@ -71,19 +70,19 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Demo03StudentForm,
@ -141,7 +140,7 @@ function handleRowCheckboxChange({
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
try {
exportLoading.value = true;
const data = await exportDemo03Student(queryParams);
@ -215,7 +214,7 @@ onMounted(() => {
<!-- 列表 -->
<ContentWrap title="学生">
<template #extra>
<TableToolbar
<VbenVxeTableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
@ -233,7 +232,7 @@ onMounted(() => {
type="primary"
class="ml-2"
:loading="exportLoading"
@click="onExport"
@click="handleExport"
v-access:code="['infra:demo03-student:export']"
>
{{ $t('ui.actionTitle.export') }}
@ -248,7 +247,7 @@ onMounted(() => {
>
批量删除
</ElButton>
</TableToolbar>
</VbenVxeTableToolbar>
</template>
<VxeTable
ref="tableRef"