waterAlarm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <template>
  2. <div class="waterAlarm">
  3. <div class="waterAlarmBlack" v-if="showType">
  4. <div class="waterAlarm-max-big-box">
  5. <div class="waterAlarm-title-box">
  6. <div class="top-img-box">
  7. <img class="top-img-one vibrate" src="@/assets/ZDimages/icon_bt_yso@1x.png">
  8. <img class="top-img-two" src="@/assets/ZDimages/icon_bt_yst@1x.png">
  9. </div>
  10. <p class="top-name-p">预警事件详情</p>
  11. <p class="top-out-p el-icon-close" @click="outPlan"></p>
  12. </div>
  13. <div class="waterAlarm-name-box">
  14. <div class="lv-box type-color-a">
  15. <div>纯水设备</div>
  16. </div>
  17. <p class="name-p">{{planData.buildingName}}:{{planData.deviceName}}</p>
  18. <p class="time-p">报警时间:{{parseTime(planData.warningTime)}}</p>
  19. </div>
  20. <div v-if="!lookImgType" class="waterAlarm-big-box">
  21. <div class="waterAlarm-left-box">
  22. <img :src="planData.deviceImg" alt="">
  23. </div>
  24. <div class="waterAlarm-right-box">
  25. <div class="waterAlarm-sensor-box waterAlarm-scrollbar">
  26. <p>所属单位:{{planData.deptName}}</p>
  27. <p>所在位置:{{planData.buildingName}} {{planData.floorName}}</p>
  28. </div>
  29. <div class="waterAlarm-text-box">
  30. <div class="waterAlarm-text-left-box waterAlarm-scrollbar">
  31. <div>
  32. <p>设备名称:</p>
  33. <p>{{planData.deviceName}}</p>
  34. </div>
  35. <div>
  36. <p>报警原因:</p>
  37. <p style="color:#FF0102;">{{planData.warningReason}}</p>
  38. </div>
  39. <div>
  40. <p>报警时间:</p>
  41. <p>{{parseTime(planData.warningTime)}}</p>
  42. </div>
  43. <div>
  44. <p>所在位置:</p>
  45. <p>{{planData.buildingName}} {{planData.floorName}}</p>
  46. </div>
  47. </div>
  48. <div class="waterAlarm-text-right-box waterAlarm-scrollbar">
  49. <div class="box-one">
  50. <p>通知人:</p>
  51. <p>{{planData.notifierName}}</p>
  52. </div>
  53. <div class="box-one">
  54. <p>通知时间:</p>
  55. <p>{{parseTime(planData.notifyTime)}}</p>
  56. </div>
  57. <div class="box-one">
  58. <p>通知方式:</p>
  59. <p>{{planData.notifyMethod}}</p>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="waterAlarm-bottom-button-box">
  66. <p class="null-p"></p>
  67. <p class="button-out-p" @click="outPlan">关闭</p>
  68. <p class="null-p"></p>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import mqtt from 'mqtt'
  76. import {
  77. waterWaterWarnRecordGetWarnById,
  78. } from "@/api/index";
  79. export default {
  80. name: 'waterAlarm',
  81. data () {
  82. return {
  83. showType:false,
  84. //预案MQTT
  85. planOpic:'water/device/collector/*/',
  86. planClient:{},
  87. //预案参数
  88. planData:{},
  89. //持续时间
  90. seconds:null,
  91. //定时器
  92. timer:null,
  93. }
  94. },
  95. created(){
  96. },
  97. mounted(){
  98. let self = this;
  99. //判断是否已有链接
  100. if(!this.planClient.unsubscribe){
  101. this.offPlanMQTT('on');
  102. }
  103. setTimeout(function(){
  104. self.waterWaterWarnRecordGetWarnById();
  105. },500)
  106. },
  107. methods:{
  108. //关闭窗口
  109. outPlan(){
  110. let self = this;
  111. if(this.lookImgType){
  112. this.$set(this,'lookImgType',false);
  113. }else{
  114. this.$confirm('纯水系统监测异常,确定要关闭窗口?', '提示', {
  115. confirmButtonText: '确定',
  116. cancelButtonText: '取消',
  117. type: 'warning'
  118. }).then(() => {
  119. clearInterval(self.timer);
  120. self.$set(self,'showType',false);
  121. }).catch(() => {});
  122. }
  123. },
  124. //预案-MQTT连接
  125. offPlanMQTT(type){
  126. let self = this;
  127. if(self.planClient.unsubscribe){
  128. self.planClient.unsubscribe(self.planOpic, error => {
  129. if (error) {
  130. // console.log('mqtt关闭连接错误:', error)
  131. }
  132. })
  133. self.planClient.end();
  134. this.$set(this,'planClient',{});
  135. }
  136. //判断传入参数如果存在 发起一次新的连接
  137. if(type){
  138. this.planMQTT();
  139. }
  140. },
  141. //预案-MQTT订阅
  142. planMQTT(){
  143. let self = this;
  144. this.planClient = mqtt.connect(localStorage.getItem('mqttUrl'), {
  145. username: localStorage.getItem('mqttUser'),
  146. password:localStorage.getItem('mqttPassword')
  147. });
  148. this.planClient.on("connect", e =>{
  149. this.planClient.subscribe(self.planOpic, (err) => {
  150. if (!err) {
  151. console.log("预案-订阅成功:" + self.planOpic);
  152. }else{
  153. // console.log("预案-连接错误:" + err);
  154. }
  155. });
  156. });
  157. this.planClient.on("message", (topic, message) => {
  158. if (message){
  159. console.log("纯水报警触发:");
  160. //获取预案数据
  161. setTimeout(function(){
  162. self.waterWaterWarnRecordGetWarnById();
  163. },500)
  164. }
  165. });
  166. },
  167. //查询当前正在发生的预案
  168. waterWaterWarnRecordGetWarnById(){
  169. clearInterval(this.timer);
  170. waterWaterWarnRecordGetWarnById().then(response => {
  171. if(response.data){
  172. if(response.data.deviceCode == null){
  173. response.data.deviceImg = require('@/assets/ZDimages/pureWater/shipinlou.png')
  174. }else if(response.data.deviceCode == '2'){
  175. response.data.deviceImg = require('@/assets/ZDimages/pureWater/shipinlou.png')
  176. }else if(response.data.deviceCode == '3'){
  177. response.data.deviceImg = require('@/assets/ZDimages/pureWater/likelou.png')
  178. }else if(response.data.deviceCode == '4'){
  179. response.data.deviceImg = require('@/assets/ZDimages/pureWater/likelou.png')
  180. }
  181. this.$set(this,'planData',response.data);
  182. this.$set(this,'showType',true);
  183. }else{
  184. this.$set(this,'showType',false);
  185. }
  186. })
  187. },
  188. //计算时间戳
  189. newTimestamp(value){
  190. let timestamp = this.accSub(this.accDiv(Date.parse(new Date()),1000),value);
  191. this.time(timestamp);
  192. },
  193. //定时器
  194. time(time){
  195. let self = this;
  196. self.seconds = parseInt(time);
  197. self.timer = window.setInterval(refreshCount, 1000);
  198. function refreshCount() {
  199. self.seconds++
  200. }
  201. },
  202. //时间格式
  203. convertSecondsToHMS(seconds) {
  204. var hours = Math.floor(seconds / 3600);
  205. var minutes = Math.floor((seconds % 3600) / 60);
  206. var remainingSeconds = seconds % 60;
  207. return hours + "小时 " + minutes + "分钟 " + remainingSeconds + "秒";
  208. },
  209. },
  210. beforeDestroy() {
  211. //清除MQTT
  212. let self = this;
  213. self.offPlanMQTT();
  214. },
  215. }
  216. </script>
  217. <style scoped lang="scss">
  218. .waterAlarm{
  219. .waterAlarmBlack{
  220. height:100%;
  221. width:100%;
  222. position: absolute;
  223. top:0;
  224. left:0;
  225. z-index:1100;
  226. background-color: rgba(0,0,0,0.8);
  227. .waterAlarm-max-big-box{
  228. position: absolute;
  229. left:50%;
  230. top:50%;
  231. margin-top:-567px;
  232. margin-left:-938px;
  233. width: 1720px;
  234. height: 1140px;
  235. display: flex;
  236. flex-direction: column;
  237. .waterAlarm-title-box{
  238. display: flex;
  239. padding:40px 0 36px 30px;
  240. border-bottom:1px solid #1ed0f8;
  241. background-color: #01232A;
  242. border-top-left-radius:20px;
  243. border-top-right-radius:20px;
  244. .top-img-box {
  245. width: 60px;
  246. position: relative;
  247. .top-img-one {
  248. z-index:5;
  249. display: block;
  250. width:18px;
  251. height:20px;
  252. position: absolute;
  253. top:5px;
  254. left:15px;
  255. }
  256. .top-img-two{
  257. z-index:1;
  258. display: block;
  259. width:28px;
  260. height:30px;
  261. position: absolute;
  262. top:0;
  263. left:25px;
  264. }
  265. .vibrate {
  266. position: relative;
  267. animation: vibrate 2s infinite;
  268. }
  269. @keyframes vibrate {
  270. 0% {
  271. left:15px;
  272. }
  273. 50% {
  274. left:20px;
  275. }
  276. 100% {
  277. left:15px;
  278. }
  279. }
  280. }
  281. .top-name-p {
  282. flex: 1;
  283. line-height: 30px;
  284. height:30px;
  285. color: #fff;
  286. font-size: 26px;
  287. margin-left:10px;
  288. }
  289. .top-out-p{
  290. cursor: pointer;
  291. font-size:26px;
  292. line-height: 30px;
  293. height:30px;
  294. color:#fff;
  295. margin-right:40px;
  296. }
  297. }
  298. .waterAlarm-name-box{
  299. height:107px;
  300. display: flex;
  301. padding:0 20px;
  302. background-color: #01232A;
  303. border-bottom:1px solid #1ed0f8;
  304. .lv-box{
  305. margin-top:26px;
  306. width:120px;
  307. height:54px;
  308. border-radius:50px;
  309. div{
  310. margin:3px 4px;
  311. width:110px;
  312. height:46px;
  313. line-height:46px;
  314. font-size:20px;
  315. text-align: center;
  316. border-radius:50px;
  317. }
  318. }
  319. .type-color-a {
  320. border:1px solid #FF0102;
  321. div{
  322. background-color: #FF0102;
  323. color:#fff;
  324. }
  325. }
  326. .type-color-b {
  327. border:1px solid rgb(256, 232, 206);
  328. div{
  329. background-color: rgb(256, 232, 206);
  330. color:#FF9900;
  331. }
  332. }
  333. .type-color-c {
  334. border:1px solid rgb(251, 228, 206);
  335. div{
  336. background-color: rgb(251, 228, 206);
  337. color:#FF4800;
  338. }
  339. }
  340. .type-color-d {
  341. border:1px solid rgb(248, 206, 205);
  342. div{
  343. background-color: rgb(248, 206, 205);
  344. color:#FF0000;
  345. }
  346. }
  347. .name-p{
  348. width:450px;
  349. font-size:20px;
  350. line-height:107px;
  351. color:#fff;
  352. margin-left:20px;
  353. }
  354. .time-p{
  355. width:450px;
  356. font-size:20px;
  357. line-height:107px;
  358. color:#fff;
  359. }
  360. }
  361. .waterAlarm-big-box{
  362. flex:1;
  363. display: flex;
  364. padding:20px 20px 0;
  365. background-color: #01232A;
  366. border-bottom-left-radius:20px;
  367. border-bottom-right-radius:20px;
  368. .waterAlarm-left-box{
  369. width: 917px;
  370. border-radius:10px;
  371. overflow: hidden;
  372. img{
  373. display: block;
  374. /*width: 548px;*/
  375. /*height: 608px;*/
  376. width: 685px;
  377. height: 760px;
  378. margin:20px auto;
  379. }
  380. }
  381. .bugle-box{
  382. width: 917px;
  383. height: 236px;
  384. margin-top:20px;
  385. border-radius:10px;
  386. background-color: #032C32;
  387. display: flex;
  388. flex-direction: column;
  389. .bugle-for-button-box{
  390. padding:20px 20px 10px;
  391. .for-button-box-check{
  392. border:1px solid #24D1F9!important;
  393. color:#24D1F9!important;
  394. }
  395. .for-button-box{
  396. display: inline-block;
  397. margin:0 22px 11px 0;
  398. cursor: pointer;
  399. width:150px;
  400. padding:0 10px;
  401. height:50px;
  402. border:1px solid #1E768E;
  403. text-align: center;
  404. font-size:18px;
  405. line-height:50px;
  406. border-radius:5px;
  407. color:#fff;
  408. /*单行省略号*/
  409. overflow:hidden;
  410. text-overflow:ellipsis;
  411. white-space:nowrap;
  412. }
  413. }
  414. .bugle-for-text-box{
  415. flex:1;
  416. padding:10px 20px;
  417. .null-p{
  418. color:#999;
  419. font-size:18px;
  420. text-align: center;
  421. }
  422. .for-text-box{
  423. display: flex;
  424. p:nth-child(1){
  425. line-height:24px;
  426. font-size:18px;
  427. color:#24D1F9;
  428. margin-bottom:5px;
  429. margin-right:10px;
  430. }
  431. p:nth-child(2){
  432. line-height:24px;
  433. font-size:18px;
  434. color:#fff;
  435. margin-bottom:5px;
  436. }
  437. }
  438. }
  439. .bugle-for-input-box{
  440. margin:20px;
  441. }
  442. ::v-deep .bugle-for-input-box{
  443. .el-input__inner{
  444. height:50px;
  445. line-height:50px;
  446. font-size:18px;
  447. background-color: rgba(0,0,0,0);
  448. border:1px solid #15827C;
  449. box-shadow:0 0 2px 1px #15827C inset;
  450. color:#FFFFFF;
  451. }
  452. .el-input-group__append, .el-input-group__prepend{
  453. height:50px;
  454. font-size:18px;
  455. cursor: pointer;
  456. background-color: rgba(0,0,0,0);
  457. color:#FFFFFF;
  458. border:1px solid #15827C;
  459. box-shadow:0 0 2px 1px #15827C inset;
  460. }
  461. }
  462. }
  463. .waterAlarm-right-box{
  464. width: 900px;
  465. margin:20px 20px 0 0;
  466. .waterAlarm-text-box{
  467. width: 900px;
  468. height: 270px;
  469. display: flex;
  470. .waterAlarm-text-left-box{
  471. width: 440px;
  472. height: 270px;
  473. margin-right:20px;
  474. border-radius:10px;
  475. background-color: #032C32;
  476. padding:20px 30px;
  477. div{
  478. display: flex;
  479. p{
  480. color:#fff;
  481. line-height:45px;
  482. font-size:20px;
  483. }
  484. p:nth-child(1){
  485. }
  486. p:nth-child(2){
  487. flex:1;
  488. }
  489. }
  490. }
  491. .waterAlarm-text-right-box{
  492. width: 440px;
  493. height: 270px;
  494. border-radius:10px;
  495. background-color: #032C32;
  496. padding:20px 30px;
  497. .box-one{
  498. display: flex;
  499. p{
  500. color:#fff;
  501. line-height:45px;
  502. font-size:20px;
  503. }
  504. p:nth-child(1){
  505. }
  506. p:nth-child(2){
  507. flex:1;
  508. }
  509. }
  510. .box-two{
  511. display: flex;
  512. .box-tile-p{
  513. color:#fff;
  514. line-height:45px;
  515. font-size:20px;
  516. }
  517. .box-two-box{
  518. flex:1;
  519. .box-two-box-min{
  520. display: inline-block;
  521. div{
  522. display: flex;
  523. p:nth-child(1){
  524. background-color: #11C01D;
  525. font-size:20px;
  526. border-radius:50%;
  527. width:26px;
  528. height:26px;
  529. color:#fff;
  530. line-height:27px;
  531. text-align: center;
  532. margin:9px;
  533. }
  534. p:nth-child(2){
  535. font-size:20px;
  536. line-height:45px;
  537. color:#fff;
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. }
  545. .waterAlarm-sensor-box{
  546. width: 900px;
  547. height: 130px;
  548. background-color: #032C32;
  549. border-radius:10px;
  550. margin-bottom:20px;
  551. display: flex;
  552. p{
  553. color:#fff;
  554. font-size:26px;
  555. line-height:130px;
  556. }
  557. p:nth-child(1){
  558. margin-left:30px;
  559. }
  560. p:nth-child(2){
  561. margin-left:60px;
  562. }
  563. }
  564. .waterAlarm-img-box{
  565. width: 900px;
  566. height: 236px;
  567. background-color: #032C32;
  568. border-radius:10px;
  569. margin-top:20px;
  570. overflow: hidden;
  571. .img-title-p{
  572. font-size:22px;
  573. height:22px;
  574. line-height:22px;
  575. margin:20px 0 20px 30px;
  576. color:#fff;
  577. }
  578. .for-max-box{
  579. img{
  580. cursor: pointer;
  581. display:inline-block;
  582. width:267px;
  583. height:150px;
  584. border-radius:10px;
  585. margin-left:25px;
  586. }
  587. }
  588. .img-null-p{
  589. line-height:150px;
  590. text-align: center;
  591. font-size:20px;
  592. color:#999;
  593. }
  594. }
  595. }
  596. .lookImg{
  597. display: block;
  598. width:1449px;
  599. height:815px;
  600. margin:20px auto 0;
  601. }
  602. }
  603. .waterAlarm-bottom-button-box{
  604. display: flex;
  605. height:81px;
  606. .null-p{
  607. flex:1;
  608. }
  609. .button-out-p{
  610. cursor: pointer;
  611. border:1px solid #15827C;
  612. background-color: #000F14;
  613. color:#15827C;
  614. width:162px;
  615. height:54px;
  616. line-height:54px;
  617. font-size:20px;
  618. text-align: center;
  619. border-radius:50px;
  620. margin-top:27px;
  621. }
  622. .button-finish-p{
  623. cursor: pointer;
  624. border:1px solid #15827C;
  625. background-color: #15827C;
  626. color:#fff;
  627. width:162px;
  628. height:54px;
  629. line-height:54px;
  630. font-size:20px;
  631. text-align: center;
  632. border-radius:50px;
  633. margin-top:27px;
  634. margin-left:64px;
  635. }
  636. }
  637. }
  638. }
  639. .waterAlarm-scrollbar{
  640. overflow-y: scroll;
  641. overflow-x: hidden;
  642. }
  643. .waterAlarm-scrollbar::-webkit-scrollbar {
  644. width: 8px; /*高宽分别对应横竖滚动条的尺寸*/
  645. height: 8px;
  646. }
  647. .waterAlarm-scrollbar::-webkit-scrollbar-thumb {
  648. border-radius: 6px;
  649. -webkit-box-shadow: inset 0 0 5px #15827C;
  650. background: #15827C;
  651. }
  652. .waterAlarm-scrollbar::-webkit-scrollbar-track {
  653. -webkit-box-shadow: inset 0 0 6px rgba(3,44,50,0);
  654. border-radius: 0;
  655. background: rgba(3,44,50,0);
  656. }
  657. }
  658. </style>