emergencyEvacuationBigFullScreen.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <view id="emergencyEvacuationBigFullScreen">
  3. <view class="emergencyEvacuationBigFullScreen-page" v-if="mapType"
  4. :style="'width:'+mapWidth+'px;height:'+mapHeight+'px;transform: scale('+zoomData+');margin-top:-'+mapHeight/2+'px;margin-left:-'+mapWidth/2+'px;'">
  5. <view class="map-max-box" :style="'width:'+mapWidth+'px;height:'+mapHeight+'px;'">
  6. <!-- :style="'width:'+mapW+'px;height:'+mapH+'px;'" -->
  7. <view class="map-max-for-box for-map-box" v-if="item.type == 1" v-for="(item,index) in mapList" :key="index"
  8. :class="!item.policeType && checkSubId ==item.subId ? 'room-type-one':(
  9. item.policeType && checkSubId !=item.subId ? 'room-type-two':(
  10. item.policeType && checkSubId ==item.subId ? 'room-type-three':(
  11. !item.loginAdmin ? 'room-type-noe':''
  12. )))" :style="'top:'+item.y+'px;left:'+item.x+'px;width:'+(item.w-4)+'px;height:'+(item.h-4)+'px;'">
  13. <view class="map-max-for-min-box">
  14. <view class="map-for-name-p" :style="'margin-top:'+((item.h/2)-20)+'px;'">
  15. {{item.roomType == '-99'?item.roomName:item.subName}}
  16. </view>
  17. <view class="map-for-num-p">({{item.roomNum}})</view>
  18. <view class="position-box" :src="imagesUrl('manage/icon_sysbjt_m.png')"
  19. :class="minItem.toward=='top'?'center-move-door-p-t':(minItem.toward=='bottom'?'center-move-door-p-b':(minItem.toward=='left'?'center-move-door-p-l':(minItem.toward=='right'?'center-move-door-p-r':'')))"
  20. v-for="(minItem,minIndex) in item.doorList" :key="minIndex"
  21. :style="'top:'+minItem.y+'px;left:'+minItem.x+'px;width:'+minItem.w+'px;height:'+minItem.h+'px;'">
  22. </view>
  23. </view>
  24. </view>
  25. <view class="map-max-for-box for-map-box-one" v-if="item.type == 2" v-for="(item,index) in mapList" :key="index"
  26. :style="'top:'+item.y+'px;left:'+item.x+'px;width:'+item.w+'px;height:'+item.h+'px;'">
  27. <view class="map-max-for-min-box">
  28. <view class="position-box" @click="lighButton(minItem)"
  29. :class="minItem.state=='1'&&minItem.openType?'lightTopOn':(minItem.state=='1'&&!minItem.openType?'lightTopOff':
  30. (minItem.state=='2'&&minItem.openType?'lightBottomOn':(minItem.state=='2'&&!minItem.openType?'lightBottomOff':
  31. (minItem.state=='3'&&minItem.openType?'lightLeftOn':(minItem.state=='3'&&!minItem.openType?'lightLeftOff':
  32. (minItem.state=='4'&&minItem.openType?'lightRightOn':(minItem.state=='4'&&!minItem.openType?'lightRightOff':'')))))))" v-for="(minItem,minIndex) in item.lightList"
  33. :key="minIndex"
  34. :style="'top:'+minItem.y+'px;left:'+minItem.x+'px;width:'+minItem.w+'px;height:'+minItem.h+'px;'">
  35. </view>
  36. </view>
  37. </view>
  38. <view class="map-max-for-box for-map-box-two" v-if="item.type == 3" v-for="(item,index) in mapList"
  39. @click="checkRoom(item)" :key="index" :class="item.roomCheckType?'for-map-box-two-check':''"
  40. :style="'top:'+item.y+'px;left:'+item.x+'px;width:'+item.w+'px;height:'+item.h+'px;'">
  41. </view>
  42. </view>
  43. </view>
  44. <view class="position-button" @click="backButton">退出全屏</view>
  45. <view class="position-button-two" @click="executeEvacuation" v-if="isEvacuate">已确定疏散出口,立即执行疏散</view>
  46. </view>
  47. </template>
  48. <script>
  49. import $mqtt from '@/utils/mqtt.min.js';
  50. import {
  51. laboratoryBigViewGetFloorByBigView,
  52. laboratoryExitLineExecuteEvacuation,
  53. laboratoryExitLineGetRedisEvacuation,
  54. laboratoryExitRelayOpenLight,
  55. laboratoryExitRelayCloseLight
  56. } from '@/pages_manage/api/index.js'
  57. export default {
  58. data() {
  59. return {
  60. // 楼栋id
  61. buildingId: null,
  62. //楼层id
  63. floorId: null,
  64. //实验室ID
  65. subId: null,
  66. //当前选中实验室
  67. checkSubId: null,
  68. //页面开关
  69. mapType: false,
  70. mapList: [],
  71. //缩放相关数据
  72. zoomData: null,
  73. mapWidth: null, //40边框距离
  74. mapHeight: null, //40边框距离
  75. //弹层地图数据
  76. buildingOptions: {},
  77. //MQTT请求参数-疏散
  78. mtopicOne: "lab/floor/exit/line",
  79. client: {},
  80. //疏散按钮
  81. buttonType: false,
  82. isEvacuate:false,
  83. }
  84. },
  85. onLoad(option) {
  86. if (option.item) {
  87. let obj = JSON.parse(decodeURIComponent(option.item));
  88. this.$set(this, 'buildingId', obj.buildingId);
  89. this.$set(this, 'floorId', obj.floorId);
  90. this.$set(this, 'subId', obj.subId);
  91. this.$set(this, 'checkSubId', obj.subId);
  92. if (obj.type == 2) {
  93. this.$set(this, 'buttonType', true);
  94. } else {
  95. this.$set(this, 'buttonType', false);
  96. }
  97. }
  98. },
  99. onShow() {
  100. // this.offMQTT('on');
  101. this.getBuildingData();
  102. },
  103. methods: {
  104. mqttPageFunction(type) {
  105. let self = this;
  106. if (type == 'FLOOR_EXITLINE') {
  107. this.getRedisEvacuation();
  108. } else if (type == 'FLOOR_OVER_EXITLINE') {
  109. uni.showToast({
  110. title: '疏散已结束',
  111. icon: "none",
  112. mask: true,
  113. duration: 2000
  114. });
  115. setTimeout(function() {
  116. self.getBuildingData();
  117. }, 2000);
  118. }
  119. },
  120. checkRoom(item) {
  121. if (this.buttonType) {
  122. item.roomCheckType = !item.roomCheckType;
  123. this.$forceUpdate();
  124. }
  125. },
  126. //开始疏散
  127. async executeEvacuation() {
  128. let self = this;
  129. let list = [];
  130. let doorPointNames = [];
  131. for (let i = 0; i < self.mapList.length; i++) {
  132. if (self.mapList[i].type == 3) {
  133. if (!self.mapList[i].roomCheckType) {
  134. list.push(self.mapList[i].key)
  135. } else {
  136. doorPointNames.push(self.mapList[i].key)
  137. }
  138. }
  139. }
  140. if (!doorPointNames[0]) {
  141. uni.showToast({
  142. title: '请选择疏散出口',
  143. icon: "none",
  144. mask: true,
  145. duration: 2000
  146. });
  147. return
  148. }
  149. let obj = {
  150. buildId: this.buildingId,
  151. floorId: this.floorId,
  152. subId: this.subId,
  153. badPointNames: list,
  154. doorPointNames: doorPointNames,
  155. }
  156. const {
  157. data
  158. } = await laboratoryExitLineExecuteEvacuation(obj)
  159. if (data.code == 200) {
  160. uni.showToast({
  161. title: '执行成功',
  162. icon: "none",
  163. mask: true,
  164. duration: 2000
  165. });
  166. setTimeout(function() {
  167. uni.navigateBack();
  168. }, 2000);
  169. }
  170. },
  171. //疏散页面
  172. backButton() {
  173. uni.navigateBack()
  174. },
  175. //地图数据
  176. async getBuildingData() {
  177. let self = this;
  178. const {
  179. data
  180. } = await laboratoryBigViewGetFloorByBigView({
  181. id: this.floorId
  182. })
  183. if (data.code == 200) {
  184. if (data.data[0].buildLayoutVoList[0]) {
  185. let list = JSON.parse(data.data[0].labExitLineVo.layoutJoinData)
  186. this.getWXSystemInfo(list);
  187. for (let i = 0; i < list.length; i++) {
  188. if (list[i].type == '2') {
  189. //楼道
  190. for (let o = 0; o < list[i].lightList.length; o++) {
  191. list[i].lightList[o].openType = false;
  192. }
  193. } else if (list[i].type == '1') {
  194. for (let o = 0; o < data.data[0].buildLayoutVoList.length; o++) {
  195. if (list[i].key == data.data[0].buildLayoutVoList[o].pointName) {
  196. list[i].id = data.data[0].buildLayoutVoList[o].id;
  197. list[i].buildId = data.data[0].buildLayoutVoList[o].buildId;
  198. list[i].floorId = data.data[0].buildLayoutVoList[o].floorId;
  199. list[i].roomType = data.data[0].buildLayoutVoList[o].roomType;
  200. list[i].roomName = data.data[0].buildLayoutVoList[o].roomName;
  201. list[i].roomNum = data.data[0].buildLayoutVoList[o].roomNum;
  202. list[i].subName = data.data[0].buildLayoutVoList[o].subName;
  203. list[i].subId = data.data[0].buildLayoutVoList[o].subId;
  204. list[i].online = data.data[0].buildLayoutVoList[o].online;
  205. list[i].loginAdmin = data.data[0].buildLayoutVoList[o].loginAdmin;
  206. list[i].policeType = false;
  207. }
  208. }
  209. } else if (list[i].type == 3) {
  210. list[i].roomCheckType = false;
  211. }
  212. }
  213. this.$set(this, 'mapList', JSON.parse(JSON.stringify(list)));
  214. this.$set(this, 'mapType', true);
  215. this.offMQTT('on');
  216. setTimeout(function() {
  217. self.getRedisEvacuation();
  218. }, 500);
  219. }
  220. }
  221. },
  222. //获取疏散数据
  223. async getRedisEvacuation() {
  224. let self = this;
  225. let obj = {
  226. buildId: this.buildingId,
  227. floorId: this.floorId,
  228. }
  229. const {
  230. data
  231. } = await laboratoryExitLineGetRedisEvacuation(obj)
  232. if (data.code == 200) {
  233. if (data.data.doorPointNames) {
  234. this.$set(this, 'isEvacuate', false);
  235. for (let o = 0; o < self.mapList.length; o++) {
  236. if (self.mapList[o].type == 2) {
  237. for (let x = 0; x < self.mapList[o].lightList.length; x++) {
  238. let num = 0;
  239. for (let i = 0; i < data.data.lightPointSet.length; i++) {
  240. if (data.data.lightPointSet[i]) { //处理后端返回的异常的NULL
  241. if (self.mapList[o].lightList[x].key == data.data.lightPointSet[i].key) {
  242. num++
  243. }
  244. }
  245. }
  246. self.mapList[o].lightList[x].openType = num != 0;
  247. }
  248. }
  249. if (self.mapList[o].type == 3) {
  250. let age = 0;
  251. for (let i = 0; i < data.data.doorPointNames.length; i++) {
  252. if (data.data.doorPointNames[i] == self.mapList[o].key) {
  253. age++
  254. }
  255. }
  256. self.mapList[o].roomCheckType = age != 0;
  257. }
  258. }
  259. } else {
  260. this.$set(this, 'isEvacuate', true);
  261. for (let o = 0; o < self.mapList.length; o++) {
  262. if (self.mapList[o].type == 2) {
  263. for (let x = 0; x < self.mapList[o].lightList.length; x++) {
  264. self.mapList[o].lightList[x].openType = false;
  265. }
  266. }
  267. if (self.mapList[o].type == 3) {
  268. self.mapList[o].roomCheckType = false;
  269. }
  270. }
  271. }
  272. };
  273. },
  274. //灯点击事件
  275. lighButton(item) {
  276. let self = this;
  277. uni.showModal({
  278. content: '确定' + (item.openType ? '关闭' : '开启') + '该疏散灯?',
  279. cancelColor: "#999",
  280. confirmColor: "#0183FA",
  281. success: function(res) {
  282. if (res.confirm) {
  283. if (item.openType) {
  284. self.closeLight(item);
  285. } else {
  286. self.openLight(item);
  287. }
  288. } else if (res.cancel) {}
  289. }
  290. });
  291. },
  292. //开灯
  293. async openLight(item) {
  294. let obj = {
  295. buildId: this.buildingId,
  296. floorId: this.floorId,
  297. pointName: item.key
  298. };
  299. const {
  300. data
  301. } = await laboratoryExitRelayOpenLight(obj)
  302. if (data.code == 200) {
  303. uni.showToast({
  304. title: '操作成功',
  305. icon: "none",
  306. mask: true,
  307. duration: 2000
  308. });
  309. }
  310. },
  311. //关灯
  312. async closeLight(item) {
  313. let obj = {
  314. buildId: this.buildingId,
  315. floorId: this.floorId,
  316. pointName: item.key
  317. };
  318. const {
  319. data
  320. } = await laboratoryExitRelayCloseLight(obj)
  321. if (data.code == 200) {
  322. uni.showToast({
  323. title: '操作成功',
  324. icon: "none",
  325. mask: true,
  326. duration: 2000
  327. });
  328. }
  329. },
  330. //计算缩放率
  331. getWXSystemInfo(list) {
  332. let self = this;
  333. wx.getSystemInfo({
  334. success: function(res) {
  335. self.zoomCalculate(list, res.windowHeight, res.windowWidth);
  336. }
  337. })
  338. },
  339. zoomCalculate(list, height, width) {
  340. let num = 0;
  341. let zoomType = 0;
  342. let maxWidth = 0
  343. let maxHeight = 0
  344. let zoomData = 1;
  345. if (height > width) {
  346. num = height / width
  347. } else {
  348. num = width / height
  349. }
  350. for (let i = 0; i < list.length; i++) {
  351. if ((list[i].x + list[i].w) > maxWidth) {
  352. maxWidth = list[i].x + list[i].w
  353. }
  354. if ((list[i].y + list[i].h) > maxHeight) {
  355. maxHeight = list[i].y + list[i].h
  356. }
  357. }
  358. this.$set(this, 'mapWidth', maxWidth);
  359. this.$set(this, 'mapHeight', maxHeight);
  360. let zoomNumOne = height / maxHeight;
  361. if (parseInt(this.accMul(zoomNumOne, maxHeight)) <= height && parseInt(this.accMul(zoomNumOne,
  362. maxWidth)) <= width) {
  363. zoomData = zoomNumOne;
  364. this.$set(this, 'zoomData', zoomNumOne);
  365. }
  366. let zoomNumTwo = width / maxWidth;
  367. if (parseInt(this.accMul(zoomNumTwo, maxHeight)) <= height && parseInt(this.accMul(zoomNumTwo,
  368. maxWidth)) <= width) {
  369. zoomData = zoomNumTwo;
  370. this.$set(this, 'zoomData', zoomNumTwo);
  371. }
  372. },
  373. accMul(arg1, arg2) {
  374. var m = 0,
  375. s1 = arg1.toString(),
  376. s2 = arg2.toString();
  377. try {
  378. m += s1.split(".")[1].length
  379. } catch (e) {}
  380. try {
  381. m += s2.split(".")[1].length
  382. } catch (e) {}
  383. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  384. },
  385. //MQTT订阅
  386. sensorMQTT() {
  387. let self = this;
  388. this.client = $mqtt.connect(
  389. // #ifdef WEB
  390. 'wss://' + uni.getStorageSync('mqttUrl')
  391. // #endif
  392. // #ifdef MP-WEIXIN
  393. 'wxs://' + uni.getStorageSync('mqttUrl')
  394. // #endif
  395. , {
  396. username: uni.getStorageSync('mqttUser'),
  397. password: uni.getStorageSync('mqttPassword')
  398. });
  399. this.client.on("connect", e => {
  400. this.client.subscribe(this.mtopicOne, (err) => {
  401. if (!err) {
  402. console.log("疏散订阅成功:" + this.mtopicOne);
  403. } else {
  404. // console.log("连接错误:" + err);
  405. }
  406. });
  407. });
  408. this.client.on("message", (topic, message) => {
  409. if (message) {
  410. if (topic == this.mtopicOne) {
  411. //疏散触发
  412. this.getRedisEvacuation();
  413. }
  414. }
  415. });
  416. },
  417. //取消订阅关闭MQTT连接
  418. offMQTT(type) {
  419. let self = this;
  420. if (self.client.unsubscribe) {
  421. self.client.unsubscribe(self.mtopicOne, error => {
  422. if (error) {
  423. // console.log('mqtt关闭连接错误:', error)
  424. }
  425. })
  426. self.client.end();
  427. this.$set(this, 'client', {});
  428. }
  429. //判断传入参数如果存在 发起一次新的连接
  430. if (type) {
  431. this.sensorMQTT();
  432. }
  433. },
  434. },
  435. beforeDestroy() {
  436. //清除定时器
  437. let self = this;
  438. self.offMQTT();
  439. },
  440. }
  441. </script>
  442. <style lang="stylus" scoped>
  443. @import '@/api/request/imagesUrl.styl';
  444. #emergencyEvacuationBigFullScreen {
  445. height: 100%;
  446. width: 100%;
  447. display: flex;
  448. overflow: hidden;
  449. .emergencyEvacuationBigFullScreen-page {
  450. // overflow: scroll;
  451. overflow: hidden;
  452. position: absolute;
  453. top: 50%;
  454. left: 50%;
  455. .map-max-box {
  456. position: relative;
  457. .map-max-for-box {
  458. position: absolute;
  459. display: flex;
  460. flex-direction: column;
  461. .map-max-for-min-box {
  462. position: relative;
  463. .position-box {
  464. position: absolute;
  465. }
  466. .map-for-name-p {
  467. padding: 0 10px;
  468. height: 20px;
  469. line-height: 20px;
  470. font-size: 14px;
  471. text-align: center;
  472. color: #333;
  473. overflow: hidden;
  474. text-overflow: ellipsis;
  475. white-space: nowrap;
  476. }
  477. .map-for-num-p {
  478. padding: 0 10px;
  479. height: 20px;
  480. line-height: 20px;
  481. font-size: 14px;
  482. text-align: center;
  483. color: #333;
  484. overflow: hidden;
  485. text-overflow: ellipsis;
  486. white-space: nowrap;
  487. }
  488. }
  489. }
  490. .for-map-box {
  491. border: 2px solid #fff;
  492. background: #CEF2FD;
  493. }
  494. .for-map-box-one {
  495. background: #CEFDD5;
  496. }
  497. .room-type-one {
  498. //选中
  499. background: rgba(178, 235, 255, 1);
  500. }
  501. .room-type-two {
  502. //报警
  503. background: rgba(232, 0, 0, 0.4);
  504. box-shadow: 0 0 10px 1px #E80000 inset;
  505. }
  506. .room-type-three {
  507. //选中报警
  508. background: rgba(178, 235, 255, 1);
  509. box-shadow: 0 0 10px 1px #E80000 inset;
  510. }
  511. }
  512. }
  513. .position-button {
  514. position: fixed;
  515. top: 10px;
  516. right: 10px;
  517. width: 100px;
  518. line-height: 30px;
  519. font-size: 16px;
  520. background: rgba(0, 0, 0, 0.5);
  521. color: #fff;
  522. text-align: center;
  523. border-radius: 18px;
  524. border: none;
  525. }
  526. .position-button-two {
  527. position: fixed;
  528. bottom: 20px;
  529. left: 50%;
  530. width: 240px;
  531. line-height: 30px;
  532. font-size: 16px;
  533. text-align: center;
  534. color: #fff;
  535. background: #0183FA;
  536. border-radius: 4px;
  537. margin-left: -120px;
  538. border: none;
  539. }
  540. .for-map-box-two {
  541. background: url($imagesUrl+'manage/icon_yjtd.png') center center no-repeat #006400;
  542. background-size: 60rpx 60rpx;
  543. }
  544. .for-map-box-two-check {
  545. background: url($imagesUrl+'manage/icon_yjtd.png') center center no-repeat rgba(50, 205, 50, 1);
  546. background-size: 80rpx 80rpx;
  547. }
  548. .center-move-door-p-t {
  549. background: url($imagesUrl+'manage/icon_sysbjt_m.png') !important;
  550. background-size: 100% !important;
  551. transform: rotate(180deg);
  552. }
  553. .center-move-door-p-b {
  554. background: url($imagesUrl+'manage/icon_sysbjt_m.png') !important;
  555. background-size: 100% !important;
  556. }
  557. .center-move-door-p-l {
  558. background: url($imagesUrl+'manage/icon_sysbjt_m.png') !important;
  559. background-size: 100% !important;
  560. transform: rotate(90deg);
  561. }
  562. .center-move-door-p-r {
  563. background: url($imagesUrl+'manage/icon_sysbjt_m.png') !important;
  564. background-size: 100% !important;
  565. transform: rotateZ(270deg);
  566. }
  567. .lightTopOn {
  568. background: url($imagesUrl+'manage/icon_sjt.png');
  569. background-size: 100%;
  570. }
  571. .lightTopOff {
  572. background: url($imagesUrl+'manage/icon_shang_hs.png');
  573. background-size: 100%;
  574. }
  575. .lightBottomOn {
  576. background: url($imagesUrl+'manage/icon_xjt.png');
  577. background-size: 100%;
  578. }
  579. .lightBottomOff {
  580. background: url($imagesUrl+'manage/icon_xia_hs.png');
  581. background-size: 100%;
  582. }
  583. .lightLeftOn {
  584. background: url($imagesUrl+'manage/icon_zuo.png');
  585. background-size: 100%;
  586. }
  587. .lightLeftOff {
  588. background: url($imagesUrl+'manage/icon_zou_hs.png');
  589. background-size: 100%;
  590. }
  591. .lightRightOn {
  592. background: url($imagesUrl+'manage/icon_yuo.png');
  593. background-size: 100%;
  594. }
  595. .lightRightOff {
  596. background: url($imagesUrl+'manage/icon_you_hs.png');
  597. background-size: 100%;
  598. }
  599. }
  600. </style>