topWarn.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!-- 顶部警告 -->
  2. <template>
  3. <view class="top-warn" v-if="pageType">
  4. <view class="left-title">预警</view>
  5. <view class="text-view">{{text}}</view>
  6. <view class="button-view" @click="buttonClick" v-if="buttonType">处置</view>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. itoOrVideoLimits
  12. } from '@/utils/index'
  13. import $mqtt from '@/utils/mqtt.min.js';
  14. import {
  15. controlsRestrictVerify
  16. } from '@/utils/index'
  17. import {
  18. laboratoryBigViewSelectTriggerInfo,
  19. laboratoryPlanCloseRiskPlan,
  20. laboratoryBigViewGetFloorByBigView,
  21. } from '@/pages_manage/api/index.js'
  22. export default {
  23. data() {
  24. return {
  25. pageType: false,
  26. buttonType:false,
  27. text: "",
  28. buildId: "",
  29. floorId: "",
  30. subId: "",
  31. //预案MQTT
  32. mtopic: 'lab/risk/plan/change',
  33. client: {},
  34. planData: {},
  35. }
  36. },
  37. created() {
  38. },
  39. mounted() {
  40. this.offPlanMQTT('on');
  41. this.laboratoryBigViewSelectTriggerInfo();
  42. },
  43. methods: {
  44. //预案-MQTT连接
  45. offPlanMQTT(type) {
  46. let self = this;
  47. if (self.client.unsubscribe) {
  48. self.client.unsubscribe(self.mtopic, error => {
  49. if (error) {
  50. // console.log('mqtt关闭连接错误:', error)
  51. }
  52. })
  53. self.client.end();
  54. this.$set(this, 'client', {});
  55. }
  56. //判断传入参数如果存在 发起一次新的连接
  57. if (type) {
  58. this.planMQTT();
  59. }
  60. },
  61. //预案-MQTT订阅
  62. planMQTT() {
  63. let self = this;
  64. this.client = $mqtt.connect(
  65. // #ifdef WEB
  66. 'wss://' + uni.getStorageSync('mqttUrl')
  67. // #endif
  68. // #ifdef MP-WEIXIN
  69. 'wxs://' + uni.getStorageSync('mqttUrl')
  70. // #endif
  71. , {
  72. username: uni.getStorageSync('mqttUser'),
  73. password: uni.getStorageSync('mqttPassword')
  74. });
  75. this.client.on("connect", e => {
  76. this.client.subscribe(this.mtopic, (err) => {
  77. if (!err) {
  78. console.log("预案订阅成功:" + this.mtopic);
  79. } else {
  80. // console.log("连接错误:" + err);
  81. }
  82. });
  83. });
  84. this.client.on("message", (topic, message) => {
  85. console.log('message', message);
  86. console.log('topic,', topic);
  87. if (message) {
  88. if (topic == this.mtopic) {
  89. //预案触发
  90. console.log('触发预案')
  91. this.laboratoryBigViewSelectTriggerInfo();
  92. }
  93. }
  94. });
  95. },
  96. //获取预案数据
  97. async laboratoryBigViewSelectTriggerInfo(type) {
  98. let self = this;
  99. const {
  100. data
  101. } = await laboratoryBigViewSelectTriggerInfo();
  102. if (data.code == 200) {
  103. // console.log('条幅触发',data.data);
  104. if (data.data[0]) {
  105. let list1 = [];
  106. let list2 = [];
  107. data.data.forEach((item)=>{
  108. if(itoOrVideoLimits(item.adminId,item.safeIds)){
  109. list1.push(item);
  110. }else{
  111. list2.push(item);
  112. }
  113. })
  114. if(list1[0]){
  115. // console.log('条幅触发-有');
  116. this.$set(this, 'planData', list1);
  117. this.$set(this, 'text', list1[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  118. this.$set(this, 'pageType', true);
  119. this.$set(this, 'buttonType', true);
  120. //传感器
  121. let planSensorList = [];
  122. list1.forEach((item) => {
  123. let list = JSON.parse(item.triggerUploadData)
  124. list.forEach((minItem) => {
  125. planSensorList.push(minItem.deviceNo)
  126. })
  127. })
  128. uni.setStorageSync("planSensorList", planSensorList);
  129. }else{
  130. this.$set(this, 'planData', list2);
  131. this.$set(this, 'text', list2[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  132. this.$set(this, 'pageType', true);
  133. this.$set(this, 'buttonType', false);
  134. //传感器
  135. let planSensorList = [];
  136. list2.forEach((item) => {
  137. let list = JSON.parse(item.triggerUploadData)
  138. list.forEach((minItem) => {
  139. planSensorList.push(minItem.deviceNo)
  140. })
  141. })
  142. uni.setStorageSync("planSensorList", planSensorList);
  143. }
  144. } else {
  145. // console.log('条幅触发-无');
  146. this.$set(this, 'pageType', false);
  147. this.$set(this, 'buttonType', false);
  148. this.$set(this, 'planData', []);
  149. this.$set(this, 'text', '');
  150. uni.setStorageSync("planSensorList", []);
  151. }
  152. }
  153. },
  154. //条幅操作按钮
  155. buttonClick() {
  156. let self = this;
  157. if(self.planData[1]){
  158. let list = [];
  159. for(let i=0;i<self.planData.length;i++){
  160. list.push(self.planData[i].subName+'-'+self.planData[i].eventName)
  161. }
  162. uni.showActionSheet({
  163. itemList: list,
  164. success: function(res) {
  165. let obj = {
  166. buildId: self.planData[res.tapIndex].buildId,
  167. floorId: self.planData[res.tapIndex].floorId,
  168. subId: self.planData[res.tapIndex].subId,
  169. adminId: self.planData[res.tapIndex].adminId,
  170. groupId: self.planData[res.tapIndex].eventId,
  171. }
  172. let buttonList = [];
  173. if (!itoOrVideoLimits(self.planData[res.tapIndex].adminId,self.planData[res.tapIndex].safeIds)) {
  174. buttonList = ['查看'];
  175. } else {
  176. buttonList = ['查看', '结束预案'];
  177. }
  178. setTimeout(() => {
  179. uni.showActionSheet({
  180. itemList: buttonList,
  181. success: function(res) {
  182. if (res.tapIndex == 0) {
  183. self.laboratoryBigViewGetFloorByBigView(obj);
  184. } else if (res.tapIndex == 1) {
  185. uni.showModal({
  186. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  187. cancelColor: "#999",
  188. confirmColor: "#0183FA",
  189. success: function(resData) {
  190. if (resData.confirm) {
  191. self.closeRiskPlan(res.tapIndex);
  192. } else if (resData.cancel) {
  193. }
  194. }
  195. });
  196. }
  197. },
  198. fail: function(res) {
  199. console.log(res.errMsg);
  200. }
  201. });
  202. }, 300);
  203. },
  204. fail: function(res) {
  205. // console.log(res.errMsg);
  206. }
  207. });
  208. }else{
  209. let obj = {
  210. buildId: self.planData[0].buildId,
  211. floorId: self.planData[0].floorId,
  212. subId: self.planData[0].subId,
  213. adminId: self.planData[0].adminId,
  214. groupId: self.planData[0].eventId,
  215. }
  216. let buttonList = [];
  217. if (!itoOrVideoLimits(self.planData[0].adminId,self.planData[0].safeIds)) {
  218. buttonList = ['查看'];
  219. } else {
  220. buttonList = ['查看', '结束预案'];
  221. }
  222. uni.showActionSheet({
  223. itemList: buttonList,
  224. success: function(res) {
  225. if (res.tapIndex == 0) {
  226. self.laboratoryBigViewGetFloorByBigView(obj);
  227. } else if (res.tapIndex == 1) {
  228. uni.showModal({
  229. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  230. cancelColor: "#999",
  231. confirmColor: "#0183FA",
  232. success: function(resData) {
  233. if (resData.confirm) {
  234. self.closeRiskPlan(0);
  235. } else if (resData.cancel) {
  236. }
  237. }
  238. });
  239. }
  240. },
  241. fail: function(res) {
  242. console.log(res.errMsg);
  243. }
  244. });
  245. }
  246. },
  247. //结束预案方法
  248. async closeRiskPlan(index) {
  249. console.log('index',index)
  250. let self = this;
  251. const {
  252. data
  253. } = await laboratoryPlanCloseRiskPlan({
  254. eventId: self.planData[index].eventId
  255. });
  256. if (data.code == 200) {
  257. uni.showToast({
  258. title: '操作成功',
  259. icon: "none",
  260. mask: true,
  261. duration: 2000
  262. });
  263. self.laboratoryBigViewSelectTriggerInfo();
  264. }
  265. },
  266. //查询实验室是否配置地图
  267. async laboratoryBigViewGetFloorByBigView(obj) {
  268. const {
  269. data
  270. } = await laboratoryBigViewGetFloorByBigView({
  271. id: obj.floorId
  272. })
  273. if (data.code == 200) {
  274. if(data.data[0]){
  275. if(data.data[0].buildLayoutVoList){
  276. if (data.data[0].buildLayoutVoList[0]) {
  277. uni.navigateTo({
  278. url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(
  279. obj))
  280. });
  281. }else{
  282. uni.showToast({
  283. title: '该实验室楼层未配置地图数据,请联系管理员.',
  284. icon: "none",
  285. mask: true,
  286. duration: 4000
  287. });
  288. }
  289. }else{
  290. uni.showToast({
  291. title: '该实验室楼层未配置地图数据,请联系管理员.',
  292. icon: "none",
  293. mask: true,
  294. duration: 4000
  295. });
  296. }
  297. }else{
  298. uni.showToast({
  299. title: '该实验室楼层未配置地图数据,请联系管理员.',
  300. icon: "none",
  301. mask: true,
  302. duration: 4000
  303. });
  304. }
  305. }
  306. },
  307. },
  308. onHide() {
  309. //清除定时器
  310. let self = this;
  311. console.log('onHide')
  312. self.offPlanMQTT();
  313. },
  314. beforeDestroy() {
  315. //清除定时器
  316. let self = this;
  317. console.log('beforeDestroy')
  318. self.offPlanMQTT();
  319. },
  320. }
  321. </script>
  322. <style lang="stylus" scoped>
  323. .top-warn {
  324. height: 80rpx;
  325. line-height: 80rpx;
  326. background rgba(2550, 0, 0, 0.2);
  327. margin: 20rpx 30rpx 0;
  328. display flex;
  329. overflow hidden;
  330. border-radius: 20rpx;
  331. .left-title {
  332. width: 100rpx;
  333. height: 40rpx;
  334. text-align: center;
  335. line-height: 40rpx;
  336. margin: 20rpx 18rpx 0 30rpx;
  337. color: #fff;
  338. font-size: 28rpx;
  339. background-color: #FF0000;
  340. border-radius: 10rpx;
  341. }
  342. .text-view {
  343. color: #FF0000;
  344. flex: 1;
  345. white-space: nowrap;
  346. }
  347. .button-view {
  348. width: 120rpx;
  349. height: 48rpx;
  350. line-height: 48rpx;
  351. color: #FF0000;
  352. border: 1px solid #FF0000;
  353. text-align center;
  354. border-radius: 50rpx;
  355. margin: 16rpx 12rpx 0 0;
  356. }
  357. }
  358. </style>