【功能新增】IoT:增加插件信息管理功能,包括插件信息接口和表单组件

pull/620/MERGE
安浩浩 2024-12-14 21:52:25 +08:00
parent 3ea61c51ef
commit 87300563dd
5 changed files with 462 additions and 1 deletions

View File

@ -0,0 +1,51 @@
import request from '@/config/axios'
// IoT 插件信息 VO
export interface PluginInfoVO {
id: number // 主键ID
pluginId: string // 插件包id
name: string // 插件名称
description: string // 描述
deployType: number // 部署方式
file: string // 插件包文件名
version: string // 插件版本
type: number // 插件类型
protocol: string // 设备插件协议类型
status: number // 状态
configSchema: string // 插件配置项描述信息
config: string // 插件配置信息
script: string // 插件脚本
}
// IoT 插件信息 API
export const PluginInfoApi = {
// 查询IoT 插件信息分页
getPluginInfoPage: async (params: any) => {
return await request.get({ url: `/iot/plugin-info/page`, params })
},
// 查询IoT 插件信息详情
getPluginInfo: async (id: number) => {
return await request.get({ url: `/iot/plugin-info/get?id=` + id })
},
// 新增IoT 插件信息
createPluginInfo: async (data: PluginInfoVO) => {
return await request.post({ url: `/iot/plugin-info/create`, data })
},
// 修改IoT 插件信息
updatePluginInfo: async (data: PluginInfoVO) => {
return await request.put({ url: `/iot/plugin-info/update`, data })
},
// 删除IoT 插件信息
deletePluginInfo: async (id: number) => {
return await request.delete({ url: `/iot/plugin-info/delete?id=` + id })
},
// 导出IoT 插件信息 Excel
exportPluginInfo: async (params) => {
return await request.download({ url: `/iot/plugin-info/export-excel`, params })
}
}

View File

@ -239,5 +239,8 @@ export enum DICT_TYPE {
IOT_PRODUCT_FUNCTION_TYPE = 'iot_product_function_type', // IOT 产品功能类型
IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型
IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
IOT_RW_TYPE = 'iot_rw_type' // IOT 读写类型
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
IOT_PLUGIN_DEPLOY_TYPE = 'iot_plugin_deploy_type', // IOT 插件部署类型
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
IOT_PLUGIN_TYPE = 'iot_plugin_type' // IOT 插件类型
}

View File

