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

View File

@ -72,7 +72,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import { isEmpty } from '@/utils/is' 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' import Demo03GradeForm from './Demo03GradeForm.vue'
const { t } = useI18n() // const { t } = useI18n() //

View File

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

View File

@ -35,13 +35,13 @@
</el-row> </el-row>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner' import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{ const props = defineProps<{
studentId: undefined // studentId: number //
}>() }>()
const formLoading = ref(false) // const formLoading = ref(false) //
const formData = ref([]) const formData = ref<any[]>([])
const formRules = reactive({ const formRules = reactive({
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }], studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
@ -57,7 +57,7 @@ watch(
formData.value = [] formData.value = []
// 2. val // 2. val
if (!val) { if (!val) {
return; return
} }
try { try {
formLoading.value = true formLoading.value = true
@ -77,7 +77,7 @@ const handleAdd = () => {
name: undefined, name: undefined,
score: undefined score: undefined
} }
row.studentId = props.studentId row.studentId = props.studentId as any
formData.value.push(row) formData.value.push(row)
} }

View File

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

View File

@ -15,13 +15,13 @@
</el-form> </el-form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as Demo03StudentApi from '@/api/infra/demo/demo03/inner' import { Demo03StudentApi } from '@/api/infra/demo/demo03/inner'
const props = defineProps<{ const props = defineProps<{
studentId: undefined // studentId: number //
}>() }>()
const formLoading = ref(false) // const formLoading = ref(false) //
const formData = ref([]) const formData = ref<any>({})
const formRules = reactive({ const formRules = reactive({
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }], studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
@ -38,11 +38,11 @@ watch(
id: undefined, id: undefined,
studentId: undefined, studentId: undefined,
name: undefined, name: undefined,
teacher: undefined, teacher: undefined
} }
// 2. val // 2. val
if (!val) { if (!val) {
return; return
} }
try { try {
formLoading.value = true formLoading.value = true

View File

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

View File

@ -1,6 +1,4 @@
<template> <template>
<doc-alert title="代码生成(主子表)" url="https://doc.iocoder.cn/new-feature/master-sub/" />
<ContentWrap> <ContentWrap>
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<el-form <el-form
@ -37,7 +35,7 @@
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" :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>
<el-form-item> <el-form-item>
@ -60,13 +58,30 @@
> >
<Icon icon="ep:download" class="mr-5px" /> 导出 <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button> </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-item>
</el-form> </el-form>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<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"> <el-table-column type="expand">
<template #default="scope"> <template #default="scope">
@ -102,7 +117,7 @@
:formatter="dateFormatter" :formatter="dateFormatter"
width="180px" width="180px"
/> />
<el-table-column label="操作" align="center"> <el-table-column label="操作" align="center" min-width="120px">
<template #default="scope"> <template #default="scope">
<el-button <el-button
link link
@ -137,28 +152,30 @@
</template> </template>
<script setup lang="ts"> <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 { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' 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 Demo03StudentForm from './Demo03StudentForm.vue'
import Demo03CourseList from './components/Demo03CourseList.vue' import Demo03CourseList from './components/Demo03CourseList.vue'
import Demo03GradeList from './components/Demo03GradeList.vue' import Demo03GradeList from './components/Demo03GradeList.vue'
/** 学生 列表 */
defineOptions({ name: 'Demo03Student' }) defineOptions({ name: 'Demo03Student' })
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const loading = ref(true) // const loading = ref(true) //
const list = ref([]) // const list = ref<Demo03Student[]>([]) //
const total = ref(0) // const total = ref(0) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
name: null, name: undefined,
sex: null, sex: undefined,
description: null, description: undefined,
createTime: [] createTime: []
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
@ -207,6 +224,22 @@ const handleDelete = async (id: number) => {
} catch {} } 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 () => { const handleExport = async () => {
try { try {