MessageList.vue
9.45 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<template>
<view class="message-list">
<!-- 消息列表 -->
<view
v-for="(item, index) in messageList"
:key="index"
class="message-item"
>
<!-- 复选框 - 仅在编辑模式下显示 -->
<view
v-if="isEditMode"
class="checkbox-container"
@click.stop="toggleSelect(item)"
>
<view
class="checkbox"
:class="{
checked: selectedItems.includes(item.taskId),
disabled: item.status === 'CLOSED'
}"
>
<uv-icon
v-if="selectedItems.includes(item.taskId)"
name="checkmark"
size="24rpx"
color="#FFFFFF"
></uv-icon>
</view>
</view>
<!-- 消息图标 -->
<view class="message-icon" @click="handleItemClick(item)">
<image
class="icon-image"
:src="getIconByType(item.isRead)"
mode="aspectFit"
></image>
</view>
<!-- 消息内容 -->
<view class="message-content" @click="handleItemClick(item)">
<view class="message-header">
<text class="message-time">{{ item.countTime }}</text>
<view class="message-status">
<image
v-if="item.childStatusValue === 'False alarm'"
class="status-icon"
src="/static/message/question.png"
mode="aspectFit"
></image>
<image
v-else-if="item.childStatusValue === 'Confirm'"
class="status-icon"
src="/static/message/checkRight.png"
mode="aspectFit"
></image>
<image
v-else
class="status-icon"
src="/static/message/gantan.png"
mode="aspectFit"
></image>
</view>
</view>
<text class="message-title">{{ item.mallName }}</text>
</view>
</view>
<!-- 底部悬浮按钮 - 仅在编辑模式下显示 -->
<view v-if="isEditMode" class="floating-buttons">
<view class="floating-button" @click="handleAll">
<view class="checkbox-container">
<view class="checkbox" :class="{ checked: allSelect }">
<uv-icon
v-if="allSelect"
name="checkmark"
size="24rpx"
color="#FFFFFF"
></uv-icon>
</view>
</view>
<text class="button-text">{{ t('maintenance.monitor.project.indexStatus.all') }}</text>
</view>
<view class="floating-button" @click="handleFalseAlarm">
<text class="button-text text-red">{{ t('TaskNotice.falseAlarm') }}</text>
</view>
<view class="floating-button" @click="handleConfirm">
<text class="button-text text-blue">{{ t('dialog.confirm') }}</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, watchEffect,watch } from "vue";
import {
t
} from '@/plugins/index.js'
const props = defineProps({
messages: {
type: Array,
default: () => [],
},
});
const selectedItems = ref([]);
const emit = defineEmits([
"itemClick",
"selectionChange",
"editModeChange",
"falseAlarm",
"confirm",
]);
// 全选标记
const allSelect = ref(false);
const messageList = computed(() => {
return props.messages || [];
});
const isEditMode = ref(false);
// watch(messageList, (newList) => {
// if (allSelect.value) {
// // 自动把新加载的数据加入 selectedItems
// const selectable = newList.filter(item => item.status !== 'CLOSED');
// selectedItems.value = selectable.map(item => item.taskId);
// }
// });
// 监听选择项 - 来改变allSelect 的状态
watchEffect(() => {
// 计算可选择的消息数量(排除CLOSED状态的消息)
const selectableMessages = messageList.value.filter(item => item.status !== 'CLOSED');
if (selectedItems.value.length === selectableMessages.length && selectableMessages.length > 0) {
allSelect.value = true;
} else {
allSelect.value = false;
}
});
// 根据消息类型获取对应图标 -
// 未读 已读 已处理 -- 目前确认仅两种状态
const getIconByType = (type) => {
const iconMap = {
// unread: "/static/message/notice_open.png",
// read: "/static/message/notice_open.png",
// processed: "/static/message/notice_open.png",
// default: "/static/message/notice_now.png",
true: "/static/message/notice_open.png",
false: "/static/message/notice_now.png",
};
return iconMap[type] || iconMap.default;
};
// 处理消息点击事件
const handleItemClick = (item) => {
// 在编辑模式下,点击消息项切换选择状态
if (isEditMode.value) {
toggleSelect(item);
} else {
emit("itemClick", item);
}
};
// 切换选择状态
const toggleSelect = (item) => {
if (!isEditMode.value) return;
// 检查消息状态是否为CLOSED
if (item.status === 'CLOSED') {
uni.showToast({
title: t('TaskNotice.msgHasBeenProcessed'),
icon: "none",
duration: 2000
});
return;
}
const index = selectedItems.value.indexOf(item.taskId);
if (index === -1) {
selectedItems.value.push(item.taskId);
} else {
selectedItems.value.splice(index, 1);
}
emit("selectionChange", selectedItems.value);
};
// 切换编辑模式 兼容强制退出编辑模式
const toggleEditMode = (type) => {
if (type === "force") {
isEditMode.value = false;
selectedItems.value = [];
return;
}
isEditMode.value = !isEditMode.value;
// 退出编辑模式时清空选择
if (!isEditMode.value) {
selectedItems.value = [];
}
emit("editModeChange", isEditMode.value);
};
// 处理编辑- 不需要处理全选了 进入编辑模式
const handleAll = () => {
allSelect.value = !allSelect.value;
if (allSelect.value) {
// 只选择状态不是CLOSED的消息
selectedItems.value = messageList.value
.filter(item => item.status !== 'CLOSED')
.map((item) => item.taskId);
} else {
selectedItems.value = [];
}
if (selectedItems.value.length > 0) {
emit("selectionChange", selectedItems.value);
} else {
allSelect.value && uni.showToast({
title: t('TaskNotice.plzSelectMsg'),
icon: "none",
});
}
};
// 处理误报操作
const handleFalseAlarm = () => {
if (selectedItems.value.length > 0) {
emit("falseAlarm", selectedItems.value);
} else {
uni.showToast({
title: t('TaskNotice.plzSelectMsg'),
icon: "none",
});
}
};
const handleEdit = () => {
toggleEditMode();
};
// 处理确认操作
const handleConfirm = () => {
if (selectedItems.value.length > 0) {
emit("confirm", selectedItems.value);
} else {
uni.showToast({
title: t('TaskNotice.plzSelectMsg'),
icon: "none",
});
}
};
// 暴露方法给父组件
defineExpose({
handleEdit,
handleAll,
handleFalseAlarm,
handleConfirm,
toggleEditMode,
selectedItems,
isEditMode,
});
</script>
<style lang="scss" scoped>
.message-list {
width: 100%;
padding: 0 0rpx;
position: relative;
}
/* 消息项样式 */
.message-item {
display: flex;
padding: 32rpx 0;
border-bottom: 2rpx solid #eef0f3;
align-items: center;
gap: 26rpx;
&:last-child {
border-bottom: none;
}
}
/* 复选框样式 */
.checkbox-container {
display: flex;
align-items: center;
justify-content: center;
}
.checkbox {
width: 33rpx;
height: 33rpx;
border-radius: 50%;
border: 2rpx solid #cccccc;
display: flex;
align-items: center;
justify-content: center;
}
.checkbox.checked {
background-color: #387cf5;
border-color: #387cf5;
}
.checkbox.disabled {
background-color: #f5f5f5;
border-color: #e0e0e0;
opacity: 0.5;
cursor: not-allowed;
}
.checkbox.disabled.checked {
background-color: #d0d0d0;
border-color: #d0d0d0;
}
.message-icon {
width: 96rpx;
height: 96rpx;
background: rgba(215, 229, 254, 0.3);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
.icon-image {
// width: 43rpx;
// height: 33rpx;
}
}
.unread-badge {
position: absolute;
top: -6rpx;
right: -6rpx;
width: 16rpx;
height: 16rpx;
background-color: #ff5151;
border-radius: 50%;
}
.message-content {
flex: 1;
}
.message-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 18rpx;
}
.message-time {
font-weight: 500;
font-size: 28rpx;
color: #262626;
}
.status-icon {
width: 32rpx;
height: 32rpx;
}
.message-title {
font-weight: 400;
font-size: 26rpx;
color: #90949d;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.message-desc {
font-size: 28rpx;
color: #666666;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
/* 底部悬浮按钮样式 */
.floating-buttons {
position: fixed;
// bottom: calc(var(--window-bottom) + 1rpx);
bottom: calc(var(--window-bottom) + env(safe-area-inset-bottom));
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
width: 100%;
height: 82rpx;
background: #ffffff;
box-shadow: 0rpx -2rpx 0rpx 0rpx #eef0f3;
border-radius: 0rpx 0rpx 0rpx 0rpx;
z-index: 100;
padding: 32rpx 26rpx;
justify-content: space-between;
border-top: 1rpx solid #eef0f3;
}
.floating-button {
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
}
.button-text {
font-size: 28rpx;
font-weight: 400;
font-size: 28rpx;
color: #4e515e;
}
.text-red {
color: #ff5730;
}
.text-blue {
color: #387cf5;
}
</style>