Initial commit
This commit is contained in:
@@ -13,8 +13,11 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.fetchHonors()
|
||||
this.fetchProjects()
|
||||
const app = getApp()
|
||||
if (app.globalData.token) {
|
||||
this.fetchHonors()
|
||||
this.fetchProjects()
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -23,6 +26,12 @@ Page({
|
||||
|
||||
getUserInfo() {
|
||||
const app = getApp()
|
||||
if (!app.globalData.token) {
|
||||
// Not logged in, clear data
|
||||
this.setData({ user: {}, honors: [], projects: [] })
|
||||
return
|
||||
}
|
||||
|
||||
// Try to get from globalData first to speed up rendering
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({ user: app.globalData.userInfo })
|
||||
@@ -36,10 +45,21 @@ Page({
|
||||
// this.fetchProjects();
|
||||
}).catch(err => {
|
||||
console.error('Failed to fetch user info', err)
|
||||
if (err && (err.code === 401 || err.code === 403)) {
|
||||
// Token invalid, clear it
|
||||
app.globalData.token = null;
|
||||
app.globalData.userInfo = null;
|
||||
this.setData({ user: {}, honors: [], projects: [] });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
const app = getApp()
|
||||
if (!app.globalData.token) {
|
||||
wx.stopPullDownRefresh()
|
||||
return
|
||||
}
|
||||
Promise.all([this.fetchHonors(), this.fetchProjects()]).then(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
@@ -12,7 +12,11 @@ Page({
|
||||
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
|
||||
selectedCategory: 'all',
|
||||
showcases: [],
|
||||
categoryStats: {}
|
||||
categoryStats: {},
|
||||
unreadCount: 0
|
||||
},
|
||||
onShow() {
|
||||
this.fetchUnreadCount();
|
||||
},
|
||||
onLoad() {
|
||||
if (wx.getUserProfile) {
|
||||
@@ -30,6 +34,26 @@ Page({
|
||||
this.setData({ selectedCategory: type });
|
||||
this.fetchData(type);
|
||||
},
|
||||
fetchUnreadCount() {
|
||||
// Only fetch if logged in
|
||||
const app = getApp()
|
||||
if (!app.globalData.token) return;
|
||||
|
||||
console.log('Fetching unread count...');
|
||||
const { request } = require('../../utils/request')
|
||||
request({ url: '/notifications/unread_count/' })
|
||||
.then(res => {
|
||||
if (res && typeof res.count === 'number') {
|
||||
this.setData({ unreadCount: res.count })
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Fetch unread count error:', err))
|
||||
},
|
||||
handleNotificationClick() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/message/index'
|
||||
})
|
||||
},
|
||||
fetchBanners() {
|
||||
const { request } = require('../../utils/request')
|
||||
request({ url: '/banners/?is_active=true' })
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
<view class="title-sub">致力成就</view>
|
||||
<view class="title-main">终身教育伟大事业</view>
|
||||
</view>
|
||||
<view class="bell-btn">🔔</view>
|
||||
<view class="bell-btn" bindtap="handleNotificationClick">
|
||||
<image class="notification-icon" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEgMTVhMiAyIDAgMCAxLTIgMkg3bC00IDRWNWEyIDIgMCAwIDEgMi0yaDE0YTIgMiAwIDAgMSAyIDJ6Ij48L3BhdGg+PC9zdmc+" />
|
||||
<view class="badge" wx:if="{{unreadCount > 0}}">{{unreadCount > 99 ? '99+' : unreadCount}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Search Bar -->
|
||||
|
||||
@@ -54,10 +54,9 @@
|
||||
.bell-btn {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(4px);
|
||||
padding: 16rpx;
|
||||
padding: 0;
|
||||
border-radius: 50%;
|
||||
color: var(--text-white);
|
||||
font-size: 32rpx;
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
display: flex;
|
||||
@@ -65,6 +64,25 @@
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.3);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.notification-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
|
||||
.badge {
|
||||
position: absolute;
|
||||
top: -6rpx;
|
||||
right: -6rpx;
|
||||
background-color: #ff4d4f;
|
||||
color: white;
|
||||
font-size: 20rpx;
|
||||
padding: 4rpx 10rpx;
|
||||
border-radius: 20rpx;
|
||||
line-height: 1;
|
||||
border: 2rpx solid #fff;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
|
||||
42
wechat-mini-program/pages/message/index.js
Normal file
42
wechat-mini-program/pages/message/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const app = getApp()
|
||||
const { request } = require('../../utils/request.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
notifications: [],
|
||||
loading: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.fetchNotifications()
|
||||
this.readAllNotifications()
|
||||
},
|
||||
|
||||
fetchNotifications() {
|
||||
this.setData({ loading: true })
|
||||
request({ url: '/notifications/' })
|
||||
.then(res => {
|
||||
// Handle paginated response if any, or direct list
|
||||
const list = Array.isArray(res) ? res : (res.results || [])
|
||||
this.setData({
|
||||
notifications: list,
|
||||
loading: false
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
this.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
|
||||
readAllNotifications() {
|
||||
request({
|
||||
url: '/notifications/read_all/',
|
||||
method: 'POST'
|
||||
})
|
||||
.then(res => {
|
||||
console.log('All read')
|
||||
})
|
||||
.catch(err => console.error(err))
|
||||
}
|
||||
})
|
||||
3
wechat-mini-program/pages/message/index.json
Normal file
3
wechat-mini-program/pages/message/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "消息通知"
|
||||
}
|
||||
16
wechat-mini-program/pages/message/index.wxml
Normal file
16
wechat-mini-program/pages/message/index.wxml
Normal file
@@ -0,0 +1,16 @@
|
||||
<view class="container">
|
||||
<view class="notification-list" wx:if="{{notifications.length > 0}}">
|
||||
<view class="notification-item" wx:for="{{notifications}}" wx:key="id">
|
||||
<view class="notification-header">
|
||||
<text class="title">{{item.title}}</text>
|
||||
<text class="time">{{item.created_at}}</text>
|
||||
</view>
|
||||
<view class="notification-content">
|
||||
{{item.content}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="empty-state" wx:else>
|
||||
<text>暂无消息</text>
|
||||
</view>
|
||||
</view>
|
||||
46
wechat-mini-program/pages/message/index.wxss
Normal file
46
wechat-mini-program/pages/message/index.wxss
Normal file
@@ -0,0 +1,46 @@
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
background-color: #f8f8f8;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.notification-item {
|
||||
background-color: #fff;
|
||||
border-radius: 12rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.notification-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.notification-content {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-top: 200rpx;
|
||||
color: #999;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
<view class="stats-card">
|
||||
<view class="stat-item">
|
||||
<view class="stat-val">{{user.stats.learning}}</view>
|
||||
<view class="stat-label">在学课程</view>
|
||||
<view class="stat-label">课程&活动</view>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<view class="stat-val">{{user.stats.coupons}}</view>
|
||||
|
||||
Reference in New Issue
Block a user