emergencyEvacuationBigFullScreen.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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="@/pages_manage/images/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. #emergencyEvacuationBigFullScreen {
  444. height: 100%;
  445. width: 100%;
  446. display: flex;
  447. overflow: hidden;
  448. .emergencyEvacuationBigFullScreen-page {
  449. // overflow: scroll;
  450. overflow: hidden;
  451. position: absolute;
  452. top: 50%;
  453. left: 50%;
  454. .map-max-box {
  455. position: relative;
  456. .map-max-for-box {
  457. position: absolute;
  458. display: flex;
  459. flex-direction: column;
  460. .map-max-for-min-box {
  461. position: relative;
  462. .position-box {
  463. position: absolute;
  464. }
  465. .map-for-name-p {
  466. padding: 0 10px;
  467. height: 20px;
  468. line-height: 20px;
  469. font-size: 14px;
  470. text-align: center;
  471. color: #333;
  472. overflow: hidden;
  473. text-overflow: ellipsis;
  474. white-space: nowrap;
  475. }
  476. .map-for-num-p {
  477. padding: 0 10px;
  478. height: 20px;
  479. line-height: 20px;
  480. font-size: 14px;
  481. text-align: center;
  482. color: #333;
  483. overflow: hidden;
  484. text-overflow: ellipsis;
  485. white-space: nowrap;
  486. }
  487. .center-move-door-p-t {
  488. background: url("@/pages_manage/images/icon_sysbjt_m.png") !important;
  489. background-size: 100% !important;
  490. transform: rotate(180deg);
  491. }
  492. .center-move-door-p-b {
  493. background: url("@/pages_manage/images/icon_sysbjt_m.png") !important;
  494. background-size: 100% !important;
  495. }
  496. .center-move-door-p-l {
  497. background: url("@/pages_manage/images/icon_sysbjt_m.png") !important;
  498. background-size: 100% !important;
  499. transform: rotate(90deg);
  500. }
  501. .center-move-door-p-r {
  502. background: url("@/pages_manage/images/icon_sysbjt_m.png") !important;
  503. background-size: 100% !important;
  504. transform: rotateZ(270deg);
  505. }
  506. .lightTopOn {
  507. background: url("@/pages_manage/images/icon_sjt.png");
  508. background-size: 100%;
  509. }
  510. .lightTopOff {
  511. background: url("@/pages_manage/images/icon_shang_hs.png");
  512. background-size: 100%;
  513. }
  514. .lightBottomOn {
  515. background: url("@/pages_manage/images/icon_xjt.png");
  516. background-size: 100%;
  517. }
  518. .lightBottomOff {
  519. background: url("@/pages_manage/images/icon_xia_hs.png");
  520. background-size: 100%;
  521. }
  522. .lightLeftOn {
  523. background: url("@/pages_manage/images/icon_zuo.png");
  524. background-size: 100%;
  525. }
  526. .lightLeftOff {
  527. background: url("@/pages_manage/images/icon_zou_hs.png");
  528. background-size: 100%;
  529. }
  530. .lightRightOn {
  531. background: url("@/pages_manage/images/icon_yuo.png");
  532. background-size: 100%;
  533. }
  534. .lightRightOff {
  535. background: url("@/pages_manage/images/icon_you_hs.png");
  536. background-size: 100%;
  537. }
  538. }
  539. }
  540. .for-map-box {
  541. border: 2px solid #fff;
  542. background: #CEF2FD;
  543. }
  544. .for-map-box-one {
  545. background: #CEFDD5;
  546. }
  547. .for-map-box-two {
  548. background: url("@/pages_manage/images/icon_yjtd.png") center center no-repeat #006400;
  549. background-size: 60px 60px;
  550. }
  551. .for-map-box-two-check {
  552. background: url("@/pages_manage/images/icon_yjtd.png") center center no-repeat rgba(50, 205, 50, 1);
  553. background-size: 80px 80px;
  554. }
  555. .room-type-one {
  556. //选中
  557. background: rgba(178, 235, 255, 1);
  558. }
  559. .room-type-two {
  560. //报警
  561. background: rgba(232, 0, 0, 0.4);
  562. box-shadow: 0 0 10px 1px #E80000 inset;
  563. }
  564. .room-type-three {
  565. //选中报警
  566. background: rgba(178, 235, 255, 1);
  567. box-shadow: 0 0 10px 1px #E80000 inset;
  568. }
  569. }
  570. }
  571. .position-button {
  572. position: fixed;
  573. top: 10px;
  574. right: 10px;
  575. width: 100px;
  576. line-height: 30px;
  577. font-size: 16px;
  578. background: rgba(0, 0, 0, 0.5);
  579. color: #fff;
  580. text-align: center;
  581. border-radius: 18px;
  582. border: none;
  583. }
  584. .position-button-two {
  585. position: fixed;
  586. bottom: 20px;
  587. left: 50%;
  588. width: 240px;
  589. line-height: 30px;
  590. font-size: 16px;
  591. text-align: center;
  592. color: #fff;
  593. background: #0183FA;
  594. border-radius: 4px;
  595. margin-left: -120px;
  596. border: none;
  597. }
  598. }
  599. </style>