主子表:同步三种模式的代码

This commit is contained in:
YunaiV 2023-11-10 19:54:55 +08:00
parent 86d9a97ccb
commit 9f9e0f8bda
16 changed files with 1294 additions and 87 deletions

View File

@ -0,0 +1,58 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="子字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
<el-form-item label="子字段 2" prop="field2">
<el-input v-model="formData.field2" placeholder="请输入字段 2" />
</el-form-item>
<el-form-item label="子字段 3" prop="field3">
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const formLoading = ref(false) //
const formData = ref({})
const formRules = reactive({
field1: [required]
})
const formRef = ref() // Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
if (val) {
formData.value = {
field2: '番茄',
field3: '西瓜'
}
} else {
formData.value = {}
}
},
{ immediate: true }
)
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 **/
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>

View File

@ -1,68 +1,89 @@
<template>
<el-table :data="formData" :stripe="true" class="-mt-10px">
<el-table-column label="序号" type="index" width="60" />
<el-table-column label="名字" prop="name" width="300">
<template #default="scope">
<el-form-item label-width="0px" :inline-message="true" class="mb-0px!">
<el-input v-model="scope.row.name" placeholder="请输入名字" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="手机号码">
<template #default="{ row, $index }">
<el-form-item
label-width="0px"
:prop="`demoStudentContactList.${$index}.mobile`"
:rules="formRules.mobile"
:inline-message="true"
class="mb-0px!"
>
<el-input type="number" placeholder="输入手机号码" v-model="row.mobile" />
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60">
<template #default="{ $index }">
<el-button @click="handleRemove($index)" link></el-button>
</template>
</el-table-column>
</el-table>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="0px"
v-loading="formLoading"
:inline-message="true"
>
<el-table :data="formData" class="-mt-10px">
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="名字" prop="name" width="300">
<template #default="row">
<el-form-item class="mb-0px!">
<el-input v-model="row.name" placeholder="请输入名字" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="手机号码">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.mobile`" :rules="formRules.mobile" class="mb-0px!">
<el-input type="number" placeholder="输入手机号码" v-model="row.mobile" />
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link></el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3">
<el-button @click="handleAdd" round>+ 添加联系人</el-button>
</el-row>
</template>
<script setup lang="ts">
const props = defineProps<{
formData: any[]
studentId: undefined //
}>()
// const formData = ref([
// {
// name: '',
// mobile: '15601691300'
// },
// {
// name: '',
// mobile: '15601691234'
// }
// ])
const formLoading = ref(false) //
const formData = ref([])
const formRules = reactive({
mobile: [required]
})
const formRef = ref() // Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
if (val) {
formData.value = [
{
name: '芋艿',
mobile: '15601691300'
}
]
} else {
formData.value = []
}
},
{ immediate: true }
)
/** 新增按钮操作 */
const emit = defineEmits(['update:formData'])
const handleAdd = () => {
emit('update:formData', [
...props.formData,
{
name: '土豆'
}
])
formData.value.push({
name: '土豆'
})
}
/** 删除按钮操作 */
const handleRemove = (index) => {
const formData = props.formData.filter((_, i) => i !== index)
emit('update:formData', formData)
const handleDelete = (index) => {
formData.value.splice(index, 1)
}
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 **/
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>

View File

@ -17,12 +17,14 @@
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
<el-tab-pane label="联系人信息" name="first">
<DemoStudentContactForm v-model:form-data="formData.demoStudentContactList" />
<!-- 子表的表单 -->
<el-tabs v-model="subTabsName">
<el-tab-pane label="联系人信息" name="DemoStudentContact">
<DemoStudentContactForm ref="demoStudentContactFormRef" :student-id="formData.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="DemoStudentAddress">
<DemoStudentAddressForm ref="demoStudentAddressFormRef" :student-id="formData.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="third">地址信息</el-tab-pane>
<el-tab-pane label="其它信息" name="fourth">其它信息</el-tab-pane>
</el-tabs>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
@ -33,6 +35,7 @@
<script setup lang="ts">
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentContactForm from './DemoStudentContactForm.vue'
import DemoStudentAddressForm from './DemoStudentAddressForm.vue'
const { t } = useI18n() //
const message = useMessage() //
@ -42,28 +45,36 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
demoStudentContactList: [
{
name: '芋艿',
mobile: '15601691300'
}
]
id: undefined
})
const formRules = reactive({
field2: [required]
})
const formRules = reactive({})
const formRef = ref() // Ref
/** 子表的表单 */
const demoStudentContactFormRef = ref()
const demoStudentAddressFormRef = ref()
const subTabsName = ref('DemoStudentContact')
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
// resetForm()
resetForm()
//
if (id) {
// debugger
formLoading.value = true
try {
formData.value = await DemoStudentApi.getDemoStudent(id)
// formData.value = await DemoStudentApi.getDemoStudent(id)
formData.value = {
id: id,
field1: '1',
field2: '22',
field3: '333'
}
} finally {
formLoading.value = false
}
@ -75,13 +86,27 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
await formRef.value.validate()
//
try {
await demoStudentContactFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentContact'
return
}
try {
await demoStudentAddressFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentAddress'
return
}
//
formLoading.value = true
try {
const data = formData.value as unknown as DemoStudentApi.DemoStudentVO
//
data.demoStudentContacts = demoStudentContactFormRef.value.getData()
data.demoStudentAddress = demoStudentAddressFormRef.value.getData()
if (formType.value === 'create') {
await DemoStudentApi.createDemoStudent(data)
message.success(t('common.createSuccess'))

View File

@ -11,12 +11,7 @@
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['infra:demo-student:create']"
>
<el-button type="primary" plain @click="openForm('create')">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
@ -35,19 +30,10 @@
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="编号" align="center" prop="id">
<template #default="scope">
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" />
</template>
</el-table-column>
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo-student:update']"
>
<el-button link type="primary" @click="openForm('update', scope.row.id)">
编辑
</el-button>
<el-button
@ -98,9 +84,13 @@ const exportLoading = ref(false) // 导出的加载中
const getList = async () => {
loading.value = true
try {
const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = data.list
total.value = data.total
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: 1
}
]
total.value = 10
} finally {
loading.value = false
}
@ -120,7 +110,10 @@ const resetQuery = () => {
/** 添加/修改操作 */
const formRef = ref()
// const demoStudentContactFormRef = ref()
const openForm = (type: string, id?: number) => {
// console.log(demoStudentContactFormRef, 'xx demoStudentContactFormRef xx')
// demoStudentContactFormRef.value.validate()
formRef.value.open(type, id)
}

View File

@ -0,0 +1,58 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="子字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
<el-form-item label="子字段 2" prop="field2">
<el-input v-model="formData.field2" placeholder="请输入字段 2" />
</el-form-item>
<el-form-item label="子字段 3" prop="field3">
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const formLoading = ref(false) //
const formData = ref({})
const formRules = reactive({
field1: [required]
})
const formRef = ref() // Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
if (val) {
formData.value = {
field2: '番茄',
field3: '西瓜'
}
} else {
formData.value = {}
}
},
{ immediate: true }
)
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 **/
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>

View File

@ -0,0 +1,38 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-table 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="mobile" />
</el-table>
</ContentWrap>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const loading = ref(true) //
const list = ref([]) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: props.studentId,
mobile: '88888'
}
]
} finally {
loading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,89 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="0px"
v-loading="formLoading"
:inline-message="true"
>
<el-table :data="formData" class="-mt-10px">
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="名字" prop="name" width="300">
<template #default="row">
<el-form-item class="mb-0px!">
<el-input v-model="row.name" placeholder="请输入名字" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="手机号码">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.mobile`" :rules="formRules.mobile" class="mb-0px!">
<el-input type="number" placeholder="输入手机号码" v-model="row.mobile" />
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link></el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3">
<el-button @click="handleAdd" round>+ 添加联系人</el-button>
</el-row>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const formLoading = ref(false) //
const formData = ref([])
const formRules = reactive({
mobile: [required]
})
const formRef = ref() // Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
if (val) {
formData.value = [
{
name: '芋艿',
mobile: '15601691300'
}
]
} else {
formData.value = []
}
},
{ immediate: true }
)
/** 新增按钮操作 */
const handleAdd = () => {
formData.value.push({
name: '土豆'
})
}
/** 删除按钮操作 */
const handleDelete = (index) => {
formData.value.splice(index, 1)
}
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 **/
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>

