diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 2c6b9cc7..132d5c60 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -30,7 +30,8 @@ "https://hk4e-api.mihoyo.com/*", "https://passport-api.mihoyo.com/*", "https://passport-api-v4.mihoyo.com/*", - "https://act-webstatic.mihoyo.com/*" + "https://act-webstatic.mihoyo.com/*", + "https://sdk-webstatic.mihoyo.com/*" ] }, "shell": { diff --git a/src/assets/css/anno-parser.css b/src/assets/css/anno-parser.css index 9da276f7..9bfb9025 100644 --- a/src/assets/css/anno-parser.css +++ b/src/assets/css/anno-parser.css @@ -1,12 +1,14 @@ /* + * @file assets css post-parser.css * @description 游戏公告解析 css - * @since Alpha v0.1.1 + * @author BTMuli + * @since Alpha v0.2.0 */ .mys-post-body { - margin: 20px auto; + margin: 0 auto; width: 800px; - font-family: "Genshin-Light", serif; + font-family: var(--font-text); color: var(--post-default-text); } diff --git a/src/components/main/t-shareBtn.vue b/src/components/main/t-shareBtn.vue new file mode 100644 index 00000000..28dbd0f8 --- /dev/null +++ b/src/components/main/t-shareBtn.vue @@ -0,0 +1,48 @@ + + + diff --git a/src/views/t-anno.vue b/src/views/t-anno.vue index 793c2b33..a20b9d88 100644 --- a/src/views/t-anno.vue +++ b/src/views/t-anno.vue @@ -1,6 +1,7 @@ @@ -19,21 +20,28 @@ import { ref, onMounted } from "vue"; import { useRoute } from "vue-router"; 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 TGRequest from "../web/request/TGRequest"; import TGUtils from "../web/utils/TGUtils"; +import { saveImgLocal } from "../utils/TGShare"; // loading const loading = ref(true as boolean); const loadingTitle = ref("正在加载"); const loadingEmpty = ref(false as boolean); +// share +const annoRef = ref({} as HTMLElement); +const annoTitle = ref(""); + // 数据 const annoId = Number(useRoute().params.anno_id); const annoData = ref({} as TGApp.BBS.Announcement.ContentItem); const annoHtml = ref(""); +const annoBanner = ref(""); onMounted(async () => { await appWindow.show(); @@ -49,8 +57,13 @@ onMounted(async () => { try { annoData.value = await TGRequest.Anno.getContent(annoId); loadingTitle.value = "正在渲染数据..."; - annoHtml.value = TGUtils.Anno.parseContent(annoData.value.content); + annoHtml.value = await TGUtils.Anno.parseContent(annoData.value.content); + annoBanner.value = await saveImgLocal(annoData.value.banner); + console.log(annoBanner.value); + annoTitle.value = annoData.value.title; + annoRef.value = document.querySelector(".anno-body") as HTMLElement; } catch (error) { + console.error(error); loadingEmpty.value = true; loadingTitle.value = "公告不存在或解析失败"; return; diff --git a/src/views/t-news.vue b/src/views/t-news.vue index 86e5ef5a..123377fc 100644 --- a/src/views/t-news.vue +++ b/src/views/t-news.vue @@ -222,7 +222,7 @@ import MysOper from "../plugins/Mys"; // utils import { createTGWindow } from "../utils/TGWindow"; // interface -import { NewsCard, NewsData } from "../plugins/Mys/interface/news"; +import { NewsCard } from "../plugins/Mys/interface/news"; // 路由 const router = useRouter(); diff --git a/src/views/t-post.vue b/src/views/t-post.vue index 769d5f1f..d77ed43a 100644 --- a/src/views/t-post.vue +++ b/src/views/t-post.vue @@ -1,6 +1,7 @@ @@ -9,21 +10,27 @@ import { ref, onMounted } from "vue"; import { useRoute } from "vue-router"; 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 TSwitchTheme from "../components/main/t-switchTheme.vue"; // loading const loading = ref(true as boolean); const loadingTitle = ref("正在加载"); const loadingEmpty = ref(false as boolean); +// share +const postRef = ref({} as HTMLElement); +const postTitle = ref(""); + // 数据 const postId = Number(useRoute().params.post_id); const postHtml = ref(""); + onMounted(async () => { await appWindow.show(); // 检查数据 @@ -39,6 +46,8 @@ onMounted(async () => { const postData = await MysOper.Post.get(postId); loadingTitle.value = "正在渲染数据..."; postHtml.value = MysOper.Post.parser(postData); + postTitle.value = postData.post.subject; + postRef.value = document.querySelector(".mys-post-body") as HTMLElement; await appWindow.setTitle(postData.post.subject); } catch (error) { console.error(error); diff --git a/src/web/utils/parseAnno.ts b/src/web/utils/parseAnno.ts index 9bcd30af..6b1ad705 100644 --- a/src/web/utils/parseAnno.ts +++ b/src/web/utils/parseAnno.ts @@ -1,19 +1,20 @@ /** * @file web utils parseAnno.ts * @description 解析游戏内公告数据 - * @author BTMuli - * @since Alpha v0.1.5 + * @author BTMuli + * @since Alpha v0.2.0 */ import { decodeRegExp } from "./tools"; +import { saveImgLocal } from "../../utils/TGShare"; /** * @description 解析游戏内公告数据 - * @since Alpha v0.1.5 + * @since Alpha v0.2.0 * @param {string} data 游戏内公告数据 - * @returns {string} 解析后的数据 + * @returns {Promise} 解析后的数据 */ -export function parseAnnoContent (data: string): string { +export async function parseAnnoContent(data: string): Promise { const htmlBase = new DOMParser().parseFromString(data, "text/html"); htmlBase.querySelectorAll("span").forEach((span) => { if (span.style.fontSize) { @@ -40,11 +41,16 @@ export function parseAnnoContent (data: string): string { }); } }); - htmlBase.querySelectorAll("img").forEach((img) => { + const imgList = Array.from(htmlBase.querySelectorAll("img")); + for (const img of imgList) { img.style.maxWidth = "100%"; img.style.borderRadius = "10px"; img.style.margin = "10px 0"; - }); + const src = img.getAttribute("src"); + if (src) { + img.setAttribute("src", await saveImgLocal(src)); + } + } htmlBase.querySelectorAll("a").forEach((a) => { const span = htmlBase.createElement("i"); span.classList.add("mdi", "mdi-link-variant", "anno-link-icon");