diff --git a/docs/.vuepress/client.js b/docs/.vuepress/client.js index d74dd557..45a6d3ab 100644 --- a/docs/.vuepress/client.js +++ b/docs/.vuepress/client.js @@ -3,6 +3,7 @@ import {defineClientConfig} from "vuepress/client"; import resourceStoreComp from "./components/ResStore.vue"; import pluginStoreComp from "./components/PluginStore.vue"; import dashComp from "./components/Dash.vue"; +import homeComp from "./components/Home.vue"; import ElementPlus from 'element-plus'; @@ -10,6 +11,7 @@ import ElementPlus from 'element-plus'; export default defineClientConfig({ enhance: ({app, router, siteData}) => { + app.component("homeComp", homeComp); app.component("dashComp", dashComp); app.component("resourceStoreComp", resourceStoreComp); app.component("pluginStoreComp", pluginStoreComp); diff --git a/docs/.vuepress/components/Home.vue b/docs/.vuepress/components/Home.vue new file mode 100644 index 00000000..5baeb6aa --- /dev/null +++ b/docs/.vuepress/components/Home.vue @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/docs/.vuepress/public/js/get_data.js b/docs/.vuepress/public/js/get_data.js index 6dad8992..d3daf221 100644 --- a/docs/.vuepress/public/js/get_data.js +++ b/docs/.vuepress/public/js/get_data.js @@ -1,27 +1,39 @@ +// 定义全局变量来存储数据 +let globalTotal = 0; +let globalOnline = 0; -function updatePageData() { - fetch("https://api.liteyuki.icu/count") - .then(res => res.json()) - .then(data => { - let total = document.getElementById("total"); - if(total !== null) { - total.innerText = data.register; - } - }) - .catch(err => console.error(err)); - - fetch("https://api.liteyuki.icu/online") - .then(res => res.json()) - .then(data => { - let online = document.getElementById("online"); - if(online !== null) { - online.innerText = data.online; - } - }) - .catch(err => console.error(err)); +// 从API获取数据并更新全局变量 +function fetchAndUpdateData() { + Promise.all([ + fetch("https://api.liteyuki.icu/count").then(res => res.json()), + fetch("https://api.liteyuki.icu/online").then(res => res.json()) + ]) + .then(([countRes, onlineRes]) => { + globalTotal = countRes.register; + globalOnline = onlineRes.online; + }) + .catch(err => { + console.error("Error fetching data:", err); + }); } -updatePageData(); -setInterval(() => { - updatePageData(); -}, 1000); \ No newline at end of file +// 更新页面显示,使用全局变量中的数据 +function updatePageDisplay() { + let countInfo = document.getElementById("count-info"); + if (!countInfo) { + let info = `