- coupons.vue / notifications.vue 由写死深色改为复用全局 CSS 变量(--bg-primary/--bg-surface/--color-brand-gradient/--text-*/--border-subtle/--nav-bg),随 theme-warm(暖阳晨曦)与默认冷光暗夜自动适配 - 大神工作台新增的服务包表单样式同步复用主题变量 - 新增回归护栏 theme-consistency.spec.ts(97 套件/673 用例全绿)
321 行
7.8 KiB
Vue
321 行
7.8 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>
|
||
/* 颜色全部取自全局主题变量(App.vue 按 theme-warm 覆盖),随主题切换自动适配 */
|
||
.notif-page {
|
||
min-height: 100vh;
|
||
background: var(--bg-primary, #0a0f1d);
|
||
}
|
||
.custom-nav-bar {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 50;
|
||
background: var(--nav-bg, #0a0f1d);
|
||
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: var(--text-primary, #fff);
|
||
font-size: 17px;
|
||
font-weight: 600;
|
||
}
|
||
.nav-action {
|
||
min-width: 56px;
|
||
text-align: right;
|
||
}
|
||
.nav-action-text {
|
||
color: var(--color-brand, #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: var(--bg-surface, #141a30);
|
||
border: 1px solid var(--border-subtle, #1e293b);
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
margin-bottom: 14px;
|
||
}
|
||
.summary-title {
|
||
color: var(--text-primary, #fff);
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
}
|
||
.summary-sub {
|
||
color: var(--text-secondary, #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: var(--text-primary, #e6eaf5);
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
}
|
||
.empty-text {
|
||
color: var(--text-muted, #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: var(--bg-surface, #141a30);
|
||
border: 1px solid var(--border-subtle, #1e293b);
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 10px;
|
||
}
|
||
.notif-card.is-unread {
|
||
background: var(--bg-surface-elevated, #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: var(--text-primary, #fff);
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
}
|
||
.notif-time {
|
||
color: var(--text-muted, #6d7997);
|
||
font-size: 11px;
|
||
flex-shrink: 0;
|
||
}
|
||
.notif-content {
|
||
display: block;
|
||
margin-top: 6px;
|
||
color: var(--text-secondary, #a8b3d1);
|
||
font-size: 12px;
|
||
line-height: 1.6;
|
||
}
|
||
.btn-active:active {
|
||
opacity: 0.75;
|
||
}
|
||
</style>
|