mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
🔊 完善基础页面的 log #83
This commit is contained in:
17
src/App.vue
17
src/App.vue
@@ -13,7 +13,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { app, event, fs, tauri, window as TauriWindow } from "@tauri-apps/api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onBeforeMount, onMounted, ref } from "vue";
|
||||
import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import TBackTop from "./components/app/t-backTop.vue";
|
||||
@@ -36,6 +36,8 @@ const vuetifyTheme = computed(() => {
|
||||
return appStore.theme === "dark" ? "dark" : "light";
|
||||
});
|
||||
|
||||
let themeListener: () => void;
|
||||
|
||||
onBeforeMount(async () => {
|
||||
const win = TauriWindow.getCurrent();
|
||||
isMain.value = win.label === "TeyvatGuide";
|
||||
@@ -49,19 +51,14 @@ onBeforeMount(async () => {
|
||||
|
||||
onMounted(async () => {
|
||||
document.documentElement.className = theme.value;
|
||||
await listenOnTheme();
|
||||
});
|
||||
|
||||
// 监听主题变化
|
||||
async function listenOnTheme(): Promise<void> {
|
||||
await event.listen("readTheme", async (e) => {
|
||||
themeListener = await event.listen("readTheme", async (e) => {
|
||||
const themeGet = <string>e.payload;
|
||||
if (theme.value !== themeGet) {
|
||||
theme.value = themeGet;
|
||||
document.documentElement.className = theme.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 启动后只执行一次的监听
|
||||
async function listenOnInit(): Promise<void> {
|
||||
@@ -230,6 +227,10 @@ async function checkUpdate(): Promise<void> {
|
||||
window.open("https://app.btmuli.ink/docs/Changelogs.html");
|
||||
}
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
themeListener();
|
||||
});
|
||||
</script>
|
||||
<style lang="css">
|
||||
.app-container {
|
||||
|
||||
@@ -228,11 +228,12 @@
|
||||
<script lang="ts" setup>
|
||||
import { event, window as TauriWindow } from "@tauri-apps/api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
|
||||
import { useAppStore } from "../../store/modules/app";
|
||||
import { useUserStore } from "../../store/modules/user";
|
||||
import mhyClient from "../../utils/TGClient";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import showSnackbar from "../func/snackbar";
|
||||
|
||||
const appStore = useAppStore();
|
||||
@@ -262,6 +263,10 @@ const themeTitle = computed(() => {
|
||||
return themeGet.value === "default" ? "夜间模式" : "日间模式";
|
||||
});
|
||||
|
||||
watch(themeTitle, async (val) => {
|
||||
await TGLogger.Info(`[App][theme] 已切换到${val}`);
|
||||
});
|
||||
|
||||
function collapse(): void {
|
||||
rail.value = !rail.value;
|
||||
appStore.sidebar.collapse = rail.value;
|
||||
|
||||
@@ -162,7 +162,7 @@ async function openPath(type: "db" | "user" | "log"): Promise<void> {
|
||||
break;
|
||||
}
|
||||
await dialog.open({
|
||||
directory: type !== "db",
|
||||
directory: false,
|
||||
defaultPath: targetPath,
|
||||
multiple: false,
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
// utils
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { generateShareImg } from "../../utils/TGShare";
|
||||
|
||||
interface TShareBtnProps {
|
||||
@@ -21,6 +22,7 @@ const props = defineProps<TShareBtnProps>();
|
||||
const emit = defineEmits<TShareBtnEmits>();
|
||||
|
||||
async function shareContent(): Promise<void> {
|
||||
await TGLogger.Info("[TShareBtn][shareContent] 开始生成分享图片");
|
||||
emit("update:loading", true);
|
||||
props.modelValue.querySelectorAll("details").forEach((item) => {
|
||||
if (item.open) {
|
||||
@@ -38,6 +40,7 @@ async function shareContent(): Promise<void> {
|
||||
}
|
||||
});
|
||||
emit("update:loading", false);
|
||||
await TGLogger.Info("[TShareBtn][shareContent] 生成分享图片完成");
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { toRaw } from "vue";
|
||||
import { onMounted, toRaw } from "vue";
|
||||
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
|
||||
interface TpUnknownProps {
|
||||
data: TGApp.Plugins.Mys.SctPost.Empty;
|
||||
@@ -13,6 +15,12 @@ interface TpUnknownProps {
|
||||
const props = defineProps<TpUnknownProps>();
|
||||
|
||||
console.warn("tpUnknown", toRaw(props.data.insert));
|
||||
|
||||
onMounted(async () => {
|
||||
await TGLogger.Warn(
|
||||
`[tpUnknown][onMounted] 未知的插件数据 ${JSON.stringify(toRaw(props.data))}}`,
|
||||
);
|
||||
});
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.tp-unknown-box {
|
||||
|
||||
@@ -114,6 +114,7 @@ import ToNamecard from "../../components/overlay/to-namecard.vue";
|
||||
import { AppAchievementSeriesData, AppNameCardsData } from "../../data";
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
import { useAchievementsStore } from "../../store/modules/achievements";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { getNowStr } from "../../utils/toolFunc";
|
||||
import { getUiafHeader, readUiafData, verifyUiafData } from "../../utils/UIAF";
|
||||
|
||||
@@ -145,10 +146,6 @@ const renderSelect = computed(() => {
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
onBeforeMount(async () => {
|
||||
await flushOverview();
|
||||
});
|
||||
|
||||
// 更改是否隐藏已完成
|
||||
async function switchHideFin() {
|
||||
const text = hideFin.value ? "显示已完成" : "隐藏已完成";
|
||||
@@ -177,8 +174,12 @@ async function flushOverview(): Promise<void> {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await TGLogger.Info("[Achievements][onMounted] 打开成就页面");
|
||||
await TGLogger.Info(`[Achievements][onMounted] 当前版本:${achievementsStore.lastVersion}`);
|
||||
loading.value = true;
|
||||
loadingTitle.value = "正在获取成就系列数据";
|
||||
await flushOverview();
|
||||
await TGLogger.Info(`[Achievements][onMounted] ${title.value}`);
|
||||
allSeriesData.value = await getSeriesData();
|
||||
achievementsStore.lastVersion = await TGSqlite.getLatestAchievementVersion();
|
||||
loadingTitle.value = "正在获取成就数据";
|
||||
@@ -247,10 +248,10 @@ async function searchCard(): Promise<void> {
|
||||
selectedSeries.value = -1;
|
||||
loadingTitle.value = "正在搜索";
|
||||
loading.value = true;
|
||||
await TGLogger.Info(`[Achievements][searchCard] 搜索内容:${search.value}`);
|
||||
selectedAchievement.value = await getAchiData("search", search.value);
|
||||
await nextTick(() => {
|
||||
loading.value = false;
|
||||
// 等 500ms 动画
|
||||
setTimeout(() => {
|
||||
if (renderSelect.value.length === 0) {
|
||||
showSnackbar({
|
||||
@@ -264,10 +265,12 @@ async function searchCard(): Promise<void> {
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
await TGLogger.Info(`[Achievements][searchCard] 搜索到 ${renderSelect.value.length} 条成就数据`);
|
||||
}
|
||||
|
||||
// 导入 UIAF 数据,进行数据合并、刷新
|
||||
async function importJson(): Promise<void> {
|
||||
await TGLogger.Info("[Achievements][importJson] 导入 UIAF 数据");
|
||||
const selectedFile = await dialog.open({
|
||||
title: "选择 UIAF 数据文件",
|
||||
multiple: false,
|
||||
@@ -285,6 +288,7 @@ async function importJson(): Promise<void> {
|
||||
color: "cancel",
|
||||
text: "已取消文件选择",
|
||||
});
|
||||
await TGLogger.Info("[Achievements][importJson] 已取消文件选择");
|
||||
return;
|
||||
}
|
||||
if (!(await verifyUiafData(<string>selectedFile))) {
|
||||
@@ -292,9 +296,15 @@ async function importJson(): Promise<void> {
|
||||
color: "error",
|
||||
text: "读取 UIAF 数据失败,请检查文件是否符合规范",
|
||||
});
|
||||
await TGLogger.Error("[Achievements][importJson] 读取 UIAF 数据失败,请检查文件是否符合规范");
|
||||
return;
|
||||
}
|
||||
const remoteRaw = await readUiafData(<string>selectedFile);
|
||||
await TGLogger.Info("[Achievements][importJson] 读取 UIAF 数据成功");
|
||||
await TGLogger.Info(`[Achievements][importJson] 导入来源:${remoteRaw.info.export_app}`);
|
||||
await TGLogger.Info(`[Achievements][importJson] 导入版本:${remoteRaw.info.export_app_version}`);
|
||||
await TGLogger.Info(`[Achievements][importJson] 导入时间:${remoteRaw.info.export_timestamp}`);
|
||||
await TGLogger.Info(`[Achievements][importJson] 导入数据:${remoteRaw.list.length} 条`);
|
||||
loadingTitle.value = "正在解析数据";
|
||||
loading.value = true;
|
||||
loadingTitle.value = "正在合并成就数据";
|
||||
@@ -307,12 +317,14 @@ async function importJson(): Promise<void> {
|
||||
|
||||
// 导出
|
||||
async function exportJson(): Promise<void> {
|
||||
await TGLogger.Info("[Achievements][exportJson] 导出 UIAF 数据");
|
||||
// 判断是否有数据
|
||||
if (achievementsStore.finAchievements === 0) {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "没有可导出的数据",
|
||||
});
|
||||
await TGLogger.Warn("[Achievements][exportJson] 没有可导出的数据");
|
||||
return;
|
||||
}
|
||||
// 获取本地数据
|
||||
@@ -331,15 +343,18 @@ async function exportJson(): Promise<void> {
|
||||
],
|
||||
defaultPath: `${await path.downloadDir()}${path.sep}${fileName}.json`,
|
||||
});
|
||||
if (isSave) {
|
||||
await fs.writeTextFile(isSave, JSON.stringify(UiafData));
|
||||
showSnackbar({ text: "导出成功" });
|
||||
} else {
|
||||
if (isSave === null) {
|
||||
showSnackbar({
|
||||
color: "warn",
|
||||
text: "导出已取消",
|
||||
text: "已取消导出",
|
||||
});
|
||||
await TGLogger.Info("[Achievements][exportJson] 已取消导出");
|
||||
return;
|
||||
}
|
||||
await fs.writeTextFile(isSave, JSON.stringify(UiafData));
|
||||
showSnackbar({ text: "导出成功" });
|
||||
await TGLogger.Info("[Achievements][exportJson] 导出成功");
|
||||
await TGLogger.Info(`[Achievements][exportJson] 导出路径:${isSave}`);
|
||||
}
|
||||
|
||||
function getIcon(series: number): string | undefined {
|
||||
@@ -348,6 +363,7 @@ function getIcon(series: number): string | undefined {
|
||||
|
||||
// 处理外部导入
|
||||
async function handleImportOuter(app: string): Promise<void> {
|
||||
await TGLogger.Info(`[Achievements][handleImportOuter] 导入来源:${app}`);
|
||||
const confirm = await showConfirm({
|
||||
title: "是否导入祈愿数据?",
|
||||
text: `来源APP:${app}`,
|
||||
@@ -357,6 +373,7 @@ async function handleImportOuter(app: string): Promise<void> {
|
||||
color: "warn",
|
||||
text: "已取消导入",
|
||||
});
|
||||
await TGLogger.Info("[Achievements][handleImportOuter] 已取消导入");
|
||||
return;
|
||||
}
|
||||
// 读取 剪贴板
|
||||
@@ -373,8 +390,11 @@ async function handleImportOuter(app: string): Promise<void> {
|
||||
color: "success",
|
||||
text: "导入成功,即将刷新页面",
|
||||
});
|
||||
await TGLogger.Info("[Achievements][handleImportOuter] 导入成功");
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (e instanceof Error)
|
||||
await TGLogger.Error(`[Achievements][handleImportOuter] 导入失败 ${e.name}: ${e.message}`);
|
||||
else console.error(e);
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "读取 UIAF 数据失败,请检查文件是否符合规范",
|
||||
@@ -411,6 +431,11 @@ async function setAchi(
|
||||
target ? "已完成" : "未完成"
|
||||
}`,
|
||||
});
|
||||
await TGLogger.Info(
|
||||
`[Achievements][setAchi] 已将成就 ${newAchievement.name}[${newAchievement.id}] 标记为 ${
|
||||
target ? "已完成" : "未完成"
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
/* 以下为数据库操作 */
|
||||
|
||||
@@ -42,6 +42,7 @@ import { nextTick, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { createTGWindow } from "../../utils/TGWindow";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
import TGUtils from "../../web/utils/TGUtils";
|
||||
@@ -74,6 +75,7 @@ const annoCards = ref<AnnoCard>({
|
||||
const annoData = ref<TGApp.BBS.Announcement.ListData>(<TGApp.BBS.Announcement.ListData>{});
|
||||
|
||||
onMounted(async () => {
|
||||
await TGLogger.Info("[Announcements][onMounted] 打开公告页面");
|
||||
loadingTitle.value = "正在获取公告数据";
|
||||
loading.value = true;
|
||||
annoData.value = await TGRequest.Anno.getList();
|
||||
@@ -84,7 +86,7 @@ onMounted(async () => {
|
||||
game: listCards.filter((item) => item.typeLabel === AnnoType.game),
|
||||
};
|
||||
loadingTitle.value = "正在渲染公告数据";
|
||||
await nextTick(() => {
|
||||
await nextTick(async () => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
@@ -96,13 +98,16 @@ function parseTitle(title: string): string {
|
||||
}
|
||||
|
||||
async function switchNews(): Promise<void> {
|
||||
await TGLogger.Info("[Announcements][switchNews] 切换米游社咨讯");
|
||||
await router.push("/news/2");
|
||||
}
|
||||
|
||||
function createAnno(item: TGApp.App.Announcement.ListCard): void {
|
||||
const annoPath = `/anno_detail/${item.id}`;
|
||||
const annoTitle = `Anno_${item.id} ${item.title}`;
|
||||
createTGWindow(annoPath, "Sub_window", annoTitle, 960, 720, false, false);
|
||||
TGLogger.Info(`[Announcements][createAnno][${item.id}] 打开公告窗口`).then(() =>
|
||||
createTGWindow(annoPath, "Sub_window", annoTitle, 960, 720, false, false),
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ import { useAppStore } from "../../store/modules/app";
|
||||
import { useHomeStore } from "../../store/modules/home";
|
||||
import { backUpUserData, restoreUserData } from "../../utils/dataBS";
|
||||
import { getBuildTime } from "../../utils/TGBuild";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { bytesToSize, getCacheDir, getDeviceInfo, getRandomString } from "../../utils/toolFunc";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
|
||||
@@ -83,7 +84,10 @@ const loadingTitle = ref<string>("正在加载...");
|
||||
const loadingSub = ref<string>("");
|
||||
const showReset = ref<boolean>(false);
|
||||
|
||||
onMounted(() => (loading.value = false));
|
||||
onMounted(async () => {
|
||||
await TGLogger.Info("[Config] 打开设置页面");
|
||||
loading.value = false;
|
||||
});
|
||||
|
||||
// 备份数据
|
||||
async function confirmBackup(): Promise<void> {
|
||||
@@ -112,6 +116,7 @@ async function confirmBackup(): Promise<void> {
|
||||
});
|
||||
return;
|
||||
}
|
||||
await TGLogger.Info(`[Config][confirmBackup] 选择备份路径 ${dir.toString()}`);
|
||||
if (typeof dir !== "string") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
@@ -120,6 +125,8 @@ async function confirmBackup(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
saveDir = dir;
|
||||
} else {
|
||||
await TGLogger.Info(`[Config][confirmBackup] 备份到默认路径 ${saveDir}`);
|
||||
}
|
||||
loadingTitle.value = "正在备份数据...";
|
||||
loading.value = true;
|
||||
@@ -127,6 +134,7 @@ async function confirmBackup(): Promise<void> {
|
||||
await backUpUserData(saveDir);
|
||||
loading.value = false;
|
||||
showSnackbar({ text: "数据已备份!" });
|
||||
await TGLogger.Info("[Config][confirmBackup] 备份完成");
|
||||
}
|
||||
|
||||
// 恢复数据
|
||||
@@ -156,6 +164,7 @@ async function confirmRestore(): Promise<void> {
|
||||
});
|
||||
return;
|
||||
}
|
||||
await TGLogger.Info(`[Config][confirmRestore] 选择恢复路径 ${dir.toString()}`);
|
||||
if (typeof dir !== "string") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
@@ -164,12 +173,16 @@ async function confirmRestore(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
saveDir = dir;
|
||||
} else {
|
||||
await TGLogger.Info(`[Config][confirmRestore] 恢复到默认路径 ${saveDir}`);
|
||||
}
|
||||
loadingTitle.value = "正在恢复数据...";
|
||||
loading.value = true;
|
||||
loadingSub.value = "祈愿数据需单独恢复";
|
||||
await restoreUserData(saveDir);
|
||||
loading.value = false;
|
||||
showSnackbar({ text: "数据已恢复!" });
|
||||
await TGLogger.Info("[Config][confirmRestore] 恢复完成");
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
@@ -194,6 +207,7 @@ async function confirmUpdate(title?: string): Promise<void> {
|
||||
showSnackbar({
|
||||
text: "数据库已更新!",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmUpdate] 数据库更新完成");
|
||||
// 刷新
|
||||
window.location.reload();
|
||||
}
|
||||
@@ -201,6 +215,7 @@ async function confirmUpdate(title?: string): Promise<void> {
|
||||
// 更新设备信息
|
||||
async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
if (force !== undefined && force) {
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice][force] 开始强制更新设备信息");
|
||||
const resF = await showConfirm({
|
||||
title: "确认强制更新设备信息吗?",
|
||||
text: `DeviceFp:${appStore.deviceInfo.device_fp}`,
|
||||
@@ -210,6 +225,7 @@ async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
text: "已取消强制更新设备信息",
|
||||
color: "cancel",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice][force] 取消强制更新设备信息");
|
||||
return;
|
||||
}
|
||||
appStore.deviceInfo = await TGRequest.Device.getFp();
|
||||
@@ -219,13 +235,17 @@ async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
text: `设备信息获取失败!已使用随机值 ${appStore.deviceInfo.device_fp} 代替`,
|
||||
color: "warn",
|
||||
});
|
||||
await TGLogger.Warn("[Config][confirmUpdateDevice][force] 设备信息获取失败!已使用随机值代替");
|
||||
} else {
|
||||
showSnackbar({
|
||||
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
|
||||
});
|
||||
}
|
||||
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(appStore.deviceInfo));
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice][force] 设备信息更新完成");
|
||||
return;
|
||||
}
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice] 开始更新设备信息");
|
||||
const localFp = getDeviceInfo("device_fp");
|
||||
if (localFp !== "0000000000000") {
|
||||
const res = await showConfirm({
|
||||
@@ -237,6 +257,7 @@ async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
text: "已取消更新设备信息",
|
||||
color: "cancel",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice] 取消更新设备信息");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -248,16 +269,19 @@ async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
showSnackbar({
|
||||
text: "设备信息获取失败!已使用随机值代替",
|
||||
});
|
||||
await TGLogger.Warn("[Config][confirmUpdateDevice] 设备信息获取失败!已使用随机值代替");
|
||||
return;
|
||||
}
|
||||
showSnackbar({
|
||||
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
|
||||
});
|
||||
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(appStore.deviceInfo));
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice] 设备信息更新完成");
|
||||
}
|
||||
|
||||
// 清除用户缓存
|
||||
async function confirmDelCache(): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmDelCache] 开始清除缓存");
|
||||
const CacheDir = await getCacheDir();
|
||||
if (CacheDir === false) {
|
||||
showSnackbar({
|
||||
@@ -276,6 +300,7 @@ async function confirmDelCache(): Promise<void> {
|
||||
cacheBSize += size;
|
||||
}
|
||||
const cacheSize = bytesToSize(cacheBSize);
|
||||
await TGLogger.Info(`[Config][confirmDelCache] 当前缓存大小为 ${cacheSize}`);
|
||||
loading.value = false;
|
||||
const timeEnd = Date.now();
|
||||
const res = await showConfirm({
|
||||
@@ -287,6 +312,7 @@ async function confirmDelCache(): Promise<void> {
|
||||
color: "cancel",
|
||||
text: "已取消清除缓存",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmDelCache] 取消清除缓存");
|
||||
return;
|
||||
}
|
||||
for (const dir of CacheDir) {
|
||||
@@ -295,15 +321,13 @@ async function confirmDelCache(): Promise<void> {
|
||||
showSnackbar({
|
||||
text: "缓存已清除!请重新启动应用!",
|
||||
});
|
||||
await new Promise(() => {
|
||||
setTimeout(async () => {
|
||||
await TauriProcess.exit();
|
||||
}, 1500);
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmDelCache] 缓存清除完成");
|
||||
await TauriProcess.exit();
|
||||
}
|
||||
|
||||
// 恢复默认设置
|
||||
async function confirmResetApp(): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmResetApp] 开始恢复默认设置");
|
||||
const res = await showConfirm({
|
||||
title: "确认恢复默认设置吗?",
|
||||
});
|
||||
@@ -312,11 +336,13 @@ async function confirmResetApp(): Promise<void> {
|
||||
color: "cancel",
|
||||
text: "已取消恢复默认设置",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmResetApp] 取消恢复默认设置");
|
||||
return;
|
||||
}
|
||||
appStore.init();
|
||||
homeStore.init();
|
||||
achievementsStore.init();
|
||||
await TGLogger.Info("[Config][confirmResetApp] 恢复默认设置完成");
|
||||
showSnackbar({ text: "已恢复默认配置!即将刷新页面..." });
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
@@ -354,6 +380,7 @@ async function tryShowReset(): Promise<void> {
|
||||
|
||||
// 重置数据库
|
||||
async function confirmResetDB(title?: string): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmResetDB] 开始重置数据库");
|
||||
const res = await showConfirm({
|
||||
title: title ?? "确认重置数据库吗?",
|
||||
text: "请确认已经备份关键数据",
|
||||
@@ -363,11 +390,13 @@ async function confirmResetDB(title?: string): Promise<void> {
|
||||
color: "cancel",
|
||||
text: "已取消重置数据库",
|
||||
});
|
||||
await TGLogger.Info("[Config][confirmResetDB] 取消重置数据库");
|
||||
return;
|
||||
}
|
||||
loadingTitle.value = "正在重置数据库...";
|
||||
loading.value = true;
|
||||
await TGSqlite.reset();
|
||||
await TGLogger.Info("[Config][confirmResetDB] 数据库重置完成");
|
||||
loading.value = false;
|
||||
showSnackbar({
|
||||
text: "数据库已重置!请进行再次检查。",
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, markRaw, onMounted, onUnmounted, onUpdated, ref, watch } from "vue";
|
||||
import { markRaw, onMounted, onUnmounted, onUpdated, ref } from "vue";
|
||||
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
import TCalendar from "../../components/home/t-calendar.vue";
|
||||
import TPool from "../../components/home/t-pool.vue";
|
||||
import TPosition from "../../components/home/t-position.vue";
|
||||
import TUserBadge from "../../components/home/t-userBadge.vue";
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import { useAppStore } from "../../store/modules/app";
|
||||
import { useHomeStore } from "../../store/modules/home";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
|
||||
// store
|
||||
const appStore = useAppStore();
|
||||
@@ -62,6 +62,8 @@ function readLoading(): void {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const items = showHome.value.join("、");
|
||||
await TGLogger.Info(`[Home][onMounted] 打开首页,当前显示:${items}`);
|
||||
loadingTitle.value = "正在加载首页";
|
||||
const isProdEnv = import.meta.env.MODE === "production";
|
||||
// 获取当前环境
|
||||
@@ -85,7 +87,7 @@ onMounted(async () => {
|
||||
timer.value = setInterval(readLoading, 100);
|
||||
});
|
||||
|
||||
function submitHome(): void {
|
||||
async function submitHome(): Promise<void> {
|
||||
// 获取已选
|
||||
const show = showHome.value;
|
||||
if (show.length < 1) {
|
||||
@@ -100,6 +102,7 @@ function submitHome(): void {
|
||||
color: "success",
|
||||
text: "设置成功!",
|
||||
});
|
||||
await TGLogger.Info("[Home][submitHome] 首页设置成功,当前显示:" + show.join("、"));
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
@@ -107,7 +110,11 @@ function submitHome(): void {
|
||||
|
||||
// 监听定时器
|
||||
onUpdated(() => {
|
||||
if (!loading.value) clearInterval(timer.value);
|
||||
if (!loading.value && timer.value !== null) {
|
||||
TGLogger.Info("[Home][onMounted] 首页加载完成");
|
||||
clearInterval(timer.value);
|
||||
timer.value = null;
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -97,6 +97,7 @@ import ToChannel from "../../components/overlay/to-channel.vue";
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import TpAvatar from "../../components/post/tp-avatar.vue";
|
||||
import Mys from "../../plugins/Mys";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { createPost } from "../../utils/TGWindow";
|
||||
|
||||
// 类型定义
|
||||
@@ -158,6 +159,7 @@ const rawData = ref<RawData>({
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await TGLogger.Info(`[News][${gid}][onMounted] 打开咨讯页面`);
|
||||
tab.value = "notice";
|
||||
await firstLoad("notice");
|
||||
});
|
||||
@@ -176,9 +178,11 @@ async function firstLoad(key: NewsKey): Promise<void> {
|
||||
await nextTick(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
await TGLogger.Info(`[News][${gid}][firstLoad] 获取${rawData.value[key].name}数据成功`);
|
||||
}
|
||||
|
||||
async function switchAnno(): Promise<void> {
|
||||
await TGLogger.Info(`[News][${gid}][switchAnno] 切换公告`);
|
||||
await router.push("/announcements");
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import TpAvatar from "../../components/post/tp-avatar.vue";
|
||||
import Mys from "../../plugins/Mys";
|
||||
import TGClient from "../../utils/TGClient";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { createPost } from "../../utils/TGWindow";
|
||||
|
||||
const loading = ref<boolean>(true);
|
||||
@@ -201,6 +202,9 @@ const nav = ref<TGApp.BBS.Navigator.Navigator[]>([]);
|
||||
const search = ref<string>();
|
||||
|
||||
onMounted(async () => {
|
||||
await TGLogger.Info(
|
||||
`[Posts][${curGameLabel.value}][onMounted][${curForumLabel.value}] 打开帖子列表`,
|
||||
);
|
||||
loading.value = true;
|
||||
await freshNavData();
|
||||
await freshPostData();
|
||||
@@ -287,10 +291,14 @@ function toBBS(link: URL): void {
|
||||
}
|
||||
|
||||
async function freshNavData(): Promise<void> {
|
||||
await TGLogger.Info(`[Posts][${curGameLabel.value}][freshNavData] 获取网页活动`);
|
||||
nav.value = await Mys.Posts.nav(curGid.value);
|
||||
}
|
||||
|
||||
async function freshPostData(): Promise<void> {
|
||||
await TGLogger.Info(
|
||||
`[Posts][${curGameLabel.value}][freshPostData][${curForumLabel.value}] 刷新帖子列表`,
|
||||
);
|
||||
loading.value = true;
|
||||
loadingTitle.value = `正在加载 ${curGameLabel.value}-${curForumLabel.value}-${curSortLabel.value} 的数据`;
|
||||
const postsGet = await Mys.Posts.get(curForum.value, curSortType.value);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/TGClient.ts
|
||||
* @desc 负责米游社客户端的 callback 处理
|
||||
* @since Beta v0.4.0
|
||||
* @since Beta v0.4.2
|
||||
*/
|
||||
|
||||
import { event, invoke } from "@tauri-apps/api";
|
||||
@@ -9,6 +9,7 @@ import type { Event } from "@tauri-apps/api/event";
|
||||
import { appWindow, WebviewWindow } from "@tauri-apps/api/window";
|
||||
|
||||
import { parseLink } from "./linkParser";
|
||||
import TGLogger from "./TGLogger";
|
||||
import { createPost } from "./TGWindow";
|
||||
import { getDeviceInfo } from "./toolFunc";
|
||||
import showSnackbar from "../components/func/snackbar";
|
||||
@@ -89,7 +90,7 @@ class TGClient {
|
||||
|
||||
/**
|
||||
* @func callback
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.4.2
|
||||
* @desc 回调函数
|
||||
* @param {string} callback - 回调函数名
|
||||
* @param {object} data - 回调数据
|
||||
@@ -103,7 +104,6 @@ class TGClient {
|
||||
};
|
||||
const js = `javascript:mhyWebBridge("${callback}", ${JSON.stringify(response)});`;
|
||||
console.info(`[callback] ${js}`);
|
||||
await invoke("create_mhy_client", { func: "execute_js", url: "" });
|
||||
await invoke("execute_js", { label: "mhy_client", js });
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ class TGClient {
|
||||
|
||||
/**
|
||||
* @func handleCallback
|
||||
* @since Beta v0.3.9
|
||||
* @since Beta v0.4.2
|
||||
* @desc 处理米游社客户端的 callback
|
||||
* @param {Event<string>} arg - 事件参数
|
||||
* @returns {Promise<void>} - 返回值
|
||||
@@ -178,7 +178,10 @@ class TGClient {
|
||||
await this.handleCustomCallback(argParse);
|
||||
return;
|
||||
}
|
||||
console.warn(`[${argParse.method}] ${JSON.stringify(argParse.payload)}`);
|
||||
await TGLogger.Warn(`[TGClient][handleCallback] ${JSON.stringify(argParse)}`, false);
|
||||
await TGLogger.Info(
|
||||
`[TGClient][handleCallback] 处理回调 ${argParse.method}:${argParse.callback}`,
|
||||
);
|
||||
await this.hideSideBar();
|
||||
await this.hideOverlay();
|
||||
switch (argParse.method) {
|
||||
@@ -275,6 +278,7 @@ class TGClient {
|
||||
* @returns {Promise<void>} - 返回值
|
||||
*/
|
||||
async handleCustomCallback(arg: TGApp.Plugins.JSBridge.Arg<any>): Promise<void> {
|
||||
await TGLogger.Info(`[TGClient][handleCustomCallback] ${JSON.stringify(arg)}`);
|
||||
switch (arg.method) {
|
||||
case "teyvat_open":
|
||||
createPost(<string>arg.payload);
|
||||
@@ -454,16 +458,13 @@ class TGClient {
|
||||
await this.window.close();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
await invoke<InvokeArg>("create_mhy_client", {
|
||||
func: "default",
|
||||
url: "https://api-static.mihoyo.com/",
|
||||
});
|
||||
await invoke<InvokeArg>("create_mhy_client", { func: "default", url: "" });
|
||||
await this.open(func, url);
|
||||
}
|
||||
}
|
||||
if (url === undefined) url = this.getUrl(func);
|
||||
this.route = [url];
|
||||
console.log(`[open] ${url}`);
|
||||
await TGLogger.Info(`[TGClient][open][${func}] ${url}`);
|
||||
await invoke<InvokeArg>("create_mhy_client", { func, url });
|
||||
this.window = WebviewWindow.getByLabel("mhy_client");
|
||||
await this.window?.show();
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**
|
||||
* @file utils/TGShare.ts
|
||||
* @description 生成分享截图并保存到本地
|
||||
* @since Beta v0.3.9
|
||||
* @since Beta v0.4.2
|
||||
*/
|
||||
|
||||
import { dialog, fs, http, path } from "@tauri-apps/api";
|
||||
import html2canvas from "html2canvas";
|
||||
|
||||
import TGLogger from "./TGLogger";
|
||||
import { bytesToSize } from "./toolFunc";
|
||||
import showConfirm from "../components/func/confirm";
|
||||
import showSnackbar from "../components/func/snackbar";
|
||||
|
||||
/**
|
||||
* @description 保存图片-canvas
|
||||
* @since Beta v0.3.7
|
||||
* @since Beta v0.4.2
|
||||
* @param {Uint8Array} buffer - 图片数据
|
||||
* @param {string} filename - 文件名
|
||||
* @returns {Promise<void>} 无返回值
|
||||
@@ -32,6 +33,7 @@ async function saveCanvasImg(buffer: Uint8Array, filename: string): Promise<void
|
||||
contents: buffer,
|
||||
});
|
||||
});
|
||||
await TGLogger.Info(`[saveCanvasImg][${filename}] 已将图像保存到本地`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +74,7 @@ function getShareImgBgColor(): string {
|
||||
|
||||
/**
|
||||
* @description 生成分享截图
|
||||
* @since Beta v0.3.9
|
||||
* @since Beta v0.4.2
|
||||
* @param {string} fileName - 文件名
|
||||
* @param {HTMLElement} element - 元素
|
||||
* @param {number} scale - 缩放比例
|
||||
@@ -108,6 +110,7 @@ export async function generateShareImg(
|
||||
);
|
||||
const size = buffer.length;
|
||||
const sizeStr = bytesToSize(size);
|
||||
await TGLogger.Info(`[generateShareImg][${fileName}] 图像大小为 ${sizeStr}`);
|
||||
if (size > 80000000) {
|
||||
showSnackbar({
|
||||
text: `图像大小为 ${sizeStr},过大,无法保存`,
|
||||
@@ -136,6 +139,7 @@ export async function generateShareImg(
|
||||
showSnackbar({
|
||||
text: `已将 ${fileName} 复制到剪贴板,大小为 ${sizeStr}`,
|
||||
});
|
||||
await TGLogger.Info(`[generateShareImg][${fileName}] 已将图像复制到剪贴板`);
|
||||
} catch (e) {
|
||||
await saveCanvasImg(buffer, fileName);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* @file utils/TGWindow.ts
|
||||
* @description 窗口创建相关工具函数
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.4.2
|
||||
*/
|
||||
|
||||
import { invoke, window as TauriWindow } from "@tauri-apps/api";
|
||||
import type { WindowOptions } from "@tauri-apps/api/types/window";
|
||||
|
||||
import TGLogger from "./TGLogger";
|
||||
|
||||
/**
|
||||
* @description 创建TG窗口
|
||||
* @since Beta v0.3.4
|
||||
@@ -71,7 +73,7 @@ export function createTGWindow(
|
||||
|
||||
/**
|
||||
* @description 打开帖子
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.4.2
|
||||
* @param {TGApp.Plugins.Mys.News.RenderCard | string | number | TGApp.Plugins.Mys.Forum.RenderCard} item 帖子内容或ID
|
||||
* @param {string} title 帖子标题
|
||||
* @returns {void}
|
||||
@@ -80,7 +82,7 @@ export function createPost(
|
||||
item: TGApp.Plugins.Mys.News.RenderCard | string | number | TGApp.Plugins.Mys.Forum.RenderCard,
|
||||
title?: string,
|
||||
): void {
|
||||
let postId, postTitle;
|
||||
let postId: string, postTitle: string;
|
||||
if (typeof item === "string" || typeof item === "number") {
|
||||
postId = item.toString();
|
||||
postTitle = title ? `Post_${postId} ${title}` : `Post_${postId}`;
|
||||
@@ -90,17 +92,7 @@ export function createPost(
|
||||
}
|
||||
const postPath = `/post_detail/${postId}`;
|
||||
createTGWindow(postPath, "Sub_window", postTitle, 960, 720, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打开 Wiki
|
||||
* @since Beta v0.3.8
|
||||
* @param {string} dir 目录
|
||||
* @param {string} name 文件名
|
||||
* @returns {void}
|
||||
*/
|
||||
export function createWiki(dir: string, name: string): void {
|
||||
const dirName = dir === "GCG" ? dir : dir.toLowerCase();
|
||||
const wikiPath = `/wiki/detail/${dirName}/${name}`;
|
||||
createTGWindow(wikiPath, "Sub_window", `Wiki_${dirName}_${name}`, 960, 720, false, false);
|
||||
TGLogger.Info(`[createPost][${postId}] 打开帖子`).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ onMounted(async () => {
|
||||
loadingEmpty.value = true;
|
||||
loadingTitle.value = "未找到数据";
|
||||
await appWindow.setTitle("未找到数据");
|
||||
await TGLogger.Error("[t-post.vue] PostID 不存在");
|
||||
await TGLogger.Error("[t-post][onMounted] PostID 不存在");
|
||||
return;
|
||||
}
|
||||
// 获取数据
|
||||
@@ -137,7 +137,7 @@ onMounted(async () => {
|
||||
await appWindow.setTitle(`Post_${postId} ${postData.value.post.subject}`);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await TGLogger.Error(`[t-post.vue] ${error.name}: ${error.message}`);
|
||||
await TGLogger.Error(`[t-post][${postId}] ${error.name}: ${error.message}`);
|
||||
loadingTitle.value = error.name;
|
||||
loadingSub.value = error.message;
|
||||
} else {
|
||||
@@ -149,9 +149,13 @@ onMounted(async () => {
|
||||
await appWindow.setTitle(`Post_${postId} Parsing Error`);
|
||||
return;
|
||||
}
|
||||
await TGLogger.Info(`[t-post][${postId}][onMounted] ${postData.value.post.subject}`);
|
||||
// 打开 json
|
||||
const isDev = useAppStore().devMode ?? false;
|
||||
if (isDev) createPostJson(postId);
|
||||
if (isDev) {
|
||||
await TGLogger.Info(`[t-post][${postId}][onMounted] 打开 JSON 窗口`);
|
||||
createPostJson(postId);
|
||||
}
|
||||
await nextTick(() => {
|
||||
shareTimeTimer.value = setInterval(() => {
|
||||
shareTime.value = Math.floor(Date.now() / 1000);
|
||||
@@ -161,15 +165,17 @@ onMounted(async () => {
|
||||
});
|
||||
});
|
||||
|
||||
watch(loadShare, (value) => {
|
||||
watch(loadShare, async (value) => {
|
||||
if (value) {
|
||||
shareTime.value = Math.floor(Date.now() / 1000);
|
||||
loadingTitle.value = "正在生成分享图片";
|
||||
loadingSub.value = `${shareTitle.value}.png`;
|
||||
loading.value = true;
|
||||
await TGLogger.Info(`[t-post.vue][${postId}][share] 生成分享图片:${shareTitle.value}.png`);
|
||||
} else {
|
||||
loadingSub.value = "";
|
||||
loading.value = false;
|
||||
await TGLogger.Info(`[t-post.vue][${postId}][share] 生成分享图片完成:${shareTitle.value}.png`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -191,8 +197,7 @@ function getRenderPost(data: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys
|
||||
jsonParse = parseContent(data.post.content);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error(e);
|
||||
TGLogger.Warn(`[t-post.vue] ${e.name}: ${e.message}`);
|
||||
TGLogger.Warn(`[t-post][${postId}] ${e.name}: ${e.message}`);
|
||||
}
|
||||
jsonParse = data.post.structured_content;
|
||||
}
|
||||
@@ -221,7 +226,7 @@ function parseContent(content: string): string {
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.warn(`[MysPostParser] Unknown key: ${key}`);
|
||||
TGLogger.Warn(`[t-post][${postId}][parseContent] Unknown key: ${key}`);
|
||||
result.push({
|
||||
insert: data[key],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user