Skip to content

Commit 99b24c1

Browse files
committed
【功能新增】IoT:设备管理界面增加设备状态枚举及状态标签显示
1 parent 646f212 commit 99b24c1

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

src/api/iot/device/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export interface DeviceHistoryDataVO {
5555
data: string // 数据
5656
}
5757

58+
// IoT 设备状态枚举
59+
export enum DeviceStatusEnum {
60+
INACTIVE = 0, // 未激活
61+
ONLINE = 1, // 在线
62+
OFFLINE = 2, // 离线
63+
DISABLED = 3 // 已禁用
64+
}
65+
5866
// 设备 API
5967
export const DeviceApi = {
6068
// 查询设备分页

src/views/iot/device/device/index.vue

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,45 @@
150150
<template v-if="viewMode === 'card'">
151151
<el-row :gutter="16">
152152
<el-col v-for="item in list" :key="item.id" :xs="24" :sm="12" :md="12" :lg="6" class="mb-4">
153-
<el-card class="h-full transition-colors" :body-style="{ padding: '0' }">
154-
<div class="p-4">
153+
<el-card
154+
class="h-full transition-colors relative overflow-hidden"
155+
:body-style="{ padding: '0' }"
156+
>
157+
<!-- 添加渐变背景层 -->
158+
<div
159+
class="absolute top-0 left-0 right-0 h-[50px] pointer-events-none"
160+
:class="[
161+
item.status === DeviceStatusEnum.ONLINE
162+
? 'bg-gradient-to-b from-[#eefaff] to-transparent'
163+
: 'bg-gradient-to-b from-[#fff1f1] to-transparent'
164+
]"
165+
>
166+
</div>
167+
<div class="p-4 relative">
155168
<!-- 标题区域 -->
156169
<div class="flex items-center mb-3">
157170
<div class="mr-2.5 flex items-center">
158171
<el-image :src="defaultIconUrl" class="w-[18px] h-[18px]" />
159172
</div>
160-
<div class="text-[16px] font-600">{{ item.deviceName }}</div>
173+
<div class="text-[16px] font-600 flex-1">{{ item.deviceName }}</div>
174+
<!-- 添加设备状态标签 -->
175+
<div class="inline-flex items-center">
176+
<div
177+
class="w-1 h-1 rounded-full mr-1.5"
178+
:class="
179+
item.status === DeviceStatusEnum.ONLINE
180+
? 'bg-[var(--el-color-success)]'
181+
: 'bg-[var(--el-color-danger)]'
182+
"
183+
>
184+
</div>
185+
<el-text
186+
class="!text-xs font-bold"
187+
:type="item.status === DeviceStatusEnum.ONLINE ? 'success' : 'danger'"
188+
>
189+
{{ getDictLabel(DICT_TYPE.IOT_DEVICE_STATUS, item.status) }}
190+
</el-text>
191+
</div>
161192
</div>
162193

163194
<!-- 信息区域 -->
@@ -186,7 +217,7 @@
186217
<!-- 分隔线 -->
187218
<el-divider class="!my-3" />
188219

189-
<!-- 按钮组 -->
220+
<!-- 按钮 -->
190221
<div class="flex items-center px-0">
191222
<el-button
192223
class="flex-1 !px-2 !h-[32px] text-[13px]"
@@ -327,9 +358,9 @@
327358
</template>
328359

329360
<script setup lang="ts">
330-
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
361+
import { DICT_TYPE, getIntDictOptions, getDictLabel } from '@/utils/dict'
331362
import { dateFormatter } from '@/utils/formatTime'
332-
import { DeviceApi, DeviceVO } from '@/api/iot/device'
363+
import { DeviceApi, DeviceVO, DeviceStatusEnum } from '@/api/iot/device'
333364
import DeviceForm from './DeviceForm.vue'
334365
import { ProductApi, ProductVO } from '@/api/iot/product/product'
335366
import { DeviceGroupApi, DeviceGroupVO } from '@/api/iot/device/group'
@@ -342,7 +373,7 @@ defineOptions({ name: 'IoTDevice' })
342373
const message = useMessage() // 消息弹窗
343374
const { t } = useI18n() // 国际化
344375
345-
const loading = ref(true) // 列表的加载中
376+
const loading = ref(true) // 列表���加载中
346377
const list = ref<DeviceVO[]>([]) // 列表的数据
347378
const total = ref(0) // 列表的总页数
348379
const queryParams = reactive({
@@ -389,7 +420,7 @@ const resetQuery = () => {
389420
handleQuery()
390421
}
391422
392-
/** 添加/修改操作 */
423+
/** ���加/修改操作 */
393424
const formRef = ref()
394425
const openForm = (type: string, id?: number) => {
395426
formRef.value.open(type, id)

0 commit comments

Comments
 (0)