event-warnings-list.vue
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
<TransitionGroup tag="ul" name="fade" class="container">
<li v-for="item in warningsList" class="warnings-list-row" :key="item">
<div class="warnings-list-text">
<p :title="item.title">{{item.title}}</p>
<p>{{item.timestamp}}</p>
</div>
<div class="warnings-list-btn">
<a-button :status="item.status==1? 'success': item.status==2? 'danger': 'warning'"
@click="buttonEvent(item)">{{item.status==1?
'已恢复': item.status==2? '不处理': '待处理'}}</a-button>
</div>
</li>
</TransitionGroup>
</template>
<script setup>
import { ref, onMounted, computed } from 'vue';
import { Notification } from '@arco-design/web-vue';
import dayjs from "dayjs";
// 按钮操作
const buttonEvent = (data) => {
Notification.info({
title: '提示',
content: data.title,
})
}
// 初始化公告消息列表
const warningsList = ref([
{ id: 1, title: 'title 1', status: 1, timestamp: '2024-5-8 12:00:00' },
{ id: 2, title: '[华一华邦多功能导轨表] 设备离线设备离线设备离线', status: 3, timestamp: '2024-5-8 12:00:00' },
{ id: 3, title: 'title 2', status: 1, timestamp: '2024-5-8 12:00:00' }
]);
onMounted(() => {
setInterval(() => {
const newNotice = {
id: Date.now(),
title: `这是新的警告消息 ${Math.floor(Math.random() * 100) + 1}`,
timestamp: dayjs().format("YYYY-MM-DD HH:mm")
};
insertNotice(newNotice);
}, 5000);
});
// 插入新消息
const insertNotice = (newNotice) => {
warningsList.value.unshift(newNotice);
}
</script>
<style lang="less" scoped>
/* 标题大小 */
@titleSize: 16px;
/* 文本大小 */
@textSize: 12px;
.container {
position: relative;
padding: 0;
margin: 0;
list-style-type: none;
}
p {
width: 100%;
list-style: none;
padding: 0;
margin: 0;
overflow: hidden;
}
.warnings-list-row {
padding: 7px 0px;
margin-bottom: 4px;
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
box-sizing: border-box;
border-bottom: 1px solid var(--color-neutral-4);
transition: all 0.5s ease-out;
&:nth-last-child(1) {
border-bottom: none;
}
}
/* 过渡效果 */
.fade-move,
.fade-enter-active,
.fade-leave-active {
transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
}
/* 进入和离开的状态 */
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: scaleY(0.01) translate(30px, 0);
}
/* 离开的项目被移除出了布局流 */
.fade-leave-active {
position: absolute;
}
.warnings-list-text {
margin-right: 10px;
cursor: pointer;
flex: 1;
overflow: hidden;
box-sizing: border-box;
p {
overflow: hiddden;
text-overflow: ellipsis;
white-space: nowrap;
&:nth-child(1) {
font-size: @titleSize;
}
&:nth-child(2) {
font-size: @textSize;
color: var(--color-neutral-6);
margin-top: 4px;
}
}
}
.warnings-list-btn {
flex-shrink: 0;
}
</style>