perf: 优化代码生成 inner 主子表示例

This commit is contained in:
puhui999 2025-06-06 18:36:03 +08:00
parent bd0ea27388
commit 6844b26f67
9 changed files with 151 additions and 93 deletions

View File

@ -1,53 +1,81 @@
import request from '@/config/axios'
import type { Dayjs } from 'dayjs';
export interface Demo03StudentVO {
id: number
name: string
sex: number
birthday: Date
description: string
/** 学生课程信息 */
export interface Demo03Course {
id: number; // 编号
studentId?: number; // 学生编号
name?: string; // 名字
score?: number; // 分数
}
// 查询学生分页
export const getDemo03StudentPage = async (params) => {
return await request.get({ url: `/infra/demo03-student/page`, params })
/** 学生班级信息 */
export interface Demo03Grade {
id: number; // 编号
studentId?: number; // 学生编号
name?: string; // 名字
teacher?: string; // 班主任
}
// 查询学生详情
export const getDemo03Student = async (id: number) => {
return await request.get({ url: `/infra/demo03-student/get?id=` + id })
/** 学生信息 */
export interface Demo03Student {
id: number; // 编号
name?: string; // 名字
sex?: number; // 性别
birthday?: string | Dayjs; // 出生日期
description?: string; // 简介
demo03courses?: Demo03Course[]
demo03grade?: Demo03Grade
}
// 新增学生
export const createDemo03Student = async (data: Demo03StudentVO) => {
return await request.post({ url: `/infra/demo03-student/create`, data })
}
// 学生 API
export const Demo03StudentApi = {
// 查询学生分页
getDemo03StudentPage: async (params: any) => {
return await request.get({ url: `/infra/demo03-student-inner/page`, params })
},
// 修改学生
export const updateDemo03Student = async (data: Demo03StudentVO) => {
return await request.put({ url: `/infra/demo03-student/update`, data })
}
// 查询学生详情
getDemo03Student: async (id: number) => {
return await request.get({ url: `/infra/demo03-student-inner/get?id=` + id })
},
// 删除学生
export const deleteDemo03Student = async (id: number) => {
return await request.delete({ url: `/infra/demo03-student/delete?id=` + id })
}
// 新增学生
createDemo03Student: async (data: Demo03Student) => {
return await request.post({ url: `/infra/demo03-student-inner/create`, data })
},
// 导出学生 Excel
export const exportDemo03Student = async (params) => {
return await request.download({ url: `/infra/demo03-student/export-excel`, params })
}
// 修改学生
updateDemo03Student: async (data: Demo03Student) => {
return await request.put({ url: `/infra/demo03-student-inner/update`, data })
},
// 删除学生
deleteDemo03Student: async (id: number) => {
return await request.delete({ url: `/infra/demo03-student-inner/delete?id=` + id })
},
/** 批量删除学生 */
deleteDemo03StudentList: async (ids: number[]) => {
return await request.delete({ url: `/infra/demo03-student-inner/delete-list?ids=${ids.join(',')}` })
},
// 导出学生 Excel
exportDemo03Student: async (params) => {
return await request.download({ url: `/infra/demo03-student-inner/export-excel`, params })
},
// ==================== 子表(学生课程) ====================
// 获得学生课程列表
export const getDemo03CourseListByStudentId = async (studentId) => {
return await request.get({ url: `/infra/demo03-student/demo03-course/list-by-student-id?studentId=` + studentId })
}
// 获得学生课程列表
getDemo03CourseListByStudentId: async (studentId) => {
return await request.get({ url: `/infra/demo03-student-inner/demo03-course/list-by-student-id?studentId=` + studentId })
},
// ==================== 子表(学生班级) ====================
// 获得学生班级
export const getDemo03GradeByStudentId = async (studentId) => {
return await request.get({ url: `/infra/demo03-student/demo03-grade/get-by-student-id?studentId=` + studentId })
}
// 获得学生班级
getDemo03GradeByStudentId: async (studentId) => {
return await request.get({ url: `/infra/demo03-student-inner/demo03-grade/get-by-student-id?studentId=` + studentId })
},
}

View File

@ -72,7 +72,7 @@
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { isEmpty } from '@/utils/is'
import { Demo03StudentApi } from '@/api/infra/demo/demo03/erp'
import {Demo03Course, Demo03StudentApi} from '@/api/infra/demo/demo03/erp'
import Demo03CourseForm from './Demo03CourseForm.vue'
const { t } = useI18n() //

View File

@ -72,7 +72,7 @@
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { isEmpty } from '@/utils/is'
import { Demo03StudentApi } from '@/api/infra/demo/demo03/erp'
import {Demo03Grade, Demo03StudentApi} from '@/api/infra/demo/demo03/erp'
import Demo03GradeForm from './Demo03GradeForm.vue'
const { t } = useI18n() //

View File

@ -49,11 +49,14 @@
</Dialog>
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { Demo03Student, Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
import Demo03CourseForm from './components/Demo03CourseForm.vue'
import Demo03GradeForm from './components/Demo03GradeForm.vue'
/** 学生 表单 */
defineOptions({ name: 'Demo03StudentForm' })
const { t } = useI18n() //
const message = useMessage() //
@ -120,7 +123,7 @@ const submitForm = async () => {
//
formLoading.value = true
try {
const data = formData.value as unknown as Demo03StudentApi.Demo03StudentVO
const data = formData.value as unknown as Demo03Student
//
data.demo03Courses = demo03CourseFormRef.value.getData()
data.demo03Grade = demo03GradeFormRef.value.getData()
@ -150,4 +153,4 @@ const resetForm = () => {
}
formRef.value?.resetFields()
}
</script>
</script>

View File

@ -9,7 +9,7 @@
>
<el-table :data="formData" class="-mt-10px">
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="名字" min-width="150">
<el-table-column label="名字" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!">
<el-input v-model="row.name" placeholder="请输入名字" />
@ -35,13 +35,13 @@
</el-row>
</template>
<script setup lang="ts">
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{
studentId: undefined //
studentId: number //
}>()
const formLoading = ref(false) //
const formData = ref([])
const formData = ref<any[]>([])
const formRules = reactive({
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
@ -57,7 +57,7 @@ watch(
formData.value = []
// 2. val
if (!val) {
return;
return
}
try {
formLoading.value = true
@ -77,7 +77,7 @@ const handleAdd = () => {
name: undefined,
score: undefined
}
row.studentId = props.studentId
row.studentId = props.studentId as any
formData.value.push(row)
}
@ -97,4 +97,4 @@ const getData = () => {
}
defineExpose({ validate, getData })
</script>
</script>

View File

@ -1,7 +1,13 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table
row-key="id"
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
>
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="名字" align="center" prop="name" />
<el-table-column label="分数" align="center" prop="score" />
@ -17,13 +23,10 @@
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
const { t } = useI18n() //
const message = useMessage() //
import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{
studentId: undefined //
studentId?: number //
}>()
const loading = ref(false) //
const list = ref([]) //
@ -38,14 +41,8 @@ const getList = async () => {
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>
</script>

View File

@ -6,7 +6,7 @@
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="名字" prop="name">
<el-form-item label="名字" prop="name">
<el-input v-model="formData.name" placeholder="请输入名字" />
</el-form-item>
<el-form-item label="班主任" prop="teacher">
@ -15,13 +15,13 @@
</el-form>
</template>
<script setup lang="ts">
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{
studentId: undefined //
studentId: number //
}>()
const formLoading = ref(false) //
const formData = ref([])
const formData = ref<any>({})
const formRules = reactive({
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
@ -38,11 +38,11 @@ watch(
id: undefined,
studentId: undefined,
name: undefined,
teacher: undefined,
teacher: undefined
}
// 2. val
if (!val) {
return;
return
}
try {
formLoading.value = true
@ -69,4 +69,4 @@ const getData = () => {
}
defineExpose({ validate, getData })
</script>
</script>

View File

@ -1,7 +1,13 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table
row-key="id"
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
>
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="名字" align="center" prop="name" />
<el-table-column label="班主任" align="center" prop="teacher" />
@ -17,13 +23,10 @@
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
const { t } = useI18n() //
const message = useMessage() //
import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{
studentId: undefined //
studentId?: number //
}>()
const loading = ref(false) //
const list = ref([]) //
@ -42,14 +45,8 @@ const getList = async () => {
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>
</script>

View File

@ -1,6 +1,4 @@
<template>
<doc-alert title="代码生成(主子表)" url="https://doc.iocoder.cn/new-feature/master-sub/" />
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
@ -37,7 +35,7 @@
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
class="!w-220px"
/>
</el-form-item>
<el-form-item>
@ -60,13 +58,30 @@
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
<el-button
type="danger"
plain
:disabled="isEmpty(checkedIds)"
@click="handleDeleteBatch"
v-hasPermi="['infra:demo03-student:delete']"
>
<Icon icon="ep:delete" class="mr-5px" /> 批量删除
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table
row-key="id"
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleRowCheckboxChange"
>
<el-table-column type="selection" width="55" />
<!-- 子表的列表 -->
<el-table-column type="expand">
<template #default="scope">
@ -102,7 +117,7 @@
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center">
<el-table-column label="操作" align="center" min-width="120px">
<template #default="scope">
<el-button
link
@ -137,28 +152,30 @@
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { isEmpty } from '@/utils/is'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner'
import { Demo03Student, Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
import Demo03StudentForm from './Demo03StudentForm.vue'
import Demo03CourseList from './components/Demo03CourseList.vue'
import Demo03GradeList from './components/Demo03GradeList.vue'
/** 学生 列表 */
defineOptions({ name: 'Demo03Student' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref([]) //
const list = ref<Demo03Student[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
sex: null,
description: null,
name: undefined,
sex: undefined,
description: undefined,
createTime: []
})
const queryFormRef = ref() //
@ -207,6 +224,22 @@ const handleDelete = async (id: number) => {
} catch {}
}
/** 批量删除学生 */
const handleDeleteBatch = async () => {
try {
//
await message.delConfirm()
await Demo03StudentApi.deleteDemo03StudentList(checkedIds.value)
message.success(t('common.delSuccess'))
await getList()
} catch {}
}
const checkedIds = ref<number[]>([])
const handleRowCheckboxChange = (records: Demo03Student[]) => {
checkedIds.value = records.map((item) => item.id)
}
/** 导出按钮操作 */
const handleExport = async () => {
try {