fix: 主子表 demo03 List props

pull/399/head
puhui999 2024-02-28 09:35:12 +08:00
parent 1694827c6c
commit c9d5ec26a2
3 changed files with 101 additions and 85 deletions

View File

@ -2,39 +2,40 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-button <el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['infra:demo03-student:create']" v-hasPermi="['infra:demo03-student:create']"
plain
type="primary"
@click="openForm('create')"
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon class="mr-5px" icon="ep:plus" />
新增
</el-button> </el-button>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
<el-table-column label="编号" align="center" prop="id" /> <el-table-column align="center" label="编号" prop="id" />
<el-table-column label="名字" align="center" prop="name" /> <el-table-column align="center" label="名字" prop="name" />
<el-table-column label="分数" align="center" prop="score" /> <el-table-column align="center" label="分数" prop="score" />
<el-table-column <el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter" :formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180px" width="180px"
/> />
<el-table-column label="操作" align="center"> <el-table-column align="center" label="操作">
<template #default="scope"> <template #default="scope">
<el-button <el-button
v-hasPermi="['infra:demo03-student:update']"
link link
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo03-student:update']"
> >
编辑 编辑
</el-button> </el-button>
<el-button <el-button
v-hasPermi="['infra:demo03-student:delete']"
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo03-student:delete']"
> >
删除 删除
</el-button> </el-button>
@ -43,9 +44,9 @@
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<Pagination <Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
@ -53,7 +54,7 @@
<Demo03CourseForm ref="formRef" @success="getList" /> <Demo03CourseForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts"> <script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp' import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp'
import Demo03CourseForm from './Demo03CourseForm.vue' import Demo03CourseForm from './Demo03CourseForm.vue'
@ -62,7 +63,7 @@ const { t } = useI18n() // 国际化
const message = useMessage() // 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([]) //
@ -70,17 +71,20 @@ const total = ref(0) // 列表的总页数
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
studentId: undefined studentId: undefined as unknown
}) })
/** 监听主表的关联字段的变化,加载对应的子表数据 */ /** 监听主表的关联字段的变化,加载对应的子表数据 */
watch( watch(
() => props.studentId, () => props.studentId,
(val) => { (val: number) => {
if (!val) {
return
}
queryParams.studentId = val queryParams.studentId = val
handleQuery() handleQuery()
}, },
{ immediate: false } { immediate: true, deep: true }
) )
/** 查询列表 */ /** 查询列表 */

View File

@ -2,39 +2,40 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-button <el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['infra:demo03-student:create']" v-hasPermi="['infra:demo03-student:create']"
plain
type="primary"
@click="openForm('create')"
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon class="mr-5px" icon="ep:plus" />
新增
</el-button> </el-button>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
<el-table-column label="编号" align="center" prop="id" /> <el-table-column align="center" label="编号" prop="id" />
<el-table-column label="名字" align="center" prop="name" /> <el-table-column align="center" label="名字" prop="name" />
<el-table-column label="班主任" align="center" prop="teacher" /> <el-table-column align="center" label="班主任" prop="teacher" />
<el-table-column <el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter" :formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180px" width="180px"
/> />
<el-table-column label="操作" align="center"> <el-table-column align="center" label="操作">
<template #default="scope"> <template #default="scope">
<el-button <el-button
v-hasPermi="['infra:demo03-student:update']"
link link
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo03-student:update']"
> >
编辑 编辑
</el-button> </el-button>
<el-button <el-button
v-hasPermi="['infra:demo03-student:delete']"
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo03-student:delete']"
> >
删除 删除
</el-button> </el-button>
@ -43,9 +44,9 @@
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<Pagination <Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
@ -53,7 +54,7 @@
<Demo03GradeForm ref="formRef" @success="getList" /> <Demo03GradeForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts"> <script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp' import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp'
import Demo03GradeForm from './Demo03GradeForm.vue' import Demo03GradeForm from './Demo03GradeForm.vue'
@ -62,7 +63,7 @@ const { t } = useI18n() // 国际化
const message = useMessage() // 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([]) //
@ -70,17 +71,20 @@ const total = ref(0) // 列表的总页数
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
studentId: undefined studentId: undefined as unknown
}) })
/** 监听主表的关联字段的变化,加载对应的子表数据 */ /** 监听主表的关联字段的变化,加载对应的子表数据 */
watch( watch(
() => props.studentId, () => props.studentId,
(val) => { (val: number) => {
if (!val) {
return
}
queryParams.studentId = val queryParams.studentId = val
handleQuery() handleQuery()
}, },
{ immediate: false } { immediate: true, deep: true }
) )
/** 查询列表 */ /** 查询列表 */

