| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <Box title="消息通知">
- <div class="l-flex__fill l-flex--col c-messageNotice">
- <div class="l-flex__none l-flex--row c-messageNotice__header">
- <div class="l-flex__none col__time">时间</div>
- <div class="l-flex__fill col__deviceName">设备名称</div>
- <div class="l-flex__none col__type">类型</div>
- <div class="l-flex__none col__handle">处理方式</div>
- <div class="l-flex__none col__status">处理结果</div>
- </div>
- <status-wrapper
- v-if="listData.length === 0"
- class="l-flex__fill l-flex--row center"
- />
- <template v-else>
- <div class="l-flex__fill u-relative">
- <div class="c-messageNotice__newList">
- <div
- v-for="item in newAlarmList.slice(0, 4)"
- :key="item.id"
- class="l-flex--row c-messageNotice__item new"
- >
- <div class="l-flex__none col__time l-flex--row center">
- <svg-icon
- class="alarm__icon"
- icon-class="v0-alarm"
- :style="{ color: colors[item.level] }"
- />
- <div>{{ item.happenTime }}</div>
- </div>
- <div class="l-flex__fill col__deviceName">
- <auto-text
- class="u-text--center"
- :text="item.deviceName"
- />
- </div>
- <div class="l-flex__none col__type">
- <auto-text
- class="u-text--center"
- :text="item.type"
- />
- </div>
- <div class="l-flex__none col__handle">
- <auto-text
- class="u-text--center"
- :text="item.handle"
- />
- </div>
- <div class="l-flex__none col__status">
- <auto-text
- class="u-text--center"
- :text="item.status.label"
- />
- </div>
- </div>
- </div>
- <div class="c-messageNotice__list">
- <vue-seamless-scroll
- ref="seamlessScroll"
- :data="listData"
- :class-option="classOption"
- >
- <div
- v-for="item in listData"
- :key="item.id"
- class="l-flex--row c-messageNotice__item"
- >
- <div class="l-flex__none col__time l-flex--row center">
- <svg-icon
- class="alarm__icon"
- icon-class="v0-alarm"
- :style="{ color: colors[item.level] }"
- />
- <div>{{ item.happenTime }}</div>
- </div>
- <div class="l-flex__fill col__deviceName">
- <auto-text
- class="u-text--center"
- :text="item.deviceName"
- />
- </div>
- <div class="l-flex__none col__type">
- <auto-text
- class="u-text--center"
- :text="item.type"
- />
- </div>
- <div class="l-flex__none col__handle">
- <auto-text
- class="u-text--center"
- :text="item.handle"
- />
- </div>
- <div class="l-flex__none col__status">
- <auto-text
- class="u-text--center"
- :text="item.status.label"
- />
- </div>
- </div>
- </vue-seamless-scroll>
- </div>
- </div>
- </template>
- </div>
- </Box>
- </template>
- <script>
- import { getDeviceAlarms } from '@/api/device'
- import { addTenant } from '@/api/base'
- import { parseTime } from '@/utils/index.js'
- import VueSeamlessScroll from 'vue-seamless-scroll'
- import Box from './Box'
- const isTest = false
- export default {
- components: {
- Box,
- VueSeamlessScroll
- },
- props: {
- deviceList: {
- type: Array,
- required: true
- }
- },
- data () {
- return {
- classOption: {
- step: 0.4,
- hoverStop: false
- },
- listData: [],
- newAlarmList: [],
- colors: ['#04A681', '#FFA000', '#F40645']
- }
- },
- created () {
- this.getDeviceAlarms()
- this.$timer = setInterval(this.getDeviceAlarms, 10000)
- },
- beforeDestroy () {
- clearTimeout(this.$timer)
- },
- methods: {
- getTag (value) {
- switch (value) {
- case 0:
- return {
- type: 'danger',
- label: '否'
- }
- case 1:
- return {
- type: 'success',
- label: '是'
- }
- default:
- return {
- label: '-'
- }
- }
- },
- getDeviceAlarms () {
- getDeviceAlarms(
- addTenant({
- pageIndex: 1,
- pageSize: 100
- })
- ).then(({ data }) => {
- if (isTest) {
- if (this.$rupdate) {
- if (!this.deviceList.length) { return }
- if (this.newAlarmList.length > 1) {
- this.newAlarmList = []
- return
- }
- data = this.listData.slice()
- const newAlarm = this.deviceList[Math.floor(Math.random() * this.deviceList.length)]
- data.push({
- id: new Date().valueOf(),
- deviceName: newAlarm.name,
- level: 2,
- happenTime: parseTime(new Date()),
- deviceId: newAlarm.id,
- type: '设备上线',
- handle: '未干预',
- status: {
- label: '-'
- }
- })
- } else {
- this.$rupdate = true
- }
- }
- if (!data.length) {
- return
- }
- const length = data.length
- const lastId = this.listData[0]?.id
- let emit = false
- for (let i = 0; i < length; i++) {
- const item = data[i]
- if (item.id === lastId) {
- break
- }
- if (item.level === 2) {
- this.newAlarmList.unshift(item)
- if (!emit) {
- this.$emit('new-alarm', item)
- emit = true
- }
- }
- }
- this.listData = data
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .c-messageNotice {
- &__header {
- color: #9ea9cd;
- background-color: #313a5a;
- }
- &__list {
- width: 100%;
- height: 100%;
- overflow: hidden;
- }
- &__item {
- color: #ffffff;
- border-bottom: 1px solid #313a5a;
- &.new {
- color: #f40645;
- font-weight: bold;
- }
- }
- &__header,
- &__item {
- font-size: 18px;
- line-height: 60px;
- text-align: center;
- }
- .alarm__icon {
- width: 19px;
- height: 19px;
- transform: translateY(-2px);
- }
- .col {
- &__time {
- width: 200px;
- }
- &__type {
- width: 250px;
- }
- &__handle {
- width: 120px;
- }
- &__status {
- width: 120px;
- }
- }
- &__newList {
- animation: sparkle 2s linear infinite;
- &:hover {
- animation: none;
- }
- }
- @keyframes sparkle {
- 0% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- }
- }
- }
- </style>
|