Initial Commit

This commit is contained in:
Rajuahamedkst 2025-09-12 16:08:17 +08:00
commit 1d71a02738
237 changed files with 64293 additions and 0 deletions

View file

@ -0,0 +1,248 @@
// 好友请求管理页面
const app = getApp();
const friendAPI = require('../../../utils/friend-api.js');
Page({
data: {
// 请求列表
friendRequests: [],
pendingRequests: [],
processedRequests: [],
loading: true,
refreshing: false,
// 统计
pendingCount: 0,
processedCount: 0,
// 系统信息
statusBarHeight: 0,
navBarHeight: 0,
// 标签页
activeTab: 'pending', // pending, processed
tabs: [
{ key: 'pending', label: '待处理', count: 0 },
{ key: 'processed', label: '已处理', count: 0 }
]
},
onLoad(options) {
console.log('好友请求页面加载');
this.initSystemInfo();
this.loadFriendRequests();
},
onShow() {
// 刷新数据
this.loadFriendRequests();
},
// 初始化系统信息
initSystemInfo() {
const systemInfo = wx.getSystemInfoSync();
const menuButton = wx.getMenuButtonBoundingClientRect();
this.setData({
statusBarHeight: systemInfo.statusBarHeight,
navBarHeight: menuButton.bottom + 10
});
},
// 返回上一页
goBack() {
wx.navigateBack();
},
// 加载好友请求
async loadFriendRequests() {
try {
this.setData({ loading: true });
const response = await friendAPI.getFriendRequests();
// 从API响应中提取数据数组
const requests = response.data || [];
// 分类请求
const pendingRequests = requests.filter(req => req.status === 0);
const processedRequests = requests.filter(req => req.status !== 0);
// 更新标签页计数
const updatedTabs = this.data.tabs.map(tab => ({
...tab,
count: tab.key === 'pending' ? pendingRequests.length : processedRequests.length
}));
this.setData({
friendRequests: requests,
pendingRequests: pendingRequests,
processedRequests: processedRequests,
pendingCount: pendingRequests.length,
processedCount: processedRequests.length,
tabs: updatedTabs,
loading: false,
refreshing: false
});
} catch (error) {
console.error('加载好友请求失败:', error);
this.setData({
loading: false,
refreshing: false
});
wx.showToast({
title: '加载失败',
icon: 'none'
});
}
},
// 下拉刷新
onRefresh() {
this.setData({ refreshing: true });
this.loadFriendRequests();
// 刷新后也通知好友页面更新数量
setTimeout(() => {
this.notifyFriendsPageRefresh();
}, 500); // 延迟一点确保数据加载完成
},
// 切换标签页
switchTab(e) {
const tab = e.currentTarget.dataset.tab;
this.setData({
activeTab: tab
});
console.log('切换到标签页:', tab);
console.log('待处理请求数量:', this.data.pendingRequests?.length || 0);
console.log('已处理请求数量:', this.data.processedRequests?.length || 0);
},
// 获取当前标签页的请求列表
getCurrentRequests() {
const { friendRequests, activeTab } = this.data;
if (activeTab === 'pending') {
return friendRequests.filter(req => req.status === 0);
} else {
return friendRequests.filter(req => req.status !== 0);
}
},
// 处理好友请求
async handleRequest(e) {
const { requestId, accept } = e.currentTarget.dataset;
const actionText = accept === 'true' ? '接受' : '拒绝';
try {
wx.showLoading({ title: `${actionText}中...` });
await friendAPI.handleFriendRequest(requestId, accept === 'true');
wx.hideLoading();
wx.showToast({
title: `${actionText}`,
icon: 'success'
});
// 刷新列表
this.loadFriendRequests();
// 通知好友页面刷新请求数量
this.notifyFriendsPageRefresh();
} catch (error) {
wx.hideLoading();
console.error('处理好友请求失败:', error);
wx.showToast({
title: error.message || `${actionText}失败`,
icon: 'none'
});
}
},
// 查看用户详情
viewUserDetail(e) {
const { customId } = e.currentTarget.dataset;
wx.navigateTo({
url: `/pages/social/user-detail/user-detail?customId=${customId}`
});
},
// 通知好友页面刷新
notifyFriendsPageRefresh() {
try {
// 通过全局事件通知好友页面刷新
const app = getApp();
if (app.globalData) {
app.globalData.needRefreshFriendRequests = true;
}
// 也可以通过页面栈找到好友页面并直接调用刷新方法
const pages = getCurrentPages();
const friendsPage = pages.find(page => page.route === 'pages/social/friends/friends');
if (friendsPage && friendsPage.loadFriendRequestsCount) {
friendsPage.loadFriendRequestsCount();
}
console.log('✅ 已通知好友页面刷新请求数量');
} catch (error) {
console.error('❌ 通知好友页面失败:', error);
}
},
// 发送消息
sendMessage(e) {
const { customId, nickname } = e.currentTarget.dataset;
wx.navigateTo({
url: `/pages/message/chat/chat?targetId=${customId}&name=${encodeURIComponent(nickname)}&chatType=0`
});
},
// 格式化时间
formatTime(timeStr) {
const time = new Date(timeStr);
const now = new Date();
const diff = now - time;
const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
const week = 7 * day;
if (diff < minute) {
return '刚刚';
} else if (diff < hour) {
return `${Math.floor(diff / minute)}分钟前`;
} else if (diff < day) {
return `${Math.floor(diff / hour)}小时前`;
} else if (diff < week) {
return `${Math.floor(diff / day)}天前`;
} else {
return time.toLocaleDateString();
}
},
// 获取状态文本
getStatusText(status) {
switch (status) {
case 0: return '待处理';
case 1: return '已接受';
case 2: return '已拒绝';
default: return '未知';
}
},
// 获取状态样式类
getStatusClass(status) {
switch (status) {
case 0: return 'pending';
case 1: return 'accepted';
case 2: return 'rejected';
default: return 'unknown';
}
}
});