View File

@ -4,23 +4,23 @@
<ContentWrap> <ContentWrap>
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<el-form <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef" ref="queryFormRef"
:inline="true" :inline="true"
:model="queryParams"
class="-mb-15px"
label-width="68px" label-width="68px"
> >
<el-form-item label="名字" prop="name"> <el-form-item label="名字" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
placeholder="请输入名字"
clearable
@keyup.enter="handleQuery"
class="!w-240px" class="!w-240px"
clearable
placeholder="请输入名字"
@keyup.enter="handleQuery"
/> />
</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" class="!w-240px" clearable placeholder="请选择性别">
<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"
@ -32,33 +32,41 @@
<el-form-item label="创建时间" prop="createTime"> <el-form-item label="创建时间" prop="createTime">
<el-date-picker <el-date-picker
v-model="queryParams.createTime" v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-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-240px"
end-placeholder="结束日期"
start-placeholder="开始日期"
type="daterange"
value-format="YYYY-MM-DD HH:mm:ss"
/> />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> <el-button @click="handleQuery">
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> <Icon class="mr-5px" icon="ep:search" />
<el-button 搜索
type="primary" </el-button>
plain <el-button @click="resetQuery">
@click="openForm('create')" <Icon class="mr-5px" icon="ep:refresh" />
v-hasPermi="['infra:demo03-student:create']" 重置
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
<el-button <el-button
type="success" v-hasPermi="['infra:demo03-student:create']"
plain plain
@click="handleExport" type="primary"
:loading="exportLoading" @click="openForm('create')"
v-hasPermi="['infra:demo03-student:export']"
> >
<Icon icon="ep:download" class="mr-5px" /> 导出 <Icon class="mr-5px" icon="ep:plus" />
新增
</el-button>
<el-button
v-hasPermi="['infra:demo03-student:export']"
:loading="exportLoading"
plain
type="success"
@click="handleExport"
>
<Icon class="mr-5px" icon="ep:download" />
导出
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -69,48 +77,48 @@
<el-table <el-table
v-loading="loading" v-loading="loading"
:data="list" :data="list"
:stripe="true"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
:stripe="true"
highlight-current-row highlight-current-row
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
> >
<el-table-column label="编号" align="center" prop="id" /> <el-table-column align="center" label="编号" prop="id" />
<el-table-column label="名字" align="center" prop="name" /> <el-table-column align="center" label="名字" prop="name" />
<el-table-column label="性别" align="center" prop="sex"> <el-table-column align="center" label="性别" prop="sex">
<template #default="scope"> <template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
:formatter="dateFormatter"
align="center"
label="出生日期" label="出生日期"
align="center"
prop="birthday" prop="birthday"
:formatter="dateFormatter"
width="180px" width="180px"
/> />
<el-table-column label="简介" align="center" prop="description" /> <el-table-column align="center" label="简介" prop="description" />
<el-table-column <el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter" :formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180px" width="180px"
/> />
<el-table-column label="操作" align="center"> <el-table-column align="center" label="操作">
<template #default="scope"> <template #default="scope">
<el-button <el-button
v-hasPermi="['infra:demo03-student:update']"
link link
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo03-student:update']"
> >
编辑 编辑
</el-button> </el-button>
<el-button <el-button
v-hasPermi="['infra:demo03-student:delete']"
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo03-student:delete']"
> >
删除 删除
</el-button> </el-button>
@ -119,9 +127,9 @@
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<Pagination <Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
@ -132,17 +140,17 @@
<ContentWrap> <ContentWrap>
<el-tabs model-value="demo03Course"> <el-tabs model-value="demo03Course">
<el-tab-pane label="学生课程" name="demo03Course"> <el-tab-pane label="学生课程" name="demo03Course">
<Demo03CourseList :student-id="currentRow.id" /> <Demo03CourseList :student-id="currentRow?.id" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="学生班级" name="demo03Grade"> <el-tab-pane label="学生班级" name="demo03Grade">
<Demo03GradeList :student-id="currentRow.id" /> <Demo03GradeList :student-id="currentRow?.id" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</ContentWrap> </ContentWrap>
</template> </template>
<script setup lang="ts"> <script lang="ts" setup>
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
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/erp' import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp'