Files
MrleeAdmin/frontend/app/pages/notification/index.vue
T

179 lines
3.7 KiB
Vue
Raw Normal View History

<template>
<view class="notification-page" :class="`theme-${themeMode}`">
<view v-if="loading" class="loading-state">
<u-loading mode="circle" color="#1677ff" size="32" />
<text>正在加载通知</text>
</view>
<view v-else-if="notifications.length === 0" class="empty-state">
<u-empty mode="message" text="暂无生产通知" />
</view>
<view v-else class="notification-list">
<view
v-for="item in notifications"
:key="item.id"
class="notification-card"
:class="{ read: Number(item.status) === 1 }"
@tap="readNotification(item)"
>
<view class="notification-heading">
<view class="notification-title-wrap">
<text v-if="Number(item.status) === 0" class="unread-dot"></text>
<text class="notification-title">{{ item.title }}</text>
</view>
<text class="notification-status">{{ Number(item.status) === 0 ? '未读' : '已读' }}</text>
</view>
<text class="notification-content">{{ item.content }}</text>
<text class="notification-time">{{ item.created_date || '-' }}</text>
</view>
</view>
</view>
</template>
<script>
import { getMemberNotifications, markNotificationRead } from '@/api/produce/notification.js'
export default {
data() {
return {
loading: false,
notifications: []
}
},
onShow() {
this.loadNotifications()
},
methods: {
async loadNotifications() {
this.loading = true
try {
const data = await getMemberNotifications({ page: 1, limit: 50 })
this.notifications = Array.isArray(data?.items) ? data.items : []
} catch (error) {
this.notifications = []
console.error('[app] 获取生产通知失败', error)
} finally {
this.loading = false
}
},
async readNotification(item) {
if (Number(item.status) === 1) {
return
}
try {
await markNotificationRead(item.id)
item.status = 1
item.read_at = Math.floor(Date.now() / 1000)
} catch (error) {
console.error('[app] 标记生产通知已读失败', error)
}
}
}
}
</script>
<style lang="scss" scoped>
.notification-page {
min-height: 100vh;
padding: 24rpx;
box-sizing: border-box;
background: #f4f6fb;
}
.loading-state,
.empty-state {
display: flex;
align-items: center;
justify-content: center;
min-height: 360rpx;
flex-direction: column;
color: #7d8798;
font-size: 22rpx;
}
.loading-state text {
margin-top: 18rpx;
}
.notification-card {
margin-bottom: 18rpx;
padding: 26rpx 24rpx;
border: 1rpx solid rgba(255, 255, 255, 0.72);
border-radius: 24rpx;
background: #ffffff;
box-shadow: 0 12rpx 30rpx rgba(23, 35, 61, 0.06);
}
.notification-card.read {
background: #fafbfc;
opacity: 0.78;
}
.notification-heading,
.notification-title-wrap {
display: flex;
align-items: center;
}
.notification-heading {
justify-content: space-between;
}
.notification-title-wrap {
min-width: 0;
}
.unread-dot {
width: 14rpx;
height: 14rpx;
margin-right: 12rpx;
border-radius: 50%;
background: #e91f3f;
flex-shrink: 0;
}
.notification-title {
overflow: hidden;
color: #17233d;
font-size: 28rpx;
font-weight: 700;
line-height: 1.4;
text-overflow: ellipsis;
white-space: nowrap;
}
.notification-status {
margin-left: 16rpx;
color: #1677ff;
font-size: 20rpx;
line-height: 1.4;
flex-shrink: 0;
}
.notification-card.read .notification-status {
color: #8b8f98;
}
.notification-content,
.notification-time {
display: block;
}
.notification-content {
margin-top: 18rpx;
color: #4d5870;
font-size: 22rpx;
line-height: 1.7;
white-space: pre-line;
}
.notification-time {
margin-top: 18rpx;
color: #98a1b2;
font-size: 20rpx;
line-height: 1.4;
}
</style>