topWarn.vue 4.7 KB

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