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. getFloorData,
  52. getRedisEvacuation,
  53. openLight,
  54. closeLight,
  55. executeEvacuation
  56. } from '@/api/apiDemo/index.js'
  57. import {
  58. laboratoryBigViewGetFloorByBigView,
  59. laboratoryExitLineExecuteEvacuation,
  60. laboratoryExitLineGetRedisEvacuation,
  61. laboratoryExitRelayOpenLight,
  62. laboratoryExitRelayCloseLight
  63. } from '@/pages_manage/api/index.js'
  64. export default {
  65. data() {
  66. return {
  67. // 楼栋id
  68. buildingId: null,
  69. //楼层id
  70. floorId: null,
  71. //实验室ID
  72. subId: null,
  73. //当前选中实验室
  74. checkSubId: null,
  75. //页面开关
  76. mapType: false,
  77. mapList: [],
  78. //缩放相关数据
  79. zoomData: null,
  80. mapWidth: null, //40边框距离
  81. mapHeight: null, //40边框距离
  82. //弹层地图数据
  83. buildingOptions: {},
  84. //MQTT请求参数-疏散
  85. mtopicOne: "lab/floor/exit/line",
  86. client: {},
  87. //疏散按钮
  88. buttonType: false,
  89. isEvacuate:false,
  90. }
  91. },
  92. onLoad(option) {
  93. if (option.item) {
  94. let obj = JSON.parse(decodeURIComponent(option.item));
  95. this.$set(this, 'buildingId', obj.buildingId);
  96. this.$set(this, 'floorId', obj.floorId);
  97. this.$set(this, 'subId', obj.subId);
  98. this.$set(this, 'checkSubId', obj.subId);
  99. if (obj.type == 2) {
  100. this.$set(this, 'buttonType', true);
  101. } else {
  102. this.$set(this, 'buttonType', false);
  103. }
  104. }
  105. },
  106. onShow() {
  107. // this.offMQTT('on');
  108. this.getBuildingData();
  109. },
  110. methods: {
  111. mqttPageFunction(type) {
  112. let self = this;
  113. if (type == 'FLOOR_EXITLINE') {
  114. this.getRedisEvacuation();
  115. } else if (type == 'FLOOR_OVER_EXITLINE') {
  116. uni.showToast({
  117. title: '疏散已结束',
  118. icon: "none",
  119. mask: true,
  120. duration: 2000
  121. });
  122. setTimeout(function() {
  123. self.getBuildingData();
  124. }, 2000);
  125. }
  126. },
  127. checkRoom(item) {
  128. if (this.buttonType) {
  129. item.roomCheckType = !item.roomCheckType;
  130. this.$forceUpdate();
  131. }
  132. },
  133. //开始疏散
  134. async executeEvacuation() {
  135. let self = this;
  136. let list = [];
  137. let doorPointNames = [];
  138. for (let i = 0; i < self.mapList.length; i++) {
  139. if (self.mapList[i].type == 3) {
  140. if (!self.mapList[i].roomCheckType) {
  141. list.push(self.mapList[i].key)
  142. } else {
  143. doorPointNames.push(self.mapList[i].key)
  144. }
  145. }
  146. }
  147. if (!doorPointNames[0]) {
  148. uni.showToast({
  149. title: '请选择疏散出口',
  150. icon: "none",
  151. mask: true,
  152. duration: 2000
  153. });
  154. return
  155. }
  156. let obj = {
  157. buildId: this.buildingId,
  158. floorId: this.floorId,
  159. subId: this.subId,
  160. badPointNames: list,
  161. doorPointNames: doorPointNames,
  162. }
  163. const {
  164. data
  165. } = await laboratoryExitLineExecuteEvacuation(obj)
  166. if (data.code == 200) {
  167. uni.showToast({
  168. title: '执行成功',
  169. icon: "none",
  170. mask: true,
  171. duration: 2000
  172. });
  173. setTimeout(function() {
  174. uni.navigateBack();
  175. }, 2000);
  176. }
  177. },
  178. //疏散页面
  179. backButton() {
  180. uni.navigateBack()
  181. },
  182. //地图数据
  183. async getBuildingData() {
  184. let self = this;
  185. const {
  186. data
  187. } = await laboratoryBigViewGetFloorByBigView({
  188. id: this.floorId
  189. })
  190. if (data.code == 200) {
  191. if (data.data[0].buildLayoutVoList[0]) {
  192. let list = JSON.parse(data.data[0].labExitLineVo.layoutJoinData)
  193. this.getWXSystemInfo(list);
  194. for (let i = 0; i < list.length; i++) {
  195. if (list[i].type == '2') {
  196. //楼道
  197. for (let o = 0; o < list[i].lightList.length; o++) {
  198. list[i].lightList[o].openType = false;
  199. }
  200. } else if (list[i].type == '1') {
  201. for (let o = 0; o < data.data[0].buildLayoutVoList.length; o++) {
  202. if (list[i].key == data.data[0].buildLayoutVoList[o].pointName) {
  203. list[i].id = data.data[0].buildLayoutVoList[o].id;
  204. list[i].buildId = data.data[0].buildLayoutVoList[o].buildId;
  205. list[i].floorId = data.data[0].buildLayoutVoList[o].floorId;
  206. list[i].roomType = data.data[0].buildLayoutVoList[o].roomType;
  207. list[i].roomName = data.data[0].buildLayoutVoList[o].roomName;
  208. list[i].roomNum = data.data[0].buildLayoutVoList[o].roomNum;
  209. list[i].subName = data.data[0].buildLayoutVoList[o].subName;
  210. list[i].subId = data.data[0].buildLayoutVoList[o].subId;
  211. list[i].online = data.data[0].buildLayoutVoList[o].online;
  212. list[i].loginAdmin = data.data[0].buildLayoutVoList[o].loginAdmin;
  213. list[i].policeType = false;
  214. }
  215. }
  216. } else if (list[i].type == 3) {
  217. list[i].roomCheckType = false;
  218. }
  219. }
  220. this.$set(this, 'mapList', JSON.parse(JSON.stringify(list)));
  221. this.$set(this, 'mapType', true);
  222. this.offMQTT('on');
  223. setTimeout(function() {
  224. self.getRedisEvacuation();
  225. }, 500);
  226. }
  227. }
  228. },
  229. //获取疏散数据
  230. async getRedisEvacuation() {
  231. let self = this;
  232. let obj = {
  233. buildId: this.buildingId,
  234. floorId: this.floorId,
  235. }
  236. const {
  237. data
  238. } = await laboratoryExitLineGetRedisEvacuation(obj)
  239. if (data.code == 200) {
  240. if (data.data.doorPointNames) {
  241. this.$set(this, 'isEvacuate', false);
  242. for (let o = 0; o < self.mapList.length; o++) {
  243. if (self.mapList[o].type == 2) {
  244. for (let x = 0; x < self.mapList[o].lightList.length; x++) {
  245. let num = 0;
  246. for (let i = 0; i < data.data.lightPointSet.length; i++) {
  247. if (data.data.lightPointSet[i]) { //处理后端返回的异常的NULL
  248. if (self.mapList[o].lightList[x].key == data.data.lightPointSet[i].key) {
  249. num++
  250. }
  251. }
  252. }
  253. self.mapList[o].lightList[x].openType = num != 0;
  254. }
  255. }
  256. if (self.mapList[o].type == 3) {
  257. let age = 0;
  258. for (let i = 0; i < data.data.doorPointNames.length; i++) {
  259. if (data.data.doorPointNames[i] == self.mapList[o].key) {
  260. age++
  261. }
  262. }
  263. self.mapList[o].roomCheckType = age != 0;
  264. }
  265. }
  266. } else {
  267. this.$set(this, 'isEvacuate', true);
  268. for (let o = 0; o < self.mapList.length; o++) {
  269. if (self.mapList[o].type == 2) {
  270. for (let x = 0; x < self.mapList[o].lightList.length; x++) {
  271. self.mapList[o].lightList[x].openType = false;
  272. }
  273. }
  274. if (self.mapList[o].type == 3) {
  275. self.mapList[o].roomCheckType = false;
  276. }
  277. }
  278. }
  279. };
  280. },
  281. //灯点击事件
  282. lighButton(item) {
  283. let self = this;
  284. uni.showModal({
  285. content: '确定' + (item.openType ? '关闭' : '开启') + '该疏散灯?',
  286. cancelColor: "#999",
  287. confirmColor: "#0183FA",
  288. success: function(res) {
  289. if (res.confirm) {
  290. if (item.openType) {
  291. self.closeLight(item);
  292. } else {
  293. self.openLight(item);
  294. }
  295. } else if (res.cancel) {}
  296. }
  297. });
  298. },
  299. //开灯
  300. async openLight(item) {
  301. let obj = {
  302. buildId: this.buildingId,
  303. floorId: this.floorId,
  304. pointName: item.key
  305. };
  306. const {
  307. data
  308. } = await laboratoryExitRelayOpenLight(obj)
  309. if (data.code == 200) {
  310. uni.showToast({
  311. title: '操作成功',
  312. icon: "none",
  313. mask: true,
  314. duration: 2000
  315. });
  316. }
  317. },
  318. //关灯
  319. async closeLight(item) {
  320. let obj = {
  321. buildId: this.buildingId,
  322. floorId: this.floorId,
  323. pointName: item.key
  324. };
  325. const {
  326. data
  327. } = await laboratoryExitRelayCloseLight(obj)
  328. if (data.code == 200) {
  329. uni.showToast({
  330. title: '操作成功',
  331. icon: "none",
  332. mask: true,
  333. duration: 2000
  334. });
  335. }
  336. },
  337. //计算缩放率
  338. getWXSystemInfo(list) {
  339. let self = this;
  340. wx.getSystemInfo({
  341. success: function(res) {
  342. self.zoomCalculate(list, res.windowHeight, res.windowWidth);
  343. }
  344. })
  345. },
  346. zoomCalculate(list, height, width) {
  347. let num = 0;
  348. let zoomType = 0;
  349. let maxWidth = 0
  350. let maxHeight = 0
  351. let zoomData = 1;
  352. if (height > width) {
  353. num = height / width
  354. } else {
  355. num = width / height
  356. }
  357. for (let i = 0; i < list.length; i++) {
  358. if ((list[i].x + list[i].w) > maxWidth) {
  359. maxWidth = list[i].x + list[i].w
  360. }
  361. if ((list[i].y + list[i].h) > maxHeight) {
  362. maxHeight = list[i].y + list[i].h
  363. }
  364. }
  365. this.$set(this, 'mapWidth', maxWidth);
  366. this.$set(this, 'mapHeight', maxHeight);
  367. let zoomNumOne = height / maxHeight;
  368. if (parseInt(this.accMul(zoomNumOne, maxHeight)) <= height && parseInt(this.accMul(zoomNumOne,
  369. maxWidth)) <= width) {
  370. zoomData = zoomNumOne;
  371. this.$set(this, 'zoomData', zoomNumOne);
  372. }
  373. let zoomNumTwo = width / maxWidth;
  374. if (parseInt(this.accMul(zoomNumTwo, maxHeight)) <= height && parseInt(this.accMul(zoomNumTwo,
  375. maxWidth)) <= width) {
  376. zoomData = zoomNumTwo;
  377. this.$set(this, 'zoomData', zoomNumTwo);
  378. }
  379. },
  380. accMul(arg1, arg2) {
  381. var m = 0,
  382. s1 = arg1.toString(),
  383. s2 = arg2.toString();
  384. try {
  385. m += s1.split(".")[1].length
  386. } catch (e) {}
  387. try {
  388. m += s2.split(".")[1].length
  389. } catch (e) {}
  390. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  391. },
  392. //MQTT订阅
  393. sensorMQTT() {
  394. let self = this;
  395. this.client = $mqtt.connect('wxs://' + uni.getStorageSync('mqttUrl'), {
  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>