Skip to content

Commit

Permalink
🐛 修复部分链接点击异常
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Aug 16, 2024
1 parent 926c0f4 commit 598f530
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/components/home/t-position.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template #title>近期活动</template>
<template #default>
<div class="position-grid">
<v-card v-for="card in positionCards" :key="card.postId" rounded class="position-card">
<v-card v-for="(card, index) in positionCards" :key="index" rounded class="position-card">
<v-list class="position-list">
<v-list-item :title="card.title" :subtitle="card.abstract">
<template #prepend>
Expand All @@ -12,9 +12,7 @@
</v-avatar>
</template>
<template #append>
<v-btn class="position-card-btn" @click="createPost(card.postId, card.title)">
查看
</v-btn>
<v-btn class="position-card-btn" @click="openPosition(card)"> 查看</v-btn>
</template>
</v-list-item>
</v-list>
Expand All @@ -41,8 +39,10 @@
import { ref, onMounted, onUnmounted } from "vue";
import Mys from "../../plugins/Mys/index.js";
import { parseLink } from "../../utils/linkParser.js";
import { createPost } from "../../utils/TGWindow.js";
import { stamp2LastTime } from "../../utils/toolFunc.js";
import showSnackbar from "../func/snackbar.js";
import THomeCard from "./t-homecard.vue";
Expand Down Expand Up @@ -94,6 +94,19 @@ onMounted(async () => {
emits("success");
});
async function openPosition(card: TGApp.Plugins.Mys.Position.RenderCard): Promise<void> {
const res = await parseLink(card.link);
if (res === "post") await createPost(card.postId, card.title);
if (res === false) {
showSnackbar({
text: `未知链接:${card.link}`,
color: "error",
timeout: 3000,
});
return;
}
}
onUnmounted(() => {
Object.keys(positionTimer.value).forEach((key) => {
clearInterval(positionTimer.value[Number(key)]);
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/Mys/types/Position.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/types/Position.d.ts
* @description Mys 插件热点追踪接口
* @since Alpha v0.2.1
* @since Beta v0.5.3
*/

/**
Expand Down Expand Up @@ -74,10 +74,11 @@ declare namespace TGApp.Plugins.Mys.Position {

/**
* @description 渲染用的热点追踪信息
* @since Alpha v0.2.1
* @since Beta v0.5.3
* @interface RenderCard
* @property {string} title 标题
* @property {number} postId 帖子ID
* @property {string} link 链接
* @property {string} icon 图标
* @property {string} abstract 摘要
* @property time 时间
Expand All @@ -90,6 +91,7 @@ declare namespace TGApp.Plugins.Mys.Position {
interface RenderCard {
title: string;
postId: number;
link: string;
icon: string;
abstract: string;
time: {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/Mys/utils/getPositionCard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @file plugins/Mys/utils/getPositionCard.ts
* @description Mys 插件热点追踪工具
* @since Beta v0.5.0
* @since Beta v0.5.3
*/

/**
* @description 根据热点追踪信息转为渲染用的数据
* @since Beta v0.5.0
* @since Beta v0.5.3
* @param {TGApp.Plugins.Mys.Position.Data[]} positionData 列表
* @returns {TGApp.Plugins.Mys.Position.RenderCard[]} 返回列表
*/
Expand All @@ -24,6 +24,7 @@ function getPositionCard(
const card: TGApp.Plugins.Mys.Position.RenderCard = {
title: position.title,
postId: Number(position.url.split("/").pop()),
link: position.url,
icon: position.icon,
abstract: position.abstract,
time: {
Expand Down

0 comments on commit 598f530

Please sign in to comment.