Initial commit
This commit is contained in:
1
miniprogram/pages/notifications/notifications.json
Normal file
1
miniprogram/pages/notifications/notifications.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "navigationStyle": "custom", "usingComponents": {} }
|
||||
36
miniprogram/pages/notifications/notifications.ts
Normal file
36
miniprogram/pages/notifications/notifications.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { getAvatarGradient, formatTime } from '../../utils/format'
|
||||
|
||||
Page({
|
||||
data: { statusBarHeight: 0, list: [] as any[] },
|
||||
|
||||
onLoad() {
|
||||
const info = wx.getSystemInfoSync()
|
||||
this.setData({ statusBarHeight: info.statusBarHeight })
|
||||
this.loadNotifications()
|
||||
},
|
||||
|
||||
async loadNotifications() {
|
||||
try {
|
||||
const res = await wx.cloud.callFunction({ name: 'getNotifications', data: {} }) as any
|
||||
const list = (res.result?.data || []).map((n: any) => ({
|
||||
...n,
|
||||
gradient: getAvatarGradient(n.fromId || ''),
|
||||
timeText: formatTime(n.createdAt),
|
||||
}))
|
||||
this.setData({ list })
|
||||
} catch {}
|
||||
},
|
||||
|
||||
onItemTap(e: WechatMiniprogram.CustomEvent) {
|
||||
const item = e.currentTarget.dataset.item as any
|
||||
if (item?.postId) wx.navigateTo({ url: `/pages/post-detail/post-detail?id=${item.postId}` })
|
||||
},
|
||||
|
||||
onReadAll() {
|
||||
wx.cloud.callFunction({ name: 'markAllRead', data: {} }).catch(() => {})
|
||||
const list = this.data.list.map((n: any) => ({ ...n, isRead: true }))
|
||||
this.setData({ list })
|
||||
},
|
||||
|
||||
onBack() { wx.navigateBack() },
|
||||
})
|
||||
23
miniprogram/pages/notifications/notifications.wxml
Normal file
23
miniprogram/pages/notifications/notifications.wxml
Normal file
@@ -0,0 +1,23 @@
|
||||
<view class="page">
|
||||
<view class="safe-top" style="height: {{statusBarHeight}}px"></view>
|
||||
<view class="nav">
|
||||
<view class="nav-back" bindtap="onBack">‹</view>
|
||||
<view class="nav-title">消息通知</view>
|
||||
<view class="nav-right" bindtap="onReadAll">全部已读</view>
|
||||
</view>
|
||||
<scroll-view scroll-y="true" enhanced="true" show-scrollbar="false">
|
||||
<view wx:if="{{list.length === 0}}" class="empty">
|
||||
<text class="empty-emoji">🔔</text>
|
||||
<text class="empty-tip">暂时没有新消息</text>
|
||||
</view>
|
||||
<view wx:for="{{list}}" wx:key="_id" class="notify-item {{item.isRead ? '' : 'unread'}}" bindtap="onItemTap" data-item="{{item}}">
|
||||
<view class="n-avatar" style="background: {{item.gradient}}">{{item.fromNick[0]}}</view>
|
||||
<view class="n-body">
|
||||
<text class="n-text">{{item.fromNick}} {{item.action}}了你的{{item.target}}</text>
|
||||
<text class="n-time">{{item.timeText}}</text>
|
||||
</view>
|
||||
<view wx:if="{{!item.isRead}}" class="unread-dot"></view>
|
||||
</view>
|
||||
<view style="height: 60rpx;"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
15
miniprogram/pages/notifications/notifications.wxss
Normal file
15
miniprogram/pages/notifications/notifications.wxss
Normal file
@@ -0,0 +1,15 @@
|
||||
.page { min-height: 100vh; background: linear-gradient(180deg, #fff8f2 0%, #f5f0ff 100%); }
|
||||
.nav { display: flex; align-items: center; padding: 14rpx 28rpx; gap: 16rpx; }
|
||||
.nav-back { font-size: 60rpx; color: #272235; font-weight: 300; line-height: 1; }
|
||||
.nav-title { flex: 1; font-size: 32rpx; font-weight: 900; color: #272235; text-align: center; }
|
||||
.nav-right { font-size: 26rpx; color: #9b8fa8; }
|
||||
.empty { display: flex; flex-direction: column; align-items: center; padding: 120rpx 60rpx; gap: 20rpx; }
|
||||
.empty-emoji { font-size: 80rpx; }
|
||||
.empty-tip { font-size: 28rpx; color: #9b8fa8; }
|
||||
.notify-item { display: flex; align-items: center; gap: 20rpx; padding: 22rpx 28rpx; background: rgba(255,255,255,0.80); border-bottom: 1rpx solid rgba(43,37,61,0.05); }
|
||||
.notify-item.unread { background: rgba(255,229,240,0.40); }
|
||||
.n-avatar { width: 80rpx; height: 80rpx; border-radius: 26rpx; display: flex; align-items: center; justify-content: center; font-size: 34rpx; font-weight: 800; color: rgba(39,34,53,0.72); flex-shrink: 0; }
|
||||
.n-body { flex: 1; }
|
||||
.n-text { display: block; font-size: 28rpx; color: #272235; line-height: 1.5; }
|
||||
.n-time { display: block; font-size: 22rpx; color: #9b8fa8; margin-top: 6rpx; }
|
||||
.unread-dot { width: 14rpx; height: 14rpx; border-radius: 50%; background: #ff4f91; flex-shrink: 0; }
|
||||
Reference in New Issue
Block a user