topWarn.vue 8.5 KB

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