index.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. <template>
  2. <a-spin :spinning="spinning">
  3. <div class="deviceDetail">
  4. <info-card
  5. title="实时点位"
  6. :class="[
  7. furnitureItems && furnitureItems.some((item) => item.type === 'bed') ? 'pointCard' : '',
  8. ]"
  9. >
  10. <template #extra>
  11. <a-space>
  12. <a-button type="primary" size="small" @click="roomConfigHandler('area')">
  13. 区域配置
  14. </a-button>
  15. <div class="extraIcon"> <FullscreenOutlined @click="openFullView = true" /> </div>
  16. </a-space>
  17. </template>
  18. <a-alert
  19. v-if="areaAvailable"
  20. message="检测区域范围未配置或数值较小,请在设备配置调整参数!"
  21. banner
  22. style="margin-bottom: 10px"
  23. />
  24. <div class="pointMap">
  25. <div
  26. class="radarArea"
  27. :style="{
  28. width: `${detailState?.length || 400}px`,
  29. height: `${detailState?.width || 400}px`,
  30. }"
  31. >
  32. <furniture-icon
  33. v-for="(item, index) in furnitureItems"
  34. :key="index"
  35. :icon="item.type"
  36. :width="item.width"
  37. :height="item.length"
  38. :style="{
  39. left: `${item.left}px`,
  40. top: `${item.top}px`,
  41. position: 'absolute',
  42. rotate: `${item.rotate}deg`,
  43. cursor: 'default',
  44. pointerEvents: 'none',
  45. }"
  46. :draggable="false"
  47. />
  48. </div>
  49. <template v-if="targets && Object.keys(targets).length > 0">
  50. <template v-for="t in targets" :key="t.id">
  51. <div
  52. class="target-dot"
  53. :style="{
  54. position: 'absolute',
  55. width: '18px',
  56. height: '18px',
  57. background: t.id === 0 ? 'red' : t.id === 1 ? 'blue' : 'green',
  58. borderRadius: '50%',
  59. transform: `translate3d(${t.displayX + 200}px, ${-t.displayY + 200}px, 0) translate(-50%, -50%)`,
  60. zIndex: 10,
  61. transition: 'transform 1s linear',
  62. willChange: 'transform',
  63. }"
  64. >
  65. <span
  66. style="
  67. color: #fff;
  68. font-size: 12px;
  69. font-weight: 600;
  70. position: absolute;
  71. left: 50%;
  72. top: 50%;
  73. transform: translate(-50%, -50%);
  74. pointer-events: none;
  75. "
  76. >
  77. {{ t.id + 1 }}
  78. </span>
  79. </div>
  80. </template>
  81. </template>
  82. <div
  83. v-if="furnitureItems && furnitureItems.some((item) => item.type === 'bed')"
  84. class="breathLine"
  85. >
  86. <BreathLineChart :data="breathRpmList"></BreathLineChart>
  87. </div>
  88. </div>
  89. </info-card>
  90. <FullViewModal v-model:open="openFullView" :title="detailState.devName">
  91. <div class="fullView">
  92. <div class="pointTitle">实时点位图</div>
  93. <div class="pointMap">
  94. <div
  95. class="radarArea"
  96. :style="{
  97. width: `${detailState?.length || 400}px`,
  98. height: `${detailState?.width || 400}px`,
  99. }"
  100. >
  101. <furniture-icon
  102. v-for="(item, index) in furnitureItems"
  103. :key="index"
  104. :icon="item.type"
  105. :width="item.width"
  106. :height="item.length"
  107. :style="{
  108. left: `${item.left}px`,
  109. top: `${item.top}px`,
  110. position: 'absolute',
  111. rotate: `${item.rotate}deg`,
  112. cursor: 'default',
  113. pointerEvents: 'none',
  114. }"
  115. :draggable="false"
  116. />
  117. </div>
  118. <template v-if="targets && Object.keys(targets).length > 0">
  119. <template v-for="t in targets" :key="t.id">
  120. <div
  121. class="target-dot"
  122. :style="{
  123. position: 'absolute',
  124. width: '18px',
  125. height: '18px',
  126. background: t.id === 0 ? 'red' : t.id === 1 ? 'blue' : 'green',
  127. borderRadius: '50%',
  128. transform: `translate3d(${t.displayX + 200}px, ${-t.displayY + 200}px, 0) translate(-50%, -50%)`,
  129. zIndex: 10,
  130. transition: 'transform 1s linear',
  131. willChange: 'transform',
  132. }"
  133. >
  134. <span
  135. style="
  136. color: #fff;
  137. font-size: 12px;
  138. font-weight: 600;
  139. position: absolute;
  140. left: 50%;
  141. top: 50%;
  142. transform: translate(-50%, -50%);
  143. pointer-events: none;
  144. "
  145. >
  146. {{ t.id + 1 }}
  147. </span>
  148. </div>
  149. </template>
  150. </template>
  151. </div>
  152. <div
  153. v-if="furnitureItems && furnitureItems.some((item) => item.type === 'bed')"
  154. class="breathLine"
  155. >
  156. <BreathLineChart :data="breathRpmList"></BreathLineChart>
  157. </div>
  158. </div>
  159. </FullViewModal>
  160. <info-card>
  161. <info-item-group title="基本信息">
  162. <template #extra>
  163. <a-button type="primary" size="small" @click="roomConfigHandler('base')">
  164. 设备配置
  165. </a-button>
  166. </template>
  167. <info-item label="设备ID">{{ detailState.clientId }}</info-item>
  168. <info-item label="设备名称">{{ detailState.devName }}</info-item>
  169. <info-item label="设备类型">{{ detailState.devType }}</info-item>
  170. <info-item label="固件版本号">{{ detailState.software }}</info-item>
  171. <info-item label="激活日期">{{ detailState.activeTime }}</info-item>
  172. <info-item label="在离线状态">
  173. <template v-if="detailState.clientId">
  174. <a-tag
  175. v-if="detailState.online === 0"
  176. :bordered="false"
  177. :color="deviceOnlineStateMap[detailState.online].color"
  178. >{{ deviceOnlineStateMap[detailState.online].name }}</a-tag
  179. >
  180. <a-tag
  181. v-if="detailState.online === 1"
  182. :bordered="false"
  183. :color="deviceOnlineStateMap[detailState.online].color"
  184. >{{ deviceOnlineStateMap[detailState.online].name }}</a-tag
  185. >
  186. </template>
  187. </info-item>
  188. <info-item label="归属租户">{{ detailState.tenantName }}</info-item>
  189. <info-item label="统计信息">
  190. <a-button
  191. v-if="detailState.clientId"
  192. type="link"
  193. size="small"
  194. @click="viewDeviceHistoryInfo"
  195. >
  196. 查看详情
  197. </a-button>
  198. </info-item>
  199. </info-item-group>
  200. <info-item-group title="安装参数">
  201. <info-item label="安装高度">
  202. <template v-if="detailState.height"> {{ detailState.height }} cm</template>
  203. </info-item>
  204. <info-item label="检测区域">
  205. <template v-if="detailState.length || detailState.width">
  206. {{ detailState.length || 0 }} x {{ detailState.width || 0 }} cm
  207. {{ [detailState.xxStart, detailState.xxEnd, detailState.yyStart, detailState.yyEnd] }}
  208. </template>
  209. </info-item>
  210. <info-item label="安装位置">
  211. <template v-if="detailState.clientId">
  212. {{
  213. deviceInstallPositionNameMap[
  214. detailState.installPosition as keyof typeof deviceInstallPositionNameMap
  215. ]
  216. }}
  217. </template>
  218. </info-item>
  219. </info-item-group>
  220. </info-card>
  221. <info-card>
  222. <info-item-group title="告警计划" class="alarmPlanGroup">
  223. <template #extra>
  224. <a-space>
  225. <a-button type="primary" size="small" :disabled="!isOnline" @click="addPlanHandler">
  226. 新增计划
  227. </a-button>
  228. </a-space>
  229. </template>
  230. <ScrollContainer style="max-height: 450px">
  231. <a-spin :spinning="alarmPlanLoading">
  232. <div v-if="alarmPlans && alarmPlans.length" class="alarmPlan">
  233. <div class="alarmPlan-item" v-for="plan in alarmPlans" :key="plan.id">
  234. <div class="alarmPlan-item-label"
  235. ><a-badge :status="plan.enable ? 'success' : 'error'"
  236. /></div>
  237. <div class="alarmPlan-item-contant" :title="plan.name">{{ plan.name }}</div>
  238. <div class="alarmPlan-item-action">
  239. <a-space :class="!isOnline && 'offline'">
  240. <a-popconfirm
  241. :title="`确认${plan.enable ? '禁用' : '启用'}计划吗?`"
  242. ok-text="确认"
  243. cancel-text="取消"
  244. :disabled="!isOnline"
  245. @confirm="swtichAlarmItem(plan.id, plan.enable, plan)"
  246. >
  247. <a-switch
  248. :checked="plan.enable"
  249. size="small"
  250. :loading="plan.loading"
  251. :disabled="!isOnline"
  252. />
  253. </a-popconfirm>
  254. <EditOutlined
  255. v-disabled="!isOnline"
  256. @click="editAlarmItem(plan.data as AlarmPlanItem)"
  257. />
  258. <a-popconfirm
  259. title="确认删除计划吗?"
  260. ok-text="确认"
  261. cancel-text="取消"
  262. :disabled="!isOnline"
  263. @confirm="deleteAlarmItem(plan.id)"
  264. >
  265. <DeleteOutlined v-disabled="!isOnline" />
  266. </a-popconfirm>
  267. </a-space>
  268. </div>
  269. </div>
  270. </div>
  271. <div v-else class="alarmPlan-empty">
  272. <a-empty :image="simpleImage" />
  273. </div>
  274. </a-spin>
  275. </ScrollContainer>
  276. </info-item-group>
  277. </info-card>
  278. <deviceConfigDrawer
  279. v-model:open="configDrawerOpen"
  280. :data="{
  281. devId: (detailState.devId as string) || '',
  282. clientId: (detailState.clientId as string) || '',
  283. length: (detailState.length as number) || 0,
  284. width: (detailState.width as number) || 0,
  285. xStart: (detailState.xxStart as number) || 0,
  286. xEnd: (detailState.xxEnd as number) || 0,
  287. yStart: (detailState.yyStart as number) || 0,
  288. yEnd: (detailState.yyEnd as number) || 0,
  289. }"
  290. :mode="configDrawerMode"
  291. :room-id="deviceRoomId"
  292. :furniture-items="furnitureItems"
  293. :sub-region-items="subRegionItems"
  294. :online="detailState.online"
  295. @success="saveConfigSuccess"
  296. ></deviceConfigDrawer>
  297. <deviceStatsDrawer
  298. v-model:open="statsDrawerOpen"
  299. :dev-id="`${detailState.devId as string}`"
  300. :title="`${detailState.devName || ''} 统计信息`"
  301. ></deviceStatsDrawer>
  302. <alarmPlanModal
  303. v-model:open="alarmPlanVisible"
  304. :title="alarmPlanTitle"
  305. type="plan"
  306. :client-id="clientId"
  307. :alarm-plan-id="alarmPlanId"
  308. :data="alarmPlanDataWithType"
  309. :area="{
  310. width: (detailState.width as number) ?? 0,
  311. length: (detailState.length as number) ?? 0,
  312. ranges: [
  313. (detailState.xxStart as number) ?? 0,
  314. (detailState.xxEnd as number) ?? 0,
  315. (detailState.yyStart as number) ?? 0,
  316. (detailState.yyEnd as number) ?? 0,
  317. ],
  318. }"
  319. @success="fetchAlarmPlanList"
  320. ></alarmPlanModal>
  321. </div>
  322. </a-spin>
  323. </template>
  324. <script setup lang="ts">
  325. import infoCard from './components/infoCard/index.vue'
  326. import infoItem from './components/infoItem/index.vue'
  327. import infoItemGroup from './components/infoItemGroup/index.vue'
  328. import { ref, reactive, onMounted, onUnmounted, computed } from 'vue'
  329. import { useRoute } from 'vue-router'
  330. import { message } from 'ant-design-vue'
  331. import * as roomApi from '@/api/room'
  332. import type { Furniture } from '@/api/room/types'
  333. import mqtt, { MqttClient } from 'mqtt'
  334. import * as deviceApi from '@/api/device'
  335. import type { DeviceDetailData } from '@/api/device/types'
  336. import { deviceOnlineStateMap, deviceInstallPositionNameMap } from '@/const/device'
  337. import deviceConfigDrawer from './components/deviceConfig/index.vue'
  338. import deviceStatsDrawer from './components/deviceStatsDrawer/index.vue'
  339. import BreathLineChart from './components/breathLineChart/index.vue'
  340. import { formatDateTime } from '@/utils'
  341. import { FullscreenOutlined } from '@ant-design/icons-vue'
  342. import FullViewModal from './components/fullViewModal/index.vue'
  343. import alarmPlanModal from './components/alarmPlanModal/index.vue'
  344. import { EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
  345. import * as alarmApi from '@/api/alarm'
  346. import { Empty } from 'ant-design-vue'
  347. const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE
  348. import { getOriginPosition } from '@/utils'
  349. defineOptions({
  350. name: 'DeviceDetail',
  351. })
  352. const route = useRoute()
  353. // const router = useRouter()
  354. const devId = ref<string>((route.query.devId as string) || '') // 设备id
  355. const clientId = ref<string>((route.query.clientId as string) || '') // 设备id
  356. interface BlockItem {
  357. startXx: number // 屏蔽子区域X开始
  358. stopXx: number // 屏蔽子区域X结束
  359. startYy: number // 屏蔽子区域Y开始
  360. stopYy: number // 屏蔽子区域Y结束
  361. startZz: number // 屏蔽子区域Z开始
  362. stopZz: number // 屏蔽子区域Z结束
  363. isLowSnr: number // 默认0
  364. isDoor: number // 是否是门 0-否,1-是 默认0
  365. presenceEnterDuration: number // 人员进入时间 默认3
  366. presenceExitDuration: number // 人员离开时间 默认3
  367. trackPresence: number // 是否开启区域跟踪存在 0-否,1-是
  368. excludeFalling: number // 是否屏蔽区域跌倒检测 0-否,1-是
  369. }
  370. const deviceRoomId = ref<string>('')
  371. const furnitureItems = ref<Furniture[]>([])
  372. const subRegionItems = ref<BlockItem[]>([])
  373. /**
  374. * 获取房间布局
  375. */
  376. const fetchRoomLayout = async () => {
  377. console.log('fetchRoomLayout', devId.value)
  378. if (!devId.value) {
  379. message.error('设备ID不能为空')
  380. return
  381. }
  382. try {
  383. const res = await roomApi.queryRoomInfo({
  384. devId: devId.value,
  385. })
  386. console.log('✅获取到房间布局信息', res)
  387. if (!res) return
  388. const { furnitures, roomId, subRegions } = res.data
  389. if (furnitures) {
  390. // 添加接口返回的家具数据
  391. furnitures!.forEach((item) => {
  392. furnitureItems.value.push({
  393. ...item,
  394. width: item.width || 45,
  395. length: item.length || 45,
  396. top: item.top || 0,
  397. left: item.left || 0,
  398. rotate: item.rotate || 0,
  399. x: item.x || 0,
  400. y: item.y || 0,
  401. })
  402. })
  403. }
  404. deviceRoomId.value = roomId || ''
  405. subRegionItems.value = subRegions || []
  406. } catch (error) {
  407. console.error('❌获取房间布局信息失败', error)
  408. }
  409. }
  410. fetchRoomLayout()
  411. const detailState = ref<DeviceDetailData>({
  412. devId: '',
  413. clientId: '',
  414. userId: '',
  415. devName: '',
  416. devType: '',
  417. online: 0,
  418. devWarn: 0,
  419. software: '',
  420. hardware: '',
  421. wifiName: '',
  422. wifiPassword: '',
  423. ip: '',
  424. mountPlain: 'Wall',
  425. installPosition: 'Toilet',
  426. xxStart: 0,
  427. xxEnd: 0,
  428. yyStart: 0,
  429. yyEnd: 0,
  430. zzStart: 0,
  431. zzEnd: 0,
  432. height: 0,
  433. length: 0,
  434. width: 0,
  435. targetPoints: [],
  436. signalTime: 0,
  437. northAngle: 0,
  438. activeTime: '',
  439. statusLight: 0,
  440. createId: '',
  441. updateId: '',
  442. createTime: '',
  443. updateTime: '',
  444. tenantName: '',
  445. tenantId: '',
  446. fallingConfirm: null,
  447. })
  448. const spinning = ref(false)
  449. // 获取设备详情
  450. const fetchDeviceDetail = async () => {
  451. console.log('fetchDeviceDetail', devId.value)
  452. if (!devId.value) {
  453. message.error('设备ID不能为空')
  454. return
  455. }
  456. try {
  457. spinning.value = true
  458. const res = await deviceApi.getDeviceDetailByDevId({
  459. devId: devId.value,
  460. })
  461. console.log('✅获取到设备详情', res)
  462. detailState.value = res.data
  463. spinning.value = false
  464. // 获取雷达图标尺寸
  465. const { radarX, radarY, radarWidth, radarHeight, originOffsetX, originOffsetY } =
  466. getOriginPosition(
  467. [
  468. res.data.xxStart as number,
  469. res.data.xxEnd as number,
  470. res.data.yyStart as number,
  471. res.data.yyEnd as number,
  472. ],
  473. [0, 0]
  474. )
  475. furnitureItems.value = furnitureItems.value.filter((item) => item.type !== 'radar')
  476. // 添加雷达图标
  477. furnitureItems.value.unshift({
  478. name: '雷达',
  479. type: 'radar',
  480. width: radarWidth,
  481. length: radarHeight,
  482. top: radarY,
  483. left: radarX,
  484. x: originOffsetX,
  485. y: originOffsetY,
  486. rotate: 0,
  487. })
  488. } catch (error) {
  489. console.error('❌获取设备详情失败', error)
  490. spinning.value = false
  491. }
  492. }
  493. fetchDeviceDetail()
  494. const saveConfigSuccess = () => {
  495. setTimeout(() => {
  496. fetchDeviceDetail()
  497. fetchRoomLayout()
  498. }, 1000)
  499. }
  500. const configDrawerOpen = ref(false)
  501. const configDrawerMode = ref<'base' | 'area'>('base')
  502. const roomConfigHandler = (type: 'base' | 'area') => {
  503. configDrawerMode.value = type
  504. configDrawerOpen.value = true
  505. }
  506. const statsDrawerOpen = ref(false)
  507. // 查看设备历史信息
  508. const viewDeviceHistoryInfo = () => {
  509. console.log('viewDeviceHistoryInfo')
  510. statsDrawerOpen.value = true
  511. }
  512. interface TargetInfo {
  513. x: number
  514. y: number
  515. z: number
  516. id: number
  517. displayX: number
  518. displayY: number
  519. lastX: number
  520. lastY: number
  521. }
  522. const targets = reactive<Record<number, TargetInfo>>({}) // 以id为key
  523. const THRESHOLD = 2 // 去抖阈值
  524. let mqttClient: MqttClient | null = null
  525. let mqttTimeout: number | null = null
  526. const MQTT_TIMEOUT_MS = 1000 // 调整为1秒
  527. const resetMqttTimeout = () => {
  528. if (mqttTimeout) clearTimeout(mqttTimeout)
  529. mqttTimeout = window.setTimeout(() => {
  530. Object.keys(targets).forEach((key) => delete targets[Number(key)])
  531. breathRpmList.value = []
  532. console.log('MQTT超时未收到新消息,隐藏所有目标点')
  533. }, MQTT_TIMEOUT_MS)
  534. }
  535. // 呼吸率
  536. const breathRpmList = ref<number[]>([])
  537. onMounted(() => {
  538. console.log('onMounted', mqttClient)
  539. const mqttConfig = {
  540. host: import.meta.env.VITE_MQTT_HOST_POINT,
  541. username: import.meta.env.VITE_MQTT_USERNAME,
  542. password: import.meta.env.VITE_MQTT_PASSWORD,
  543. clientId: `web_mqtt_data${Math.random().toString(16).slice(2)}`,
  544. }
  545. mqttClient = mqtt.connect(mqttConfig.host, {
  546. clientId: mqttConfig.clientId,
  547. username: mqttConfig.username,
  548. password: mqttConfig.password,
  549. })
  550. console.log('⌛️ mqttClient connect ready', mqttClient)
  551. mqttClient.on('connect', () => {
  552. console.log('✅ MQTT已连接')
  553. // 订阅所有设备的主题
  554. // const sub = `/dev/${clientId.value}/dsp_data`
  555. const sub = `/dev/${clientId.value}/tracker_targets`
  556. mqttClient?.subscribe(sub, (err) => {
  557. if (err) {
  558. console.error('❌ MQTT订阅失败', err)
  559. } else {
  560. console.log(`⚛️ 已订阅主题 ${sub}`)
  561. }
  562. })
  563. })
  564. mqttClient.on('error', (err) => {
  565. console.error('❌ MQTT连接错误', err)
  566. })
  567. mqttClient.on('message', (topic: string, message: Uint8Array) => {
  568. resetMqttTimeout()
  569. // const subMatch = /^\/dev\/(.+)\/dsp_data$/
  570. const subMatch = /^\/dev\/(.+)\/tracker_targets$/
  571. const match = topic.match(subMatch)
  572. if (!match) return
  573. const msgDevId = match[1]
  574. if (msgDevId !== clientId.value) return // 只处理当前设备
  575. try {
  576. const data = JSON.parse(message.toString())
  577. const targetPoints = data?.tracker_targets || [] // 点位图数据
  578. const breathRpm = data.health?.breath_rpm || 0 // 呼吸率数据
  579. if (breathRpm) {
  580. breathRpmList.value.push(Math.floor(breathRpm || 0))
  581. } else {
  582. breathRpmList.value = []
  583. }
  584. console.log(`🚀 收到MQTT消息 ${formatDateTime(new Date())}`, {
  585. '🔴 目标人数': targetPoints.length,
  586. '🟢 呼吸率': breathRpm,
  587. '🟡 点位图': targetPoints,
  588. '🔵 接口数据': data,
  589. })
  590. if (
  591. Array.isArray(targetPoints) &&
  592. targetPoints.length > 0 &&
  593. Array.isArray(targetPoints[0])
  594. ) {
  595. // 记录本次出现的所有id
  596. const currentIds = new Set<number>()
  597. targetPoints.forEach((item: number[]) => {
  598. if (item.length < 4) return
  599. const [x, y, z, id] = item
  600. currentIds.add(id)
  601. if (!(id in targets)) {
  602. targets[id] = { x, y, z, id, displayX: x, displayY: y, lastX: x, lastY: y }
  603. }
  604. // 去抖动
  605. const dx = x - targets[id].lastX
  606. const dy = y - targets[id].lastY
  607. if (Math.sqrt(dx * dx + dy * dy) > THRESHOLD) {
  608. targets[id].x = x
  609. targets[id].y = y
  610. targets[id].z = z
  611. targets[id].lastX = x
  612. targets[id].lastY = y
  613. targets[id].displayX = x
  614. targets[id].displayY = y
  615. // console.log(`🔄 更新目标点: id=${id}, x=${x}, y=${y}`, targets[id])
  616. } else {
  617. // 距离太小,忽略本次更新
  618. // console.log(`忽略微小抖动 id=${id}`)
  619. }
  620. })
  621. // 删除本次未出现的id
  622. Object.keys(targets).forEach((key) => {
  623. const id = Number(key)
  624. if (!currentIds.has(id)) {
  625. delete targets[id]
  626. // console.log(`ID=${id} 消失,隐藏对应红点`)
  627. }
  628. })
  629. } else {
  630. // 没有目标时,隐藏所有红点
  631. Object.keys(targets).forEach((key) => delete targets[Number(key)])
  632. breathRpmList.value = []
  633. }
  634. } catch (e) {
  635. console.error('MQTT消息解析失败', e)
  636. }
  637. })
  638. })
  639. // setInterval(() => {
  640. // breathRpmList.value.push(Math.floor(Math.random() * 30))
  641. // }, 100)
  642. const areaAvailable = computed(() => {
  643. const { length, width } = detailState.value
  644. return Number(length) < 50 || Number(width) < 50
  645. })
  646. // 设备是否在线
  647. const isOnline = computed(() => detailState.value.online === 1)
  648. onUnmounted(() => {
  649. if (mqttClient) mqttClient.end()
  650. if (mqttTimeout) clearTimeout(mqttTimeout)
  651. })
  652. const openFullView = ref(false) // 全屏展示点位图
  653. const alarmPlanVisible = ref(false) // 告警计划弹窗
  654. const alarmPlanTitle = ref('新增告警计划') // 告警计划弹窗标题
  655. const alarmPlanId = ref<number | null>(null) // 当前编辑的告警计划id
  656. const alarmPlanLoading = ref(false) // 告警计划加载中
  657. const alarmPlans = ref<
  658. { id: number; name: string; enable: boolean; loading: boolean; data: object }[]
  659. >([])
  660. // 获取告警计划列表
  661. const fetchAlarmPlanList = async () => {
  662. try {
  663. alarmPlanLoading.value = true
  664. await alarmApi
  665. .getAlarmPlanList({
  666. clientId: clientId.value,
  667. })
  668. .then((res) => {
  669. console.log('获取告警计划列表成功✅', res)
  670. const data = res.data
  671. if (Array.isArray(data) && data.length) {
  672. alarmPlans.value = data.map((item) => ({
  673. id: item.id || '',
  674. name: item.name || '',
  675. enable: item.enable === 1,
  676. loading: false,
  677. data: item,
  678. }))
  679. } else {
  680. alarmPlans.value = []
  681. }
  682. })
  683. .catch((err) => {
  684. console.log('获取告警计划列表失败❌', err)
  685. })
  686. .finally(() => {
  687. alarmPlanLoading.value = false
  688. })
  689. } catch (err) {
  690. console.log('获取告警计划列表失败❌', err)
  691. }
  692. }
  693. fetchAlarmPlanList()
  694. type AlarmPlan = {
  695. id: number
  696. uuid: ID
  697. name: string
  698. clientId: string
  699. enable: SwitchType
  700. region: string
  701. eventVal: number
  702. alarmTimePlanId: ID
  703. thresholdTime: ID
  704. mergeTime: ID
  705. param: string
  706. createTime: string
  707. updateTime: string
  708. remark: string | null
  709. alarmTimePlan: {
  710. createId: ID
  711. updateId: ID
  712. createTime: ID
  713. updateTime: ID
  714. isDeleted: SwitchType | null
  715. remark: ID
  716. id: ID
  717. startDate: string
  718. stopDate: string
  719. timeRange: string
  720. monthDays: string
  721. weekdays: string
  722. }
  723. }
  724. interface AlarmPlanItem {
  725. id?: number
  726. loading?: boolean
  727. [key: string]: unknown
  728. }
  729. const alarmPlanData = ref<AlarmPlanItem | undefined>(undefined)
  730. const alarmPlanDataWithType = computed(() => alarmPlanData.value as AlarmPlan)
  731. // 编辑告警计划
  732. const editAlarmItem = async (item: AlarmPlanItem) => {
  733. console.log('editAlarmItem', item)
  734. alarmPlanVisible.value = true
  735. alarmPlanTitle.value = '编辑告警计划'
  736. alarmPlanData.value = item
  737. alarmPlanId.value = item?.id ?? null
  738. }
  739. // 添加告警计划
  740. const addPlanHandler = () => {
  741. alarmPlanVisible.value = true
  742. alarmPlanTitle.value = '新增告警计划'
  743. alarmPlanData.value = undefined
  744. alarmPlanId.value = null
  745. }
  746. // 删除告警计划
  747. const deleteAlarmItem = async (id: number) => {
  748. console.log('deleteAlarmItem', id)
  749. try {
  750. alarmApi.deleteAlarmPlan({ id }).then(() => {
  751. message.success('删除成功')
  752. fetchAlarmPlanList()
  753. })
  754. } catch (err) {
  755. console.log('删除告警计划失败❌', err)
  756. message.error('删除失败')
  757. }
  758. }
  759. // 启用/禁用告警计划
  760. const swtichAlarmItem = async (id: number, swtich: boolean, item: AlarmPlanItem) => {
  761. console.log('swtichAlarmItem', id, swtich, item)
  762. try {
  763. item.loading = true
  764. alarmApi
  765. .enableAlarmPlan({ id, enable: Number(!swtich) as 0 | 1 })
  766. .then(() => {
  767. message.success('变更成功')
  768. item.loading = false
  769. fetchAlarmPlanList()
  770. })
  771. .catch((err) => {
  772. console.log('启用/禁用告警计划失败❌', err)
  773. item.loading = false
  774. message.error('操作失败')
  775. })
  776. } catch (err) {
  777. console.log('启用/禁用告警计划失败❌', err)
  778. message.error('变更失败')
  779. }
  780. }
  781. </script>
  782. <style scoped lang="less">
  783. .deviceDetail {
  784. display: flex;
  785. flex-wrap: wrap;
  786. gap: 16px;
  787. }
  788. .info.pointCard {
  789. min-width: 800px;
  790. }
  791. .pointCloudMap {
  792. width: 770px;
  793. height: 100%;
  794. height: 500px;
  795. }
  796. .pointMap {
  797. flex-shrink: 0;
  798. min-width: 400px;
  799. min-height: 400px;
  800. border-radius: 10px;
  801. display: flex;
  802. flex-direction: row;
  803. }
  804. .radarArea {
  805. position: relative;
  806. background-image:
  807. linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
  808. linear-gradient(to right, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
  809. background-size: 20px 20px;
  810. border: 1px solid rgba(0, 0, 0, 0.8);
  811. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  812. overflow: hidden;
  813. flex-shrink: 0;
  814. .furniture-item {
  815. position: absolute;
  816. user-select: none;
  817. cursor: move;
  818. width: 30px;
  819. height: 30px;
  820. }
  821. }
  822. .extraIcon {
  823. font-size: 16px;
  824. font-weight: 600;
  825. cursor: pointer;
  826. &:hover {
  827. color: #1890ff;
  828. }
  829. }
  830. .fullView {
  831. margin-top: 50px;
  832. display: flex;
  833. flex-direction: column;
  834. .pointMap {
  835. min-height: auto;
  836. margin: auto;
  837. }
  838. .breathLine {
  839. margin-left: 0;
  840. }
  841. .pointTitle {
  842. font-size: 16px;
  843. font-weight: 600;
  844. margin-bottom: 10px;
  845. text-align: center;
  846. }
  847. }
  848. .breathLine {
  849. margin-left: 16px;
  850. flex-shrink: 0;
  851. flex-grow: 1;
  852. flex-basis: 350px;
  853. position: relative;
  854. }
  855. .alarmPlanGroup {
  856. :deep(.info-item-group-content) {
  857. padding: 12px 0 !important;
  858. overflow-y: auto;
  859. max-height: 500px;
  860. }
  861. .alarmPlan {
  862. display: flex;
  863. flex-direction: column;
  864. flex-wrap: wrap;
  865. width: 100%;
  866. color: #555;
  867. &-empty {
  868. padding: 50px 0;
  869. }
  870. .alarmPlan-item {
  871. display: flex;
  872. align-items: center;
  873. flex: 1;
  874. padding: 8px 12px;
  875. border-radius: 8px;
  876. border: 1px solid #d9d9d9;
  877. margin-bottom: 10px;
  878. &:hover {
  879. border-radius: 8px;
  880. background: #f5f5f5;
  881. }
  882. }
  883. .alarmPlan-item-label {
  884. text-align: right;
  885. flex-shrink: 0;
  886. }
  887. .alarmPlan-item-contant {
  888. font-size: 14px;
  889. flex-grow: 1;
  890. max-width: 200px;
  891. word-break: break-all;
  892. line-height: 1.5;
  893. padding: 0 12px;
  894. // 超出一行显示省略号
  895. overflow: hidden;
  896. text-overflow: ellipsis;
  897. white-space: nowrap;
  898. cursor: default;
  899. }
  900. .alarmPlan-item-action {
  901. flex-shrink: 0;
  902. color: #888;
  903. :deep(.ant-space) {
  904. cursor: pointer;
  905. .ant-space-item:hover {
  906. color: #40a9ff;
  907. }
  908. }
  909. :deep(.ant-space.offline) {
  910. cursor: not-allowed;
  911. .ant-space-item:hover {
  912. color: #888;
  913. }
  914. }
  915. }
  916. }
  917. }
  918. </style>