Switch to a basic API endpoint to get tab info.

This commit is contained in:
吳元皓 2025-05-25 09:27:58 +08:00
parent 79e133c167
commit c2ec1b6668
3 changed files with 45 additions and 47 deletions

View File

@ -1,36 +1,25 @@
<script setup lang="ts"> <script setup lang="ts">
//const { data: tabs, error: tabserror } = await useFetch("/api/cached/tabs");
const tabs = [ const pullTabsData = async () => {
{ const req = await fetch("/api/cached/tabs");
text: "國內", const data = await req.json();
url: "domestic", return data.data;
default: true, }
},
{
text: "國外",
url: "global",
default: false,
},
];
const primary = ref<string>(
tabs.find((tab) => tab.default === true).url || "domestic",
);
const contentArray = ref([]); const contentArray = ref([]);
const errorr = ref(false); const errorr = ref(false);
const switchTabs = ref(false); const switchTabs = ref(false);
const tabs = ref([]);
const primary = ref<string>("domestic");
const updateContent = async (url: string, tabAction: boolean) => { const updateContent = async (url: string, tabAction: boolean) => {
if (tabAction === true) { if (tabAction === true) {
primary.value = url; primary.value = url;
switchTabs.value = true; switchTabs.value = true;
} }
console.log(url.trim());
try { try {
const req = await fetch(`/api/home/lt?query=${url.trim()}`); const req = await fetch(`/api/home/lt?query=${url.trim()}`);
const data = await req.json(); const data = await req.json();
console.log(data);
if (data) { if (data) {
contentArray.value = [...data.uuidData, ...(data.nuuiddata?.items || [])]; contentArray.value = [...data.uuidData, ...(data.nuuiddata?.items || [])];
switchTabs.value = false; switchTabs.value = false;
@ -43,14 +32,9 @@ const updateContent = async (url: string, tabAction: boolean) => {
}; };
const isPrimary = (url: string, defaultAction: boolean) => { const isPrimary = (url: string, defaultAction: boolean) => {
if (defaultAction === true) { if (primary.value === url) {
const item = tabs.find((tab) => tab.url === url);
if (item.default === true) {
return "text-sky-600 text-bold"; return "text-sky-600 text-bold";
} }
}
if (defaultAction === false) {
}
return "text-black"; return "text-black";
}; };
@ -59,6 +43,8 @@ const openNews = (url: string) => {
}; };
onMounted(async () => { onMounted(async () => {
tabs.value = await pullTabsData();
primary.value = tabs.value.find((tab) => tab.default === true)?.url || "domestic";
await updateContent(primary.value, false); await updateContent(primary.value, false);
}); });
</script> </script>
@ -66,7 +52,7 @@ onMounted(async () => {
<div class="justify-center align-center text-center"> <div class="justify-center align-center text-center">
<!--Tabs--> <!--Tabs-->
<div <div
class="sticky inset-x-0 top-0 bg-gray-300/90 backdrop-blur-xl border shadow-lg rounded-xl p-1 m-1 mt-0 justify-center align-center text-center" class="sticky inset-x-0 top-0 bg-gray-300/90 backdrop-blur-xl border shadow-lg rounded-xl p-1 m-1 mt-0 justify-center align-center text-center z-[50]"
> >
<div class="gap-2 flex flex-row justify-center align-center text-center"> <div class="gap-2 flex flex-row justify-center align-center text-center">
<button <button
@ -79,7 +65,6 @@ onMounted(async () => {
</button> </button>
</div> </div>
</div> </div>
<div v-if="switchTabs">Loading...</div>
<Transition <Transition
enter-active-class="animate__animated animate__fadeIn" enter-active-class="animate__animated animate__fadeIn"
leave-active-class="animate__animated animate__fadeOut" leave-active-class="animate__animated animate__fadeOut"

View File

@ -166,8 +166,8 @@ const associAppWindow = [
id: "11", id: "11",
title: t("app.newsview"), title: t("app.newsview"),
component: NewsViewWindow, component: NewsViewWindow,
width: "700px", width: "800px",
height: "500px", height: "600px",
}, },
]; ];

View File

@ -1,3 +1,16 @@
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
return "cool"; return {
}); data: [
{
text: "國內",
url: "domestic",
default: true,
},
{
text: "國外",
url: "global",
default: false,
},
]
}
})