文件
NHCshopro/pages/index/message.vue
可乐加冰 9d2488a631 chore: 纳入小程序完整源码
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 20:25:01 +08:00

294 行
5.5 KiB
Vue

<template>
<view>
<view class="container">
<view class="header">
<view class="header-title">消息中心</view>
<view class="unread-count" v-if="noMessageNum > 0">
{{noMessageNum}}条未读
</view>
</view>
<view class="filter-tabs">
<view class="filter-tab" :class="{active: currentFilter === 'all'}" @click="changeFilter('all')">
全部消息
</view>
<view class="filter-tab" :class="{active: currentFilter === 'unread'}" @click="changeFilter('unread')">
未读消息
</view>
<view class="filter-tab" :class="{active: currentFilter === 'read'}" @click="changeFilter('read')">
已读消息
</view>
</view>
<view class="message-list">
<view class="message-item" :class="{unread: message.read == 2}" v-for="message in messages"
:key="message.id">
<view class="message-header">
<view class="message-title">系统消息</view>
<view class="message-time">{{message.create_time}}</view>
</view>
<view class="message-content">
{{message.content}}
</view>
<view class="message-footer">
<view class="message-status">
<view class="status-dot" :class="message.status == 1 ? 'read' : 'unread'"></view>
<text class="status-text">{{message.status == 1 ? '已读' : '未读'}}</text>
</view>
<view v-if="message.status == 2" class="expand-btn" @click.stop="handleMessage(message)">
确认已阅
</view>
</view>
</view>
<view class="empty-state" v-if="messages.length === 0">
<view class="empty-icon">📭</view>
<view class="empty-text">暂无消息</view>
</view>
</view>
</view>
<shopro-tabbar></shopro-tabbar>
</view>
</template>
<script>
export default {
data() {
return {
currentFilter: 'all',
page: 1,
loadState: 'loadmore',
noMessageNum: 0,
messages: [],
status: 0
}
},
onLoad() {
this.getMessageList();
},
onReachBottom() {
if (this.loadState == 'nomore') return
this.page += 1
this.getMessageList();
},
computed: {},
methods: {
handleMessage(item) {
this.$http('common.readMessage', {
id: item.id,
}).then(res => {
item.status = 1;
});
},
getMessageList() {
uni.showLoading();
this.$http('common.messageList', {
page: this.page,
status: this.status
}).then(res => {
uni.hideLoading();
if (res.data && res.data.list.length > 0) {
this.messages = this.messages.concat(res.data.list);
this.noMessageNum = res.data.noMessageNum;
} else {
this.loadState = 'nomore'
}
})
},
changeFilter(filter) {
this.currentFilter = filter;
switch (filter) {
case 'all':
this.status = 0;
break;
case 'unread':
this.status = 2;
break;
case 'read':
this.status = 1;
break;
}
this.messages = [];
this.page = 1;
this.getMessageList();
},
}
}
</script>
<style lang="scss">
.container {
width: 750rpx;
margin: 0 auto;
padding: 30rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 30rpx 0;
margin-bottom: 20rpx;
border-bottom: 1rpx solid #eee;
}
.header-title {
font-size: 40rpx;
font-weight: 600;
color: #333;
}
.unread-count {
background-color: #FF3B30;
color: white;
padding: 8rpx 16rpx;
border-radius: 20rpx;
font-size: 24rpx;
}
.filter-tabs {
display: flex;
margin-bottom: 30rpx;
background: white;
border-radius: 16rpx;
overflow: hidden;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
.filter-tab {
flex: 1;
text-align: center;
padding: 24rpx 0;
font-size: 28rpx;
color: #666;
transition: all 0.3s;
}
.filter-tab.active {
color: #ff4544;
font-weight: bold;
background-color: rgba(255, 69, 68, 0.05);
font-weight: 500;
}
.message-list {
margin-bottom: 40rpx;
}
.message-item {
background: white;
border-radius: 16rpx;
padding: 30rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
transition: all 0.3s;
}
.message-item.unread {
border-left: 6rpx solid #ff4544;
}
.message-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 16rpx;
}
.message-title {
font-weight: 500;
font-size: 32rpx;
color: #333;
flex: 1;
margin-right: 20rpx;
}
.message-time {
font-size: 24rpx;
color: #999;
white-space: nowrap;
}
.message-content {
font-size: 28rpx;
color: #666;
line-height: 1.5;
overflow: hidden;
transition: all 0.3s;
}
.message-content.collapsed {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.message-footer {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 24rpx;
padding-top: 16rpx;
border-top: 1rpx solid #f0f0f0;
}
.message-status {
display: flex;
align-items: center;
}
.status-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
margin-right: 12rpx;
}
.status-dot.unread {
background-color: #ff4544;
}
.status-dot.read {
background-color: #999;
}
.status-text {
font-size: 24rpx;
color: #999;
}
.expand-btn {
font-size: 24rpx;
color: #ff4544;
background: none;
border: none;
outline: none;
}
.empty-state {
text-align: center;
padding: 80rpx 40rpx;
color: #999;
}
.empty-icon {
font-size: 96rpx;
margin-bottom: 30rpx;
opacity: 0.5;
}
.empty-text {
font-size: 28rpx;
}
</style>