mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-24 00:01:03 +08:00
Switch to a basic API endpoint to get tab info.
This commit is contained in:
parent
79e133c167
commit
c2ec1b6668
@ -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,13 +32,8 @@ 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);
|
return "text-sky-600 text-bold";
|
||||||
if (item.default === true) {
|
|
||||||
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,25 +65,24 @@ 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"
|
||||||
>
|
>
|
||||||
<div v-if="!switchTabs">
|
<div v-if="!switchTabs">
|
||||||
<div
|
<div
|
||||||
v-for="item in contentArray"
|
v-for="item in contentArray"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:class="item.contentType !== 'GENERAL' && 'hidden'"
|
:class="item.contentType !== 'GENERAL' && 'hidden'"
|
||||||
>
|
>
|
||||||
<button @click="openNews(item.url.hash)">
|
<button @click="openNews(item.url.hash)">
|
||||||
<div class="p-2 bg-gray-200 rounded m-1 p-1">
|
<div class="p-2 bg-gray-200 rounded m-1 p-1">
|
||||||
<h1 class="text-2xl text-bold">{{ item.title }}</h1>
|
<h1 class="text-2xl text-bold">{{ item.title }}</h1>
|
||||||
<p>{{ item.shortDescription }}</p>
|
<p>{{ item.shortDescription }}</p>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</Transition>
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -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",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user