优化弹窗被GuideBar遮挡的问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef, useContext } from "react";
|
||||||
import Taro, { useDidShow } from "@tarojs/taro";
|
import Taro, { useDidShow } from "@tarojs/taro";
|
||||||
import { View, Text, Image, Button } from "@tarojs/components";
|
import { View, Text, Image, Button } from "@tarojs/components";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
@@ -10,6 +10,7 @@ import { useUserActions } from "@/store/userStore";
|
|||||||
import { UserInfoType } from "@/services/userService";
|
import { UserInfoType } from "@/services/userService";
|
||||||
import { useCities, useProfessions } from "@/store/pickerOptionsStore";
|
import { useCities, useProfessions } from "@/store/pickerOptionsStore";
|
||||||
import { formatNtrpDisplay } from "@/utils/helper";
|
import { formatNtrpDisplay } from "@/utils/helper";
|
||||||
|
import FamilyContext from '@/context';
|
||||||
|
|
||||||
// 用户信息接口
|
// 用户信息接口
|
||||||
// export interface UserInfo {
|
// export interface UserInfo {
|
||||||
@@ -71,6 +72,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
|||||||
set_user_info,
|
set_user_info,
|
||||||
onTab,
|
onTab,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { handleGrandchildTrigger } = useContext(FamilyContext);
|
||||||
const { updateUserInfo } = useUserActions();
|
const { updateUserInfo } = useUserActions();
|
||||||
|
|
||||||
// 使用 useRef 记录上一次的 user_info,只在真正变化时打印
|
// 使用 useRef 记录上一次的 user_info,只在真正变化时打印
|
||||||
@@ -102,6 +104,14 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
|||||||
set_form_data({ ...user_info });
|
set_form_data({ ...user_info });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const visibles = [gender_picker_visible, location_picker_visible, ntrp_picker_visible, occupation_picker_visible]
|
||||||
|
const showGuideBar = visibles.every(item => !item)
|
||||||
|
if (showGuideBar) {
|
||||||
|
handleGrandchildTrigger(false)
|
||||||
|
}
|
||||||
|
}, [gender_picker_visible, location_picker_visible, ntrp_picker_visible, occupation_picker_visible])
|
||||||
|
|
||||||
// 职业数据
|
// 职业数据
|
||||||
const professions = useProfessions();
|
const professions = useProfessions();
|
||||||
|
|
||||||
@@ -132,6 +142,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
|||||||
// };
|
// };
|
||||||
// 处理编辑弹窗
|
// 处理编辑弹窗
|
||||||
const handle_open_edit_modal = (field: string) => {
|
const handle_open_edit_modal = (field: string) => {
|
||||||
|
handleGrandchildTrigger(true)
|
||||||
if (field === "gender") {
|
if (field === "gender") {
|
||||||
setGenderPickerVisible(true);
|
setGenderPickerVisible(true);
|
||||||
return;
|
return;
|
||||||
@@ -150,9 +161,11 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
|||||||
}
|
}
|
||||||
if (field === "nickname") {
|
if (field === "nickname") {
|
||||||
// 手动输入
|
// 手动输入
|
||||||
|
handleGrandchildTrigger(true)
|
||||||
setEditingField(field);
|
setEditingField(field);
|
||||||
setEditModalVisible(true);
|
setEditModalVisible(true);
|
||||||
} else {
|
} else {
|
||||||
|
handleGrandchildTrigger(true)
|
||||||
setEditingField(field);
|
setEditingField(field);
|
||||||
setEditModalVisible(true);
|
setEditModalVisible(true);
|
||||||
}
|
}
|
||||||
@@ -256,6 +269,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
|||||||
handle_field_edit("occupation", `${country} ${province} ${city}`);
|
handle_field_edit("occupation", `${country} ${province} ${city}`);
|
||||||
};
|
};
|
||||||
const handle_edit_modal_cancel = () => {
|
const handle_edit_modal_cancel = () => {
|
||||||
|
handleGrandchildTrigger(false);
|
||||||
setEditModalVisible(false);
|
setEditModalVisible(false);
|
||||||
setEditingField("");
|
setEditingField("");
|
||||||
};
|
};
|
||||||
|
|||||||
13
src/context/index.ts
Normal file
13
src/context/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
// 定义Context类型
|
||||||
|
interface FamilyContextType {
|
||||||
|
handleGrandchildTrigger: (data: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建Context对象
|
||||||
|
const FamilyContext = React.createContext < FamilyContextType > ({
|
||||||
|
handleGrandchildTrigger: () => { }
|
||||||
|
});
|
||||||
|
|
||||||
|
export default FamilyContext;
|
||||||
@@ -10,6 +10,7 @@ import ListPageContent from "./components/ListPageContent";
|
|||||||
import MessagePageContent from "./components/MessagePageContent";
|
import MessagePageContent from "./components/MessagePageContent";
|
||||||
import MyselfPageContent from "./components/MyselfPageContent";
|
import MyselfPageContent from "./components/MyselfPageContent";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
|
import FamilyContext from '@/context';
|
||||||
|
|
||||||
type TabType = "list" | "message" | "personal";
|
type TabType = "list" | "message" | "personal";
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ const MainPage: React.FC = () => {
|
|||||||
const [isFilterPopupVisible, setIsFilterPopupVisible] = useState(false);
|
const [isFilterPopupVisible, setIsFilterPopupVisible] = useState(false);
|
||||||
const [isShowInputCustomerNavBar, setIsShowInputCustomerNavBar] = useState(false);
|
const [isShowInputCustomerNavBar, setIsShowInputCustomerNavBar] = useState(false);
|
||||||
const [listPageScrollToTopTrigger, setListPageScrollToTopTrigger] = useState(0);
|
const [listPageScrollToTopTrigger, setListPageScrollToTopTrigger] = useState(0);
|
||||||
|
const [showGuideBar, setShowGuideBar] = useState(true);
|
||||||
|
|
||||||
const { fetchUserInfo } = useUserActions();
|
const { fetchUserInfo } = useUserActions();
|
||||||
|
|
||||||
@@ -155,7 +157,12 @@ const MainPage: React.FC = () => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGrandchildTrigger = (value) => {
|
||||||
|
setShowGuideBar(!value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<FamilyContext.Provider value={{ handleGrandchildTrigger }}>
|
||||||
<View className="main-page">
|
<View className="main-page">
|
||||||
{/* 自定义导航栏 */}
|
{/* 自定义导航栏 */}
|
||||||
{renderCustomNavbar()}
|
{renderCustomNavbar()}
|
||||||
@@ -189,13 +196,19 @@ const MainPage: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 底部导航栏 */}
|
{/* 底部导航栏 */}
|
||||||
|
{
|
||||||
|
showGuideBar ?
|
||||||
<GuideBar
|
<GuideBar
|
||||||
currentPage={currentTab}
|
currentPage={currentTab}
|
||||||
guideBarClassName={guideBarZIndex === 'low' ? 'guide-bar-low-z-index' : 'guide-bar-high-z-index'}
|
guideBarClassName={guideBarZIndex === 'low' ? 'guide-bar-low-z-index' : 'guide-bar-high-z-index'}
|
||||||
onTabChange={handleTabChange}
|
onTabChange={handleTabChange}
|
||||||
onPublishMenuVisibleChange={handlePublishMenuVisibleChange}
|
onPublishMenuVisibleChange={handlePublishMenuVisibleChange}
|
||||||
/>
|
/> :
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
|
</FamilyContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user