♻️ 二次简化

This commit is contained in:
BTMuli
2023-10-14 14:46:58 +08:00
parent 58e3c0e1a6
commit 214991fdd9
4 changed files with 21 additions and 40 deletions

View File

@@ -6,7 +6,7 @@
</div> </div>
<div v-if="!loading" class="pool-grid"> <div v-if="!loading" class="pool-grid">
<div v-for="pool in poolCards" :key="pool.postId" class="pool-card"> <div v-for="pool in poolCards" :key="pool.postId" class="pool-card">
<div class="pool-cover" @click="toPost(pool)"> <div class="pool-cover" @click="createPost(pool.postId, pool.title)">
<img :src="pool.cover" alt="cover" /> <img :src="pool.cover" alt="cover" />
</div> </div>
<div class="pool-bottom"> <div class="pool-bottom">
@@ -49,17 +49,12 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted, onUnmounted } from "vue"; import { ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import Mys from "../../plugins/Mys"; import Mys from "../../plugins/Mys";
import { useAppStore } from "../../store/modules/app";
import { useHomeStore } from "../../store/modules/home"; import { useHomeStore } from "../../store/modules/home";
import { createPost, createTGWindow } from "../../utils/TGWindow"; import { createPost, createTGWindow } from "../../utils/TGWindow";
import { stamp2LastTime } from "../../utils/toolFunc"; import { stamp2LastTime } from "../../utils/toolFunc";
// vue
const router = useRouter();
// store // store
const homeStore = useHomeStore(); const homeStore = useHomeStore();
@@ -176,11 +171,6 @@ async function toOuter(url: string, title: string): Promise<void> {
createTGWindow(url, "Sub_window", `Pool_${title}`, 1200, 800, true, true); createTGWindow(url, "Sub_window", `Pool_${title}`, 1200, 800, true, true);
} }
function toPost(pool: TGApp.Plugins.Mys.Gacha.RenderCard): void {
const isDev = useAppStore().devMode;
createPost(pool.postId.toString(), isDev);
}
onUnmounted(() => { onUnmounted(() => {
Object.keys(timer.value).forEach((key) => { Object.keys(timer.value).forEach((key) => {
clearInterval(timer.value[Number(key)]); clearInterval(timer.value[Number(key)]);

View File

@@ -15,12 +15,14 @@
<v-list class="position-list"> <v-list class="position-list">
<v-list-item :title="card.title" :subtitle="card.abstract"> <v-list-item :title="card.title" :subtitle="card.abstract">
<template #prepend> <template #prepend>
<v-avatar rounded="0" @click="toPost(card)"> <v-avatar rounded="0" @click="createPost(card.postId, card.title)">
<v-img :src="card.icon" class="position-icon" /> <v-img :src="card.icon" class="position-icon" />
</v-avatar> </v-avatar>
</template> </template>
<template #append> <template #append>
<v-btn class="position-card-btn" @click="toPost(card)"> 查看 </v-btn> <v-btn class="position-card-btn" @click="createPost(card.postId, card.title)">
查看
</v-btn>
</template> </template>
</v-list-item> </v-list-item>
</v-list> </v-list>
@@ -45,16 +47,11 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted, onUnmounted } from "vue"; import { ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import Mys from "../../plugins/Mys"; import Mys from "../../plugins/Mys";
import { useAppStore } from "../../store/modules/app";
import { createPost } from "../../utils/TGWindow"; import { createPost } from "../../utils/TGWindow";
import { stamp2LastTime } from "../../utils/toolFunc"; import { stamp2LastTime } from "../../utils/toolFunc";
// vue
const router = useRouter();
// loading // loading
const loading = ref<boolean>(true); const loading = ref<boolean>(true);
@@ -106,11 +103,6 @@ onMounted(async () => {
loading.value = false; loading.value = false;
}); });
function toPost(card: TGApp.Plugins.Mys.Position.RenderCard): void {
const isDev = useAppStore().devMode;
createPost(card.postId.toString(), isDev);
}
onUnmounted(() => { onUnmounted(() => {
Object.keys(positionTimer.value).forEach((key) => { Object.keys(positionTimer.value).forEach((key) => {
clearInterval(positionTimer.value[Number(key)]); clearInterval(positionTimer.value[Number(key)]);

View File

@@ -6,6 +6,8 @@
import { window as TauriWindow } from "@tauri-apps/api"; import { window as TauriWindow } from "@tauri-apps/api";
import { useAppStore } from "../store/modules/app";
/** /**
* @description 创建TG窗口 * @description 创建TG窗口
* @since Alpha v0.1.2 * @since Alpha v0.1.2
@@ -58,19 +60,19 @@ export function createTGWindow(
/** /**
* @description 打开帖子 * @description 打开帖子
* @since Beta v0.3.3 * @since Beta v0.3.3
* @param {TGApp.Plugins.Mys.News.RenderCard|string} item 帖子内容或ID * @param {TGApp.Plugins.Mys.News.RenderCard|string|number} item 帖子内容或ID
* @param {boolean} isDev 是否为开发模式 * @param {string} title 帖子标题
* @returns {void} * @returns {void}
*/ */
export function createPost( export function createPost(
item: TGApp.Plugins.Mys.News.RenderCard | string, item: TGApp.Plugins.Mys.News.RenderCard | string | number,
isDev: boolean = false, title?: string,
): void { ): void {
let postId, postTitle, jsonTitle; let postId, postTitle, jsonTitle;
if (typeof item === "string") { if (typeof item === "string" || typeof item === "number") {
postId = item; postId = item.toString();
postTitle = `Post_${postId}`; postTitle = title ? `Post_${postId} ${title}` : `Post_${postId}`;
jsonTitle = `Post_${postId}_JSON`; jsonTitle = title ? `Post_${postId}_JSON ${title}` : `Post_${postId}_JSON`;
} else { } else {
postId = item.postId.toString(); postId = item.postId.toString();
postTitle = `Post_${postId} ${item.title}`; postTitle = `Post_${postId} ${item.title}`;
@@ -78,6 +80,7 @@ export function createPost(
} }
const postPath = `/post_detail/${postId}`; const postPath = `/post_detail/${postId}`;
const jsonPath = `/post_detail_json/${postId}`; const jsonPath = `/post_detail_json/${postId}`;
const isDev = useAppStore().devMode ?? false;
if (isDev) { if (isDev) {
createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false); createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false);
} }

View File

@@ -33,7 +33,7 @@
<v-window-item v-for="(value, index) in tabValues" :key="index" :value="value"> <v-window-item v-for="(value, index) in tabValues" :key="index" :value="value">
<div class="news-grid"> <div class="news-grid">
<v-card v-for="item in postData[value]" :key="item.postId" class="news-card"> <v-card v-for="item in postData[value]" :key="item.postId" class="news-card">
<div class="news-cover" @click="toPost(item)"> <div class="news-cover" @click="createPost(item)">
<img :src="item.cover" alt="cover" /> <img :src="item.cover" alt="cover" />
<div v-if="value === 'activity'" class="news-card-act"> <div v-if="value === 'activity'" class="news-card-act">
<div <div
@@ -66,7 +66,9 @@
<span>{{ item.user.label }}</span> <span>{{ item.user.label }}</span>
</div> </div>
</div> </div>
<v-btn class="news-card-btn" variant="outlined" @click="toPost(item)"> 查看详情 </v-btn> <v-btn class="news-card-btn" variant="outlined" @click="createPost(item)">
查看详情
</v-btn>
<div class="news-card-forum"> <div class="news-card-forum">
<img :src="item.forum.icon" alt="forumIcon" /> <img :src="item.forum.icon" alt="forumIcon" />
<span>{{ item.forum.name }}</span> <span>{{ item.forum.name }}</span>
@@ -114,7 +116,6 @@ import showSnackbar from "../components/func/snackbar";
import ToChannel from "../components/overlay/to-channel.vue"; import ToChannel from "../components/overlay/to-channel.vue";
import ToLoading from "../components/overlay/to-loading.vue"; import ToLoading from "../components/overlay/to-loading.vue";
import Mys from "../plugins/Mys"; import Mys from "../plugins/Mys";
import { useAppStore } from "../store/modules/app";
import { createPost } from "../utils/TGWindow"; import { createPost } from "../utils/TGWindow";
// 类型定义 // 类型定义
@@ -246,11 +247,6 @@ async function loadMore(key: NewsKey): Promise<void> {
}, 1500); }, 1500);
} }
function toPost(item: TGApp.Plugins.Mys.News.RenderCard | string): void {
const isDev = useAppStore().devMode;
createPost(item, isDev);
}
function searchPost(): void { function searchPost(): void {
if (search.value === "") { if (search.value === "") {
showSnackbar({ showSnackbar({
@@ -260,7 +256,7 @@ function searchPost(): void {
return; return;
} }
if (!isNaN(Number(search.value))) { if (!isNaN(Number(search.value))) {
toPost(search.value); createPost(search.value);
} else { } else {
showSnackbar({ showSnackbar({
text: "请输入搜索内容", text: "请输入搜索内容",