mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🐛 修复帖子跳转异常
This commit is contained in:
@@ -14,8 +14,9 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { toRaw } from "vue";
|
import { toRaw } from "vue";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
import { parseLink } from "../../utils/linkParser";
|
import { parseLink, parsePost } from "../../utils/linkParser";
|
||||||
import showSnackbar from "../func/snackbar";
|
import showSnackbar from "../func/snackbar";
|
||||||
|
|
||||||
interface TpLinkCard {
|
interface TpLinkCard {
|
||||||
@@ -41,11 +42,22 @@ interface TpLinkCardProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<TpLinkCardProps>();
|
const props = defineProps<TpLinkCardProps>();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
console.log("tpLinkCard", props.data.insert.link_card.card_id, toRaw(props.data).insert.link_card);
|
console.log("tpLinkCard", props.data.insert.link_card.card_id, toRaw(props.data).insert.link_card);
|
||||||
|
|
||||||
async function toLink() {
|
async function toLink() {
|
||||||
const link = props.data.insert.link_card.landing_url;
|
const link = props.data.insert.link_card.landing_url;
|
||||||
|
const isPost = await parsePost(link);
|
||||||
|
if (isPost !== false) {
|
||||||
|
await router.push({
|
||||||
|
name: "帖子详情",
|
||||||
|
params: {
|
||||||
|
post_id: isPost,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const res = await parseLink(link);
|
const res = await parseLink(link);
|
||||||
if (res === true) return;
|
if (res === true) return;
|
||||||
if (res === false) {
|
if (res === false) {
|
||||||
|
|||||||
@@ -22,9 +22,10 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref, StyleValue, toRaw } from "vue";
|
import { onMounted, ref, StyleValue, toRaw } from "vue";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
import { getEmojis } from "../../plugins/Mys/request/getEmojis";
|
import { getEmojis } from "../../plugins/Mys/request/getEmojis";
|
||||||
import { parseLink } from "../../utils/linkParser";
|
import { parseLink, parsePost } from "../../utils/linkParser";
|
||||||
import { isColorSimilar } from "../../utils/toolFunc";
|
import { isColorSimilar } from "../../utils/toolFunc";
|
||||||
import showSnackbar from "../func/snackbar";
|
import showSnackbar from "../func/snackbar";
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ const props = defineProps<TpTextProps>();
|
|||||||
const mode = ref<string>("text");
|
const mode = ref<string>("text");
|
||||||
const localEmojis = ref(localStorage.getItem("emojis"));
|
const localEmojis = ref(localStorage.getItem("emojis"));
|
||||||
const emojis = ref<TpText[]>([]);
|
const emojis = ref<TpText[]>([]);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
console.log("tpText", JSON.stringify(props.data.insert), toRaw(props.data)?.attributes);
|
console.log("tpText", JSON.stringify(props.data.insert), toRaw(props.data)?.attributes);
|
||||||
|
|
||||||
@@ -101,6 +103,16 @@ async function toLink() {
|
|||||||
if (!props.data.attributes) return;
|
if (!props.data.attributes) return;
|
||||||
if (!props.data.attributes.link) return;
|
if (!props.data.attributes.link) return;
|
||||||
const link = props.data.attributes.link;
|
const link = props.data.attributes.link;
|
||||||
|
const isPost = await parsePost(link);
|
||||||
|
if (isPost !== false) {
|
||||||
|
await router.push({
|
||||||
|
name: "帖子详情",
|
||||||
|
params: {
|
||||||
|
post_id: isPost,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const res = await parseLink(link);
|
const res = await parseLink(link);
|
||||||
if (res === true) return;
|
if (res === true) return;
|
||||||
if (res === false) {
|
if (res === false) {
|
||||||
|
|||||||
@@ -8,6 +8,44 @@ import TGClient from "./TGClient";
|
|||||||
import { createPost } from "./TGWindow";
|
import { createPost } from "./TGWindow";
|
||||||
import showConfirm from "../components/func/confirm";
|
import showConfirm from "../components/func/confirm";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function parsePost
|
||||||
|
* @since Beta v0.3.8
|
||||||
|
* @description 处理帖子
|
||||||
|
* @param {string} link
|
||||||
|
* @returns {Promise<false|string>} - 处理情况,或者转换后的链接
|
||||||
|
*/
|
||||||
|
export async function parsePost(link: string): Promise<false | string> {
|
||||||
|
const url = new URL(link);
|
||||||
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
||||||
|
if (url.protocol === "mihoyobbs:") {
|
||||||
|
if (url.pathname.startsWith("//article/")) {
|
||||||
|
const postId = url.pathname.split("/").pop();
|
||||||
|
if (!postId) return false;
|
||||||
|
return postId;
|
||||||
|
}
|
||||||
|
if (url.pathname === "//webview" && url.search.startsWith("?link=")) {
|
||||||
|
const urlTransform = decodeURIComponent(url.search.replace("?link=", ""));
|
||||||
|
return await parsePost(urlTransform);
|
||||||
|
}
|
||||||
|
// todo 不保证转换后的链接可用
|
||||||
|
if (url.pathname === "//openURL" && url.search.startsWith("?url=")) {
|
||||||
|
const urlTransform = decodeURIComponent(url.search.replace("?url=", ""));
|
||||||
|
return await parsePost(urlTransform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (url.hostname === "bbs.mihoyo.com" || url.hostname === "www.miyoushe.com") {
|
||||||
|
if (url.pathname.includes("/article/")) {
|
||||||
|
const postId = url.pathname.split("/").pop();
|
||||||
|
if (typeof postId !== "string") return false;
|
||||||
|
return postId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function parseLink
|
* @function parseLink
|
||||||
* @since Beta v0.3.8
|
* @since Beta v0.3.8
|
||||||
@@ -45,6 +83,9 @@ export async function parseLink(
|
|||||||
if (url.pathname.includes("/article/")) {
|
if (url.pathname.includes("/article/")) {
|
||||||
const postId = url.pathname.split("/").pop();
|
const postId = url.pathname.split("/").pop();
|
||||||
if (typeof postId !== "string") return false;
|
if (typeof postId !== "string") return false;
|
||||||
|
if (!useInner) {
|
||||||
|
return "post";
|
||||||
|
}
|
||||||
createPost(postId);
|
createPost(postId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user