Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b69a784e
authored
Sep 21, 2024
by
安浩浩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】 IOT 设备管理
parent
85c0da5a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
478 additions
and
7 deletions
+478
-7
src/api/iot/device/index.ts
+64
-0
src/api/iot/product/index.ts
+5
-0
src/router/modules/remaining.ts
+1
-1
src/utils/dict.ts
+2
-1
src/views/iot/device/DeviceForm.vue
+121
-0
src/views/iot/device/index.vue
+276
-0
src/views/iot/product/ProductForm.vue
+1
-1
src/views/iot/product/detail/index.vue
+1
-1
src/views/iot/product/index.vue
+7
-3
No files found.
src/api/iot/device/index.ts
0 → 100644
View file @
b69a784e
import
request
from
'@/config/axios'
// IoT 设备 VO
export
interface
DeviceVO
{
id
:
number
// 设备 ID,主键,自增
deviceKey
:
string
// 设备唯一标识符,全局唯一,用于识别设备
deviceName
:
string
// 设备名称,在产品内唯一,用于标识设备
productId
:
number
// 产品 ID,关联 iot_product 表的 id
productKey
:
string
// 产品 Key,关联 iot_product 表的 product_key
deviceType
:
number
// 设备类型:0 - 直连设备,1 - 网关子设备,2 - 网关设备
nickname
:
string
// 设备备注名称,供用户自定义备注
gatewayId
:
number
// 网关设备 ID,子设备需要关联的网关设备 ID
status
:
number
// 设备状态:0 - 未激活,1 - 在线,2 - 离线,3 - 已禁用
statusLastUpdateTime
:
Date
// 设备状态最后更新时间
lastOnlineTime
:
Date
// 最后上线时间
lastOfflineTime
:
Date
// 最后离线时间
activeTime
:
Date
// 设备激活时间
ip
:
string
// 设备的 IP 地址
firmwareVersion
:
string
// 设备的固件版本
deviceSecret
:
string
// 设备密钥,用于设备认证,需安全存储
mqttClientId
:
string
// MQTT 客户端 ID
mqttUsername
:
string
// MQTT 用户名
mqttPassword
:
string
// MQTT 密码
authType
:
string
// 认证类型(如一机一密、动态注册)
latitude
:
number
// 设备位置的纬度,范围 -90.000000 ~ 90.000000
longitude
:
number
// 设备位置的经度,范围 -180.000000 ~ 180.000000
areaId
:
number
// 地区编码,符合国家地区编码标准,关联地区表
address
:
string
// 设备详细地址
serialNumber
:
string
// 设备序列号
}
// IoT 设备 API
export
const
DeviceApi
=
{
// 查询IoT 设备分页
getDevicePage
:
async
(
params
:
any
)
=>
{
return
await
request
.
get
({
url
:
`/iot/device/page`
,
params
})
},
// 查询IoT 设备详情
getDevice
:
async
(
id
:
number
)
=>
{
return
await
request
.
get
({
url
:
`/iot/device/get?id=`
+
id
})
},
// 新增IoT 设备
createDevice
:
async
(
data
:
DeviceVO
)
=>
{
return
await
request
.
post
({
url
:
`/iot/device/create`
,
data
})
},
// 修改IoT 设备
updateDevice
:
async
(
data
:
DeviceVO
)
=>
{
return
await
request
.
put
({
url
:
`/iot/device/update`
,
data
})
},
// 删除IoT 设备
deleteDevice
:
async
(
id
:
number
)
=>
{
return
await
request
.
delete
({
url
:
`/iot/device/delete?id=`
+
id
})
},
// 导出IoT 设备 Excel
exportDevice
:
async
(
params
)
=>
{
return
await
request
.
download
({
url
:
`/iot/device/export-excel`
,
params
})
}
}
\ No newline at end of file
src/api/iot/product/index.ts
View file @
b69a784e
...
@@ -51,5 +51,10 @@ export const ProductApi = {
...
@@ -51,5 +51,10 @@ export const ProductApi = {
// 更新产品状态
// 更新产品状态
updateProductStatus
:
async
(
id
:
number
,
status
:
number
)
=>
{
updateProductStatus
:
async
(
id
:
number
,
status
:
number
)
=>
{
return
await
request
.
put
({
url
:
`/iot/product/update-status?id=`
+
id
+
`&status=`
+
status
})
return
await
request
.
put
({
url
:
`/iot/product/update-status?id=`
+
id
+
`&status=`
+
status
})
},
// 查询产品(精简)列表
getSimpleProductList
()
{
return
request
.
get
({
url
:
'/iot/product/list-all-simple'
})
}
}
}
}
src/router/modules/remaining.ts
View file @
b69a784e
...
@@ -614,7 +614,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
...
@@ -614,7 +614,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
children
:
[
children
:
[
{
{
path
:
'product/detail/:id'
,
path
:
'product/detail/:id'
,
name
:
'Io
t
ProductDetail'
,
name
:
'Io
T
ProductDetail'
,
meta
:
{
meta
:
{
title
:
'产品详情'
,
title
:
'产品详情'
,
noCache
:
true
,
noCache
:
true
,
...
...
src/utils/dict.ts
View file @
b69a784e
...
@@ -234,5 +234,6 @@ export enum DICT_TYPE {
...
@@ -234,5 +234,6 @@ export enum DICT_TYPE {
IOT_PRODUCT_STATUS
=
'iot_product_status'
,
// IOT 产品状态
IOT_PRODUCT_STATUS
=
'iot_product_status'
,
// IOT 产品状态
IOT_PRODUCT_DEVICE_TYPE
=
'iot_product_device_type'
,
// IOT 产品设备类型
IOT_PRODUCT_DEVICE_TYPE
=
'iot_product_device_type'
,
// IOT 产品设备类型
IOT_DATA_FORMAT
=
'iot_data_format'
,
// IOT 数据格式
IOT_DATA_FORMAT
=
'iot_data_format'
,
// IOT 数据格式
IOT_PROTOCOL_TYPE
=
'iot_protocol_type'
// IOT 接入网关协议
IOT_PROTOCOL_TYPE
=
'iot_protocol_type'
,
// IOT 接入网关协议
IOT_DEVICE_STATUS
=
'iot_device_status'
// IOT 设备状态
}
}
src/views/iot/device/DeviceForm.vue
0 → 100644
View file @
b69a784e
<
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=
"productId"
>
<el-select
v-model=
"formData.productId"
placeholder=
"请选择产品"
clearable
>
<el-option
v-for=
"product in products"
:key=
"product.id"
:label=
"product.name"
:value=
"product.id"
/>
</el-select>
</el-form-item>
<el-form-item
label=
"DeviceName"
prop=
"deviceName"
>
<el-input
v-model=
"formData.deviceName"
placeholder=
"请输入 DeviceName"
/>
</el-form-item>
<el-form-item
label=
"备注名称"
prop=
"nickname"
>
<el-input
v-model=
"formData.nickname"
placeholder=
"请输入备注名称"
/>
</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
{
DeviceApi
,
DeviceVO
}
from
'@/api/iot/device'
import
{
ProductApi
}
from
'@/api/iot/product'
/** IoT 设备 表单 */
defineOptions
({
name
:
'IoTDeviceForm'
})
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
,
productId
:
undefined
,
deviceName
:
undefined
,
nickname
:
undefined
,
serialNumber
:
undefined
})
const
formRules
=
reactive
({
productId
:
[{
required
:
true
,
message
:
'产品不能为空'
,
trigger
:
'blur'
}]
})
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
DeviceApi
.
getDevice
(
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
DeviceVO
if
(
formType
.
value
===
'create'
)
{
await
DeviceApi
.
createDevice
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
}
else
{
await
DeviceApi
.
updateDevice
(
data
)
message
.
success
(
t
(
'common.updateSuccess'
))
}
dialogVisible
.
value
=
false
// 发送操作成功的事件
emit
(
'success'
)
}
finally
{
formLoading
.
value
=
false
}
}
/** 重置表单 */
const
resetForm
=
()
=>
{
formData
.
value
=
{
id
:
undefined
,
productId
:
undefined
,
deviceName
:
undefined
,
nickname
:
undefined
}
formRef
.
value
?.
resetFields
()
}
/** 查询字典下拉列表 */
const
products
=
ref
()
const
getProducts
=
async
()
=>
{
products
.
value
=
await
ProductApi
.
getSimpleProductList
()
}
onMounted
(()
=>
{
getProducts
()
})
</
script
>
src/views/iot/device/index.vue
0 → 100644
View file @
b69a784e
<
template
>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class=
"-mb-15px"
:model=
"queryParams"
ref=
"queryFormRef"
:inline=
"true"
label-width=
"68px"
>
<el-form-item
label=
"产品"
prop=
"productId"
>
<el-select
v-model=
"queryParams.productId"
placeholder=
"请选择产品"
clearable
class=
"!w-240px"
>
<el-option
v-for=
"product in products"
:key=
"product.id"
:label=
"product.name"
:value=
"product.id"
/>
</el-select>
</el-form-item>
<el-form-item
label=
"DeviceName"
prop=
"deviceName"
>
<el-input
v-model=
"queryParams.deviceName"
placeholder=
"请输入 DeviceName"
clearable
@
keyup
.
enter=
"handleQuery"
class=
"!w-240px"
/>
</el-form-item>
<el-form-item
label=
"备注名称"
prop=
"nickname"
>
<el-input
v-model=
"queryParams.nickname"
placeholder=
"请输入备注名称"
clearable
@
keyup
.
enter=
"handleQuery"
class=
"!w-240px"
/>
</el-form-item>
<el-form-item
label=
"设备类型"
prop=
"deviceType"
>
<el-select
v-model=
"queryParams.deviceType"
placeholder=
"请选择设备类型"
clearable
class=
"!w-240px"
>
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE)"
:key=
"dict.value"
:label=
"dict.label"
:value=
"dict.value"
/>
</el-select>
</el-form-item>
<el-form-item
label=
"设备状态"
prop=
"status"
>
<el-select
v-model=
"queryParams.status"
placeholder=
"请选择设备状态"
clearable
class=
"!w-240px"
>
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.IOT_DEVICE_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:device:create']"
>
<Icon
icon=
"ep:plus"
class=
"mr-5px"
/>
新增
</el-button>
<el-button
type=
"success"
plain
@
click=
"handleExport"
:loading=
"exportLoading"
v-hasPermi=
"['iot:device:export']"
>
<Icon
icon=
"ep:download"
class=
"mr-5px"
/>
导出
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table
v-loading=
"loading"
:data=
"list"
:stripe=
"true"
:show-overflow-tooltip=
"true"
>
<el-table-column
label=
"DeviceName"
align=
"center"
prop=
"deviceName"
/>
<el-table-column
label=
"备注名称"
align=
"center"
prop=
"nickname"
/>
<el-table-column
label=
"设备所属产品"
align=
"center"
prop=
"productName"
/>
<el-table-column
label=
"设备类型"
align=
"center"
prop=
"deviceType"
/>
<el-table-column
label=
"设备状态"
align=
"center"
prop=
"status"
/>
<el-table-column
label=
"最后上线时间"
align=
"center"
prop=
"lastOnlineTime"
:formatter=
"dateFormatter"
width=
"180px"
/>
<el-table-column
label=
"启用禁用"
>
<template
#
default=
"scope"
>
<el-switch
v-model=
"scope.row.status"
active-value=
"1"
inactive-value=
"0"
active-text=
"启用"
inactive-text=
"禁用"
@
change=
"handleUpdate(scope.row)"
/>
</
template
>
</el-table-column>
<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:device:update']"
>
编辑
</el-button>
<el-button
link
type=
"danger"
@
click=
"handleDelete(scope.row.id)"
v-hasPermi=
"['iot:device:delete']"
>
删除
</el-button>
</
template
>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total=
"total"
v-model:page=
"queryParams.pageNo"
v-model:limit=
"queryParams.pageSize"
@
pagination=
"getList"
/>
</ContentWrap>
<!-- 表单弹窗:添加/修改 -->
<DeviceForm
ref=
"formRef"
@
success=
"getList"
/>
</template>
<
script
setup
lang=
"ts"
>
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
dateFormatter
}
from
'@/utils/formatTime'
import
download
from
'@/utils/download'
import
{
DeviceApi
,
DeviceVO
}
from
'@/api/iot/device'
import
DeviceForm
from
'./DeviceForm.vue'
import
{
ProductApi
}
from
'@/api/iot/product'
/** IoT 设备 列表 */
defineOptions
({
name
:
'IoTDevice'
})
const
message
=
useMessage
()
// 消息弹窗
const
{
t
}
=
useI18n
()
// 国际化
const
loading
=
ref
(
true
)
// 列表的加载中
const
list
=
ref
<
DeviceVO
[]
>
([])
// 列表的数据
const
total
=
ref
(
0
)
// 列表的总页数
const
queryParams
=
reactive
({
pageNo
:
1
,
pageSize
:
10
,
deviceKey
:
undefined
,
deviceName
:
undefined
,
productId
:
undefined
,
productKey
:
undefined
,
deviceType
:
undefined
,
nickname
:
undefined
,
gatewayId
:
undefined
,
status
:
undefined
,
statusLastUpdateTime
:
[],
lastOnlineTime
:
[],
lastOfflineTime
:
[],
activeTime
:
[],
ip
:
undefined
,
firmwareVersion
:
undefined
,
deviceSecret
:
undefined
,
mqttClientId
:
undefined
,
mqttUsername
:
undefined
,
mqttPassword
:
undefined
,
authType
:
undefined
,
latitude
:
undefined
,
longitude
:
undefined
,
areaId
:
undefined
,
address
:
undefined
,
serialNumber
:
undefined
,
createTime
:
[]
})
const
queryFormRef
=
ref
()
// 搜索的表单
const
exportLoading
=
ref
(
false
)
// 导出的加载中
/** 查询列表 */
const
getList
=
async
()
=>
{
loading
.
value
=
true
try
{
const
data
=
await
DeviceApi
.
getDevicePage
(
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
DeviceApi
.
deleteDevice
(
id
)
message
.
success
(
t
(
'common.delSuccess'
))
// 刷新列表
await
getList
()
}
catch
{}
}
/** 导出按钮操作 */
const
handleExport
=
async
()
=>
{
try
{
// 导出的二次确认
await
message
.
exportConfirm
()
// 发起导出
exportLoading
.
value
=
true
const
data
=
await
DeviceApi
.
exportDevice
(
queryParams
)
download
.
excel
(
data
,
'设备.xls'
)
}
catch
{
}
finally
{
exportLoading
.
value
=
false
}
}
/** 查询字典下拉列表 */
const
products
=
ref
()
const
getProducts
=
async
()
=>
{
products
.
value
=
await
ProductApi
.
getSimpleProductList
()
}
/** 初始化 **/
onMounted
(()
=>
{
getList
()
getProducts
()
})
</
script
>
src/views/iot/product/ProductForm.vue
View file @
b69a784e
...
@@ -103,7 +103,7 @@
...
@@ -103,7 +103,7 @@
import
{
ProductApi
,
ProductVO
}
from
'@/api/iot/product'
import
{
ProductApi
,
ProductVO
}
from
'@/api/iot/product'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
defineOptions
({
name
:
'ProductForm'
})
defineOptions
({
name
:
'
IoT
ProductForm'
})
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
const
message
=
useMessage
()
const
message
=
useMessage
()
...
...
src/views/iot/product/detail/index.vue
View file @
b69a784e
...
@@ -20,7 +20,7 @@ import { ProductApi, ProductVO } from '@/api/iot/product'
...
@@ -20,7 +20,7 @@ import { ProductApi, ProductVO } from '@/api/iot/product'
import
ProductDetailsHeader
from
'@/views/iot/product/detail/ProductDetailsHeader.vue'
import
ProductDetailsHeader
from
'@/views/iot/product/detail/ProductDetailsHeader.vue'
import
ProductDetailsInfo
from
'@/views/iot/product/detail/ProductDetailsInfo.vue'
import
ProductDetailsInfo
from
'@/views/iot/product/detail/ProductDetailsInfo.vue'
defineOptions
({
name
:
'Io
t
ProductDetail'
})
defineOptions
({
name
:
'Io
T
ProductDetail'
})
const
route
=
useRoute
()
const
route
=
useRoute
()
const
message
=
useMessage
()
const
message
=
useMessage
()
...
...
src/views/iot/product/index.vue
View file @
b69a784e
...
@@ -44,7 +44,11 @@
...
@@ -44,7 +44,11 @@
<!-- 列表 -->
<!-- 列表 -->
<ContentWrap>
<ContentWrap>
<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=
"name"
/>
<el-table-column
label=
"产品名称"
align=
"center"
prop=
"name"
>
<template
#
default=
"scope"
>
<el-link
@
click=
"openDetail(scope.row.id)"
>
{{
scope
.
row
.
name
}}
</el-link>
</
template
>
</el-table-column>
<el-table-column
label=
"ProductKey"
align=
"center"
prop=
"productKey"
/>
<el-table-column
label=
"ProductKey"
align=
"center"
prop=
"productKey"
/>
<el-table-column
label=
"设备类型"
align=
"center"
prop=
"deviceType"
>
<el-table-column
label=
"设备类型"
align=
"center"
prop=
"deviceType"
>
<
template
#
default=
"scope"
>
<
template
#
default=
"scope"
>
...
@@ -106,7 +110,7 @@ import ProductForm from './ProductForm.vue'
...
@@ -106,7 +110,7 @@ import ProductForm from './ProductForm.vue'
import
{
DICT_TYPE
}
from
'@/utils/dict'
import
{
DICT_TYPE
}
from
'@/utils/dict'
/** iot 产品 列表 */
/** iot 产品 列表 */
defineOptions
({
name
:
'Product'
})
defineOptions
({
name
:
'
IoT
Product'
})
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
const
{
t
}
=
useI18n
()
// 国际化
const
{
t
}
=
useI18n
()
// 国际化
...
@@ -166,7 +170,7 @@ const openForm = (type: string, id?: number) => {
...
@@ -166,7 +170,7 @@ const openForm = (type: string, id?: number) => {
/** 打开详情 */
/** 打开详情 */
const
{
currentRoute
,
push
}
=
useRouter
()
const
{
currentRoute
,
push
}
=
useRouter
()
const
openDetail
=
(
id
:
number
)
=>
{
const
openDetail
=
(
id
:
number
)
=>
{
push
({
name
:
'Io
t
ProductDetail'
,
params
:
{
id
}
})
push
({
name
:
'Io
T
ProductDetail'
,
params
:
{
id
}
})
}
}
/** 删除按钮操作 */
/** 删除按钮操作 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment