AppMain.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <section class="app-main">
  3. <div class="app-main-top-text-box" v-if="textType">
  4. <p>{{text}}</p>
  5. <p @click="buttonClick">查看</p>
  6. </div>
  7. <div class="app-main-top-text-box-two" :class="workType == 1?'work-color-a':(workType == 2?'work-color-b':'')" v-if="!textType&&(workType == 1 || workType == 2)">
  8. <p>{{textWork}}</p>
  9. <p @click="goWorkPage">立即完成</p>
  10. <p class="el-icon-circle-close" @click="workClickOff"></p>
  11. </div>
  12. <transition name="fade-transform" mode="out-in">
  13. <!--<keep-alive :include="cachedViews">-->
  14. <router-view :key="key" />
  15. <!--</keep-alive>-->
  16. </transition>
  17. </section>
  18. </template>
  19. <script>
  20. import { airbottleBluetoothGetBeaconNotice } from "@/api/gasBottleManage/index";
  21. import { selectTriggerInfo } from '@/api/evacuationBigData/index.js'
  22. import store from '@/store'
  23. import mqtt from 'mqtt'
  24. export default {
  25. name: 'AppMain',
  26. computed: {
  27. cachedViews() {
  28. return this.$store.state.tagsView.cachedViews
  29. },
  30. key() {
  31. return this.$route.path
  32. }
  33. },
  34. data() {
  35. return {
  36. //MQTT请求参数-传感器
  37. mtopic:"lab/riskPlan/trigger/notice",
  38. mtopicTwo:"manage/work"+localStorage.getItem('userId'),
  39. textType:false,
  40. closePlan:false,
  41. text:"",
  42. textWork:"",
  43. workType:"",
  44. userType:"",
  45. buttonId:"",
  46. buildingId:"",
  47. address:"",
  48. buildId:null,
  49. floorId:null,
  50. subId:null,
  51. groupId:null,
  52. }
  53. },
  54. created() {
  55. },
  56. mounted(){
  57. this.userType = localStorage.getItem('userType')
  58. if( this.userType != 22 && this.versionField() != 'xiBeiNongLinDaXue'){
  59. this.selectTriggerInfo();
  60. this.subscriptionMQTT();
  61. }
  62. },
  63. methods:{
  64. workClickOff(){
  65. this.workType = "";
  66. },
  67. goWorkPage(){
  68. let self = this;
  69. const h = this.$createElement;
  70. this.$msgbox({
  71. title: '',
  72. message: h('p', null, [
  73. h('p', { style:'font-size:16px;margin:20px 0;' }, self.textWork),
  74. ]),
  75. showCancelButton: true,
  76. confirmButtonText: '完成',
  77. cancelButtonText: '取消',
  78. beforeClose: (action, instance, done) => {
  79. if (action === 'confirm') {
  80. //执行
  81. this.$router.push({
  82. path: "/laboratory/gradeManageWork"
  83. })
  84. done();
  85. } else {
  86. //取消
  87. done();
  88. }
  89. }
  90. }).then(action => {
  91. //成功回掉
  92. });
  93. },
  94. //MQTT订阅
  95. subscriptionMQTT(){
  96. let self = this;
  97. this.client = mqtt.connect(localStorage.getItem('mqttUrl'), {
  98. username: localStorage.getItem('mqttUser'),
  99. password: localStorage.getItem('mqttPassword')
  100. });
  101. this.client.on("connect", e =>{
  102. console.log("连接成功");
  103. this.client.subscribe(this.mtopic, (err) => {
  104. if (!err) {
  105. console.log("警报通道订阅成功:" + this.mtopic);
  106. }
  107. });
  108. this.client.subscribe(this.mtopicTwo, (err) => {
  109. if (!err) {
  110. console.log("工作通道订阅成功:" + this.mtopicTwo);
  111. }
  112. });
  113. });
  114. this.client.on("message", (topic, message) => {
  115. if (message){
  116. console.log("topic",topic);
  117. let data = JSON.parse(message)
  118. console.log("data",data);
  119. if(topic == this.mtopic){
  120. //报警
  121. store.dispatch('settings/setPlanData', data)
  122. self.selectTriggerInfo();
  123. }
  124. if(topic == this.mtopicTwo){
  125. //工作通知
  126. console.log("工作通知",data);
  127. this.textWork = data.msg;
  128. this.workType = data.type;
  129. }
  130. }
  131. });
  132. },
  133. //执行按钮
  134. buttonClick(){
  135. let self = this;
  136. if(this.$route.path == '/emergencyManagement/newPerformEvacuation'){
  137. return
  138. }
  139. const h = this.$createElement;
  140. this.$msgbox({
  141. title: '',
  142. message: h('p', null, [
  143. h('i', { style: 'color: #ea9518;font-size:100px;' ,class:"el-icon-warning-outline"}),
  144. h('p', { style:'font-size:16px;margin:20px 0;' }, self.text+',是否立即查看? '),
  145. ]),
  146. showCancelButton: true,
  147. confirmButtonText: '查看',
  148. cancelButtonText: '取消',
  149. beforeClose: (action, instance, done) => {
  150. if (action === 'confirm') {
  151. //执行
  152. this.$router.push({
  153. path: "/emergencyManagement/newPerformEvacuation",
  154. query: {
  155. buildId: self.buildId,
  156. floorId:self.floorId,
  157. subId:self.subId,
  158. }
  159. })
  160. done();
  161. } else {
  162. //取消
  163. done();
  164. }
  165. }
  166. }).then(action => {
  167. //成功回掉
  168. });
  169. },
  170. //查询当前用户下的预案触发数据
  171. selectTriggerInfo(){
  172. let self = this;
  173. let newList = [];
  174. selectTriggerInfo().then(responseOne => {
  175. newList = newList.concat(responseOne.data);
  176. airbottleBluetoothGetBeaconNotice().then(responseTow => {
  177. newList = newList.concat(responseTow.data);
  178. let arr = JSON.stringify(newList);
  179. //预案发生时候,存储值用于实验室配置传感器状态
  180. localStorage.setItem('selectTriggerList',arr)
  181. if(newList[0]){
  182. this.$set(this,'text',newList.length>1?'有多个实验室发生预案':'有实验室发生预案');
  183. this.$set(this,'buildId',newList[0].buildId);
  184. this.$set(this,'floorId',newList[0].floorId);
  185. this.$set(this,'subId',newList[0].subId);
  186. this.$set(this,'groupId',newList[0].groupId);
  187. if(newList[0].riskAttribute == 1){
  188. this.$set(this,'closePlan',true);
  189. }
  190. this.$set(this,'textType',true);
  191. //没有火焰预案并且没有查看过
  192. console.log('newList=================>',newList);
  193. // for(let i=0;i<newList.length;i++){
  194. // if(newList[i].riskAttribute != '1'&&newList[i].ifCheck != '1'){
  195. // console.log('跳转2',self.$route.path);
  196. // //如果就在应急预案页面责终止跳转
  197. // if(self.$route.path == '/emergencyManagement/newPerformEvacuation' || self.$route.path == '/newEvacuationBigData'){
  198. // return
  199. // }
  200. // this.$router.push({
  201. // path: "/emergencyManagement/newPerformEvacuation",
  202. // query: {
  203. // buildId: newList[i].buildId,
  204. // floorId:newList[i].floorId,
  205. // subId:newList[i].subId,
  206. // groupId:newList[i].groupId,
  207. // }
  208. // })
  209. // return
  210. // }
  211. // }
  212. }else{
  213. this.$set(this,'textType',false);
  214. }
  215. })
  216. })
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .app-main {
  223. /* 50= navbar 50 */
  224. /*min-height: calc(100vh - 50px);*/
  225. width: 100%;
  226. position: relative;
  227. overflow: hidden;
  228. display: flex;
  229. flex-direction: column;
  230. }
  231. .work-color-a{
  232. background: rgba(30,144,255,0.2);
  233. p{
  234. color:#0045AF;
  235. }
  236. }
  237. .work-color-b{
  238. background: rgba(255,0,0,0.2);
  239. p{
  240. color:#FF0000;
  241. }
  242. }
  243. .app-main-top-text-box-two{
  244. margin:10px 20px 0 10px;
  245. border-radius:10px;
  246. padding:0 0 0 20px;
  247. display: flex;
  248. p{
  249. line-height:60px;
  250. font-size:16px;
  251. margin:0;
  252. }
  253. p:nth-child(1){
  254. flex:1;
  255. }
  256. p:nth-child(2){
  257. width:100px;
  258. cursor: pointer;
  259. }
  260. p:nth-child(3){
  261. font-size:22px;
  262. margin-right:20px;
  263. cursor: pointer;
  264. }
  265. }
  266. .app-main-top-text-box{
  267. background: rgba(255,0,0,0.2);
  268. margin:10px 20px 0 10px;
  269. border-radius:10px;
  270. padding:0 0 0 20px;
  271. display: flex;
  272. p{
  273. line-height:60px;
  274. font-size:16px;
  275. margin:0;
  276. }
  277. p:nth-child(1){
  278. flex:1;
  279. color:#FF0000;
  280. }
  281. p:nth-child(2){
  282. width:100px;
  283. color:#0045AF;
  284. cursor: pointer;
  285. text-align: center;
  286. }
  287. p:nth-child(3){
  288. color:#0045AF;
  289. text-align: center;
  290. width:30px;
  291. font-weight:500;
  292. }
  293. p:nth-child(4){
  294. width:100px;
  295. color:#0045AF;
  296. cursor: pointer;
  297. text-align: center;
  298. }
  299. }
  300. .app-main-position-max-box{
  301. position: fixed;
  302. height:100%;
  303. width:100%;
  304. background: rgba(0,0,0,0.2);
  305. z-index: 100;
  306. .app-main-position-big-box{
  307. .app-main-position-box{
  308. position: absolute;
  309. top: 50%;
  310. left: 50%;
  311. background: #fff;
  312. width:500px;
  313. height:300px;
  314. margin-left:-250px;
  315. margin-top:-150px;
  316. border-radius:10px;
  317. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  318. .app-main-position-box-bottom-button-box{
  319. display: flex;
  320. }
  321. }
  322. }
  323. }
  324. .fixed-header+.app-main {
  325. padding-top: 50px;
  326. }
  327. .hasTagsView {
  328. .app-main {
  329. /* 84 = navbar + tags-view = 50 + 34 */
  330. /*min-height: calc(100vh - 84px);*/
  331. }
  332. .fixed-header+.app-main {
  333. padding-top: 84px;
  334. }
  335. }
  336. </style>
  337. <style lang="scss">
  338. // fix css style bug in open el-dialog
  339. .el-popup-parent--hidden {
  340. .fixed-header {
  341. padding-right: 15px;
  342. }
  343. }
  344. </style>