emergencyEvacuationBigFullScreen.vue 18 KB

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