Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bd0ea273
authored
Jun 06, 2025
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 优化代码生成 normal 主子表示例
parent
54d18945
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
62 deletions
+131
-62
src/api/infra/demo/demo03/normal/index.ts
+63
-35
src/views/infra/demo/demo03/normal/Demo03StudentForm.vue
+8
-5
src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue
+6
-6
src/views/infra/demo/demo03/normal/components/Demo03GradeForm.vue
+4
-4
src/views/infra/demo/demo03/normal/index.vue
+50
-12
No files found.
src/api/infra/demo/demo03/normal/index.ts
View file @
bd0ea273
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
;
// 编号
s
ex
:
number
s
tudentId
?:
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-normal/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-normal/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-normal/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-normal/update`
,
data
})
}
},
// 删除学生
deleteDemo03Student
:
async
(
id
:
number
)
=>
{
return
await
request
.
delete
({
url
:
`/infra/demo03-student-normal/delete?id=`
+
id
})
},
/** 批量删除学生 */
deleteDemo03StudentList
:
async
(
ids
:
number
[])
=>
{
return
await
request
.
delete
({
url
:
`/infra/demo03-student-normal/delete-list?ids=
${
ids
.
join
(
','
)}
`
})
},
// 导出学生 Excel
exportDemo03Student
:
async
(
params
)
=>
{
return
await
request
.
download
({
url
:
`/infra/demo03-student-normal/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-normal
/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-normal/demo03-grade/get-by-student-id?studentId=`
+
studentId
})
},
}
}
src/views/infra/demo/demo03/normal/Demo03StudentForm.vue
View file @
bd0ea273
...
@@ -50,10 +50,13 @@
...
@@ -50,10 +50,13 @@
</template>
</template>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
getIntDictOptions
,
DICT_TYPE
}
from
'@/utils/dict'
import
{
getIntDictOptions
,
DICT_TYPE
}
from
'@/utils/dict'
import
*
as
Demo03StudentApi
from
'@/api/infra/demo/demo03/normal'
import
{
Demo03StudentApi
,
Demo03Student
}
from
'@/api/infra/demo/demo03/normal'
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
()
// 消息弹窗
...
@@ -66,13 +69,13 @@ const formData = ref({
...
@@ -66,13 +69,13 @@ const formData = ref({
name
:
undefined
,
name
:
undefined
,
sex
:
undefined
,
sex
:
undefined
,
birthday
:
undefined
,
birthday
:
undefined
,
description
:
undefined
description
:
undefined
,
})
})
const
formRules
=
reactive
({
const
formRules
=
reactive
({
name
:
[{
required
:
true
,
message
:
'名字不能为空'
,
trigger
:
'blur'
}],
name
:
[{
required
:
true
,
message
:
'名字不能为空'
,
trigger
:
'blur'
}],
sex
:
[{
required
:
true
,
message
:
'性别不能为空'
,
trigger
:
'blur'
}],
sex
:
[{
required
:
true
,
message
:
'性别不能为空'
,
trigger
:
'blur'
}],
birthday
:
[{
required
:
true
,
message
:
'出生日期不能为空'
,
trigger
:
'blur'
}],
birthday
:
[{
required
:
true
,
message
:
'出生日期不能为空'
,
trigger
:
'blur'
}],
description
:
[{
required
:
true
,
message
:
'简介不能为空'
,
trigger
:
'blur'
}]
description
:
[{
required
:
true
,
message
:
'简介不能为空'
,
trigger
:
'blur'
}]
,
})
})
const
formRef
=
ref
()
// 表单 Ref
const
formRef
=
ref
()
// 表单 Ref
...
@@ -120,7 +123,7 @@ const submitForm = async () => {
...
@@ -120,7 +123,7 @@ const submitForm = async () => {
// 提交请求
// 提交请求
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
data
=
formData
.
value
as
unknown
as
Demo03Student
Api
.
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
()
...
@@ -146,7 +149,7 @@ const resetForm = () => {
...
@@ -146,7 +149,7 @@ const resetForm = () => {
name
:
undefined
,
name
:
undefined
,
sex
:
undefined
,
sex
:
undefined
,
birthday
:
undefined
,
birthday
:
undefined
,
description
:
undefined
description
:
undefined
,
}
}
formRef
.
value
?.
resetFields
()
formRef
.
value
?.
resetFields
()
}
}
...
...
src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue
View file @
bd0ea273
...
@@ -35,17 +35,17 @@
...
@@ -35,17 +35,17 @@
</el-row>
</el-row>
</template>
</template>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
*
as
Demo03StudentApi
from
'@/api/infra/demo/demo03/normal'
import
{
Demo03StudentApi
}
from
'@/api/infra/demo/demo03/normal'
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'
}],
score
:
[{
required
:
true
,
message
:
'分数不能为空'
,
trigger
:
'blur'
}]
score
:
[{
required
:
true
,
message
:
'分数不能为空'
,
trigger
:
'blur'
}]
,
})
})
const
formRef
=
ref
()
// 表单 Ref
const
formRef
=
ref
()
// 表单 Ref
...
@@ -75,9 +75,9 @@ const handleAdd = () => {
...
@@ -75,9 +75,9 @@ const handleAdd = () => {
id
:
undefined
,
id
:
undefined
,
studentId
:
undefined
,
studentId
:
undefined
,
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
)
}
}
...
...
src/views/infra/demo/demo03/normal/components/Demo03GradeForm.vue
View file @
bd0ea273
...
@@ -15,17 +15,17 @@
...
@@ -15,17 +15,17 @@
</el-form>
</el-form>
</
template
>
</
template
>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
*
as
Demo03StudentApi
from
'@/api/infra/demo/demo03/normal'
import
{
Demo03StudentApi
}
from
'@/api/infra/demo/demo03/normal'
const
props
=
defineProps
<
{
const
props
=
defineProps
<
{
studentId
:
undefined
// 学生编号(主表的关联字段)
studentId
:
number
// 学生编号(主表的关联字段)
}
>
()
}
>
()
const
formLoading
=
ref
(
false
)
// 表单的加载中
const
formLoading
=
ref
(
false
)
// 表单的加载中
const
formData
=
ref
(
[]
)
const
formData
=
ref
(
{}
)
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'
}],
teacher
:
[{
required
:
true
,
message
:
'班主任不能为空'
,
trigger
:
'blur'
}]
teacher
:
[{
required
:
true
,
message
:
'班主任不能为空'
,
trigger
:
'blur'
}]
,
})
})
const
formRef
=
ref
()
// 表单 Ref
const
formRef
=
ref
()
// 表单 Ref
...
...
src/views/infra/demo/demo03/normal/index.vue
View file @
bd0ea273
<
template
>
<
template
>
<doc-alert
title=
"代码生成(主子表)"
url=
"https://doc.iocoder.cn/new-feature/master-sub/"
/>
<ContentWrap>
<ContentWrap>
<!-- 搜索工作栏 -->
<!-- 搜索工作栏 -->
<el-form
<el-form
...
@@ -20,7 +18,12 @@
...
@@ -20,7 +18,12 @@
/>
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"性别"
prop=
"sex"
>
<el-form-item
label=
"性别"
prop=
"sex"
>
<el-select
v-model=
"queryParams.sex"
placeholder=
"请选择性别"
clearable
class=
"!w-240px"
>
<el-select
v-model=
"queryParams.sex"
placeholder=
"请选择性别"
clearable
class=
"!w-240px"
>
<el-option
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
v-for=
"dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
:key=
"dict.value"
:key=
"dict.value"
...
@@ -37,7 +40,7 @@
...
@@ -37,7 +40,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-2
4
0px"
class=
"!w-2
2
0px"
/>
/>
</el-form-item>
</el-form-item>
<el-form-item>
<el-form-item>
...
@@ -60,13 +63,30 @@
...
@@ -60,13 +63,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
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=
"sex"
>
<el-table-column
label=
"性别"
align=
"center"
prop=
"sex"
>
...
@@ -89,7 +109,7 @@
...
@@ -89,7 +109,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
...
@@ -125,26 +145,28 @@
...
@@ -125,26 +145,28 @@
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
getIntDictOptions
,
DICT_TYPE
}
from
'@/utils/dict'
import
{
getIntDictOptions
,
DICT_TYPE
}
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/normal'
import
{
Demo03StudentApi
,
Demo03Student
}
from
'@/api/infra/demo/demo03/normal'
import
Demo03StudentForm
from
'./Demo03StudentForm.vue'
import
Demo03StudentForm
from
'./Demo03StudentForm.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
()
// 搜索的表单
const
exportLoading
=
ref
(
false
)
// 导出的加载中
const
exportLoading
=
ref
(
false
)
// 导出的加载中
...
@@ -192,6 +214,22 @@ const handleDelete = async (id: number) => {
...
@@ -192,6 +214,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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment