emergencyEvacuationBigFullScreen.vue 18 KB

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