MessageNotice.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <Box title="消息通知">
  3. <div class="l-flex__fill l-flex--col c-messageNotice">
  4. <div class="l-flex__none l-flex--row c-messageNotice__header">
  5. <div class="l-flex__none col__time">时间</div>
  6. <div class="l-flex__fill col__deviceName">设备名称</div>
  7. <div class="l-flex__none col__type">类型</div>
  8. <div class="l-flex__none col__handle">处理方式</div>
  9. <div class="l-flex__none col__status">处理结果</div>
  10. </div>
  11. <status-wrapper
  12. v-if="listData.length === 0"
  13. class="l-flex__fill l-flex--row center"
  14. />
  15. <template v-else>
  16. <div class="l-flex__fill u-relative">
  17. <div class="c-messageNotice__newList">
  18. <div
  19. v-for="item in newAlarmList.slice(0, 4)"
  20. :key="item.id"
  21. class="l-flex--row c-messageNotice__item new"
  22. >
  23. <div class="l-flex__none col__time l-flex--row center">
  24. <svg-icon
  25. class="alarm__icon"
  26. icon-class="v0-alarm"
  27. :style="{ color: colors[item.level] }"
  28. />
  29. <div>{{ item.happenTime }}</div>
  30. </div>
  31. <div class="l-flex__fill col__deviceName">
  32. <auto-text
  33. class="u-text--center"
  34. :text="item.deviceName"
  35. />
  36. </div>
  37. <div class="l-flex__none col__type">
  38. <auto-text
  39. class="u-text--center"
  40. :text="item.type"
  41. />
  42. </div>
  43. <div class="l-flex__none col__handle">
  44. <auto-text
  45. class="u-text--center"
  46. :text="item.handle"
  47. />
  48. </div>
  49. <div class="l-flex__none col__status">
  50. <auto-text
  51. class="u-text--center"
  52. :text="item.status.label"
  53. />
  54. </div>
  55. </div>
  56. </div>
  57. <div class="c-messageNotice__list">
  58. <vue-seamless-scroll
  59. ref="seamlessScroll"
  60. :data="listData"
  61. :class-option="classOption"
  62. >
  63. <div
  64. v-for="item in listData"
  65. :key="item.id"
  66. class="l-flex--row c-messageNotice__item"
  67. >
  68. <div class="l-flex__none col__time l-flex--row center">
  69. <svg-icon
  70. class="alarm__icon"
  71. icon-class="v0-alarm"
  72. :style="{ color: colors[item.level] }"
  73. />
  74. <div>{{ item.happenTime }}</div>
  75. </div>
  76. <div class="l-flex__fill col__deviceName">
  77. <auto-text
  78. class="u-text--center"
  79. :text="item.deviceName"
  80. />
  81. </div>
  82. <div class="l-flex__none col__type">
  83. <auto-text
  84. class="u-text--center"
  85. :text="item.type"
  86. />
  87. </div>
  88. <div class="l-flex__none col__handle">
  89. <auto-text
  90. class="u-text--center"
  91. :text="item.handle"
  92. />
  93. </div>
  94. <div class="l-flex__none col__status">
  95. <auto-text
  96. class="u-text--center"
  97. :text="item.status.label"
  98. />
  99. </div>
  100. </div>
  101. </vue-seamless-scroll>
  102. </div>
  103. </div>
  104. </template>
  105. </div>
  106. </Box>
  107. </template>
  108. <script>
  109. import { getDeviceAlarms } from '@/api/device'
  110. import { addTenant } from '@/api/base'
  111. import { parseTime } from '@/utils/index.js'
  112. import VueSeamlessScroll from 'vue-seamless-scroll'
  113. import Box from './Box'
  114. const isTest = false
  115. export default {
  116. components: {
  117. Box,
  118. VueSeamlessScroll
  119. },
  120. props: {
  121. deviceList: {
  122. type: Array,
  123. required: true
  124. }
  125. },
  126. data () {
  127. return {
  128. classOption: {
  129. step: 0.4,
  130. hoverStop: false
  131. },
  132. listData: [],
  133. newAlarmList: [],
  134. colors: ['#04A681', '#FFA000', '#F40645']
  135. }
  136. },
  137. created () {
  138. this.getDeviceAlarms()
  139. this.$timer = setInterval(this.getDeviceAlarms, 10000)
  140. },
  141. beforeDestroy () {
  142. clearTimeout(this.$timer)
  143. },
  144. methods: {
  145. getTag (value) {
  146. switch (value) {
  147. case 0:
  148. return {
  149. type: 'danger',
  150. label: '否'
  151. }
  152. case 1:
  153. return {
  154. type: 'success',
  155. label: '是'
  156. }
  157. default:
  158. return {
  159. label: '-'
  160. }
  161. }
  162. },
  163. getDeviceAlarms () {
  164. getDeviceAlarms(
  165. addTenant({
  166. pageIndex: 1,
  167. pageSize: 100
  168. })
  169. ).then(({ data }) => {
  170. if (isTest) {
  171. if (this.$rupdate) {
  172. if (!this.deviceList.length) { return }
  173. if (this.newAlarmList.length > 1) {
  174. this.newAlarmList = []
  175. return
  176. }
  177. data = this.listData.slice()
  178. const newAlarm = this.deviceList[Math.floor(Math.random() * this.deviceList.length)]
  179. data.push({
  180. id: new Date().valueOf(),
  181. deviceName: newAlarm.name,
  182. level: 2,
  183. happenTime: parseTime(new Date()),
  184. deviceId: newAlarm.id,
  185. type: '设备上线',
  186. handle: '未干预',
  187. status: {
  188. label: '-'
  189. }
  190. })
  191. } else {
  192. this.$rupdate = true
  193. }
  194. }
  195. if (!data.length) {
  196. return
  197. }
  198. const length = data.length
  199. const lastId = this.listData[0]?.id
  200. let emit = false
  201. for (let i = 0; i < length; i++) {
  202. const item = data[i]
  203. if (item.id === lastId) {
  204. break
  205. }
  206. if (item.level === 2) {
  207. this.newAlarmList.unshift(item)
  208. if (!emit) {
  209. this.$emit('new-alarm', item)
  210. emit = true
  211. }
  212. }
  213. }
  214. this.listData = data
  215. })
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .c-messageNotice {
  222. &__header {
  223. color: #9ea9cd;
  224. background-color: #313a5a;
  225. }
  226. &__list {
  227. width: 100%;
  228. height: 100%;
  229. overflow: hidden;
  230. }
  231. &__item {
  232. color: #ffffff;
  233. border-bottom: 1px solid #313a5a;
  234. &.new {
  235. color: #f40645;
  236. font-weight: bold;
  237. }
  238. }
  239. &__header,
  240. &__item {
  241. font-size: 18px;
  242. line-height: 60px;
  243. text-align: center;
  244. }
  245. .alarm__icon {
  246. width: 19px;
  247. height: 19px;
  248. transform: translateY(-2px);
  249. }
  250. .col {
  251. &__time {
  252. width: 200px;
  253. }
  254. &__type {
  255. width: 250px;
  256. }
  257. &__handle {
  258. width: 120px;
  259. }
  260. &__status {
  261. width: 120px;
  262. }
  263. }
  264. &__newList {
  265. animation: sparkle 2s linear infinite;
  266. &:hover {
  267. animation: none;
  268. }
  269. }
  270. @keyframes sparkle {
  271. 0% {
  272. opacity: 1;
  273. }
  274. 100% {
  275. opacity: 0;
  276. }
  277. }
  278. }
  279. </style>