♻️ 姑且能跑 dev,尚需调试功能

This commit is contained in:
目棃
2024-07-02 23:05:33 +08:00
parent 1214501691
commit 367307029b
66 changed files with 12626 additions and 2887 deletions

View File

@@ -243,7 +243,7 @@
<script lang="ts" setup>
import { event, window as TauriWindow } from "@tauri-apps/api";
import { UnlistenFn, Event } from "@tauri-apps/api/helpers/event";
import { UnlistenFn, Event } from "@tauri-apps/api/event";
import { storeToRefs } from "pinia";
import { computed, onMounted, onUnmounted, ref, watch } from "vue";

View File

@@ -9,7 +9,7 @@
</template>
<script lang="ts" setup>
import { event } from "@tauri-apps/api";
import { UnlistenFn, Event } from "@tauri-apps/api/helpers/event";
import { UnlistenFn, Event } from "@tauri-apps/api/event";
import { computed, onMounted, onUnmounted } from "vue";
import { useAppStore } from "../../store/modules/app.js";
@@ -25,8 +25,8 @@ const themeGet = computed({
});
let themeListener: UnlistenFn;
onMounted(async () => {
themeListener = await listenOnTheme();
onMounted(() => {
themeListener = listenOnTheme();
});
async function switchTheme(): Promise<void> {
@@ -34,8 +34,8 @@ async function switchTheme(): Promise<void> {
await event.emit("readTheme", themeGet.value);
}
async function listenOnTheme(): Promise<UnlistenFn> {
return await event.listen("readTheme", (e: Event<string>) => {
function listenOnTheme(): UnlistenFn {
return event.listen("readTheme", (e: Event<string>) => {
const theme = e.payload;
themeGet.value = theme === "default" ? "default" : "dark";
});

View File

@@ -42,8 +42,9 @@
</v-list>
</template>
<script lang="ts" setup>
import { dialog, fs, path } from "@tauri-apps/api";
import { FileEntry } from "@tauri-apps/api/fs";
import { path } from "@tauri-apps/api";
import { open } from "@tauri-apps/plugin-dialog";
import { readDir, remove } from "@tauri-apps/plugin-fs";
import TGSqlite from "../../plugins/Sqlite/index.js";
import { useAppStore } from "../../store/modules/app.js";
@@ -67,7 +68,7 @@ async function confirmCUD(): Promise<void> {
});
return;
}
const dir = await dialog.open({
const dir: string | null = await open({
directory: true,
defaultPath: oriDir,
multiple: false,
@@ -79,13 +80,6 @@ async function confirmCUD(): Promise<void> {
});
return;
}
if (typeof dir !== "string") {
showSnackbar({
color: "error",
text: "路径错误!",
});
return;
}
if (dir === oriDir) {
showSnackbar({
color: "warn",
@@ -96,7 +90,7 @@ async function confirmCUD(): Promise<void> {
appStore.userDir = dir;
await TGSqlite.saveAppData("userDir", dir);
await backUpUserData(dir);
await fs.removeDir(oriDir, { recursive: true });
await remove(oriDir, { recursive: true });
showSnackbar({
text: "已重新备份数据!即将刷新页面!",
timeout: 3000,
@@ -127,11 +121,11 @@ async function confirmCLD(): Promise<void> {
return;
}
const logDir = appStore.logDir;
const files = await fs.readDir(logDir);
const delFiles = files.filter((file: FileEntry) => {
const files = await readDir(logDir);
const delFiles = files.filter((file) => {
// yyyy-mm-dd.log
const reg = /(\d{4}-\d{2}-\d{2}\.log)/;
const match = file.path.match(reg);
const match = file.name.match(reg);
if (!Array.isArray(match) || match.length < 1) return false;
const date = match[1].replace(".log", "");
return isOverWeek(date);
@@ -144,7 +138,8 @@ async function confirmCLD(): Promise<void> {
return;
}
for (const file of delFiles) {
await fs.removeFile(file.path);
const filePath = `${logDir}/${file.name}`;
await remove(filePath);
}
showSnackbar({
text: `已清理 ${delFiles.length} 个日志文件!`,

View File

@@ -77,7 +77,7 @@ async function toWebLogin(): Promise<void> {
return;
}
await TGClient.open("config_sign_in", "https://user.mihoyo.com");
signListener = await event.listen("config_user_sign", async (e: Event<unknown>) => {
signListener = event.listen("config_user_sign", async (e: Event<unknown>) => {
if (typeof e.payload !== "string") {
showSnackbar({
color: "error",

View File

@@ -28,8 +28,7 @@
</TOverlay>
</template>
<script setup lang="ts">
import { http } from "@tauri-apps/api";
import { ResponseType } from "@tauri-apps/api/http";
import { fetch } from "@tauri-apps/plugin-http";
import { computed, onMounted, ref, watch } from "vue";
import { xml2json } from "xml-js";
@@ -166,11 +165,10 @@ async function loadText(): Promise<void> {
async function parseXml(link: string) {
try {
const res = await http.fetch<string>(link, {
method: "GET",
responseType: ResponseType.Text,
});
return JSON.parse(xml2json(res.data));
const response = await fetch(link, { method: "GET" });
const data = await response.arrayBuffer();
const xml = new TextDecoder("utf-8").decode(data);
return JSON.parse(xml2json(xml));
} catch (error) {
console.error(error);
return false;

View File

@@ -40,7 +40,7 @@
</template>
<script lang="ts" setup>
import { event } from "@tauri-apps/api";
import { UnlistenFn } from "@tauri-apps/api/helpers/event";
import { UnlistenFn } from "@tauri-apps/api/event";
import { onMounted, onUnmounted, ref } from "vue";
import { saveImgLocal } from "../../utils/TGShare.js";
@@ -59,7 +59,7 @@ const iconDark = ref<string>();
const offer = ref<string>();
onMounted(async () => {
themeListener = await event.listen("readTheme", (e) => {
themeListener = event.listen("readTheme", (e) => {
const theme = <string>e.payload;
if (theme === "dark") {
icon.value = iconLight.value;
@@ -77,9 +77,7 @@ onMounted(async () => {
});
onUnmounted(() => {
if (themeListener) {
themeListener();
}
themeListener();
const urlList = [iconLight.value, iconDark.value, offer.value];
urlList.forEach((url) => {
URL.revokeObjectURL(typeof url === "string" ? url : "");