代码生成:增加 crud 单表示例

This commit is contained in:
YunaiV 2023-11-15 23:48:00 +08:00
parent 45656562a8
commit 40b1522ed0
4 changed files with 92 additions and 153 deletions

View File

@ -0,0 +1,40 @@
import request from '@/config/axios'
export interface Demo01ContactVO {
id: number
name: string
sex: number
birthday: Date
description: string
avatar: string
}
// 查询示例联系人分页
export const getDemo01ContactPage = async (params) => {
return await request.get({ url: `/infra/demo01-contact/page`, params })
}
// 查询示例联系人详情
export const getDemo01Contact = async (id: number) => {
return await request.get({ url: `/infra/demo01-contact/get?id=` + id })
}
// 新增示例联系人
export const createDemo01Contact = async (data: Demo01ContactVO) => {
return await request.post({ url: `/infra/demo01-contact/create`, data })
}
// 修改示例联系人
export const updateDemo01Contact = async (data: Demo01ContactVO) => {
return await request.put({ url: `/infra/demo01-contact/update`, data })
}
// 删除示例联系人
export const deleteDemo01Contact = async (id: number) => {
return await request.delete({ url: `/infra/demo01-contact/delete?id=` + id })
}
// 导出示例联系人 Excel
export const exportDemo01Contact = async (params) => {
return await request.download({ url: `/infra/demo01-contact/export-excel`, params })
}

View File

@ -1,43 +0,0 @@
import request from '@/config/axios'
export interface Demo01StudentVO {
id: number
name: string
description: string
birthday: Date
sex: number
enabled: boolean
avatar: string
video: string
memo: string
}
// 查询学生列表
export const getDemo01StudentPage = async (params) => {
return await request.get({ url: `/infra/demo01-student/page`, params })
}
// 查询学生详情
export const getDemo01Student = async (id: number) => {
return await request.get({ url: `/infra/demo01-student/get?id=` + id })
}
// 新增学生
export const createDemo01Student = async (data: Demo01StudentVO) => {
return await request.post({ url: `/infra/demo01-student/create`, data })
}
// 修改学生
export const updateDemo01Student = async (data: Demo01StudentVO) => {
return await request.put({ url: `/infra/demo01-student/update`, data })
}
// 删除学生
export const deleteDemo01Student = async (id: number) => {
return await request.delete({ url: `/infra/demo01-student/delete?id=` + id })
}
// 导出学生 Excel
export const exportDemo01Student = async (params) => {
return await request.download({ url: `/infra/demo01-student/export-excel`, params })
}

View File

