NotificationItem.vue
3.24 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
<view class="notification-item" @click="onClick">
<view class="icon-container" :class="[`bg-${type}`]">
<uv-icon :name="iconName" color="#FFFFFF" size="24"></uv-icon>
</view>
<view class="content">
<view class="title">{{ title }}</view>
<view class="message">{{ message }}</view>
</view>
<view class="time">{{ time }}</view>
<view v-if="unread" class="badge">{{ unreadCount }}</view>
</view>
</template>
<script setup>
import { computed } from 'vue';
// 定义props
const props = defineProps({
type: {
type: String,
default: 'info',
validator: (value) => ['system', 'task', 'alert', 'work', 'alarm'].includes(value)
},
title: {
type: String,
required: true
},
message: {
type: String,
required: true
},
time: {
type: String,
required: true
},
unread: {
type: Boolean,
default: false
},
unreadCount: {
type: [String, Number],
default: '0'
}
});
const emit = defineEmits(['click']);
const iconName = computed(() => {
const iconMap = {
system: 'bell',
task: 'checkmark-circle',
alert: 'error-circle',
work: 'file-text',
alarm: 'warning'
};
return iconMap[props.type] || 'bell';
});
// 方法
const onClick = () => {
emit('click');
};
</script>
<style lang="scss" scoped>
.notification-item {
display: flex;
align-items: center;
padding: 32rpx;
background-color: #FFFFFF;
border-bottom: 2rpx solid #F0F0F0;
position: relative;
.icon-container {
width: 40rpx;
height: 40rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12rpx;
}
.bg-system {
background-color: #4080FF;
}
.bg-task {
background-color: #00C389;
}
.bg-alert {
background-color: #FF4D4F;
}
.bg-work {
background-color: #FFA940;
}
.bg-alarm {
background-color: #722ED1;
}
.content {
flex: 1;
overflow: hidden;
.title {
font-size: 32rpx;
font-weight: 500;
color: #333333;
margin-bottom: 8rpx;
}
.message {
font-size: 28rpx;
color: #999999;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
}
.time {
font-size: 24rpx;
color: #999999;
margin-left: 16rpx;
}
.badge {
position: absolute;
top: 32rpx;
right: 32rpx;
min-width: 36rpx;
height: 36rpx;
border-radius: 18rpx;
background-color: #FF4D4F;
color: #FFFFFF;
font-size: 24rpx;
display: flex;
align-items: center;
justify-content: center;
padding: 0 5px;
}
}
/* 适配iOS和Android的差异 */
/* iOS通常需要更圆润的视觉效果 */
/* Android通常需要更扁平的视觉效果 */
/* 使用条件编译实现平台特定样式 */
/* #ifdef APP-PLUS */
.notification-item {
/* App平台通用样式 */
}
/* #endif */
/* #ifdef APP-PLUS-NVUE */
.notification-item {
/* App nvue平台特定样式 */
}
/* #endif */
/* #ifdef APP-PLUS-IOS */
.notification-item {
.icon-container {
border-radius: 20rpx; /* iOS更圆润 */
}
}
/* #endif */
/* #ifdef APP-PLUS-ANDROID */
.notification-item {
.icon-container {
border-radius: 12rpx; /* Android更方正 */
}
}
/* #endif */
</style>