@ -0,0 +1,106 @@
<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="name">
<el-input v-model="formData.name" placeholder="请输入插件名称" />
</el-form-item>
<el-form-item label="部署方式" prop="deployType">
<el-select v-model="formData.deployType" placeholder="请选择部署方式">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PLUGIN_DEPLOY_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</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 { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { PluginInfoApi, PluginInfoVO } from '@/api/iot/plugininfo'
/** IoT 插件信息 表单 */
defineOptions({ name: 'PluginInfoForm' })
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,
name: undefined,
deployType: undefined
})
const formRules = reactive({
name: [{ required: true, message: '插件名称不能为空', trigger: 'blur' }],
deployType: [{ required: true, message: '部署方式不能为空', trigger: 'change' }]
})
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 PluginInfoApi.getPluginInfo(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 PluginInfoVO
if (formType.value === 'create') {
await PluginInfoApi.createPluginInfo(data)
message.success(t('common.createSuccess'))
} else {
await PluginInfoApi.updatePluginInfo(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: undefined,
deployType: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,44 @@
<template>
<ContentWrap>
<el-descriptions title="插件详情" :column="2" border>
<el-descriptions-item label="插件名称">{{ pluginInfo.name }}</el-descriptions-item>
<el-descriptions-item label="组件ID">{{ pluginInfo.pluginId }}</el-descriptions-item>
<el-descriptions-item label="Jar包">{{ pluginInfo.file }}</el-descriptions-item>
<el-descriptions-item label="版本号">{{ pluginInfo.version }}</el-descriptions-item>
<el-descriptions-item label="部署方式">
<dict-tag :type="DICT_TYPE.IOT_PLUGIN_DEPLOY_TYPE" :value="pluginInfo.deployType" />
</el-descriptions-item>
<el-descriptions-item label="状态">
<dict-tag :type="DICT_TYPE.IOT_PLUGIN_STATUS" :value="pluginInfo.status" />
</el-descriptions-item>
</el-descriptions>
<el-button type="primary" @click="goBack"></el-button>
</ContentWrap>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { PluginInfoApi, PluginInfoVO } from '@/api/iot/plugininfo'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const pluginInfo = ref<PluginInfoVO>({})
const getPluginInfo = async (id: number) => {
const data = await PluginInfoApi.getPluginInfo(id)
pluginInfo.value = data
}
const goBack = () => {
router.back()
}
onMounted(() => {
const id = Number(route.params.id)
if (id) {
getPluginInfo(id)
}
})
</script>

View File

@ -0,0 +1,257 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="插件名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入插件名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="请选择状态"
clearable
@change="handleQuery"
class="!w-240px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PLUGIN_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<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="['iot:plugin-info:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
</el-form-item>
<!-- 视图切换按钮 -->
<el-form-item class="float-right !mr-0 !mb-0">
<el-button-group>
<el-button :type="viewType === 'card' ? 'primary' : 'default'" @click="viewType = 'card'">
<Icon icon="ep:grid" />
</el-button>
<el-button
:type="viewType === 'table' ? 'primary' : 'default'"
@click="viewType = 'table'"
>
<Icon icon="ep:list" />
</el-button>
</el-button-group>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap v-if="viewType === 'table'">
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="插件名称" align="center" prop="name" />
<el-table-column label="组件id" align="center" prop="pluginId" />
<el-table-column label="jar包" align="center" prop="file" />
<el-table-column label="版本号" align="center" prop="version" />
<el-table-column label="部署方式" align="center" prop="deployType">
<template #default="scope">
<dict-tag :type="DICT_TYPE.IOT_PLUGIN_DEPLOY_TYPE" :value="scope.row.deployType" />
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.IOT_PLUGIN_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center" min-width="120px">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['iot:plugin-info:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['iot:plugin-info:delete']"
>
删除
</el-button>
<el-button
link
type="info"
@click="viewDetail(scope.row.id)"
>
详情
</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 v-else>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<el-card
v-for="item in list"
:key="item.pluginId"
class="cursor-pointer hover:shadow-lg transition-shadow"
>
<div class="flex items-center mb-4">
<div class="flex-1">
<div class="font-bold text-lg">{{ item.name }}</div>
<div class="text-gray-500 text-sm">组件ID: {{ item.pluginId }}</div>
</div>
</div>
<div class="text-sm text-gray-500">
<div>Jar包: {{ item.file }}</div>
<div>版本号: {{ item.version }}</div>
<div
>部署方式: <dict-tag :type="DICT_TYPE.IOT_PLUGIN_DEPLOY_TYPE" :value="item.deployType"
/></div>
<div>状态: <dict-tag :type="DICT_TYPE.IOT_PLUGIN_STATUS" :value="item.status" /></div>
</div>
<div class="flex justify-end mt-4">
<el-button
link
type="primary"
@click.stop="openForm('update', item.id)"
v-hasPermi="['iot:plugin-info:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click.stop="handleDelete(item.id)"
v-hasPermi="['iot:plugin-info:delete']"
>
删除
</el-button>
</div>
</el-card>
</div>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<PluginInfoForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { PluginInfoApi, PluginInfoVO } from '@/api/iot/plugininfo'
import PluginInfoForm from './PluginInfoForm.vue'
/** IoT 插件信息 列表 */
defineOptions({ name: 'PluginInfo' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref<PluginInfoVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: undefined,
status: undefined
})
const queryFormRef = ref() //
const viewType = ref<'card' | 'table'>('table') //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await PluginInfoApi.getPluginInfoPage(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 PluginInfoApi.deletePluginInfo(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 查看详情操作 */
const viewDetail = (id: number) => {
router.push({ path: `/iot/plugininfo/detail/${id}` })
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>