fix: codegen demo
This commit is contained in:
@@ -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', ['学生课程']) }}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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', ['学生课程']) }}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user