1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '首页',
|
||||
navigationStyle: 'custom',
|
||||
navigationBarBackgroundColor: '#FAFAFA'
|
||||
})
|
||||
navigationBarTitleText: '首页',
|
||||
navigationStyle: 'custom',
|
||||
navigationBarBackgroundColor: '#FAFAFA',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import { View } from "@tarojs/components";
|
||||
import Taro from "@tarojs/taro";
|
||||
import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
|
||||
import { OSS_BASE } from "@/config/api";
|
||||
import { wechat_auth_login, save_login_state } from "@/services/loginService";
|
||||
import { useUserActions } from "@/store/userStore";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
@@ -18,7 +19,11 @@ import { useDictionaryStore } from "@/store/dictionaryStore";
|
||||
type TabType = "list" | "message" | "personal";
|
||||
|
||||
const MainPage: React.FC = () => {
|
||||
const [currentTab, setCurrentTab] = useState<TabType>("list");
|
||||
const { params } = useRouter();
|
||||
const [currentTab, setCurrentTab] = useState<TabType>(() => {
|
||||
const tab = params?.tab as TabType | undefined;
|
||||
return tab === "list" || tab === "message" || tab === "personal" ? tab : "list";
|
||||
});
|
||||
const [isPublishMenuVisible, setIsPublishMenuVisible] = useState(false);
|
||||
const [isDistanceFilterVisible, setIsDistanceFilterVisible] = useState(false);
|
||||
const [isCityPickerVisible, setIsCityPickerVisible] = useState(false);
|
||||
@@ -35,6 +40,14 @@ const MainPage: React.FC = () => {
|
||||
const { showGuideBar, guideBarZIndex, setShowGuideBar, setGuideBarZIndex } =
|
||||
useGlobalState();
|
||||
|
||||
// 从分享链接进入时根据 ?tab= 定位到对应 tab
|
||||
useEffect(() => {
|
||||
const tab = params?.tab as TabType | undefined;
|
||||
if (tab === "list" || tab === "message" || tab === "personal") {
|
||||
setCurrentTab(tab);
|
||||
}
|
||||
}, [params?.tab]);
|
||||
|
||||
// 初始化:自动微信授权并获取用户信息
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
@@ -153,6 +166,21 @@ const MainPage: React.FC = () => {
|
||||
[]
|
||||
);
|
||||
|
||||
// 分享:首页、个人页均支持转发
|
||||
// 分享图:配置 OSS 地址 + 路径(不含 ? 后参数),首页用 share_home.png,个人页用 share_self.png
|
||||
useShareAppMessage(() => {
|
||||
const isList = currentTab === "list";
|
||||
const isPersonal = currentTab === "personal";
|
||||
const title = isList ? "约球 - 发现身边的球局" : isPersonal ? "约球 - 我的约球" : "约球";
|
||||
const image_path = isPersonal ? "system/share_self.png" : "system/share_home.png";
|
||||
const imageUrl = OSS_BASE ? `${OSS_BASE.replace(/\/$/, "")}/${image_path}` : "";
|
||||
return {
|
||||
title,
|
||||
path: "/main_pages/index" + (isList ? "?tab=list" : isPersonal ? "?tab=personal" : ""),
|
||||
imageUrl: imageUrl,
|
||||
};
|
||||
});
|
||||
|
||||
// 滚动到顶部
|
||||
const scrollToTop = useCallback(() => {
|
||||
// 如果当前是列表页,触发列表页内部滚动
|
||||
|
||||
Reference in New Issue
Block a user