- 新表 user_notifications + 仓储方法(创建/列表/未读数/标记已读) - 用户接口 GET /api/notifications、POST /api/notifications/read(生产需登录) - 关键节点落库:订单开始服务/接单/拒单/申请完成/完成结算/提现到账/报名成功/退款受理 - 小程序新增「消息通知」页(pages/user/notifications) + 个人中心入口与未读角标;api.js 增加 getNotifications/markNotificationsRead - 清理后台伪造数据:/api/user/certification 改空态、/api/user/my-project/list 改空数组、/api/user/info 去掉编造邮箱/电话/网址 - 更新 pages 数量断言(26→27);新增回归护栏 notification-center.spec.ts(92 套件/658 用例全绿);冒烟 9/9
318 行
7.4 KiB
Vue
318 行
7.4 KiB
Vue
<template>
|
|
<view class="notif-page" :class="['theme-' + currentThemeKey]" :style="navStyle">
|
|
<!-- 顶部沉浸式自定义导航栏 -->
|
|
<view class="custom-nav-bar">
|
|
<view class="nav-content">
|
|
<view class="btn-nav-back btn-active" @click="handleBack">
|
|
<image class="nav-back-icon" :src="ICONS.chevronLeft" mode="aspectFit" />
|
|
</view>
|
|
<view class="nav-title-wrap">
|
|
<text class="nav-title">消息通知</text>
|
|
</view>
|
|
<view class="nav-action btn-active" v-if="unreadCount > 0" @click="handleReadAll">
|
|
<text class="nav-action-text">全部已读</text>
|
|
</view>
|
|
<view class="nav-capsule-placeholder" v-else></view>
|
|
</view>
|
|
</view>
|
|
|
|
<scroll-view
|
|
scroll-y
|
|
class="notif-scroll"
|
|
refresher-enabled
|
|
:refresher-triggered="isRefreshing"
|
|
@refresherrefresh="onRefresh"
|
|
>
|
|
<view class="notif-body">
|
|
<view class="notif-summary">
|
|
<text class="summary-title">通知中心</text>
|
|
<text class="summary-sub">{{ unreadCount > 0 ? `你有 ${unreadCount} 条未读通知` : '暂无未读通知,订单/提现/报名进展都会在这里留痕' }}</text>
|
|
</view>
|
|
|
|
<view v-if="isLoading" class="notif-empty">
|
|
<text class="empty-text">加载中…</text>
|
|
</view>
|
|
|
|
<view v-else-if="list.length === 0" class="notif-empty">
|
|
<text class="empty-title">暂无消息</text>
|
|
<text class="empty-text">下单、支付、接单、提现到账等节点,平台都会在此提醒你</text>
|
|
</view>
|
|
|
|
<view v-else class="notif-list">
|
|
<view
|
|
v-for="item in list"
|
|
:key="item.id"
|
|
class="notif-card btn-active"
|
|
:class="{ 'is-unread': !item.isRead }"
|
|
@click="handleOpen(item)"
|
|
>
|
|
<view class="notif-dot" v-if="!item.isRead"></view>
|
|
<view class="notif-main">
|
|
<view class="notif-head">
|
|
<text class="notif-title">{{ item.title }}</text>
|
|
<text class="notif-time">{{ formatTime(item.createdAt) }}</text>
|
|
</view>
|
|
<text class="notif-content">{{ item.content }}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, computed } from 'vue';
|
|
import { onShow } from '@dcloudio/uni-app';
|
|
import { ICONS } from '@/common/icons.js';
|
|
import { getCurrentThemeKey } from '@/common/theme.js';
|
|
import { getNavBarInfo } from '@/common/nav.js';
|
|
import { getNotifications, markNotificationsRead } from '@/common/api.js';
|
|
|
|
const currentThemeKey = ref(getCurrentThemeKey());
|
|
const navInfo = ref(getNavBarInfo());
|
|
const isLoading = ref(true);
|
|
const isRefreshing = ref(false);
|
|
const list = ref([]);
|
|
const unreadCount = ref(0);
|
|
|
|
const navStyle = computed(() => ({
|
|
'--safe-header-gap': `${navInfo.value.totalHeaderHeight}px`,
|
|
'--capsule-right-space': `${navInfo.value.capsuleRightSpace}px`,
|
|
'--capsule-height': `${navInfo.value.capsuleHeight}px`
|
|
}));
|
|
|
|
const currentUserId = () => uni.getStorageSync('userId') || uni.getStorageSync('uid') || 0;
|
|
|
|
const formatTime = (v) => {
|
|
if (!v) return '';
|
|
const s = String(v).replace('T', ' ').replace('Z', '');
|
|
return s.length >= 16 ? s.slice(0, 16) : s;
|
|
};
|
|
|
|
const loadData = async () => {
|
|
const uid = currentUserId();
|
|
if (!uid) {
|
|
isLoading.value = false;
|
|
return;
|
|
}
|
|
try {
|
|
const res = await getNotifications(uid, 50);
|
|
list.value = Array.isArray(res?.list) ? res.list : [];
|
|
unreadCount.value = Number(res?.unread || 0);
|
|
} catch (_) {
|
|
list.value = [];
|
|
unreadCount.value = 0;
|
|
} finally {
|
|
isLoading.value = false;
|
|
isRefreshing.value = false;
|
|
}
|
|
};
|
|
|
|
const onRefresh = () => {
|
|
isRefreshing.value = true;
|
|
loadData();
|
|
};
|
|
|
|
const handleReadAll = async () => {
|
|
const uid = currentUserId();
|
|
if (!uid) return;
|
|
try {
|
|
await markNotificationsRead(uid);
|
|
list.value = list.value.map((x) => ({ ...x, isRead: 1 }));
|
|
unreadCount.value = 0;
|
|
uni.showToast({ title: '已全部标记为已读', icon: 'none' });
|
|
} catch (err) {
|
|
uni.showToast({ title: err.message || '操作失败', icon: 'none' });
|
|
}
|
|
};
|
|
|
|
const handleOpen = async (item) => {
|
|
const uid = currentUserId();
|
|
if (!item.isRead && uid) {
|
|
try {
|
|
await markNotificationsRead(uid, [item.id]);
|
|
item.isRead = 1;
|
|
unreadCount.value = Math.max(0, unreadCount.value - 1);
|
|
} catch (_) {}
|
|
}
|
|
const link = String(item.link || '');
|
|
if (!link) return;
|
|
const tabPages = [
|
|
'/pages/index/index',
|
|
'/pages/activity/list',
|
|
'/pages/order/create',
|
|
'/pages/community/index',
|
|
'/pages/user/index'
|
|
];
|
|
if (tabPages.includes(link)) {
|
|
uni.switchTab({ url: link, fail: () => {} });
|
|
} else {
|
|
uni.navigateTo({ url: link, fail: () => {} });
|
|
}
|
|
};
|
|
|
|
const handleBack = () => {
|
|
const pages = getCurrentPages();
|
|
if (pages && pages.length > 1) {
|
|
uni.navigateBack();
|
|
} else {
|
|
uni.switchTab({ url: '/pages/user/index' });
|
|
}
|
|
};
|
|
|
|
onShow(() => {
|
|
navInfo.value = getNavBarInfo();
|
|
currentThemeKey.value = getCurrentThemeKey();
|
|
loadData();
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.notif-page {
|
|
min-height: 100vh;
|
|
background: #0a0f1d;
|
|
}
|
|
.custom-nav-bar {
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 50;
|
|
background: rgba(10, 15, 29, 0.92);
|
|
padding-top: var(--safe-header-gap, 0);
|
|
}
|
|
.nav-content {
|
|
display: flex;
|
|
align-items: center;
|
|
height: 44px;
|
|
padding: 0 12px;
|
|
}
|
|
.btn-nav-back {
|
|
width: 32px;
|
|
height: 32px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.nav-back-icon {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
.nav-title-wrap {
|
|
flex: 1;
|
|
text-align: center;
|
|
}
|
|
.nav-title {
|
|
color: #fff;
|
|
font-size: 17px;
|
|
font-weight: 600;
|
|
}
|
|
.nav-action {
|
|
min-width: 56px;
|
|
text-align: right;
|
|
}
|
|
.nav-action-text {
|
|
color: #8b9cff;
|
|
font-size: 13px;
|
|
}
|
|
.nav-capsule-placeholder {
|
|
width: 56px;
|
|
}
|
|
.notif-scroll {
|
|
height: calc(100vh - 44px - var(--safe-header-gap, 0px));
|
|
}
|
|
.notif-body {
|
|
padding: 12px 16px 40px;
|
|
}
|
|
.notif-summary {
|
|
padding: 16px;
|
|
border-radius: 16px;
|
|
background: linear-gradient(135deg, #1b2340 0%, #141a30 100%);
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6px;
|
|
margin-bottom: 14px;
|
|
}
|
|
.summary-title {
|
|
color: #fff;
|
|
font-size: 16px;
|
|
font-weight: 700;
|
|
}
|
|
.summary-sub {
|
|
color: #9aa7c7;
|
|
font-size: 12px;
|
|
line-height: 1.5;
|
|
}
|
|
.notif-empty {
|
|
padding: 48px 16px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.empty-title {
|
|
color: #e6eaf5;
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
}
|
|
.empty-text {
|
|
color: #7d89a8;
|
|
font-size: 12px;
|
|
text-align: center;
|
|
line-height: 1.6;
|
|
}
|
|
.notif-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
.notif-card {
|
|
position: relative;
|
|
padding: 14px 14px 14px 18px;
|
|
border-radius: 14px;
|
|
background: #141a30;
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 10px;
|
|
}
|
|
.notif-card.is-unread {
|
|
background: #182143;
|
|
}
|
|
.notif-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: #ff5f57;
|
|
margin-top: 6px;
|
|
}
|
|
.notif-main {
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
.notif-head {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.notif-title {
|
|
color: #fff;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
}
|
|
.notif-time {
|
|
color: #6d7997;
|
|
font-size: 11px;
|
|
flex-shrink: 0;
|
|
}
|
|
.notif-content {
|
|
display: block;
|
|
margin-top: 6px;
|
|
color: #a8b3d1;
|
|
font-size: 12px;
|
|
line-height: 1.6;
|
|
}
|
|
.btn-active:active {
|
|
opacity: 0.75;
|
|
}
|
|
</style>
|