index.vue 28 KB

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