feat: 对接了首页的接口
This commit is contained in:
@@ -1,26 +1,38 @@
|
||||
<template>
|
||||
<view>
|
||||
<FindTabs
|
||||
v-if="discoveryTabs.length > 0"
|
||||
v-model="activeIndex"
|
||||
:tabs="discoveryTabs"
|
||||
@change="handleTabChange"
|
||||
/>
|
||||
|
||||
<CardSwiper
|
||||
v-if="discoveryCards.length > 0"
|
||||
:list="discoveryCards"
|
||||
@card-click="cardClick" />
|
||||
<QuickQuestions />
|
||||
|
||||
<QuickQuestions />
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import FindTabs from "./components/FindTabs/index.vue";
|
||||
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";
|
||||
const appStore = useAppStore();
|
||||
/// 从个渠道获取如二维码
|
||||
const sceneId = appStore.sceneId || "";
|
||||
|
||||
const activeIndex = ref(0);
|
||||
const discoveryTabs = ref([]);
|
||||
|
||||
const discoveryCards = ref([
|
||||
{
|
||||
title: "卧龙潭漂流",
|
||||
@@ -52,16 +64,71 @@ const discoveryCards = ref([
|
||||
},
|
||||
]);
|
||||
|
||||
const discoveryTabs = computed(() =>
|
||||
discoveryCards.value.map((item) => ({
|
||||
label: item.tabLabel || item.title,
|
||||
}))
|
||||
);
|
||||
/// tabs 切换事件
|
||||
const handleTabChange = ({ tab, idx }) => {
|
||||
if (activeIndex.value === idx) return;
|
||||
activeIndex.value = idx;
|
||||
queryDiscoveryData(tab.id);
|
||||
}
|
||||
|
||||
/// 卡片点击事件
|
||||
const cardClick = (item) => {
|
||||
console.log(JSON.stringify(item));
|
||||
};
|
||||
|
||||
/// 请求发现页tab数据
|
||||
const queryTabsList = async () => {
|
||||
const res = await homeTabsData();
|
||||
if (res.code === 0) {
|
||||
/// 处理tab数据
|
||||
const tabList = res.data.map((item) => ({
|
||||
id: item.id,
|
||||
label: item.tagName,
|
||||
}));
|
||||
/// 设置tab数据
|
||||
discoveryTabs.value = tabList;
|
||||
|
||||
/// 查询是否有sceneId参数
|
||||
const activeTab = discoveryTabs.value.find((tab) => {
|
||||
return tab.id === sceneId;
|
||||
});
|
||||
|
||||
/// 如果有则优先展示对应tab数据,没有则展示第一个tab数据
|
||||
if (activeTab) {
|
||||
queryDiscoveryData(sceneId);
|
||||
} else {
|
||||
queryDiscoveryData(discoveryTabs.value[0].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 统一请求发现页数据
|
||||
const queryDiscoveryData = async (tabId) => {
|
||||
queryDiscoveryCards(tabId);
|
||||
queryQuickQuestionData(tabId);
|
||||
};
|
||||
|
||||
/// 请求发现页卡片数据
|
||||
const queryDiscoveryCards = async (tabId) => {
|
||||
const res = await homeTabContentData({ tagId: tabId });
|
||||
if (res.code === 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// 请求快速问题列表数据
|
||||
const queryQuickQuestionData = async (tabId) => {
|
||||
const res = await homeQuickQuestionData({ tagId: tabId });
|
||||
if (res.code === 0) {
|
||||
console.log("快速问题列表:", res.data);
|
||||
}
|
||||
}
|
||||
|
||||
/// 组件挂载后请求数据
|
||||
onMounted(() => {
|
||||
queryTabsList();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user