wlzboy
2025-10-25 a5b842f1f6ab32f1af39f4bcb7e45217e94db761
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
<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: []
      }
    },
    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>