mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-26 07:05:05 +08:00
📝 新增全球统计
This commit is contained in:
parent
2451849fd6
commit
5d22f20ce3
@ -3,6 +3,7 @@ import {defineClientConfig} from "vuepress/client";
|
|||||||
import resourceStoreComp from "./components/ResStore.vue";
|
import resourceStoreComp from "./components/ResStore.vue";
|
||||||
import pluginStoreComp from "./components/PluginStore.vue";
|
import pluginStoreComp from "./components/PluginStore.vue";
|
||||||
import dashComp from "./components/Dash.vue";
|
import dashComp from "./components/Dash.vue";
|
||||||
|
import homeComp from "./components/Home.vue";
|
||||||
|
|
||||||
|
|
||||||
import ElementPlus from 'element-plus';
|
import ElementPlus from 'element-plus';
|
||||||
@ -10,6 +11,7 @@ import ElementPlus from 'element-plus';
|
|||||||
|
|
||||||
export default defineClientConfig({
|
export default defineClientConfig({
|
||||||
enhance: ({app, router, siteData}) => {
|
enhance: ({app, router, siteData}) => {
|
||||||
|
app.component("homeComp", homeComp);
|
||||||
app.component("dashComp", dashComp);
|
app.component("dashComp", dashComp);
|
||||||
app.component("resourceStoreComp", resourceStoreComp);
|
app.component("resourceStoreComp", resourceStoreComp);
|
||||||
app.component("pluginStoreComp", pluginStoreComp);
|
app.component("pluginStoreComp", pluginStoreComp);
|
||||||
|
10
docs/.vuepress/components/Home.vue
Normal file
10
docs/.vuepress/components/Home.vue
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -1,27 +1,39 @@
|
|||||||
|
// 定义全局变量来存储数据
|
||||||
|
let globalTotal = 0;
|
||||||
|
let globalOnline = 0;
|
||||||
|
|
||||||
function updatePageData() {
|
// 从API获取数据并更新全局变量
|
||||||
fetch("https://api.liteyuki.icu/count")
|
function fetchAndUpdateData() {
|
||||||
.then(res => res.json())
|
Promise.all([
|
||||||
.then(data => {
|
fetch("https://api.liteyuki.icu/count").then(res => res.json()),
|
||||||
let total = document.getElementById("total");
|
fetch("https://api.liteyuki.icu/online").then(res => res.json())
|
||||||
if(total !== null) {
|
])
|
||||||
total.innerText = data.register;
|
.then(([countRes, onlineRes]) => {
|
||||||
}
|
globalTotal = countRes.register;
|
||||||
})
|
globalOnline = onlineRes.online;
|
||||||
.catch(err => console.error(err));
|
})
|
||||||
|
.catch(err => {
|
||||||
fetch("https://api.liteyuki.icu/online")
|
console.error("Error fetching data:", err);
|
||||||
.then(res => res.json())
|
});
|
||||||
.then(data => {
|
|
||||||
let online = document.getElementById("online");
|
|
||||||
if(online !== null) {
|
|
||||||
online.innerText = data.online;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => console.error(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePageData();
|
// 更新页面显示,使用全局变量中的数据
|
||||||
setInterval(() => {
|
function updatePageDisplay() {
|
||||||
updatePageData();
|
let countInfo = document.getElementById("count-info");
|
||||||
}, 1000);
|
if (!countInfo) {
|
||||||
|
let info = `<div id="count-info" style="text-align: center; font-size: 20px; font-weight: 500">
|
||||||
|
全球实例:<span id="total">${globalTotal}</span> 当前在线:<span id="online">${globalOnline}</span></div>`;
|
||||||
|
let mainDescription = document.querySelector("#main-description");
|
||||||
|
if (mainDescription) {
|
||||||
|
mainDescription.insertAdjacentHTML('afterend', info);
|
||||||
|
}
|
||||||
|
// 如果countInfo存在,可以在这里添加逻辑来更新现有的DOM元素
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始调用更新数据
|
||||||
|
fetchAndUpdateData();
|
||||||
|
|
||||||
|
// 设置定时器,分别以不同频率调用更新数据和更新页面的函数
|
||||||
|
setInterval(fetchAndUpdateData, 10000); // 每10秒更新一次数据
|
||||||
|
setInterval(updatePageDisplay, 1000); // 每1秒更新一次页面显示
|
@ -9,7 +9,7 @@ bgImageDark:
|
|||||||
bgImageStyle:
|
bgImageStyle:
|
||||||
background-attachment: fixed
|
background-attachment: fixed
|
||||||
heroText: LiteyukiBot
|
heroText: LiteyukiBot
|
||||||
tagline: LiteyukiBot 轻雪机器人,基于NoneBot2构建的综合应用型聊天机器人 总实例:<span id="total">0</span> 当前在线:<span id="online">0</span>
|
tagline: LiteyukiBot 轻雪机器人,基于NoneBot2构建的综合应用型聊天机器人
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
- text: 快速部署
|
- text: 快速部署
|
||||||
|
Loading…
Reference in New Issue
Block a user