添加 消息 页面更新

This commit is contained in:
张成
2025-10-01 00:36:51 +08:00
parent dd26282540
commit 78d8ec659e
22 changed files with 1450 additions and 292 deletions

View File

@@ -0,0 +1,4 @@
export default definePageConfig({
navigationStyle: "custom",
navigationBarTitleText: "新增关注",
});

View File

@@ -0,0 +1,199 @@
@use '~@/scss/images.scss' as img;
.new-follow-container {
width: 100%;
height: 100vh;
box-sizing: border-box;
display: flex;
flex-direction: column;
background: #FFFFFF;
// 顶部导航栏
.navbar {
height: 100px;
background: #FFFFFF;
position: sticky;
top: 0;
z-index: 100;
.navbar-content {
height: 56px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 15px;
margin-top: 44px;
position: relative;
.back-button {
position: absolute;
left: 10px;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
.back-icon {
width: 8px;
height: 16px;
position: relative;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 8px;
height: 8px;
border-left: 2.67px solid #000000;
border-bottom: 2.67px solid #000000;
transform: rotate(45deg);
}
}
}
.navbar-title {
font-family: 'PingFang SC';
font-weight: 600;
font-size: 20px;
line-height: 1.4;
letter-spacing: 0.019em;
color: #000000;
}
}
}
// 关注列表滚动区域
.follow-scroll {
flex: 1;
height: 100%;
}
// 关注列表
.follow-list {
display: flex;
flex-direction: column;
gap: 12px;
padding: 0 0 20px;
}
// 关注项
.follow-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
padding: 8px 20px;
.follow-left {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-width: 0;
cursor: pointer;
.user-avatar {
width: 40px;
height: 40px;
border-radius: 999px;
flex-shrink: 0;
}
.user-info {
display: flex;
flex-direction: column;
gap: 8px;
flex: 1;
min-width: 0;
height: 40px;
justify-content: center;
.user-nickname {
font-family: 'PingFang SC';
font-weight: 600;
font-size: 14px;
line-height: 1.14;
color: rgba(0, 0, 0, 0.8);
}
.user-signature {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 12px;
line-height: 1.33;
color: rgba(60, 60, 67, 0.6);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.action-row {
display: flex;
align-items: center;
gap: 8px;
.action-text,
.time-text {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 12px;
line-height: 1.33;
color: rgba(60, 60, 67, 0.6);
}
}
}
}
// 回关按钮
.follow-button {
display: flex;
justify-content: center;
align-items: center;
padding: 4px 16px;
border: 0.5px solid #000000;
border-radius: 20px;
cursor: pointer;
flex-shrink: 0;
&:active {
opacity: 0.8;
}
&.mutual {
border-color: rgba(120, 120, 128, 0.12);
background: transparent;
}
.button-text {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 12px;
line-height: 1.33;
color: #000000;
}
&.mutual .button-text {
color: rgba(0, 0, 0, 0.8);
}
}
}
// 到底了提示
.bottom-tip {
display: flex;
justify-content: center;
align-items: center;
padding: 24px 0 12px;
.tip-text {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
line-height: 1.71;
color: rgba(0, 0, 0, 0.35);
}
}
}

View File

