topWarn.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 { controlsRestrictVerify} from '@/utils/index'
  12. import {
  13. laboratoryBigViewSelectTriggerInfo,
  14. laboratoryPlanCloseRiskPlan,
  15. } from '@/pages_manage/api/index.js'
  16. export default {
  17. data() {
  18. return {
  19. pageType: false,
  20. text: "",
  21. buildId: "",
  22. floorId: "",
  23. subId: "",
  24. //预案MQTT
  25. mtopic: 'lab/risk/plan/change',
  26. client: {},
  27. planData: {},
  28. }
  29. },
  30. created() {
  31. },
  32. mounted() {
  33. this.offPlanMQTT('on');
  34. this.laboratoryBigViewSelectTriggerInfo();
  35. },
  36. methods: {
  37. //预案-MQTT连接
  38. offPlanMQTT(type) {
  39. let self = this;
  40. if (self.client.unsubscribe) {
  41. self.client.unsubscribe(self.mtopic, error => {
  42. if (error) {
  43. // console.log('mqtt关闭连接错误:', error)
  44. }
  45. })
  46. self.client.end();
  47. this.$set(this, 'client', {});
  48. }
  49. //判断传入参数如果存在 发起一次新的连接
  50. if (type) {
  51. this.planMQTT();
  52. }
  53. },
  54. //预案-MQTT订阅
  55. planMQTT() {
  56. let self = this;
  57. this.client = $mqtt.connect('wxs://' + uni.getStorageSync('mqttUrl'), {
  58. username: uni.getStorageSync('mqttUser'),
  59. password: uni.getStorageSync('mqttPassword')
  60. });
  61. this.client.on("connect", e => {
  62. this.client.subscribe(this.mtopic, (err) => {
  63. if (!err) {
  64. console.log("预案订阅成功:" + this.mtopic);
  65. } else {
  66. // console.log("连接错误:" + err);
  67. }
  68. });
  69. });
  70. this.client.on("message", (topic, message) => {
  71. console.log('message', message);
  72. console.log('topic,', topic);
  73. if (message) {
  74. if (topic == this.mtopic) {
  75. //预案触发
  76. console.log('触发预案')
  77. this.laboratoryBigViewSelectTriggerInfo();
  78. }
  79. }
  80. });
  81. },
  82. //获取预案数据
  83. async laboratoryBigViewSelectTriggerInfo(type) {
  84. let self = this;
  85. const {
  86. data
  87. } = await laboratoryBigViewSelectTriggerInfo();
  88. if (data.code == 200) {
  89. // console.log('条幅触发',data.data);
  90. if (data.data[0]) {
  91. // console.log('条幅触发-有');
  92. this.$set(this, 'planData', data.data);
  93. this.$set(this, 'text', data.data[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  94. this.$set(this, 'pageType', true);
  95. } else {
  96. // console.log('条幅触发-无');
  97. this.$set(this, 'pageType', false);
  98. this.$set(this, 'planData', []);
  99. this.$set(this, 'text', '');
  100. }
  101. }
  102. },
  103. //条幅操作按钮
  104. buttonClick() {
  105. let self = this;
  106. let list = [];
  107. if(!controlsRestrictVerify('performEvacuation')){
  108. list = ['查看'];
  109. }else{
  110. list = ['查看', '结束预案'];
  111. }
  112. uni.showActionSheet({
  113. itemList: list,
  114. success: function(res) {
  115. if (res.tapIndex == 0) {
  116. self.goPage();
  117. } else if (res.tapIndex == 1) {
  118. self.closePlan();
  119. }
  120. },
  121. fail: function(res) {
  122. console.log(res.errMsg);
  123. }
  124. });
  125. },
  126. //结束预案弹窗
  127. closePlan() {
  128. let self = this;
  129. uni.showModal({
  130. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  131. cancelColor: "#999",
  132. confirmColor: "#0183FA",
  133. success: function(res) {
  134. if (res.confirm) {
  135. self.closeRiskPlan();
  136. } else if (res.cancel) {
  137. }
  138. }
  139. });
  140. },
  141. //结束预案方法
  142. async closeRiskPlan() {
  143. const {
  144. data
  145. } = await laboratoryPlanCloseRiskPlan({
  146. eventId: this.planData[0].eventId
  147. });
  148. if (data.code == 200) {
  149. uni.showToast({
  150. title: '操作成功',
  151. icon: "none",
  152. mask: true,
  153. duration: 2000
  154. });
  155. this.laboratoryBigViewSelectTriggerInfo();
  156. }
  157. },
  158. //页面跳转
  159. goPage() {
  160. let obj = {
  161. buildId: this.planData[0].buildId,
  162. floorId: this.planData[0].floorId,
  163. subId: this.planData[0].subId,
  164. groupId: this.planData[0].eventId,
  165. }
  166. uni.navigateTo({
  167. url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(obj))
  168. });
  169. },
  170. },
  171. onHide() {
  172. //清除定时器
  173. let self = this;
  174. self.offPlanMQTT();
  175. },
  176. beforeDestroy() {
  177. //清除定时器
  178. let self = this;
  179. self.offPlanMQTT();
  180. },
  181. }
  182. </script>
  183. <style lang="stylus" scoped>
  184. .top-warn {
  185. height: 80rpx;
  186. line-height: 80rpx;
  187. background rgba(2550, 0, 0, 0.2);
  188. margin: 20rpx 30rpx 0;
  189. display flex;
  190. overflow hidden;
  191. border-radius:20rpx;
  192. .left-title{
  193. width:100rpx;
  194. height:40rpx;
  195. text-align: center;
  196. line-height:40rpx;
  197. margin:20rpx 18rpx 0 30rpx;
  198. color:#fff;
  199. font-size:28rpx;
  200. background-color: #FF0000;
  201. border-radius:10rpx;
  202. }
  203. .text-view {
  204. color: #FF0000;
  205. flex: 1;
  206. white-space: nowrap;
  207. }
  208. .button-view {
  209. width: 120rpx;
  210. height:48rpx;
  211. line-height:48rpx;
  212. color: #FF0000;
  213. border:1px solid #FF0000;
  214. text-align center;
  215. border-radius:50rpx;
  216. margin:16rpx 12rpx 0 0;
  217. }
  218. }
  219. </style>