mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
♻️ 精简代码
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<TLoading v-model="loading" :title="loadingTitle" />
|
||||
<TOLoading v-model="loading" :title="loadingTitle" />
|
||||
<v-tabs v-model="tab" align-tabs="start" class="news-tab">
|
||||
<v-tab value="notice">
|
||||
公告
|
||||
@@ -209,14 +208,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</v-overlay>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import TLoading from "../components/main/t-loading.vue";
|
||||
import TOLoading from "../components/overlay/to-loading.vue";
|
||||
// store
|
||||
import { useAppStore } from "../store/modules/app";
|
||||
// plugin
|
||||
@@ -257,14 +255,17 @@ const postData = ref({
|
||||
const rawData = ref({
|
||||
notice: {
|
||||
isLast: false,
|
||||
name: "公告",
|
||||
lastId: 0,
|
||||
},
|
||||
activity: {
|
||||
isLast: false,
|
||||
name: "活动",
|
||||
lastId: 0,
|
||||
},
|
||||
news: {
|
||||
isLast: false,
|
||||
name: "咨讯",
|
||||
lastId: 0,
|
||||
},
|
||||
});
|
||||
@@ -276,10 +277,12 @@ onMounted(async () => {
|
||||
rawData.value.notice.lastId = noticeData.list.length;
|
||||
postData.value.notice = MysOper.News.card.notice(noticeData);
|
||||
tab.value = "notice";
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
async function firstLoad (data:string) {
|
||||
async function firstLoad (data: string) {
|
||||
if (rawData.value.activity.lastId !== 0 && rawData.value.news.lastId !== 0) {
|
||||
return;
|
||||
}
|
||||
@@ -290,7 +293,6 @@ async function firstLoad (data:string) {
|
||||
rawData.value.activity.isLast = activityData.is_last;
|
||||
rawData.value.activity.lastId = activityData.list.length;
|
||||
postData.value.activity = MysOper.News.card.activity(activityData);
|
||||
loading.value = false;
|
||||
}
|
||||
if (data === "news" && rawData.value.news.lastId === 0) {
|
||||
loadingTitle.value = "正在获取咨讯数据...";
|
||||
@@ -299,15 +301,17 @@ async function firstLoad (data:string) {
|
||||
rawData.value.news.isLast = newsData.is_last;
|
||||
rawData.value.news.lastId = newsData.list.length;
|
||||
postData.value.news = MysOper.News.card.news(newsData);
|
||||
loading.value = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
async function switchAnno () {
|
||||
await router.push("/announcements");
|
||||
}
|
||||
|
||||
async function toChannel (chan:string) {
|
||||
async function toChannel (chan: string) {
|
||||
showList.value = false;
|
||||
await router.push(chan);
|
||||
await window.location.reload();
|
||||
@@ -316,57 +320,32 @@ async function toChannel (chan:string) {
|
||||
// 加载更多
|
||||
async function loadMore (data: string) {
|
||||
loadingSub.value = true;
|
||||
let getData: NewsData;
|
||||
let getCard: NewsCard[];
|
||||
switch (data) {
|
||||
case "notice":
|
||||
if (rawData.value.notice.isLast) {
|
||||
if (rawData.value[data].isLast) {
|
||||
snackbarText.value = "已经是最后一页了";
|
||||
snackbarColor.value = "#35acce";
|
||||
snackbar.value = true;
|
||||
loadingSub.value = false;
|
||||
return;
|
||||
}
|
||||
getData = await MysOper.News.get.notice(gid, 20, rawData.value.notice.lastId);
|
||||
rawData.value.notice.lastId = rawData.value.notice.lastId + getData.list.length;
|
||||
rawData.value.notice.isLast = getData.is_last;
|
||||
getCard = MysOper.News.card.notice(getData);
|
||||
postData.value.notice = postData.value.notice.concat(getCard);
|
||||
loadingSub.value = false;
|
||||
break;
|
||||
case "activity":
|
||||
if (rawData.value.activity.isLast) {
|
||||
loadingTitle.value = `正在获取${rawData.value[data].name}数据...`;
|
||||
loading.value = true;
|
||||
const getData = await MysOper.News.get[data](gid, 20, rawData.value[data].lastId);
|
||||
rawData.value[data].lastId = rawData.value[data].lastId + getData.list.length;
|
||||
rawData.value[data].isLast = getData.is_last;
|
||||
const getCard = MysOper.News.card[data](getData);
|
||||
postData.value[data] = postData.value[data].concat(getCard);
|
||||
if (rawData.value[data].isLast) {
|
||||
snackbarText.value = "已经是最后一页了";
|
||||
snackbarColor.value = "#35acce";
|
||||
snackbar.value = true;
|
||||
loadingSub.value = false;
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
getData = await MysOper.News.get.activity(gid, 20, rawData.value.activity.lastId);
|
||||
rawData.value.activity.lastId = rawData.value.activity.lastId + getData.list.length;
|
||||
rawData.value.activity.isLast = getData.is_last;
|
||||
getCard = MysOper.News.card.activity(getData);
|
||||
postData.value.activity = postData.value.activity.concat(getCard);
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
loadingSub.value = false;
|
||||
break;
|
||||
case "news":
|
||||
if (rawData.value.news.isLast) {
|
||||
snackbarText.value = "已经是最后一页了";
|
||||
snackbarColor.value = "#35acce";
|
||||
snackbar.value = true;
|
||||
loadingSub.value = false;
|
||||
return;
|
||||
}
|
||||
getData = await MysOper.News.get.news(gid, 20, rawData.value.news.lastId);
|
||||
rawData.value.news.lastId = rawData.value.news.lastId + getData.list.length;
|
||||
rawData.value.news.isLast = getData.is_last;
|
||||
getCard = MysOper.News.card.news(getData);
|
||||
postData.value.news = postData.value.news.concat(getCard);
|
||||
loadingSub.value = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
async function toPost (item: NewsCard | string) {
|
||||
@@ -390,6 +369,7 @@ async function toPost (item: NewsCard | string) {
|
||||
createTGWindow(path, "帖子", item.title, 960, 720, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function toJson (item: NewsCard | string) {
|
||||
if (typeof item === "string") {
|
||||
const path = router.resolve({
|
||||
|
||||
Reference in New Issue
Block a user