View file

@ -0,0 +1,190 @@
<!-- 好友请求管理页面 -->
<view class="requests-container">
<!-- 自定义导航栏 -->
<view class="custom-nav-bar" style="padding-top: {{statusBarHeight}}px; height: {{navBarHeight}}px;">
<view class="nav-content">
<view class="nav-left" bindtap="goBack">
<text class="back-icon">←</text>
</view>
<view class="nav-center">
<text class="nav-title">好友请求</text>
</view>
<view class="nav-right"></view>
</view>
</view>
<!-- 标签页 -->
<view class="tabs-container">
<view class="tab-item {{activeTab === item.key ? 'active' : ''}}"
wx:for="{{tabs}}"
wx:key="key"
bindtap="switchTab"
data-tab="{{item.key}}">
<text class="tab-text">{{item.label}}</text>
<view class="tab-badge" wx:if="{{item.count > 0}}">
<text class="badge-text">{{item.count > 99 ? '99+' : item.count}}</text>
</view>
</view>
</view>
<!-- 内容区域 -->
<scroll-view class="content-container"
scroll-y="true"
refresher-enabled="true"
refresher-triggered="{{refreshing}}"
bindrefresherrefresh="onRefresh">
<!-- 加载中 -->
<view class="loading-container" wx:if="{{loading}}">
<view class="loading-spinner"></view>
<text class="loading-text">加载中...</text>
</view>
<!-- 空状态 -->
<view class="empty-container" wx:if="{{!loading && (activeTab === 'pending' ? pendingRequests.length === 0 : processedRequests.length === 0)}}">
<view class="empty-icon">
<text class="icon-text">{{activeTab === 'pending' ? '📭' : '📋'}}</text>
</view>
<text class="empty-title">{{activeTab === 'pending' ? '暂无待处理请求' : '暂无已处理记录'}}</text>
<text class="empty-desc">{{activeTab === 'pending' ? '当有人向您发送好友请求时,会在这里显示' : '您处理过的好友请求会在这里显示'}}</text>
</view>
<!-- 请求列表 -->
<view class="requests-list" wx:if="{{!loading && (activeTab === 'pending' ? pendingRequests.length > 0 : processedRequests.length > 0)}}">
<view class="request-item"
wx:for="{{activeTab === 'pending' ? pendingRequests : processedRequests}}"
wx:key="requestId">
<!-- 用户信息 -->
<view class="user-section" bindtap="viewUserDetail" data-custom-id="{{item.senderCustomId}}">
<!-- 头像 -->
<view class="user-avatar">
<image wx:if="{{item.senderAvatar}}"
src="{{item.senderAvatar}}"
class="avatar-image"
mode="aspectFill" />
<view wx:else class="avatar-placeholder">
<text class="avatar-text">{{item.senderNickname ? item.senderNickname.charAt(0) : '?'}}</text>
</view>
</view>
<!-- 用户详情 -->
<view class="user-info">
<view class="user-name">
<text class="nickname">{{item.senderNickname}}</text>
<view class="status-badge {{getStatusClass(item.status)}}" wx:if="{{activeTab === 'processed'}}">
<text class="status-text">{{getStatusText(item.status)}}</text>
</view>
</view>
<text class="user-id">ID: {{item.senderCustomId}}</text>
<view class="request-message" wx:if="{{item.message}}">
<text class="message-text">{{item.message}}</text>
</view>
<view class="time-info">
<text class="time-text">{{formatTime(item.createdAt)}}</text>
<text class="handle-time" wx:if="{{item.handleTime}}">处理时间: {{formatTime(item.handleTime)}}</text>
</view>
</view>
</view>
<!-- 操作按钮 -->
<view class="action-section" wx:if="{{item.status === 0}}">
<view class="action-buttons">
<view class="action-btn reject-btn"
bindtap="handleRequest"
data-request-id="{{item.requestId}}"
data-accept="false">
<text class="btn-text">拒绝</text>
</view>
<view class="action-btn accept-btn"
bindtap="handleRequest"
data-request-id="{{item.requestId}}"
data-accept="true">
<text class="btn-text">接受</text>
</view>
</view>
</view>
<!-- 已处理状态的操作 -->
<view class="processed-actions" wx:if="{{item.status === 1}}">
<view class="message-btn"
bindtap="sendMessage"
data-custom-id="{{item.senderCustomId}}"
data-nickname="{{item.senderNickname}}">
<text class="message-btn-text">发消息</text>
</view>
</view>
</view>
</view>
<!-- 底部安全区域 -->
<view class="safe-area-bottom"></view>
</scroll-view>
</view>
<wxs module="utils">
var getCurrentRequests = function(friendRequests, activeTab) {
if (!friendRequests || !friendRequests.length) return [];
if (activeTab === 'pending') {
return friendRequests.filter(function(req) {
return req.status === 0;
});
} else {
return friendRequests.filter(function(req) {
return req.status !== 0;
});
}
};
var formatTime = function(timeStr) {
if (!timeStr) return '';
var time = getDate(timeStr);
var now = getDate();
var diff = now.getTime() - time.getTime();
var minute = 60 * 1000;
var hour = 60 * minute;
var day = 24 * hour;
var week = 7 * day;
if (diff < minute) {
return '刚刚';
} else if (diff < hour) {
return Math.floor(diff / minute) + '分钟前';
} else if (diff < day) {
return Math.floor(diff / hour) + '小时前';
} else if (diff < week) {
return Math.floor(diff / day) + '天前';
} else {
return time.toLocaleDateString();
}
};
var getStatusText = function(status) {
if (status === 0) return '待处理';
if (status === 1) return '已接受';
if (status === 2) return '已拒绝';
return '未知';
};
var getStatusClass = function(status) {
if (status === 0) return 'pending';
if (status === 1) return 'accepted';
if (status === 2) return 'rejected';
return 'unknown';
};
module.exports = {
getCurrentRequests: getCurrentRequests,
formatTime: formatTime,
getStatusText: getStatusText,
getStatusClass: getStatusClass
};
</wxs>

