♻️ Mys 类型重构,优化目录结构

This commit is contained in:
BTMuli
2023-06-27 21:01:24 +08:00
parent dc51257e6b
commit 99a6f38c5c
45 changed files with 1864 additions and 1902 deletions

View File

@@ -1,6 +1,6 @@
<template>
<TSwitchTheme />
<TOLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<ToLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<div v-if="!loading" class="lottery-box">
<div class="lottery-title">
抽奖详情
@@ -25,18 +25,16 @@
<div class="reward-title">抽奖 ID{{ lotteryCard.id }}</div>
<div class="reward-title">
奖品详情
<div v-for="reward in lotteryCard.rewards" :key="reward.rewardName" class="reward-subtitle">
{{ reward.rewardName }} {{ reward.scheduledWinnerNumber }}
<div v-for="reward in lotteryCard.rewards" :key="reward.name" class="reward-subtitle">
{{ reward.name }} {{ reward.goal }}
</div>
</div>
</div>
</div>
<div v-if="timeStatus === '已开奖'" class="lottery-box">
<div class="lottery-title">中奖详情</div>
<div v-for="reward in lotteryCard.rewards" :key="reward.rewardName" class="lottery-list">
<div class="reward-title">
{{ reward.rewardName }} {{ reward.scheduledWinnerNumber }}/{{ reward.winnerNumber }}
</div>
<div v-for="reward in lotteryCard.rewards" :key="reward.name" class="lottery-list">
<div class="reward-title">{{ reward.name }} {{ reward.win }}/{{ reward.goal }}</div>
<div class="lottery-grid">
<div v-for="user in reward.users" :key="user.uid" class="lottery-sub-list">
<div class="lottery-user-avatar">
@@ -58,29 +56,27 @@
import { computed, onMounted, onUpdated, reactive, ref } from "vue";
import { useRoute } from "vue-router";
import JsonViewer from "vue-json-viewer";
import TOLoading from "../components/overlay/to-loading.vue";
import ToLoading from "../components/overlay/to-loading.vue";
import TSwitchTheme from "../components/main/t-switchTheme.vue";
// tauri
import { appWindow } from "@tauri-apps/api/window";
// store
import { useAppStore } from "../store/modules/app";
// plugins
import MysOper from "../plugins/Mys";
// interface
import { LotteryCard, LotteryData } from "../plugins/Mys/interface/lottery";
import Mys from "../plugins/Mys";
// loading
const loading = ref(true as boolean);
const loadingTitle = ref("正在加载");
const loadingEmpty = ref(false as boolean);
const loading = ref<boolean>(true);
const loadingTitle = ref<string>("正在加载");
const loadingEmpty = ref<boolean>(false);
// store
const appStore = useAppStore();
const showJson = computed(() => appStore.devMode);
// 定时器
const lotteryTimer = ref(null as any);
const lotteryTimer = ref<any>(null);
// 参与方式
const participationMethod = ref("未知" as string);
const participationMethod = ref<string>("未知");
function flushTimeStatus() {
const timeNow = new Date().getTime();
@@ -99,9 +95,13 @@ function flushTimeStatus() {
// 数据
const lotteryId = useRoute().params.lottery_id as string;
const lotteryCard = ref({} as LotteryCard);
let jsonData = reactive({} as LotteryData);
const timeStatus = ref("未知" as string);
const lotteryCard = ref<TGApp.Plugins.Mys.Lottery.RenderCard>(
{} as TGApp.Plugins.Mys.Lottery.RenderCard,
);
let jsonData = reactive<TGApp.Plugins.Mys.Lottery.FullData>(
{} as TGApp.Plugins.Mys.Lottery.FullData,
);
const timeStatus = ref<string>("未知");
function backPost() {
window.history.back();
@@ -117,7 +117,7 @@ onMounted(async () => {
}
// 获取数据
loadingTitle.value = "正在获取数据...";
jsonData = await MysOper.Lottery.get(lotteryId);
jsonData = await Mys.Lottery.get(lotteryId);
if (!jsonData) {
loadingEmpty.value = true;
loadingTitle.value = "未找到数据";
@@ -125,7 +125,7 @@ onMounted(async () => {
}
await appWindow.setTitle("抽奖详情 " + jsonData.lottery_entity_summary);
loadingTitle.value = "正在渲染数据...";
lotteryCard.value = MysOper.Lottery.card.lottery(jsonData);
lotteryCard.value = Mys.Lottery.card(jsonData);
if (jsonData.status === "Settled") {
timeStatus.value = "已开奖";
} else {
@@ -133,19 +133,19 @@ onMounted(async () => {
flushTimeStatus();
}, 1000);
}
participationMethod.value = getParticipationMethod(lotteryCard.value.participantWay);
participationMethod.value = getUpWay(lotteryCard.value.upWay);
setTimeout(() => {
loading.value = false;
}, 1000);
});
// 获取参与方式
function getParticipationMethod(participantWay: string) {
switch (participantWay) {
function getUpWay(upWay: string) {
switch (upWay) {
case "Forward":
return "转发";
default:
return participantWay;
return upWay;
}
}

View File

@@ -28,7 +28,7 @@
<v-window v-model="tab">
<v-window-item value="notice">
<div class="news-grid">
<v-card v-for="item in postData.notice" :key="item.post_id" class="news-card">
<v-card v-for="item in postData.notice" :key="item.postId" class="news-card">
<div class="news-cover" @click="toPost(item)">
<img :src="item.cover" alt="cover" />
</div>
@@ -38,7 +38,7 @@
<img src="../assets/icons/circle-check.svg" alt="check" />
<span>查看</span>
</v-btn>
<v-card-subtitle>id:{{ item.post_id }}</v-card-subtitle>
<v-card-subtitle>id:{{ item.postId }}</v-card-subtitle>
<v-btn v-show="appStore.devMode" class="card-dev-btn" @click="toJson(item)">
<template #prepend>
<img src="../assets/icons/arrow-right.svg" alt="right" />
@@ -59,7 +59,7 @@
</v-window-item>
<v-window-item value="activity">
<div class="news-grid">
<v-card v-for="item in postData.activity" :key="item.post_id" class="news-card">
<v-card v-for="item in postData.activity" :key="item.postId" class="news-card">
<div class="news-cover" @click="toPost(item)">
<img :src="item.cover" alt="cover" />
</div>
@@ -72,7 +72,7 @@
<span>查看</span>
</template>
</v-btn>
<v-card-subtitle>id:{{ item.post_id }}</v-card-subtitle>
<v-card-subtitle>id:{{ item.postId }}</v-card-subtitle>
<div v-show="!appStore.devMode">
<v-btn
:style="{
@@ -103,7 +103,7 @@
</v-window-item>
<v-window-item v-if="showNews" value="news">
<div class="news-grid">
<v-card v-for="item in postData.news" :key="item.post_id" class="news-card">
<v-card v-for="item in postData.news" :key="item.postId" class="news-card">
<div class="news-cover" @click="toPost(item)">
<img :src="item.cover" alt="cover" />
</div>
@@ -115,7 +115,7 @@
<span>查看</span>
</template>
</v-btn>
<v-card-subtitle>id:{{ item.post_id }}</v-card-subtitle>
<v-card-subtitle>id:{{ item.postId }}</v-card-subtitle>
<v-btn v-show="appStore.devMode" class="card-dev-btn" @click="toJson(item)">
<template #prepend>
<img src="../assets/icons/arrow-right.svg" alt="right" />
@@ -150,39 +150,37 @@ import ToChannel from "../components/overlay/to-channel.vue";
// store
import { useAppStore } from "../store/modules/app";
// plugin
import MysOper from "../plugins/Mys";
import Mys from "../plugins/Mys";
// utils
import { createTGWindow } from "../utils/TGWindow";
// interface
import { NewsCard } from "../plugins/Mys/interface/news";
// 路由
const router = useRouter();
const gid = useRoute().params.gid as string;
const showNews = ref((gid !== "5") as boolean);
const gid = useRoute().params.gid;
const showNews = ref<boolean>(gid !== "5");
// Store
const appStore = useAppStore();
// loading
const loading = ref(true as boolean);
const loadingTitle = ref("正在加载" as string);
const loadingSub = ref(false as boolean);
const loading = ref<boolean>(true);
const loadingTitle = ref<string>("正在加载");
const loadingSub = ref<boolean>(false);
// snackbar
const snackbar = ref(false as boolean);
const snackbarText = ref("" as string);
const snackbarColor = ref("success" as string);
const snackbar = ref<boolean>(false);
const snackbarText = ref<string>("");
const snackbarColor = ref<string>("success");
// search
const search = ref("" as string);
const search = ref<string>("");
// 数据
const tab = ref("" as string);
const showList = ref(false as boolean);
const tab = ref<string>("");
const showList = ref<boolean>(false);
const postData = ref({
notice: [] as NewsCard[],
activity: [] as NewsCard[],
news: [] as NewsCard[],
notice: [] as TGApp.Plugins.Mys.News.RenderCard[],
activity: [] as TGApp.Plugins.Mys.News.RenderCard[],
news: [] as TGApp.Plugins.Mys.News.RenderCard[],
});
const rawData = ref({
notice: {
@@ -204,10 +202,10 @@ const rawData = ref({
onMounted(async () => {
loadingTitle.value = "正在获取公告数据";
const noticeData = await MysOper.News.get.notice(gid);
const noticeData = await Mys.News.get(gid);
rawData.value.notice.isLast = noticeData.is_last;
rawData.value.notice.lastId = noticeData.list.length;
postData.value.notice = MysOper.News.card.notice(noticeData);
postData.value.notice = Mys.News.card.notice(noticeData);
tab.value = "notice";
setTimeout(() => {
loading.value = false;
@@ -221,18 +219,18 @@ async function firstLoad(data: string) {
if (data === "activity" && rawData.value.activity.lastId === 0) {
loadingTitle.value = "正在获取活动数据...";
loading.value = true;
const activityData = await MysOper.News.get.activity(gid);
const activityData = await Mys.News.get(gid, "2");
rawData.value.activity.isLast = activityData.is_last;
rawData.value.activity.lastId = activityData.list.length;
postData.value.activity = MysOper.News.card.activity(activityData);
postData.value.activity = Mys.News.card.activity(activityData);
}
if (data === "news" && rawData.value.news.lastId === 0) {
loadingTitle.value = "正在获取咨讯数据...";
loading.value = true;
const newsData = await MysOper.News.get.news(gid);
const newsData = await Mys.News.get(gid, "3");
rawData.value.news.isLast = newsData.is_last;
rawData.value.news.lastId = newsData.list.length;
postData.value.news = MysOper.News.card.news(newsData);
postData.value.news = Mys.News.card.news(newsData);
}
setTimeout(() => {
loading.value = false;
@@ -244,7 +242,7 @@ async function switchAnno() {
}
// 加载更多
async function loadMore(data: string) {
async function loadMore(data: "notice" | "activity" | "news"): Promise<void> {
loadingSub.value = true;
if (rawData.value[data].isLast) {
snackbarText.value = "已经是最后一页了";
@@ -255,10 +253,12 @@ async function loadMore(data: string) {
}
loadingTitle.value = `正在获取${rawData.value[data].name}数据...`;
loading.value = true;
const getData = await MysOper.News.get[data](gid, 20, rawData.value[data].lastId);
const dataList = ["notice", "activity", "news"];
const dataIndex = (dataList.indexOf(data) + 1).toString();
const getData = await Mys.News.get(gid, dataIndex, 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);
const getCard = Mys.News.card[data](getData);
postData.value[data] = postData.value[data].concat(getCard);
if (rawData.value[data].isLast) {
snackbarText.value = "已经是最后一页了";
@@ -274,30 +274,28 @@ async function loadMore(data: string) {
}, 1500);
}
async function toPost(item: NewsCard | string) {
console.log(item);
// if (typeof item === "string") {
// const path = router.resolve({
// name: "帖子详情",
// params: {
// // eslint-disable-next-line camelcase
// post_id: item,
// },
// }).href;
// createTGWindow(path, "帖子-Dev", item, 960, 720, false, false);
// } else {
// const path = router.resolve({
// name: "帖子详情",
// params: {
// // eslint-disable-next-line camelcase
// post_id: item.post_id.toString(),
// },
// }).href;
// createTGWindow(path, "帖子", item.title, 960, 720, false, false);
// }
async function toPost(item: TGApp.Plugins.Mys.News.RenderCard | string) {
if (typeof item === "string") {
const path = router.resolve({
name: "帖子详情",
params: {
// eslint-disable-next-line camelcase
post_id: item,
},
}).href;
createTGWindow(path, "帖子-Dev", item, 960, 720, false, false);
} else {
const path = router.resolve({
name: "帖子详情",
params: {
post_id: item.postId.toString(),
},
}).href;
createTGWindow(path, "帖子", item.title, 960, 720, false, false);
}
}
async function toJson(item: NewsCard | string) {
async function toJson(item: TGApp.Plugins.Mys.News.RenderCard | string) {
if (typeof item === "string") {
const path = router.resolve({
name: "帖子详情JSON",
@@ -311,8 +309,7 @@ async function toJson(item: NewsCard | string) {
const path = router.resolve({
name: "帖子详情JSON",
params: {
// eslint-disable-next-line camelcase
post_id: item.post_id.toString(),
post_id: item.postId.toString(),
},
}).href;
createTGWindow(path, "帖子-JSON", `${item.title}-JSON`, 960, 720, false, false);

View File

@@ -1,6 +1,6 @@
<template>
<TSwitchTheme />
<TOLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<ToLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<div class="post-json">
<div class="post-title">帖子返回内容 JSON</div>
<JsonViewer :value="jsonData" copyable boxed />
@@ -11,17 +11,17 @@
import { ref, onMounted, reactive } from "vue";
import { useRoute } from "vue-router";
import JsonViewer from "vue-json-viewer";
import TOLoading from "../components/overlay/to-loading.vue";
import ToLoading from "../components/overlay/to-loading.vue";
import TSwitchTheme from "../components/main/t-switchTheme.vue";
// tauri
import { appWindow } from "@tauri-apps/api/window";
// plugins
import MysOper from "../plugins/Mys";
import Mys from "../plugins/Mys";
// loading
const loading = ref(true as boolean);
const loadingTitle = ref("正在加载");
const loadingEmpty = ref(false as boolean);
const loading = ref<boolean>(true);
const loadingTitle = ref<string>("正在加载");
const loadingEmpty = ref<boolean>(false);
// 数据
const postId = Number(useRoute().params.post_id);
@@ -38,7 +38,7 @@ onMounted(async () => {
// 获取数据
loadingTitle.value = "正在获取数据...";
try {
jsonData = await MysOper.Post.get(postId);
jsonData = await Mys.Post.get(postId);
loading.value = false;
} catch (e) {
loadingTitle.value = "帖子不存在或解析失败";

View File

@@ -2,7 +2,7 @@
<template>
<TSwitchTheme />
<TShareBtn v-show="!loadingEmpty" v-model="postRef" :title="shareTitle" />
<TOLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<ToLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" />
<div class="mys-post-body">
<div class="mys-post-title">
{{ postRender.title }}
@@ -18,26 +18,26 @@
// vue
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import TOLoading from "../components/overlay/to-loading.vue";
import ToLoading from "../components/overlay/to-loading.vue";
import TSwitchTheme from "../components/main/t-switchTheme.vue";
import TShareBtn from "../components/main/t-shareBtn.vue";
// tauri
import { appWindow } from "@tauri-apps/api/window";
// plugins
import MysOper from "../plugins/Mys";
import Mys from "../plugins/Mys";
// loading
const loading = ref(true as boolean);
const loadingTitle = ref("正在加载");
const loadingEmpty = ref(false as boolean);
const loading = ref<boolean>(true);
const loadingTitle = ref<string>("正在加载");
const loadingEmpty = ref<boolean>(false);
// share
const postRef = ref({} as HTMLElement);
const shareTitle = ref("");
const postRef = ref<HTMLElement>({} as HTMLElement);
const shareTitle = ref<string>("");
// 数据
const postId = Number(useRoute().params.post_id);
const postHtml = ref("");
const postHtml = ref<string>("");
const postRender = ref({
title: "",
created: "",
@@ -56,9 +56,9 @@ onMounted(async () => {
// 获取数据
loadingTitle.value = "正在获取数据...";
try {
const postData = await MysOper.Post.get(postId);
const postData = await Mys.Post.get(postId);
loadingTitle.value = "正在渲染数据...";
postHtml.value = MysOper.Post.parser(postData);
postHtml.value = Mys.Post.parser(postData);
postRender.value = {
title: postData.post.subject,
created: new Date(postData.post.created_at * 1000).toLocaleString().replace(/\//g, "-"),