代码生成:增加 crud 单表示例
This commit is contained in:
parent
45656562a8
commit
40b1522ed0
40
src/api/infra/demo/demo01/index.ts
Normal file
40
src/api/infra/demo/demo01/index.ts
Normal 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 })
|
||||
}
|
@ -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 })
|
||||
}
|
@ -10,31 +10,10 @@
|
||||
<el-form-item label="名字" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入名字" />
|
||||
</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-select v-model="formData.sex" placeholder="请选择性别">
|
||||
<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-group v-model="formData.sex">
|
||||
<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"
|
||||
:label="dict.value"
|
||||
>
|
||||
@ -42,15 +21,20 @@
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</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" />
|
||||
</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>
|
||||
<template #footer>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||
@ -59,8 +43,8 @@
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import * as Demo01StudentApi from '@/api/infra/demo01'
|
||||
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import * as Demo01ContactApi from '@/api/infra/demo/demo01'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
@ -72,21 +56,16 @@ const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
description: undefined,
|
||||
birthday: undefined,
|
||||
sex: undefined,
|
||||
enabled: undefined,
|
||||
avatar: undefined,
|
||||
video: undefined,
|
||||
memo: undefined
|
||||
birthday: undefined,
|
||||
description: undefined,
|
||||
avatar: undefined
|
||||
})
|
||||
const formRules = reactive({
|
||||
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||
birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }],
|
||||
sex: [{ required: true, message: '性别不能为空', trigger: 'change' }],
|
||||
enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }],
|
||||
avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }],
|
||||
memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }]
|
||||
sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
|
||||
birthday: [{ required: true, message: '出生年不能为空', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '简介不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
@ -100,7 +79,7 @@ const open = async (type: string, id?: number) => {
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await Demo01StudentApi.getDemo01Student(id)
|
||||
formData.value = await Demo01ContactApi.getDemo01Contact(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
@ -116,12 +95,12 @@ const submitForm = async () => {
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as Demo01StudentApi.Demo01StudentVO
|
||||
const data = formData.value as unknown as Demo01ContactApi.Demo01ContactVO
|
||||
if (formType.value === 'create') {
|
||||
await Demo01StudentApi.createDemo01Student(data)
|
||||
await Demo01ContactApi.createDemo01Contact(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await Demo01StudentApi.updateDemo01Student(data)
|
||||
await Demo01ContactApi.updateDemo01Contact(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
@ -137,14 +116,11 @@ const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
description: undefined,
|
||||
birthday: undefined,
|
||||
sex: undefined,
|
||||
enabled: undefined,
|
||||
avatar: undefined,
|
||||
video: undefined,
|
||||
memo: undefined
|
||||
birthday: undefined,
|
||||
description: undefined,
|
||||
avatar: undefined
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
</script>
|
@ -17,16 +17,6 @@
|
||||
class="!w-240px"
|
||||
/>
|
||||
</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-select
|
||||
v-model="queryParams.sex"
|
||||
@ -42,21 +32,6 @@
|
||||
/>
|
||||
</el-select>
|
||||
</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-date-picker
|
||||
v-model="queryParams.createTime"
|
||||
@ -75,7 +50,7 @@
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['infra:demo01-student:create']"
|
||||
v-hasPermi="['infra:demo01-contact:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
@ -84,7 +59,7 @@
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
v-hasPermi="['infra:demo01-student:export']"
|
||||
v-hasPermi="['infra:demo01-contact:export']"
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
@ -97,26 +72,20 @@
|
||||
<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="name" />
|
||||
<el-table-column
|
||||
label="出生日期"
|
||||
align="center"
|
||||
prop="birthday"
|
||||
:formatter="dateFormatter"
|
||||
width="180px"
|
||||
/>
|
||||
<el-table-column label="性别" align="center" prop="sex">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="是否有效" align="center" prop="enabled">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="出生年"
|
||||
align="center"
|
||||
prop="birthday"
|
||||
: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="video" />
|
||||
<el-table-column label="备注" align="center" prop="memo" />
|
||||
<el-table-column
|
||||
label="创建时间"
|
||||
align="center"
|
||||
@ -130,7 +99,7 @@
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['infra:demo01-student:update']"
|
||||
v-hasPermi="['infra:demo01-contact:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
@ -138,7 +107,7 @@
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-hasPermi="['infra:demo01-student:delete']"
|
||||
v-hasPermi="['infra:demo01-contact:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
@ -155,32 +124,29 @@
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<Demo01StudentForm ref="formRef" @success="getList" />
|
||||
<Demo01ContactForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<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 download from '@/utils/download'
|
||||
import * as Demo01StudentApi from '@/api/infra/demo01'
|
||||
import Demo01StudentForm from './Demo01StudentForm.vue'
|
||||
import * as Demo01ContactApi from '@/api/infra/demo/demo01'
|
||||
import Demo01ContactForm from './Demo01ContactForm.vue'
|
||||
|
||||
defineOptions({ name: 'InfraDemo01Student' })
|
||||
defineOptions({ name: 'Demo01Contact' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const total = ref(0) // 列表的总页数
|
||||
const list = ref([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
birthday: null,
|
||||
birthday: [],
|
||||
sex: null,
|
||||
enabled: null,
|
||||
createTime: []
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
@ -190,7 +156,7 @@ const exportLoading = ref(false) // 导出的加载中
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await Demo01StudentApi.getDemo01StudentPage(queryParams)
|
||||
const data = await Demo01ContactApi.getDemo01ContactPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
@ -222,7 +188,7 @@ const handleDelete = async (id: number) => {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await Demo01StudentApi.deleteDemo01Student(id)
|
||||
await Demo01ContactApi.deleteDemo01Contact(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
@ -236,8 +202,8 @@ const handleExport = async () => {
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await Demo01StudentApi.exportDemo01Student(queryParams)
|
||||
download.excel(data, '学生.xls')
|
||||
const data = await Demo01ContactApi.exportDemo01Contact(queryParams)
|
||||
download.excel(data, '示例联系人.xls')
|
||||
} catch {
|
||||
} finally {
|
||||
exportLoading.value = false
|
Loading…
Reference in New Issue
Block a user