新增模版管理界面
This commit is contained in:
parent
7553f16226
commit
4bb3239161
48
src/api/system/template/index.ts
Normal file
48
src/api/system/template/index.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import request from '@/config/axios'
|
||||
|
||||
// 模板 VO
|
||||
export interface TemplateVO {
|
||||
id: number // 主键ID
|
||||
type: string // 类型
|
||||
orgid: number // 组织ID
|
||||
content: string // 内容
|
||||
createtime: Date // 创建时间
|
||||
updatetime: Date // 更新时间
|
||||
}
|
||||
|
||||
// 模板 API
|
||||
export const TemplateApi = {
|
||||
// 查询模板分页
|
||||
getTemplatePage: async (params: any) => {
|
||||
return await request.get({ url: `/system/template/page`, params })
|
||||
},
|
||||
|
||||
// 查询模板详情
|
||||
getTemplate: async (id: number) => {
|
||||
return await request.get({ url: `/system/template/get?id=` + id })
|
||||
},
|
||||
// 查询模板列表
|
||||
getTemplateList: async (type: string, orgid: number) => {
|
||||
return await request.get({ url: `/system/template/list?type=` + type + `&orgid=` + orgid })
|
||||
},
|
||||
|
||||
// 新增模板
|
||||
createTemplate: async (data: TemplateVO) => {
|
||||
return await request.post({ url: `/system/template/create`, data })
|
||||
},
|
||||
|
||||
// 修改模板
|
||||
updateTemplate: async (data: TemplateVO) => {
|
||||
return await request.put({ url: `/system/template/update`, data })
|
||||
},
|
||||
|
||||
// 删除模板
|
||||
deleteTemplate: async (id: number) => {
|
||||
return await request.delete({ url: `/system/template/delete?id=` + id })
|
||||
},
|
||||
|
||||
// 导出模板 Excel
|
||||
exportTemplate: async (params) => {
|
||||
return await request.download({ url: `/system/template/export-excel`, params })
|
||||
}
|
||||
}
|
||||
@ -244,5 +244,7 @@ export enum DICT_TYPE {
|
||||
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
|
||||
IOT_PLUGIN_TYPE = 'iot_plugin_type', // IOT 插件类型
|
||||
IOT_DATA_BRIDGE_DIRECTION_ENUM = 'iot_data_bridge_direction_enum', // 桥梁方向
|
||||
IOT_DATA_BRIDGE_TYPE_ENUM = 'iot_data_bridge_type_enum' // 桥梁类型
|
||||
IOT_DATA_BRIDGE_TYPE_ENUM = 'iot_data_bridge_type_enum', // 桥梁类型
|
||||
//=================TEMPLATE_TYPE=================
|
||||
TEMPLATE_TYPE = 'template_type' // 模板类型
|
||||
}
|
||||
|
||||
133
src/views/system/template/TemplateForm.vue
Normal file
133
src/views/system/template/TemplateForm.vue
Normal file
@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
class="modern-form"
|
||||
>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="formData.type" placeholder="请选择类型" class="!w-180px">
|
||||
<el-option
|
||||
v-for="dict in getStrDictOptions(DICT_TYPE.TEMPLATE_TYPE)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" prop="content">
|
||||
<el-input v-model="formData.content" type="textarea" :rows="4" placeholder="请输入内容" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button
|
||||
@click="submitForm"
|
||||
type="primary"
|
||||
class="modern-btn primary"
|
||||
:disabled="formLoading"
|
||||
>确 定</el-button
|
||||
>
|
||||
<el-button @click="dialogVisible = false" class="modern-btn">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { TemplateApi, TemplateVO } from '@/api/system/template'
|
||||
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
||||
import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
|
||||
/** 模板 表单 */
|
||||
defineOptions({ name: 'TemplateForm' })
|
||||
|
||||
const Profilevo = ref<ProfileVO>({} as ProfileVO) //当前登录人信息
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
type: undefined,
|
||||
content: undefined
|
||||
})
|
||||
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
|
||||
Profilevo.value = await getUserProfile()
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await TemplateApi.getTemplate(id)
|
||||
} 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 TemplateVO
|
||||
data.orgid = Profilevo.value.orgid
|
||||
if (formType.value === 'create') {
|
||||
await TemplateApi.createTemplate(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await TemplateApi.updateTemplate(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
type: undefined,
|
||||
content: undefined
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.modern-form {
|
||||
.el-form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
.modern-btn {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
border: none;
|
||||
&.primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
300
src/views/system/template/index.vue
Normal file
300
src/views/system/template/index.vue
Normal file
@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-card class="search-card-modern" shadow="never">
|
||||
<el-form
|
||||
class="search-bar-modern flex items-center justify-between"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="68px"
|
||||
style="margin-bottom: 0"
|
||||
>
|
||||
<el-form-item label="类型" prop="type" class="!mb-0">
|
||||
<el-select v-model="queryParams.type" placeholder="请选择类型" clearable class="!w-180px">
|
||||
<el-option
|
||||
v-for="dict in getStrDictOptions(DICT_TYPE.TEMPLATE_TYPE)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<div class="flex gap-1 ml-auto search-buttons-group">
|
||||
<el-button @click="handleQuery" class="modern-btn primary"
|
||||
><Icon icon="ep:search" class="mr-4px" /> 搜索</el-button
|
||||
>
|
||||
<el-button @click="resetQuery" class="modern-btn"
|
||||
><Icon icon="ep:refresh" class="mr-4px" /> 重置</el-button
|
||||
>
|
||||
<el-button type="primary" plain @click="openForm('create')" class="modern-btn success">
|
||||
<Icon icon="ep:plus" class="mr-4px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
class="modern-btn warning"
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-4px" /> 导出
|
||||
</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-card shadow="never" class="table-card-modern">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
:stripe="true"
|
||||
:show-overflow-tooltip="true"
|
||||
class="modern-table"
|
||||
style="border-radius: 10px; overflow: hidden"
|
||||
>
|
||||
<el-table-column label="序号" type="index" width="60" align="center" />
|
||||
<el-table-column label="类型" align="center" prop="type" />
|
||||
<el-table-column label="内容" align="center" prop="content" />
|
||||
<el-table-column label="操作" align="center" min-width="120px">
|
||||
<template #default="scope">
|
||||
<div class="action-buttons">
|
||||
<el-button
|
||||
link
|
||||
size="small"
|
||||
class="action-btn-modern edit-btn"
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
size="small"
|
||||
class="action-btn-modern delete-btn"
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-wrapper">
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<TemplateForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { TemplateApi, TemplateVO } from '@/api/system/template'
|
||||
import TemplateForm from './TemplateForm.vue'
|
||||
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
||||
import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
|
||||
/** 模板 列表 */
|
||||
defineOptions({ name: 'Template' })
|
||||
|
||||
const Profilevo = ref<ProfileVO>({} as ProfileVO) //当前登录人信息
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<TemplateVO[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
type: undefined,
|
||||
orgid: undefined as number | undefined
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
queryParams.orgid = Profilevo.value.orgid
|
||||
const data = await TemplateApi.getTemplatePage(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 TemplateApi.deleteTemplate(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
// 导出的二次确认
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await TemplateApi.exportTemplate(queryParams)
|
||||
download.excel(data, '模板.xls')
|
||||
} catch {
|
||||
} finally {
|
||||
exportLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(async () => {
|
||||
Profilevo.value = await getUserProfile()
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.search-card-modern {
|
||||
margin-bottom: 12px;
|
||||
border-radius: 10px;
|
||||
padding: 8px 12px 4px 12px;
|
||||
background: #f8fafd;
|
||||
border: none;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.search-bar-modern {
|
||||
background: transparent;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin-bottom: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
.search-buttons-group {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.modern-btn {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
border: none;
|
||||
&.primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
|
||||
}
|
||||
}
|
||||
&.success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #0f8a7d 0%, #2dd66e 100%);
|
||||
}
|
||||
}
|
||||
&.warning {
|
||||
background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #f7971e 0%, #fceabb 100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
.table-card-modern {
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
|
||||
border: none;
|
||||
}
|
||||
.modern-table {
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
:deep(.el-table__header) {
|
||||
background: #f5f7fa;
|
||||
th {
|
||||
background: #f5f7fa;
|
||||
color: #303133;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
:deep(.el-table__row) {
|
||||
transition: all 0.3s;
|
||||
&:hover {
|
||||
background: #f0f9ff;
|
||||
}
|
||||
}
|
||||
}
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.action-btn-modern {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
&.edit-btn {
|
||||
background: linear-gradient(135deg, #409eff 0%, #67c23a 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #337ecc 0%, #5daf34 100%);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px rgba(64, 158, 255, 0.18);
|
||||
}
|
||||
}
|
||||
&.delete-btn {
|
||||
background: linear-gradient(135deg, #f56c6c 0%, #e6a23c 100%);
|
||||
color: #fff;
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #f78989 0%, #ebb563 100%);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px rgba(245, 108, 108, 0.18);
|
||||
}
|
||||
}
|
||||
}
|
||||
.pagination-wrapper {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user