@ -10,31 +10,10 @@
<el-form-item label="名字" prop="name"> <el-form-item label="名字" prop="name">
<el-input v-model="formData.name" placeholder="请输入名字" /> <el-input v-model="formData.name" placeholder="请输入名字" />
</el-form-item> </el-form-item>
<el-form-item label="简介" prop="description">
<el-input v-model="formData.description" type="textarea" placeholder="请输入简介" />
</el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker
v-model="formData.birthday"
type="date"
value-format="x"
placeholder="选择出生日期"
/>
</el-form-item>
<el-form-item label="性别" prop="sex"> <el-form-item label="性别" prop="sex">
<el-select v-model="formData.sex" placeholder="请选择性别"> <el-radio-group v-model="formData.sex">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="是否有效" prop="enabled">
<el-radio-group v-model="formData.enabled">
<el-radio <el-radio
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)" v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
:key="dict.value" :key="dict.value"
:label="dict.value" :label="dict.value"
> >
@ -42,15 +21,20 @@
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="头像"> <el-form-item label="出生年" prop="birthday">
<el-date-picker
v-model="formData.birthday"
type="date"
value-format="x"
placeholder="选择出生年"
/>
</el-form-item>
<el-form-item label="简介" prop="description">
<Editor v-model="formData.description" height="150px" />
</el-form-item>
<el-form-item label="头像" prop="avatar">
<UploadImg v-model="formData.avatar" /> <UploadImg v-model="formData.avatar" />
</el-form-item> </el-form-item>
<el-form-item label="附件" prop="video">
<UploadFile v-model="formData.video" />
</el-form-item>
<el-form-item label="备注" prop="memo">
<Editor v-model="formData.memo" height="150px" />
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button> <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
@ -59,8 +43,8 @@
</Dialog> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import * as Demo01StudentApi from '@/api/infra/demo01' import * as Demo01ContactApi from '@/api/infra/demo/demo01'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -72,21 +56,16 @@ const formType = ref('') // 表单的类型create - 新增update - 修改
const formData = ref({ const formData = ref({
id: undefined, id: undefined,
name: undefined, name: undefined,
description: undefined,
birthday: undefined,
sex: undefined, sex: undefined,
enabled: undefined, birthday: undefined,
avatar: undefined, description: undefined,
video: undefined, avatar: undefined
memo: undefined
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], birthday: [{ required: true, message: '出生年不能为空', trigger: 'blur' }],
enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], description: [{ required: true, message: '简介不能为空', trigger: 'blur' }]
avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }],
memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
@ -100,7 +79,7 @@ const open = async (type: string, id?: number) => {
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await Demo01StudentApi.getDemo01Student(id) formData.value = await Demo01ContactApi.getDemo01Contact(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -116,12 +95,12 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value as unknown as Demo01StudentApi.Demo01StudentVO const data = formData.value as unknown as Demo01ContactApi.Demo01ContactVO
if (formType.value === 'create') { if (formType.value === 'create') {
await Demo01StudentApi.createDemo01Student(data) await Demo01ContactApi.createDemo01Contact(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await Demo01StudentApi.updateDemo01Student(data) await Demo01ContactApi.updateDemo01Contact(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
dialogVisible.value = false dialogVisible.value = false
@ -137,13 +116,10 @@ const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,
name: undefined, name: undefined,
description: undefined,
birthday: undefined,
sex: undefined, sex: undefined,
enabled: undefined, birthday: undefined,
avatar: undefined, description: undefined,
video: undefined, avatar: undefined
memo: undefined
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

View File

@ -17,16 +17,6 @@
class="!w-240px" class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker
v-model="queryParams.birthday"
value-format="YYYY-MM-DD"
type="date"
placeholder="选择出生日期"
clearable
class="!w-240px"
/>
</el-form-item>
<el-form-item label="性别" prop="sex"> <el-form-item label="性别" prop="sex">
<el-select <el-select
v-model="queryParams.sex" v-model="queryParams.sex"
@ -42,21 +32,6 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="是否有效" prop="enabled">
<el-select
v-model="queryParams.enabled"
placeholder="请选择是否有效"
clearable
class="!w-240px"
>
<el-option
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<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"
@ -75,7 +50,7 @@
type="primary" type="primary"
plain plain
@click="openForm('create')" @click="openForm('create')"
v-hasPermi="['infra:demo01-student:create']" v-hasPermi="['infra:demo01-contact:create']"
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
@ -84,7 +59,7 @@
plain plain
@click="handleExport" @click="handleExport"
:loading="exportLoading" :loading="exportLoading"
v-hasPermi="['infra:demo01-student:export']" v-hasPermi="['infra:demo01-contact:export']"
> >
<Icon icon="ep:download" class="mr-5px" /> 导出 <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button> </el-button>
@ -97,26 +72,20 @@
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> <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="id" />
<el-table-column label="名字" align="center" prop="name" /> <el-table-column label="名字" align="center" prop="name" />
<el-table-column
label="出生日期"
align="center"
prop="birthday"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="性别" align="center" prop="sex"> <el-table-column label="性别" align="center" 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 label="是否有效" align="center" prop="enabled"> <el-table-column
<template #default="scope"> label="出生年"
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> align="center"
</template> prop="birthday"
</el-table-column> :formatter="dateFormatter"
width="180px"
/>
<el-table-column label="简介" align="center" prop="description" />
<el-table-column label="头像" align="center" prop="avatar" /> <el-table-column label="头像" align="center" prop="avatar" />
<el-table-column label="附件" align="center" prop="video" />
<el-table-column label="备注" align="center" prop="memo" />
<el-table-column <el-table-column
label="创建时间" label="创建时间"
align="center" align="center"
@ -130,7 +99,7 @@
link link
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:demo01-student:update']" v-hasPermi="['infra:demo01-contact:update']"
> >
编辑 编辑
</el-button> </el-button>
@ -138,7 +107,7 @@
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:demo01-student:delete']" v-hasPermi="['infra:demo01-contact:delete']"
> >
删除 删除
</el-button> </el-button>
@ -155,32 +124,29 @@
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<Demo01StudentForm ref="formRef" @success="getList" /> <Demo01ContactForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { getIntDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' import { getIntDictOptions, DICT_TYPE } 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 Demo01StudentApi from '@/api/infra/demo01' import * as Demo01ContactApi from '@/api/infra/demo/demo01'
import Demo01StudentForm from './Demo01StudentForm.vue' import Demo01ContactForm from './Demo01ContactForm.vue'
defineOptions({ name: 'InfraDemo01Student' }) defineOptions({ name: 'Demo01Contact' })
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const loading = ref(true) // const loading = ref(true) //
const total = ref(0) //
const list = ref([]) // const list = ref([]) //
const total = ref(0) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
name: null, name: null,
birthday: null,
birthday: [],
sex: null, sex: null,
enabled: null,
createTime: [] createTime: []
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
@ -190,7 +156,7 @@ const exportLoading = ref(false) // 导出的加载中
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await Demo01StudentApi.getDemo01StudentPage(queryParams) const data = await Demo01ContactApi.getDemo01ContactPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -222,7 +188,7 @@ const handleDelete = async (id: number) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await Demo01StudentApi.deleteDemo01Student(id) await Demo01ContactApi.deleteDemo01Contact(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()
@ -236,8 +202,8 @@ const handleExport = async () => {
await message.exportConfirm() await message.exportConfirm()
// //
exportLoading.value = true exportLoading.value = true
const data = await Demo01StudentApi.exportDemo01Student(queryParams) const data = await Demo01ContactApi.exportDemo01Contact(queryParams)
download.excel(data, '学生.xls') download.excel(data, '示例联系人.xls')
} catch { } catch {
} finally { } finally {
exportLoading.value = false exportLoading.value = false