RiskHint.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="riskHint-container">
  3. <base-title title="风险提示" />
  4. <div class="hint-box" v-if="hintData1.length">
  5. <vue-seamless
  6. :data="hintData1"
  7. class="seamless-warp"
  8. :class-option="scrollOption"
  9. ref="seamlessScroll"
  10. >
  11. <div class="hint-content">
  12. <div
  13. class="hint-item"
  14. v-for="item of hintData1"
  15. :key="item.id"
  16. @click="openRiskDialog(item)"
  17. >
  18. <div
  19. class="title"
  20. :style="{
  21. 'background-image': `linear-gradient(90deg, ${
  22. riskColors[item.level].color
  23. } 2%, rgba(249, 40, 40, 0) 100%)`,
  24. }"
  25. >
  26. <img :src="require('@/assets/imgs/maps/img_dian.png')" alt="" />
  27. <span class="type">{{ riskColors[item.level].name }}</span>
  28. <span class="split"></span>
  29. <span class="time">{{
  30. Dayjs(item.eventTime).format("YYYY-MM-DD HH:mm:ss")
  31. }}</span>
  32. </div>
  33. <div
  34. class="content"
  35. :style="{
  36. color: `${riskColors[item.level].color}`,
  37. }"
  38. >
  39. {{ item.content }}
  40. </div>
  41. </div>
  42. </div>
  43. </vue-seamless>
  44. </div>
  45. <div class="hint-box no-data" v-else>暂无数据</div>
  46. </div>
  47. </template>
  48. <script>
  49. import BaseTitle from "./BaseTitle.vue";
  50. import VueSeamless from "vue-seamless-scroll";
  51. import Dayjs from "dayjs";
  52. import { getAlarmDataList } from "@/API/alarm";
  53. import { mapGetters } from "vuex";
  54. export default {
  55. name: "",
  56. components: { BaseTitle, VueSeamless },
  57. props: {
  58. hintData: {
  59. type: Array,
  60. default: () => [],
  61. },
  62. },
  63. data() {
  64. return {
  65. scrollOption: {
  66. limitMoveNum: 2.5,
  67. singleHeight: 81.5,
  68. waitTime: 2000,
  69. },
  70. dId: "",
  71. riskColors: {
  72. ["306001"]: { name: "重大级别", color: "#FF3636" },
  73. ["306002"]: { name: "较大级别", color: "#FF9F00" },
  74. ["306003"]: { name: "一般级别", color: "#F8E71C" },
  75. ["306004"]: { name: "低级别", color: "#53A3FF" },
  76. ["024001"]: { name: "一级", color: "#FF3636" },
  77. ["024002"]: { name: "二级", color: "#F8E71C" },
  78. ["024003"]: { name: "三级", color: "#53A3FF" },
  79. },
  80. hintData1: [],
  81. };
  82. },
  83. computed: {
  84. ...mapGetters(["departmentId"]),
  85. },
  86. mounted() {
  87. this.getAlarmDataList();
  88. // this.startMqtt();
  89. let timer = null;
  90. if (!timer) {
  91. timer = setInterval(() => {
  92. this.getAlarmDataList();
  93. }, 5000);
  94. }
  95. this.$once("hook:beforeDestroy", () => {
  96. !!timer && clearTimeout(timer);
  97. timer = null;
  98. });
  99. },
  100. watch: {
  101. departmentId(newVal) {
  102. // console.log("部门id信息", newVal);
  103. this.dId = newVal;
  104. setTimeout(() => {
  105. this.getAlarmDataList();
  106. }, 200);
  107. },
  108. },
  109. methods: {
  110. Dayjs,
  111. async getAlarmDataList() {
  112. try {
  113. const params = {
  114. // pageSize: 10000,
  115. // pageIndex: 1,
  116. dealStatus: "", //0
  117. confirmStatus: "0",
  118. recoveryStatus: "",
  119. category: "",
  120. level: "",
  121. type: "",
  122. startTime: Dayjs(
  123. Dayjs(new Date()).subtract(7, "day").format("YYYY-MM-DD HH:mm:ss")
  124. ).format(),
  125. endTime: Dayjs(
  126. Dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
  127. ).format(),
  128. key: "",
  129. tag: "",
  130. departmentId: this.dId,
  131. };
  132. const res = await getAlarmDataList(params);
  133. let alarmData = res.data.content;
  134. this.hintData1 = alarmData.map((e) => {
  135. return {
  136. id: e.id,
  137. level: e.level ? e.level : "024003",
  138. riskTime: e.eventTime,
  139. content:
  140. (e.departmentName ? e.departmentName : "") +
  141. (e.categoryStr ? e.categoryStr : "") +
  142. e.content,
  143. };
  144. });
  145. // console.log("风险报警数据", alarmData, this.hintData1);
  146. } catch (err) {}
  147. },
  148. openRiskDialog(data) {
  149. // console.log("风险报警数据", data);
  150. // let dialogConfig = {
  151. // dialogId: "risk_" + data.id,
  152. // show: true, //是否显示
  153. // title: "事件详情",
  154. // width: 500, //px宽度
  155. // height: 320, //px高度
  156. // center: true, //是否居中定位
  157. // zIndex: 10,
  158. // data,
  159. // };
  160. // this.$store.dispatch("dialog/addRiskDialog", dialogConfig);
  161. },
  162. startMqtt() {
  163. const topics = [
  164. "DataCommunication/TagData/xxx",
  165. "DataCommunication/TagData/xxx",
  166. "DataCommunication/TagData/xxx",
  167. "DataCommunication/TagData/xxx",
  168. "DataCommunication/TagData/xxx",
  169. "DataCommunication/TagData/xxx",
  170. ];
  171. const _this = this;
  172. this.$store.dispatch("mqtt/subscribe", {
  173. topic: topics,
  174. onMessage: (topic, message, packet) => {
  175. const content = message.toString();
  176. const data = JSON.parse(content);
  177. if (topic === "Visualization/Number/StationLevelCount") {
  178. const topicIndex = topics.indexOf(topic);
  179. if (topicIndex > -1) {
  180. _this.weatherList[topicIndex] = data.Value;
  181. _this.weatherList[topicIndex] = data.Unit;
  182. }
  183. }
  184. },
  185. });
  186. this.$once("hook:beforeDestroy", () => {
  187. this.$store.dispatch("mqtt/unsubscribe", topics);
  188. });
  189. },
  190. },
  191. };
  192. </script>
  193. <style lang="less" scoped>
  194. .riskHint-container {
  195. width: 410px;
  196. z-index: 2;
  197. .hint-box {
  198. width: 100%;
  199. height: 210px;
  200. overflow: hidden;
  201. padding: 0 15px;
  202. // display: flex;
  203. position: relative;
  204. .hint-content {
  205. padding-left: 20px;
  206. .hint-item:last-child {
  207. margin-bottom: 10px;
  208. }
  209. }
  210. .hint-item {
  211. width: 100%;
  212. height: 70px;
  213. margin: 10px;
  214. cursor: pointer;
  215. }
  216. .title {
  217. height: 27px;
  218. background-image: linear-gradient(
  219. 90deg,
  220. #f92828 2%,
  221. rgba(249, 40, 40, 0) 100%
  222. );
  223. display: flex;
  224. align-items: center;
  225. color: #fff;
  226. position: relative;
  227. img {
  228. width: 14px;
  229. height: 14px;
  230. position: absolute;
  231. left: -20px;
  232. }
  233. .type {
  234. margin-left: 5px;
  235. }
  236. .split {
  237. width: 2px;
  238. height: 10px;
  239. border-left: 2px solid #fff;
  240. margin: 0 8px;
  241. }
  242. }
  243. .content {
  244. padding: 10px 0;
  245. font-size: 14px;
  246. color: #ffffff;
  247. letter-spacing: 1px;
  248. font-weight: 550;
  249. }
  250. }
  251. .no-data {
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. font-size: 18px;
  256. font-weight: 500;
  257. color: #fff;
  258. letter-spacing: 5px;
  259. }
  260. }
  261. </style>