feat: 抽屉效果再app不兼容问题处理

This commit is contained in:
2026-05-11 16:04:41 +08:00
parent 9cd3916ab2
commit 0dfd4fda1e
5 changed files with 41 additions and 17 deletions

View File

@@ -5,6 +5,7 @@
<ChatTopNavBar <ChatTopNavBar
ref="topNavBarRef" ref="topNavBarRef"
:mainPageDataModel="mainPageDataModel" :mainPageDataModel="mainPageDataModel"
@showDrawer="handleShowDrawer"
/> />
</view> </view>
@@ -257,6 +258,7 @@ import { checkToken } from "@/hooks/useGoLogin";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
import { getAccessToken } from "@/constant/token"; import { getAccessToken } from "@/constant/token";
const emit = defineEmits(["showDrawer"]);
const appStore = useAppStore(); const appStore = useAppStore();
/// 导航栏相关 /// 导航栏相关
const statusBarHeight = ref(20); const statusBarHeight = ref(20);
@@ -331,6 +333,10 @@ const handleChange = (i) => {
console.log("切换:", i); console.log("切换:", i);
}; };
const handleShowDrawer = () => {
emit("showDrawer");
};
/// =============事件函数↓================ /// =============事件函数↓================
const handleTouchEnd = () => { const handleTouchEnd = () => {
clearTimeout(holdKeyboardTimer.value); clearTimeout(holdKeyboardTimer.value);

View File

@@ -1,6 +1,8 @@
<template> <template>
<view class="border-box h-44 flex flex-items-center pl-12 pr-12"> <view class="border-box h-44 flex flex-items-center pl-12 pr-12">
<uni-icons type="bars" size="24" color="#333" @click="showDrawer" /> <view class="nav-icon-button" @tap.stop="showDrawer">
<uni-icons type="bars" size="24" color="#ffffff" />
</view>
<!-- 隐藏 --> <!-- 隐藏 -->
<view class="flex-full h-full flex flex-items-center flex-justify-center"> <view class="flex-full h-full flex flex-items-center flex-justify-center">
@@ -54,7 +56,9 @@ const spriteStyle = computed(() => {
}; };
}); });
const showDrawer = () => uni.$emit("SHOW_DRAWER"); const emit = defineEmits(["showDrawer"]);
const showDrawer = () => emit("showDrawer");
defineExpose({ show }); defineExpose({ show });
</script> </script>

View File

@@ -1,3 +1,11 @@
.nav-icon-button {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
}
// 图片从0%到100%动画 // 图片从0%到100%动画
.image-animated { .image-animated {
animation: logo-scale 0.3s ease-in-out; animation: logo-scale 0.3s ease-in-out;

View File

@@ -26,15 +26,20 @@ const drawerRef = ref(null);
// 监听抽屉显示事件 // 监听抽屉显示事件
const mineSettingRef = ref(null); const mineSettingRef = ref(null);
const open = () => { const open = async () => {
checkToken().then(async () => { await checkToken();
await mineSettingRef.value.getLoginUserPhoneInfo();
drawerRef.value.open(); drawerRef.value?.open?.();
});
try {
await mineSettingRef.value?.getLoginUserPhoneInfo?.();
} catch (error) {
console.warn("获取登录用户手机号失败:", error);
}
}; };
// 监听抽屉隐藏事件 // 监听抽屉隐藏事件
const close = () => drawerRef.value.close(); const close = () => drawerRef.value?.close?.();
defineExpose({ defineExpose({
open, open,

View File

@@ -1,6 +1,6 @@
<template> <template>
<view class="index-page w-full h-screen overflow-hidden bg-liner"> <view class="index-page w-full h-screen overflow-hidden bg-liner">
<ChatMainList /> <ChatMainList @showDrawer="showDrawer" />
<!-- 日历组件 --> <!-- 日历组件 -->
<Calender <Calender
@@ -47,9 +47,9 @@ const handleDateSelect = (data) => {
uni.$emit("selectCalendarDate", selectedDate.value); // 传回父组件 uni.$emit("selectCalendarDate", selectedDate.value); // 传回父组件
}; };
uni.$on("openCalendar", () => { const openCalendar = () => {
calendarVisible.value = true; calendarVisible.value = true;
}); };
// 打开窗口 // 打开窗口
@@ -57,11 +57,10 @@ const drawerRef = ref(null);
const showDrawer = async (e) => { const showDrawer = async (e) => {
await checkToken(); await checkToken();
drawerRef.value.open(); drawerRef.value?.open?.();
}; };
uni.$on("SHOW_DRAWER", showDrawer);
// 关闭窗口 // 关闭窗口
const closeDrawer = (e) => drawerRef.value.close(); const closeDrawer = (e) => drawerRef.value?.close?.();
///获取到二维码原始链接内容 ///获取到二维码原始链接内容
const getWeixinMiniProgramParams = (e) => { const getWeixinMiniProgramParams = (e) => {
@@ -78,11 +77,13 @@ onLoad((e) => {
}); });
onMounted(() => { onMounted(() => {
uni.$on("openCalendar", openCalendar);
uni.$on("SHOW_DRAWER", showDrawer);
}); });
onUnmounted(() => { onUnmounted(() => {
// uni.$off('openCalendar') uni.$off("openCalendar", openCalendar);
uni.$off("SHOW_DRAWER", showDrawer);
}); });
</script> </script>