文件
fenleixinxi/uniapp/pages/message/index.vue
MiAn d508949921 feat: 规范化页面导航与交互体验,优化多端适配
- 统一定制顶部导航组件,支持沉浸式渐变主题与返回逻辑
- 适配 H5 环境的页面跳转逻辑,避免 reLaunch 导致的闪屏问题
- 重构会员、充值、发布等页面布局,改用 Grid 提升移动端适配
- 优化搜索、收藏、消息等页面交互细节,增加点击反馈
- 统一配置页面导航样式,替换原生导航为自定义组件
2026-10-20 13:56:05 +08:00

248 行
5.3 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="msg fc-page">
<!-- 规范化顶部导航:与首页、分类、我的统一沉浸式渐变顶栏 -->
<fc-navbar title="通知中心" theme="gradient" />
<!-- 分类 tab -->
<view class="msg__tabs">
<view
v-for="t in tabs"
:key="t.value"
class="msg__tab"
:class="{ 'msg__tab--active': type === t.value }"
@click="changeType(t.value)"
>
<text class="msg__tab-label">{{ t.label }}</text>
<view v-if="type === t.value" class="msg__tab-line"></view>
</view>
</view>
<fc-empty v-if="!loading && !list.length" icon="inbox" text="暂无通知" />
<view v-else class="msg__list">
<view
v-for="m in list"
:key="m.id"
class="msg__item"
:class="{ 'msg__item--unread': !m.read }"
@click="openMsg(m)"
>
<view class="msg__icon">
<image class="fc-icon--badge-sm" :src="iconUrl(meta(m.type).iconKey)" mode="aspectFit" />
</view>
<view class="msg__body">
<view class="msg__head">
<text class="msg__title fc-ellipsis">{{ m.title }}</text>
<text class="msg__time">{{ timeText(m.createdAt) }}</text>
</view>
<text class="msg__content fc-ellipsis-2">{{ m.content }}</text>
</view>
<view v-if="!m.read" class="msg__dot"></view>
</view>
</view>
<!-- 底部 Tabbar 占位 -->
<view class="msg__tabbar-space"></view>
<fc-tabbar :current="3" />
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import FcTabbar from '@/components/fc-tabbar/fc-tabbar.vue'
import messageApi from '@/common/api/message.js'
import { MESSAGE_TYPE } from '@/common/constants/ui.js'
import { fromNow } from '@/common/utils/format.js'
import { iconUrl } from '@/common/store/ui.js'
export default {
components: { FcNavbar, FcEmpty, FcTabbar },
data() {
return {
type: 'system',
list: [],
loading: false,
tabs: [
{ label: '系统通知', value: 'system' },
{ label: '互动提醒', value: 'interact' },
],
}
},
onLoad() {
this.fetch()
},
methods: {
/** 暴露给模板:获取图标完整地址 */
iconUrl,
/**
* 获取指定通知类型的元信息
* @param {string} t 通知类型 system|interact
* @returns {Object} 包含 iconKey 与标题配置的对象
*/
meta(t) {
return MESSAGE_TYPE[t] || MESSAGE_TYPE.system
},
/**
* 格式化相对时间文本
* @param {string|number} t 时间戳或日期字符串
* @returns {string} 相对时间文本,如“刚刚”、“5分钟前”
*/
timeText(t) {
return fromNow(t)
},
/**
* 拉取当前类型的通知列表
*/
async fetch() {
this.loading = true
try {
const res = await messageApi.list({ type: this.type, page: 1, size: 20 })
this.list = res.list || []
} catch (e) {
uni.showToast({ title: '通知加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
/**
* 切换通知频道
* @param {string} v 频道类型值 system|interact
*/
changeType(v) {
if (this.type === v) return
this.type = v
this.fetch()
},
/**
* 点击查看通知详情并标记已读
* @param {Object} m 通知项对象
*/
async openMsg(m) {
if (!m.read) {
m.read = true
try {
await messageApi.read(m.id)
} catch (e) {}
}
uni.showModal({
title: m.title || '通知详情',
content: m.content || '',
showCancel: false,
confirmText: '我知道了',
confirmColor: '#04874a',
})
},
},
}
</script>
<style lang="scss" scoped>
.msg__tabs {
display: flex;
background: #ffffff;
padding: 0 32rpx;
border-bottom: 2rpx solid $fc-border;
box-shadow: $fc-shadow-sm;
position: sticky;
top: 0;
z-index: 10;
}
.msg__tab {
flex: 1;
height: 88rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: $fc-font;
color: $fc-text-secondary;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
&--active {
color: $fc-primary-text;
font-weight: 700;
}
}
.msg__tab-line {
position: absolute;
bottom: 0;
width: 56rpx;
height: 6rpx;
border-radius: 4rpx;
background: $fc-gradient-primary;
}
.msg__list {
padding: 20rpx 0;
}
.msg__item {
position: relative;
margin: 0 24rpx 20rpx;
padding: 24rpx;
background: #ffffff;
border-radius: $fc-radius-lg;
display: flex;
box-shadow: $fc-shadow-sm;
border: 1rpx solid rgba(4, 48, 30, 0.05);
cursor: pointer;
transition: all 0.2s ease;
&:active {
transform: scale(0.985);
}
&--unread {
background: #f7fffb;
border-left: 6rpx solid $fc-primary;
}
}
.msg__icon {
width: 80rpx;
height: 80rpx;
flex: 0 0 80rpx;
display: flex;
align-items: center;
justify-content: center;
}
.msg__body {
flex: 1;
margin-left: 20rpx;
min-width: 0;
}
.msg__head {
display: flex;
align-items: center;
justify-content: space-between;
}
.msg__title {
font-size: 30rpx;
font-weight: 600;
color: $fc-text;
margin-right: 16rpx;
}
.msg__time {
font-size: 22rpx;
color: $fc-text-placeholder;
white-space: nowrap;
}
.msg__content {
display: block;
margin-top: 10rpx;
font-size: 26rpx;
color: $fc-text-regular;
line-height: 1.5;
}
.msg__dot {
position: absolute;
top: 24rpx;
right: 24rpx;
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: $fc-primary;
box-shadow: 0 0 8rpx rgba(0, 224, 112, 0.6);
}
.msg__tabbar-space {
height: 140rpx;
}
</style>