主子表:暂时存储,准备重构

This commit is contained in:
YunaiV 2023-11-09 23:10:54 +08:00
parent eb9f8c9f6f
commit 4e413a10e6
4 changed files with 362 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import request from '@/config/axios'
export interface DemoStudentVO {
id: number
}
// 查询学生列表
export const getDemoStudentPage = async (params) => {
return await request.get({ url: `/infra/demo-student/page`, params })
}
// 查询学生详情
export const getDemoStudent = async (id: number) => {
return await request.get({ url: `/infra/demo-student/get?id=` + id })
}
// 新增学生
export const createDemoStudent = async (data: DemoStudentVO) => {
return await request.post({ url: `/infra/demo-student/create`, data })
}
// 修改学生
export const updateDemoStudent = async (data: DemoStudentVO) => {
return await request.put({ url: `/infra/demo-student/update`, data })
}
// 删除学生
export const deleteDemoStudent = async (id: number) => {
return await request.delete({ url: `/infra/demo-student/delete?id=` + id })
}
// 导出学生 Excel
export const exportDemoStudent = async (params) => {
return await request.download({ url: `/infra/demo-student/export-excel`, params })
}

View File

@ -0,0 +1,71 @@
<template>
<!-- <el-row :gutter="10" class="mb2">-->
<!-- <el-col :span="1.5">-->
<!-- <el-button type="primary" @click="handleAdd">添加</el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button type="danger">删除</el-button>-->
<!-- </el-col>-->
<!-- </el-row>-->
<el-table
:data="formData"
@selection-change="handleDemoStudentContactSelectionChange"
ref="demoStudentContactRef"
:stripe="true"
>
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="名字" prop="name" width="300">
<template #default="scope">
<el-form-item label-width="0px" :inline-message="true">
<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="`formData.${$index}.mobile`"
:rules="formRules.mobile"
:inline-message="true"
>
<el-input type="number" placeholder="输入手机号码" v-model="row.mobile" />
</el-form-item>
</template>
</el-table-column>
</el-table>
<el-button @click="handleAdd" class="w-1/1">+ 添加客户信息</el-button>
</template>
<script setup lang="ts">
const formData = ref([
{
name: '芋艿'
},
{
name: '土豆'
}
])
const formRules = reactive({
mobile: [required]
})
const handleDemoStudentContactSelectionChange = (val) => {
demoStudentContactList.value = val
}
const demoStudentContactRef = ref()
/** 新增按钮操作 */
const handleAdd = () => {
formData.value.push({
name: '测试'
})
}
/** 删除按钮操作 */
const handleRemove = () => {
formData.value.push({
name: '测试'
})
}
</script>

View File

@ -0,0 +1,97 @@
<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="表描述" prop="tableComment">
<el-input v-model="formData.tableComment" placeholder="请输入" />
</el-form-item>
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
<el-tab-pane label="User" name="first">
<DemoStudentContactForm />
</el-tab-pane>
<el-tab-pane label="Config" name="second">Config</el-tab-pane>
<el-tab-pane label="Role" name="third">Role</el-tab-pane>
<el-tab-pane label="Task" name="fourth">Task</el-tab-pane>
</el-tabs>
</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'
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,
demoStudentContactList: []
})
const formRules = reactive({})
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) {
formLoading.value = true
try {
formData.value = await DemoStudentApi.getDemoStudent(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as DemoStudentApi.DemoStudentVO
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,159 @@
<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')"
v-hasPermi="['infra:demo-student: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">
<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">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo-student:update']"
>
编辑
</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'
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 = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
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>