emergencyEvacuationBigFullScreen.vue 16 KB

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