1
This commit is contained in:
@@ -7,7 +7,7 @@ import PublishMenu from "../PublishMenu";
|
||||
export type currentPageType = "games" | "message" | "personal";
|
||||
|
||||
const GuideBar = (props) => {
|
||||
const { currentPage, guideBarClassName, onPublishMenuVisibleChange } = props;
|
||||
const { currentPage, guideBarClassName, onPublishMenuVisibleChange, onTabChange } = props;
|
||||
|
||||
const guideItems = [
|
||||
{
|
||||
@@ -34,7 +34,14 @@ const GuideBar = (props) => {
|
||||
if (code === currentPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果提供了 onTabChange 回调,优先使用(单页面模式)
|
||||
if (onTabChange) {
|
||||
onTabChange(code);
|
||||
return;
|
||||
}
|
||||
|
||||
// 否则使用路由跳转(兼容模式)
|
||||
let url = `/pages/${code}/index`;
|
||||
if (code === "personal") {
|
||||
url = "/user_pages/myself/index";
|
||||
@@ -48,7 +55,7 @@ const GuideBar = (props) => {
|
||||
Taro.redirectTo({
|
||||
url: url,
|
||||
}).then(() => {
|
||||
Taro.pageScrollTo({
|
||||
(Taro as any).pageScrollTo({
|
||||
scrollTop: 0,
|
||||
duration: 300,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import Taro, { useDidShow } from "@tarojs/taro";
|
||||
import { View, Text, Image, Button } from "@tarojs/components";
|
||||
import "./index.scss";
|
||||
@@ -59,7 +59,7 @@ const on_edit = () => {
|
||||
});
|
||||
};
|
||||
// 用户信息卡片组件
|
||||
export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
||||
editable = true,
|
||||
user_info,
|
||||
is_current_user,
|
||||
@@ -71,7 +71,20 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
onTab,
|
||||
}) => {
|
||||
const { updateUserInfo } = useUserActions();
|
||||
console.log("UserInfoCard 用户信息:", user_info);
|
||||
|
||||
// 使用 useRef 记录上一次的 user_info,只在真正变化时打印
|
||||
const prevUserInfoRef = useRef<Partial<UserInfoType>>();
|
||||
|
||||
useEffect(() => {
|
||||
// 只在 user_info 真正变化时打印(通过 JSON 序列化比较)
|
||||
const prevStr = JSON.stringify(prevUserInfoRef.current);
|
||||
const currentStr = JSON.stringify(user_info);
|
||||
if (prevStr !== currentStr) {
|
||||
console.log("UserInfoCard 用户信息变化:", user_info);
|
||||
prevUserInfoRef.current = user_info;
|
||||
}
|
||||
}, [user_info]);
|
||||
|
||||
// 编辑个人简介弹窗状态
|
||||
const [edit_modal_visible, setEditModalVisible] = useState(false);
|
||||
const [editing_field, setEditingField] = useState<string>("");
|
||||
@@ -603,6 +616,23 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
// 自定义比较函数:只在关键 props 变化时重新渲染
|
||||
const arePropsEqual = (prevProps: UserInfoCardProps, nextProps: UserInfoCardProps) => {
|
||||
// 使用 JSON.stringify 进行深度比较(注意:对于复杂对象可能有性能问题)
|
||||
const prevUserInfoStr = JSON.stringify(prevProps.user_info);
|
||||
const nextUserInfoStr = JSON.stringify(nextProps.user_info);
|
||||
|
||||
return (
|
||||
prevUserInfoStr === nextUserInfoStr &&
|
||||
prevProps.editable === nextProps.editable &&
|
||||
prevProps.is_current_user === nextProps.is_current_user &&
|
||||
prevProps.is_following === nextProps.is_following
|
||||
);
|
||||
};
|
||||
|
||||
// 使用 React.memo 优化组件,减少不必要的重新渲染
|
||||
export const UserInfoCard = React.memo(UserInfoCardComponent, arePropsEqual);
|
||||
|
||||
// 球局记录接口
|
||||
export interface GameRecord {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user