View File

@ -0,0 +1,38 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-table 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="mobile" />
</el-table>
</ContentWrap>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const loading = ref(true) //
const list = ref([]) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: props.studentId,
mobile: '15601691300'
}
]
} finally {
loading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,132 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
<el-form-item label="字段 2" prop="field2">
<el-input v-model="formData.field2" placeholder="请输入字段 2" />
</el-form-item>
<el-form-item label="字段 3" prop="field3">
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
<!-- 子表的表单 -->
<el-tabs v-model="subTabsName">
<el-tab-pane label="联系人信息" name="DemoStudentContact">
<DemoStudentContactForm ref="demoStudentContactFormRef" :student-id="formData.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="DemoStudentAddress">
<DemoStudentAddressForm ref="demoStudentAddressFormRef" :student-id="formData.id" />
</el-tab-pane>
</el-tabs>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentContactForm from './DemoStudentContactForm.vue'
import DemoStudentAddressForm from './DemoStudentAddressForm.vue'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined
})
const formRules = reactive({
field2: [required]
})
const formRef = ref() // Ref
/** 子表的表单 */
const demoStudentContactFormRef = ref()
const demoStudentAddressFormRef = ref()
const subTabsName = ref('DemoStudentContact')
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
// debugger
formLoading.value = true
try {
// formData.value = await DemoStudentApi.getDemoStudent(id)
formData.value = {
id: id,
field1: '1',
field2: '22',
field3: '333'
}
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
try {
await demoStudentContactFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentContact'
return
}
try {
await demoStudentAddressFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentAddress'
return
}
//
formLoading.value = true
try {
const data = formData.value as unknown as DemoStudentApi.DemoStudentVO
//
data.demoStudentContacts = demoStudentContactFormRef.value.getData()
data.demoStudentAddress = demoStudentAddressFormRef.value.getData()
if (formType.value === 'create') {
await DemoStudentApi.createDemoStudent(data)
message.success(t('common.createSuccess'))
} else {
await DemoStudentApi.updateDemoStudent(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,176 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" plain @click="openForm('create')">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['infra:demo-student:export']"
>
<Icon icon="ep:download" 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"
row-key="id"
>
<el-table-column type="expand">
<template #default="scope">
<!-- 子表的表单 -->
<el-tabs model-value="DemoStudentContact">
<el-tab-pane label="联系人信息" name="DemoStudentContact">
<DemoStudentContactList :student-id="scope.row.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="DemoStudentAddress">
<DemoStudentAddressList :student-id="scope.row.id" />
</el-tab-pane>
</el-tabs>
</template>
</el-table-column>
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button link type="primary" @click="openForm('update', scope.row.id)">
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo-student:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<DemoStudentForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import download from '@/utils/download'
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentForm from './DemoStudentForm.vue'
import DemoStudentContactList from './DemoStudentContactList.vue'
import DemoStudentAddressList from './DemoStudentAddressList.vue'
defineOptions({ name: 'InfraDemoStudent' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: 1
},
{
id: 10
}
]
total.value = 10
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
// const demoStudentContactFormRef = ref()
const openForm = (type: string, id?: number) => {
// console.log(demoStudentContactFormRef, 'xx demoStudentContactFormRef xx')
// demoStudentContactFormRef.value.validate()
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await DemoStudentApi.deleteDemoStudent(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await DemoStudentApi.exportDemoStudent(queryParams)
download.excel(data, '学生.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,58 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="子字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
<el-form-item label="子字段 2" prop="field2">
<el-input v-model="formData.field2" placeholder="请输入字段 2" />
</el-form-item>
<el-form-item label="子字段 3" prop="field3">
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const formLoading = ref(false) //
const formData = ref({})
const formRules = reactive({
field1: [required]
})
const formRef = ref() // Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
if (val) {
formData.value = {
field2: '番茄',
field3: '西瓜'
}
} else {
formData.value = {}
}
},
{ immediate: true }
)
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 **/
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>

View File

@ -0,0 +1,39 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-table 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="mobile" />
</el-table>
</ContentWrap>
</template>
<script setup lang="ts">
const props = defineProps<{
studentId: undefined //
}>()
const loading = ref(true) //
const list = ref([]) //
// TODO
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: props.studentId,
mobile: '88888'
}
]
} finally {
loading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,96 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentContactForm from './DemoStudentContactForm.vue'
import DemoStudentAddressForm from './DemoStudentAddressForm.vue'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined
})
const formRules = reactive({
field2: [required]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
// debugger
formLoading.value = true
try {
// formData.value = await DemoStudentApi.getDemoStudent(id)
formData.value = {
id: id,
field1: '1',
field2: '22',
field3: '333'
}
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as DemoStudentApi.DemoStudentVO
if (formType.value === 'create') {
// await DemoStudentApi.createDemoStudent(data) // TODO
message.success(t('common.createSuccess'))
} else {
await DemoStudentApi.updateDemoStudent(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,70 @@
<template>
<!-- 列表 -->
<ContentWrap>
<el-button type="primary" plain @click="openForm('create')">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-table 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="mobile" />
</el-table>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<DemoStudentContactForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import DemoStudentContactForm from './DemoStudentContactForm.vue'
const props = defineProps<{
studentId: undefined //
}>()
const loading = ref(false) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
studentId: undefined
})
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.studentId,
(val) => {
queryParams.studentId = val
handleQuery()
},
{ immediate: false }
)
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: props.studentId,
mobile: '15601691300'
}
]
total.value = 10
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
</script>

View File

@ -0,0 +1,132 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="字段 1" prop="field1">
<el-input v-model="formData.field1" placeholder="请输入字段 1" />
</el-form-item>
<el-form-item label="字段 2" prop="field2">
<el-input v-model="formData.field2" placeholder="请输入字段 2" />
</el-form-item>
<el-form-item label="字段 3" prop="field3">
<el-input v-model="formData.field3" placeholder="请输入字段 3" />
</el-form-item>
</el-form>
<!-- 子表的表单 -->
<el-tabs v-model="subTabsName">
<el-tab-pane label="联系人信息" name="DemoStudentContact">
<DemoStudentContactForm ref="demoStudentContactFormRef" :student-id="formData.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="DemoStudentAddress">
<DemoStudentAddressForm ref="demoStudentAddressFormRef" :student-id="formData.id" />
</el-tab-pane>
</el-tabs>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentContactForm from './DemoStudentContactForm.vue'
import DemoStudentAddressForm from './DemoStudentAddressForm.vue'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined
})
const formRules = reactive({
field2: [required]
})
const formRef = ref() // Ref
/** 子表的表单 */
const demoStudentContactFormRef = ref()
const demoStudentAddressFormRef = ref()
const subTabsName = ref('DemoStudentContact')
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
// debugger
formLoading.value = true
try {
// formData.value = await DemoStudentApi.getDemoStudent(id)
formData.value = {
id: id,
field1: '1',
field2: '22',
field3: '333'
}
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
try {
await demoStudentContactFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentContact'
return
}
try {
await demoStudentAddressFormRef.value.validate()
} catch (e) {
subTabsName.value = 'DemoStudentAddress'
return
}
//
formLoading.value = true
try {
const data = formData.value as unknown as DemoStudentApi.DemoStudentVO
//
data.demoStudentContacts = demoStudentContactFormRef.value.getData()
data.demoStudentAddress = demoStudentAddressFormRef.value.getData()
if (formType.value === 'create') {
await DemoStudentApi.createDemoStudent(data)
message.success(t('common.createSuccess'))
} else {
await DemoStudentApi.updateDemoStudent(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,184 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" plain @click="openForm('create')">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['infra:demo-student:export']"
>
<Icon icon="ep:download" 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"
highlight-current-row
@current-change="handleCurrentChange"
>
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button link type="primary" @click="openForm('update', scope.row.id)">
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo-student:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 子列表 -->
<ContentWrap>
<el-tabs model-value="DemoStudentContact">
<el-tab-pane label="联系人信息" name="DemoStudentContact">
<DemoStudentContactList :student-id="currentRow.id" />
</el-tab-pane>
<el-tab-pane label="地址信息" name="DemoStudentAddress">
<DemoStudentAddressList :student-id="currentRow.id" />
</el-tab-pane>
</el-tabs>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<DemoStudentForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import download from '@/utils/download'
import * as DemoStudentApi from '@/api/infra/demo02'
import DemoStudentForm from './DemoStudentForm.vue'
import DemoStudentContactList from './DemoStudentContactList.vue'
import DemoStudentAddressList from './DemoStudentAddressList.vue'
defineOptions({ name: 'InfraDemoStudent' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
const currentRow = ref({}) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
// const data = await DemoStudentApi.getDemoStudentPage(queryParams)
list.value = [
{
id: 1
},
{
id: 10
}
]
total.value = 10
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
// const demoStudentContactFormRef = ref()
const openForm = (type: string, id?: number) => {
// console.log(demoStudentContactFormRef, 'xx demoStudentContactFormRef xx')
// demoStudentContactFormRef.value.validate()
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await DemoStudentApi.deleteDemoStudent(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await DemoStudentApi.exportDemoStudent(queryParams)
download.excel(data, '学生.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 选中行操作 */
const handleCurrentChange = (row) => {
console.log(currentRow.value, '==== currentRow.value ====')
console.log(row, '==== row ====')
currentRow.value = row
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>