♻️ 二次简化

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 v-if="!loading" class="pool-grid">
<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" />
</div>
<div class="pool-bottom">
@@ -49,17 +49,12 @@
</template>
<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import Mys from "../../plugins/Mys";
import { useAppStore } from "../../store/modules/app";
import { useHomeStore } from "../../store/modules/home";
import { createPost, createTGWindow } from "../../utils/TGWindow";
import { stamp2LastTime } from "../../utils/toolFunc";
// vue
const router = useRouter();
// store
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);
}
function toPost(pool: TGApp.Plugins.Mys.Gacha.RenderCard): void {
const isDev = useAppStore().devMode;
createPost(pool.postId.toString(), isDev);
}
onUnmounted(() => {
Object.keys(timer.value).forEach((key) => {
clearInterval(timer.value[Number(key)]);

View File

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

View File

@@ -6,6 +6,8 @@
import { window as TauriWindow } from "@tauri-apps/api";
import { useAppStore } from "../store/modules/app";
/**
* @description 创建TG窗口
* @since Alpha v0.1.2
@@ -58,19 +60,19 @@ export function createTGWindow(
/**
* @description 打开帖子
* @since Beta v0.3.3
* @param {TGApp.Plugins.Mys.News.RenderCard|string} item 帖子内容或ID
* @param {boolean} isDev 是否为开发模式
* @param {TGApp.Plugins.Mys.News.RenderCard|string|number} item 帖子内容或ID
* @param {string} title 帖子标题
* @returns {void}
*/
export function createPost(
item: TGApp.Plugins.Mys.News.RenderCard | string,
isDev: boolean = false,
item: TGApp.Plugins.Mys.News.RenderCard | string | number,
title?: string,
): void {
let postId, postTitle, jsonTitle;
if (typeof item === "string") {
postId = item;
postTitle = `Post_${postId}`;
jsonTitle = `Post_${postId}_JSON`;
if (typeof item === "string" || typeof item === "number") {
postId = item.toString();
postTitle = title ? `Post_${postId} ${title}` : `Post_${postId}`;
jsonTitle = title ? `Post_${postId}_JSON ${title}` : `Post_${postId}_JSON`;
} else {
postId = item.postId.toString();
postTitle = `Post_${postId} ${item.title}`;
@@ -78,6 +80,7 @@ export function createPost(
}
const postPath = `/post_detail/${postId}`;
const jsonPath = `/post_detail_json/${postId}`;
const isDev = useAppStore().devMode ?? false;
if (isDev) {
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">
<div class="news-grid">
<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" />
<div v-if="value === 'activity'" class="news-card-act">
<div
@@ -66,7 +66,9 @@
<span>{{ item.user.label }}</span>
</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">
<img :src="item.forum.icon" alt="forumIcon" />
<span>{{ item.forum.name }}</span>
@@ -114,7 +116,6 @@ import showSnackbar from "../components/func/snackbar";
import ToChannel from "../components/overlay/to-channel.vue";
import ToLoading from "../components/overlay/to-loading.vue";
import Mys from "../plugins/Mys";
import { useAppStore } from "../store/modules/app";
import { createPost } from "../utils/TGWindow";
// 类型定义
@@ -246,11 +247,6 @@ async function loadMore(key: NewsKey): Promise<void> {
}, 1500);
}
function toPost(item: TGApp.Plugins.Mys.News.RenderCard | string): void {
const isDev = useAppStore().devMode;
createPost(item, isDev);
}
function searchPost(): void {
if (search.value === "") {
showSnackbar({
@@ -260,7 +256,7 @@ function searchPost(): void {
return;
}
if (!isNaN(Number(search.value))) {
toPost(search.value);
createPost(search.value);
} else {
showSnackbar({
text: "请输入搜索内容",