View file

@ -0,0 +1,353 @@
/* 好友请求管理页面样式 */
.requests-container {
height: 100vh;
background-color: #f8f9fa;
display: flex;
flex-direction: column;
}
/* 自定义导航栏 */
.custom-nav-bar {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1000;
}
.nav-content {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
height: 88rpx;
}
.nav-left {
width: 80rpx;
display: flex;
align-items: center;
}
.back-icon {
font-size: 40rpx;
color: white;
font-weight: bold;
}
.nav-center {
flex: 1;
text-align: center;
}
.nav-title {
font-size: 36rpx;
font-weight: 600;
color: white;
}
.nav-right {
width: 80rpx;
}
/* 标签页 */
.tabs-container {
margin-top: 176rpx;
background: white;
display: flex;
border-bottom: 1px solid #f0f0f0;
}
.tab-item {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 32rpx 0;
position: relative;
gap: 16rpx;
}
.tab-item.active {
border-bottom: 4rpx solid #667eea;
}
.tab-text {
font-size: 32rpx;
color: #666;
font-weight: 500;
}
.tab-item.active .tab-text {
color: #667eea;
font-weight: 600;
}
.tab-badge {
background: #ff4757;
border-radius: 20rpx;
padding: 4rpx 12rpx;
min-width: 32rpx;
height: 32rpx;
display: flex;
align-items: center;
justify-content: center;
}
.badge-text {
font-size: 20rpx;
color: white;
font-weight: 600;
}
/* 内容区域 */
.content-container {
flex: 1;
padding: 0 32rpx;
}
/* 加载中 */
.loading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 0;
}
.loading-spinner {
width: 60rpx;
height: 60rpx;
border: 4rpx solid #f3f3f3;
border-top: 4rpx solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 24rpx;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loading-text {
font-size: 28rpx;
color: #999;
}
/* 空状态 */
.empty-container {
display: flex;
flex-direction: column;
align-items: center;
padding: 120rpx 0;
text-align: center;
}
.empty-icon {
font-size: 120rpx;
margin-bottom: 32rpx;
opacity: 0.6;
}
.empty-title {
font-size: 36rpx;
font-weight: 600;
color: #333;
margin-bottom: 16rpx;
}
.empty-desc {
font-size: 28rpx;
color: #666;
line-height: 1.5;
}
/* 请求列表 */
.requests-list {
padding: 32rpx 0;
}
.request-item {
background: white;
border-radius: 24rpx;
padding: 32rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
/* 用户信息区域 */
.user-section {
display: flex;
align-items: flex-start;
margin-bottom: 24rpx;
}
.user-avatar {
margin-right: 24rpx;
}
.avatar-image {
width: 96rpx;
height: 96rpx;
border-radius: 48rpx;
}
.avatar-placeholder {
width: 96rpx;
height: 96rpx;
border-radius: 48rpx;
background: #e0e0e0;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-text {
font-size: 36rpx;
font-weight: 600;
color: #666;
}
.user-info {
flex: 1;
}
.user-name {
display: flex;
align-items: center;
margin-bottom: 8rpx;
gap: 16rpx;
}
.nickname {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.status-badge {
padding: 4rpx 12rpx;
border-radius: 12rpx;
font-size: 22rpx;
}
.status-badge.pending {
background: #fff3e0;
color: #ff9800;
}
.status-badge.accepted {
background: #e8f5e8;
color: #4caf50;
}
.status-badge.rejected {
background: #ffebee;
color: #f44336;
}
.status-text {
font-weight: 600;
}
.user-id {
font-size: 24rpx;
color: #999;
margin-bottom: 16rpx;
}
.request-message {
background: #f8f9fa;
border-radius: 12rpx;
padding: 16rpx;
margin-bottom: 16rpx;
}
.message-text {
font-size: 28rpx;
color: #333;
line-height: 1.4;
}
.time-info {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.time-text {
font-size: 24rpx;
color: #999;
}
.handle-time {
font-size: 22rpx;
color: #ccc;
}
/* 操作按钮区域 */
.action-section {
border-top: 1px solid #f0f0f0;
padding-top: 24rpx;
}
.action-buttons {
display: flex;
gap: 24rpx;
}
.action-btn {
flex: 1;
padding: 20rpx 0;
border-radius: 50rpx;
text-align: center;
font-weight: 600;
}
.reject-btn {
background: #f8f9fa;
border: 2rpx solid #e0e0e0;
}
.reject-btn .btn-text {
color: #666;
font-size: 28rpx;
}
.accept-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.accept-btn .btn-text {
color: white;
font-size: 28rpx;
}
/* 已处理状态的操作 */
.processed-actions {
border-top: 1px solid #f0f0f0;
padding-top: 24rpx;
display: flex;
justify-content: flex-end;
}
.message-btn {
background: #e3f2fd;
border: 2rpx solid #2196f3;
border-radius: 50rpx;
padding: 16rpx 32rpx;
}
.message-btn-text {
color: #2196f3;
font-size: 26rpx;
font-weight: 600;
}
/* 底部安全区域 */
.safe-area-bottom {
height: 60rpx;
}