<template>
|
<view class="message-container">
|
<view class="message-header">
|
<view class="header-title">消息中心</view>
|
</view>
|
|
<scroll-view class="message-list-scroll" scroll-y="true">
|
<view class="message-list">
|
<!-- 未读消息在前 -->
|
<view
|
class="message-item"
|
v-for="message in sortedMessages"
|
:key="message.id"
|
@click="viewMessageDetail(message)"
|
>
|
<view class="message-main">
|
<view class="message-title">
|
<text class="title-text">{{ getMessageTypeText(message.type) }}</text>
|
<view class="unread-dot" v-if="!message.read"></view>
|
</view>
|
<view class="message-content">{{ message.content }}</view>
|
<view class="message-time">{{ message.time }}</view>
|
</view>
|
</view>
|
|
<view class="no-data" v-if="sortedMessages.length === 0">
|
<uni-icons type="info" size="40" color="#ccc"></uni-icons>
|
<text>暂无消息</text>
|
</view>
|
</view>
|
</scroll-view>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
// 消息列表
|
messages: [
|
{
|
id: 1,
|
type: 'create', // 创建成功
|
content: 'TD 1011 广州天河->广州东站,时间:13:20 任务创建成功',
|
time: '2023-05-15 13:20',
|
read: false,
|
taskId: 1
|
},
|
{
|
id: 2,
|
type: 'push', // 任务推送
|
content: 'TD1021 广州天河->广州东站,时间:13:20 出发,请及时处理',
|
time: '2023-05-15 13:25',
|
read: false,
|
taskId: 2
|
},
|
{
|
id: 3,
|
type: 'status', // 任务状态变更
|
content: 'TD1021 广州天河->广州东站,时间:13:20,任务正在转运中',
|
time: '2023-05-15 14:30',
|
read: true,
|
taskId: 2
|
},
|
{
|
id: 4,
|
type: 'create', // 创建成功
|
content: 'TD 1022 深圳南山->深圳福田,时间:15:10 任务创建成功',
|
time: '2023-05-15 15:10',
|
read: false,
|
taskId: 3
|
},
|
{
|
id: 5,
|
type: 'push', // 任务推送
|
content: 'TD1023 深圳南山->深圳福田,时间:16:00 出发,请及时处理',
|
time: '2023-05-15 16:00',
|
read: true,
|
taskId: 4
|
}
|
]
|
}
|
},
|
computed: {
|
// 按未读/已读排序,未读的在前面
|
sortedMessages() {
|
return [...this.messages].sort((a, b) => {
|
if (a.read === b.read) {
|
// 相同状态按时间倒序
|
return new Date(b.time) - new Date(a.time);
|
}
|
// 未读的排在前面
|
return a.read ? 1 : -1;
|
});
|
}
|
},
|
methods: {
|
// 获取消息类型文本
|
getMessageTypeText(type) {
|
const typeMap = {
|
'create': '创建成功',
|
'push': '任务推送',
|
'status': '任务状态'
|
}
|
return typeMap[type] || '系统消息';
|
},
|
|
// 查看消息详情(跳转到任务详情)
|
viewMessageDetail(message) {
|
// 标记为已读
|
message.read = true;
|
|
// 跳转到任务详情页面
|
if (message.taskId) {
|
this.$tab.navigateTo(`/pages/task/detail?id=${message.taskId}`);
|
} else {
|
this.$modal.showToast('无法找到关联任务');
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.message-container {
|
padding: 20rpx;
|
background-color: #f5f5f5;
|
height: 100vh;
|
display: flex;
|
flex-direction: column;
|
// 隐藏滚动条但保持滚动功能
|
::-webkit-scrollbar {
|
display: none;
|
width: 0 !important;
|
height: 0 !important;
|
background: transparent;
|
}
|
|
// Firefox滚动条隐藏
|
* {
|
scrollbar-width: none; /* Firefox */
|
}
|
|
// IE/Edge滚动条隐藏
|
* {
|
-ms-overflow-style: none; /* IE 10+ */
|
}
|
}
|
|
.message-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 20rpx 0;
|
flex-shrink: 0; // 防止收缩
|
|
.header-title {
|
font-size: 36rpx;
|
font-weight: bold;
|
}
|
}
|
|
.message-list-scroll {
|
flex: 1;
|
// 隐藏滚动条但保持滚动功能
|
::-webkit-scrollbar {
|
display: none;
|
width: 0 !important;
|
height: 0 !important;
|
background: transparent;
|
}
|
|
// Firefox滚动条隐藏
|
* {
|
scrollbar-width: none; /* Firefox */
|
}
|
|
// IE/Edge滚动条隐藏
|
* {
|
-ms-overflow-style: none; /* IE 10+ */
|
}
|
}
|
|
.message-list {
|
.message-item {
|
background-color: white;
|
border-radius: 15rpx;
|
margin-bottom: 20rpx;
|
padding: 30rpx;
|
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
|
|
.message-main {
|
.message-title {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 20rpx;
|
|
.title-text {
|
font-size: 32rpx;
|
font-weight: bold;
|
color: #333;
|
}
|
|
.unread-dot {
|
width: 16rpx;
|
height: 16rpx;
|
border-radius: 50%;
|
background-color: #ff4d4f;
|
}
|
}
|
|
.message-content {
|
font-size: 28rpx;
|
color: #666;
|
margin-bottom: 20rpx;
|
line-height: 1.5;
|
}
|
|
.message-time {
|
font-size: 24rpx;
|
color: #999;
|
text-align: right;
|
}
|
}
|
}
|
|
.no-data {
|
text-align: center;
|
padding: 100rpx 0;
|
color: #999;
|
|
text {
|
display: block;
|
margin-top: 20rpx;
|
}
|
}
|
}
|
</style>
|