feat:采集设备列表-添加连接/断开连接按钮

main
黄伟杰 3 months ago
parent 1e60bd6de5
commit 468b563fc3

@ -7,6 +7,7 @@ export interface DeviceVO {
deviceName: string // 设备名称
deviceType: string // 设备类型
status: string // 状态
isConnect?: string | number
readTopic: string // 读主题
writeTopic: string // 写主题
gatewayId: number // 网关id
@ -25,6 +26,11 @@ export interface DeviceVO {
secretKey?: string // 秘钥
}
export interface DeviceConnectParams {
id: string | number
isConnect: string | number
}
// 物联设备 API
export const DeviceApi = {
// 查询物联设备分页
@ -60,6 +66,10 @@ export const DeviceApi = {
return await request.post({ url: `/iot/device/copy`, params: { id } })
},
connectDevice: async (params: DeviceConnectParams) => {
return await request.post({ url: `/iot/device/connect`, data: params })
},
// 导出物联设备 Excel
exportDevice: async (params) => {
return await request.download({ url: `/iot/device/export-excel`, params })
@ -89,10 +99,5 @@ export const DeviceApi = {
// 获得设备属性
getDeviceAttribute: async (id: number) => {
return await request.get({ url: `/iot/device-contact-model/get?id=` + id })
},
// 导出设备属性 Excel
exportDeviceAttribute: async (params) => {
return await request.download({ url: `/iot/device-contact-model/export-excel`, params })
}
}

@ -2,11 +2,13 @@
<ContentWrap>
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
<el-form-item label="点位编码" prop="attributeCode">
<el-input v-model="queryParams.attributeCode" placeholder="请输入点位编码" clearable @keyup.enter="handleQuery"
<el-input
v-model="queryParams.attributeCode" placeholder="请输入点位编码" clearable @keyup.enter="handleQuery"
class="!w-240px" />
</el-form-item>
<el-form-item label="点位名称" prop="attributeName">
<el-input v-model="queryParams.attributeName" placeholder="请输入点位名称" clearable @keyup.enter="handleQuery"
<el-input
v-model="queryParams.attributeName" placeholder="请输入点位名称" clearable @keyup.enter="handleQuery"
class="!w-240px" />
</el-form-item>
<el-form-item label="点位类型" prop="attributeType">
@ -24,7 +26,8 @@
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['iot:device:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button type="success" plain @click="handleExport" :loading="exportLoading"
<el-button
type="success" plain @click="handleExport" :loading="exportLoading"
v-hasPermi="['iot:device:export']">
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
@ -36,7 +39,8 @@
</ContentWrap>
<ContentWrap>
<el-table ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" row-key="id"
<el-table
ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" row-key="id"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" reserve-selection />
<el-table-column label="点位编码" align="left" prop="attributeCode" width="150px" />
@ -59,7 +63,8 @@
</el-table-column>
<el-table-column label="单位" align="center" prop="dataUnit" width="80px" />
<el-table-column label="倍率" align="center" prop="ratio" width="80px" />
<el-table-column label="最新采集时间" align="center" prop="latestCollectTime" :formatter="dateFormatter"
<el-table-column
label="最新采集时间" align="center" prop="latestCollectTime" :formatter="dateFormatter"
width="170px" />
<el-table-column label="顺序" align="center" prop="sort" width="80px">
<template #default="scope">
@ -78,7 +83,8 @@
</template>
</el-table-column>
</el-table>
<Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
<Pagination
:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
@pagination="getList" />
</ContentWrap>
@ -89,6 +95,7 @@ import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { DeviceApi } from '@/api/iot/device'
import { DeviceModelAttributeApi } from '@/api/iot/devicemodelattribute'
import DeviceAttributeForm from './DeviceAttributeForm.vue'
import { DeviceAttributeTypeApi, DeviceAttributeTypeVO } from '@/api/iot/deviceattributetype'
@ -226,7 +233,7 @@ const handleExport = async () => {
try {
await message.exportConfirm()
exportLoading.value = true
const data = await DeviceApi.exportDeviceAttribute({ ids: selectedIds.value.join(',') })
const data = await DeviceModelAttributeApi.exportDeviceModelAttribute({ ids: selectedIds.value.join(',') })
download.excel(data, '采集设备-点位管理.xls')
} catch {
} finally {

@ -137,7 +137,7 @@
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.isEnable" />
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="320px">
<el-table-column label="操作" align="center" fixed="right" width="380px">
<template #default="scope">
<el-button link type="primary" @click.stop="handleShowAttribute(scope.row)">点位</el-button>
<el-button
@ -164,6 +164,14 @@
>
编辑
</el-button>
<el-button
link
:type="isRowConnected(scope.row) ? 'warning' : 'success'"
:loading="!!connectLoadingMap[scope.row.id]"
@click.stop="handleToggleConnect(scope.row)"
>
{{ isRowConnected(scope.row) ? '断开连接' : '连接' }}
</el-button>
<el-button
link
type="danger"
@ -201,7 +209,7 @@
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { DeviceApi, DeviceVO } from '@/api/iot/device'
import { DeviceApi, DeviceConnectParams, DeviceVO } from '@/api/iot/device'
import DeviceForm from './DeviceForm.vue'
import DeviceAttributeList from './components/DeviceAttributeList.vue'
@ -346,6 +354,40 @@ const handleShowAttribute = (row: any) => {
attributeDeviceName.value = row?.deviceName ?? ''
}
const connectLoadingMap = reactive<Record<number, boolean>>({})
const getRowConnectValue = (row: any) => {
return row?.isConnect ?? row?.status
}
const isRowConnected = (row: any) => {
return String(getRowConnectValue(row)) === '1'
}
const handleToggleConnect = async (row: DeviceVO) => {
const id = row?.id
if (!id) {
message.error('设备信息不完整')
return
}
const nextIsConnect = isRowConnected(row) ? '2' : '1'
const actionText = nextIsConnect === '1' ? '连接' : '断开连接'
try {
await message.confirm(`确认${actionText}设备“${row.deviceName ?? ''}”吗?`)
connectLoadingMap[id] = true
const params: DeviceConnectParams = { id: String(id), isConnect: nextIsConnect }
await DeviceApi.connectDevice(params)
message.success(`${actionText}成功`)
await getList()
} catch {
} finally {
connectLoadingMap[id] = false
}
}
let timer: any = null;
/** 初始化 **/
onMounted(() => {

@ -3,11 +3,13 @@
<!-- 搜索工作栏 -->
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
<el-form-item label="点位编码" prop="attributeCode">
<el-input v-model="queryParams.attributeCode" placeholder="请输入点位编码" clearable @keyup.enter="handleQuery"
<el-input
v-model="queryParams.attributeCode" placeholder="请输入点位编码" clearable @keyup.enter="handleQuery"
class="!w-240px" />
</el-form-item>
<el-form-item label="点位名称" prop="attributeName">
<el-input v-model="queryParams.attributeName" placeholder="请输入点位名称" clearable @keyup.enter="handleQuery"
<el-input
v-model="queryParams.attributeName" placeholder="请输入点位名称" clearable @keyup.enter="handleQuery"
class="!w-240px" />
</el-form-item>
<el-form-item label="点位类型" prop="attributeType">
@ -45,7 +47,8 @@
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['iot:device-model:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button type="success" plain @click="handleExport" :loading="exportLoading"
<el-button
type="success" plain @click="handleExport" :loading="exportLoading"
v-hasPermi="['iot:device-model:export']">
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
@ -59,7 +62,8 @@
<!-- 列表 -->
<ContentWrap>
<el-table ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" row-key="id"
<el-table
ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" row-key="id"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" reserve-selection />
<!-- <el-table-column label="ID" align="center" prop="id" /> -->
@ -75,7 +79,8 @@
<el-table-column label="创建时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
<el-table-column label="操作" align="center" width="150px" fixed="right">
<template #default="scope">
<el-button link type="primary" @click="openForm('update', scope.row.id)"
<el-button
link type="primary" @click="openForm('update', scope.row.id)"
v-hasPermi="['iot:device-model:update']">
编辑
</el-button>
@ -86,7 +91,8 @@
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
<Pagination
:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
@pagination="getList" />
</ContentWrap>

Loading…
Cancel
Save