@@ -0,0 +1,206 @@
import { useState, useEffect } from "react";
import { View, Text, ScrollView } from "@tarojs/components";
import { Avatar } from "@nutui/nutui-react-taro";
import { withAuth, EmptyState } from "@/components";
import noticeService from "@/services/noticeService";
import Taro from "@tarojs/taro";
import "./index.scss";
// 关注项类型定义
interface FollowItem {
id: string;
user_id: string;
user_avatar: string;
user_nickname: string;
user_signature?: string;
time: string;
is_mutual: boolean; // 是否互相关注
is_read: number;
}
const NewFollow = () => {
const [followList, setFollowList] = useState<FollowItem[]>([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
getFollowList();
}, []);
// 获取新增关注列表
const getFollowList = async () => {
if (loading) return;
setLoading(true);
try {
const res = await noticeService.getNotificationList({
notification_type: "follow", // 筛选关注类型
});
if (res.code === 0) {
// 映射数据
const mappedList = res.data.list.map((item: any) => ({
id: item.id,
user_id: item.related_user_id || "",
user_avatar: item.related_user_avatar || "",
user_nickname: item.related_user_nickname || "匿名用户",
user_signature: item.related_user_signature || "",
time: item.created_at,
is_mutual: item.is_mutual_follow || false,
is_read: item.is_read,
}));
setFollowList(mappedList);
}
} catch (e) {
Taro.showToast({
title: "获取列表失败",
icon: "none",
duration: 2000,
});
} finally {
setLoading(false);
}
};
// 格式化时间显示
const formatTime = (timeStr: string) => {
if (!timeStr) return "";
const date = new Date(timeStr);
const now = new Date();
const diff = now.getTime() - date.getTime();
const hours = Math.floor(diff / (1000 * 60 * 60));
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
if (hours < 24) {
return `${hours}小时前`;
} else if (days === 1) {
return "1天前";
} else if (days < 7) {
return `${days}天前`;
} else {
const month = date.getMonth() + 1;
const day = date.getDate();
return `${month}${day}`;
}
};
// 处理回关
const handleFollowBack = async (item: FollowItem) => {
if (item.is_mutual) {
// 已经互相关注,无需操作
return;
}
try {
// TODO: 调用关注接口
// await userService.followUser({ user_id: item.user_id });
Taro.showToast({
title: "关注成功",
icon: "success",
duration: 2000,
});
// 更新列表
setFollowList(prevList =>
prevList.map(followItem =>
followItem.id === item.id
? { ...followItem, is_mutual: true }
: followItem
)
);
} catch (e) {
Taro.showToast({
title: "关注失败",
icon: "none",
duration: 2000,
});
}
};
// 处理返回
const handleBack = () => {
Taro.navigateBack();
};
// 处理点击用户
const handleUserClick = (userId: string) => {
Taro.navigateTo({
url: `/user_pages/other/index?user_id=${userId}`,
});
};
// 渲染关注项
const renderFollowItem = (item: FollowItem) => {
return (
<View className="follow-item" key={item.id}>
<View className="follow-left" onClick={() => handleUserClick(item.user_id)}>
<Avatar
className="user-avatar"
src={item.user_avatar || "https://img.yzcdn.cn/vant/cat.jpeg"}
size="40px"
/>
<View className="user-info">
<Text className="user-nickname">{item.user_nickname}</Text>
{item.user_signature ? (
<Text className="user-signature">{item.user_signature}</Text>
) : (
<View className="action-row">
<Text className="action-text"></Text>
<Text className="time-text">{formatTime(item.time)}</Text>
</View>
)}
</View>
</View>
<View
className={`follow-button ${item.is_mutual ? "mutual" : ""}`}
onClick={() => handleFollowBack(item)}
>
<Text className="button-text">{item.is_mutual ? "互相关注" : "回关"}</Text>
</View>
</View>
);
};
return (
<View className="new-follow-container">
{/* 顶部导航栏 */}
<View className="navbar">
<View className="navbar-content">
<View className="back-button" onClick={handleBack}>
<View className="back-icon"></View>
</View>
<Text className="navbar-title"></Text>
</View>
</View>
{/* 关注列表 */}
<ScrollView
scrollY
className="follow-scroll"
scrollWithAnimation
enhanced
showScrollbar={false}
>
{followList.length > 0 ? (
<View className="follow-list">
{followList.map(renderFollowItem)}
{/* 到底了提示 */}
<View className="bottom-tip">
<Text className="tip-text"></Text>
</View>
</View>
) : (
<EmptyState text="暂无新增关注" />
)}
</ScrollView>
</View>
);
};
export default withAuth(NewFollow);