diff --git a/src/pages/Discovery/index.vue b/src/pages/Discovery/index.vue
index 7f1e764..3803d3c 100644
--- a/src/pages/Discovery/index.vue
+++ b/src/pages/Discovery/index.vue
@@ -29,10 +29,12 @@ import CardSwiper from "./components/CardSwiper/index.vue";
import QuickQuestions from "./components/QuickQuestions/index.vue";
import discoveryCover from "@/components/ImageSwiper/images/2025-07-12_180248.jpg";
-import { homeTabsData, homeTabContentData, homeQuickQuestionData } from "../../request/api/MainPageDataApi";
-import { useAppStore } from "@/store";
+import { homeTabsData, getNearbyTags, homeTabContentData, homeQuickQuestionData } from "../../request/api/MainPageDataApi";
+import { useAppStore, useLocationStore } from "@/store";
import { JumpType } from "../../model/ChatModel";
+
const appStore = useAppStore();
+const locationStore = useLocationStore();
/// 从个渠道获取如二维码
const sceneId = appStore.sceneId || "";
@@ -58,15 +60,20 @@ const queryTabsList = async () => {
}));
/// 设置tab数据
discoveryTabs.value = tabList;
-
- /// 查询是否有sceneId参数
- const activeTabIndex = discoveryTabs.value.findIndex((tab) => tab.id === sceneId);
-
- /// 如果有则优先展示对应tab数据,没有则展示第一个tab数据
- if (activeTabIndex > -1) {
- activeIndex.value = activeTabIndex;
- queryDiscoveryData(sceneId);
- } else {
+ /// 根据sceneId查询对应tab数据
+ findTabByIdWithActiveTabIndex(sceneId);
+ }
+}
+/// 根据id查询tab并设置activeIndex
+const findTabByIdWithActiveTabIndex = (tabsId) => {
+ /// 查询是否有id参数
+ const activeTabIndex = discoveryTabs.value.findIndex((tab) => tab.id === tabsId);
+ /// 如果有则优先展示对应tab数据,没有则展示第一个tab数据
+ if (activeTabIndex > -1) {
+ activeIndex.value = activeTabIndex;
+ queryDiscoveryData(tabsId);
+ } else {
+ if (discoveryTabs.value.length > 0) {
activeIndex.value = 0;
queryDiscoveryData(discoveryTabs.value[0].id);
}
@@ -145,10 +152,37 @@ const handleClick = async (item) => {
}
}
+/// 获取位置信息
+const getLocation = () => {
+ /// 已经有sceneId了,说明之前已经获取过位置信息了,就不需要再获取一次了
+ if (sceneId) return;
+ uni.getLocation({
+ type: 'wgs84',
+ success: function (res) {
+ // 将位置信息存储到 Pinia 中
+ locationStore.setLocationData({
+ latitude: res.latitude,
+ longitude: res.longitude,
+ });
+ console.log('当前位置:' + JSON.stringify(res));
+ getNearbyTagsData();
+ }
+ });
+}
+
+/// 获取附近标签数据
+const getNearbyTagsData = async () => {
+ const res = await getNearbyTags();
+ if (res.code === 0) {
+ const nearbyTagId = res.data;
+ findTabByIdWithActiveTabIndex(nearbyTagId);
+ }
+}
/// 组件挂载后请求数据
onMounted(() => {
queryTabsList();
+ getLocation();
});
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 7c2b755..e4cd9db 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -21,7 +21,7 @@