diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts
index 4ee6d8d9..39a2e5a8 100644
--- a/src/api/iot/device/index.ts
+++ b/src/api/iot/device/index.ts
@@ -1,6 +1,6 @@
import request from '@/config/axios'
-// IoT 设备 VO
+// 设备 VO
export interface DeviceVO {
id: number // 设备 ID,主键,自增
deviceKey: string // 设备唯一标识符,全局唯一,用于识别设备
@@ -29,35 +29,45 @@ export interface DeviceVO {
serialNumber: string // 设备序列号
}
-// IoT 设备 API
+export interface DeviceUpdateStatusVO {
+ id: number // 设备 ID,主键,自增
+ status: number // 设备状态:0 - 未激活,1 - 在线,2 - 离线,3 - 已禁用
+}
+
+// 设备 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 设备
+ // 修改设备状态
+ updateDeviceStatus: async (data: DeviceUpdateStatusVO) => {
+ return await request.put({ url: `/iot/device/update-status`, data })
+ },
+
+ // 删除设备
deleteDevice: async (id: number) => {
return await request.delete({ url: `/iot/device/delete?id=` + id })
},
- // 导出IoT 设备 Excel
+ // 导出设备 Excel
exportDevice: async (params) => {
return await request.download({ url: `/iot/device/export-excel`, params })
}
-}
\ No newline at end of file
+}
diff --git a/src/views/iot/device/DeviceForm.vue b/src/views/iot/device/DeviceForm.vue
index a77045c9..f926b6d4 100644
--- a/src/views/iot/device/DeviceForm.vue
+++ b/src/views/iot/device/DeviceForm.vue
@@ -8,7 +8,12 @@
v-loading="formLoading"
>
-
+
-
+
@@ -52,7 +61,34 @@ const formData = ref({
serialNumber: undefined
})
const formRules = reactive({
- productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }]
+ productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
+ deviceName: [
+ {
+ pattern: /^[a-zA-Z0-9_.\-:@]{4,32}$/,
+ message:
+ '支持英文字母、数字、下划线(_)、中划线(-)、点号(.)、半角冒号(:)和特殊字符@,长度限制为4~32个字符',
+ trigger: 'blur'
+ }
+ ],
+ nickname: [
+ {
+ validator: (rule, value, callback) => {
+ if (value === undefined || value === null) {
+ callback()
+ return
+ }
+ const length = value.replace(/[\u4e00-\u9fa5\u3040-\u30ff]/g, 'aa').length
+ if (length < 4 || length > 64) {
+ callback(new Error('备注名称长度限制为4~64个字符,中文及日文算2个字符'))
+ } else if (!/^[\u4e00-\u9fa5\u3040-\u30ff_a-zA-Z0-9]+$/.test(value)) {
+ callback(new Error('备注名称只能包含中文、英文字母、日文、数字和下划线(_)'))
+ } else {
+ callback()
+ }
+ },
+ trigger: 'blur'
+ }
+ ]
})
const formRef = ref() // 表单 Ref
diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue
index e50819bd..bb733250 100644
--- a/src/views/iot/device/index.vue
+++ b/src/views/iot/device/index.vue
@@ -72,24 +72,22 @@
- 搜索
- 重置
+
+
+ 搜索
+
+
+
+ 重置
+
- 新增
-
-
- 导出
+
+ 新增
@@ -100,9 +98,21 @@
-
-
-
+
+
+ {{ productMap[scope.row.productId] }}
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
{
loading.value = true
@@ -212,6 +193,13 @@ const getList = async () => {
const data = await DeviceApi.getDevicePage(queryParams)
list.value = data.list
total.value = data.total
+ // 获取产品ID列表
+ const productIds = [...new Set(data.list.map((device) => device.productId))]
+ // 获取产品名称
+ const products = await Promise.all(productIds.map((id) => ProductApi.getProduct(id)))
+ products.forEach((product) => {
+ productMap[product.id] = product.name
+ })
} finally {
loading.value = false
}