1
0
forked from bot/app

📝 [docs]: 新增在线展示

This commit is contained in:
2024-09-01 18:25:37 +08:00
parent 499caca7e3
commit d485e095ae
10 changed files with 241 additions and 59 deletions

View File

@ -1,32 +1,39 @@
<script setup>
import getText from "../components/scripts/i18nData.ts";
import {ref} from "vue";
<script setup lang="ts">
import {ref, onMounted, onUnmounted} from "vue";
import getText from "./scripts/i18n";
const onlineText = getText('online');
const totalText = getText('total')
const totalText = getText('total');
const onlineFetchUrl = "https://api.liteyuki.icu/online"
const totalFetchUrl = "https://api.liteyuki.icu/count"
const onlineFetchUrl = "https://api.liteyuki.icu/online";
const totalFetchUrl = "https://api.liteyuki.icu/count";
let online = ref(-1);
let total = ref(-1);
const online = ref(0);
const total = ref(0);
async function updateData() {
try {
const onlineResponse = await fetch(onlineFetchUrl);
const onlineData = await onlineResponse.json();
online.value = onlineData.online;
function updateData() {
const totalResponse = await fetch(totalFetchUrl);
const totalData = await totalResponse.json();
total.value = totalData.register;
} catch (error) {
console.error('Error fetching data:', error);
}
fetch(onlineFetchUrl)
.then(response => response.json())
.then(data => online.value = data.online)
.catch(error => console.error('Error fetching online data:', error));
fetch(totalFetchUrl)
.then(response => response.json())
.then(data => total.value = data.register)
.catch(error => console.error('Error fetching total data:', error));
}
updateData();
setInterval(updateData, 10000);
onMounted(() => {
const intervalId = setInterval(updateData, 10000);
updateData();
onUnmounted(() => {
clearInterval(intervalId);
});
});
</script>