mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
refactor(vue): 重构代码,采用setup语法
This commit is contained in:
82
src/App.vue
82
src/App.vue
@@ -11,53 +11,51 @@
|
|||||||
</v-layout>
|
</v-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from "vue";
|
|
||||||
import TSidebar from "./components/t-sidebar.vue";
|
import TSidebar from "./components/t-sidebar.vue";
|
||||||
import useAppStore from "./store/modules/app";
|
import useAppStore from "./store/modules/app";
|
||||||
import { TGAppDataList } from "./data";
|
import { TGAppDataList } from "./data";
|
||||||
import { fs } from "@tauri-apps/api";
|
import { fs } from "@tauri-apps/api";
|
||||||
import { BaseDirectory } from "@tauri-apps/api/fs";
|
import { BaseDirectory } from "@tauri-apps/api/fs";
|
||||||
|
import { onMounted } from "vue";
|
||||||
|
|
||||||
export default defineComponent({
|
const appStore = useAppStore();
|
||||||
name: "App",
|
|
||||||
components: {
|
onMounted(async () => {
|
||||||
TSidebar,
|
await checkLoad();
|
||||||
},
|
|
||||||
async mounted() {
|
|
||||||
const appStore = useAppStore();
|
|
||||||
if (!appStore.loading) {
|
|
||||||
try {
|
|
||||||
await fs.readDir(`${appStore.dataPath.app}`);
|
|
||||||
} catch (e) {
|
|
||||||
await fs.createDir("appData", { dir: BaseDirectory.AppLocalData });
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await fs.readDir(`${appStore.dataPath.user}`);
|
|
||||||
} catch (e) {
|
|
||||||
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await fs.readDir(`${appStore.dataPath.merge}`);
|
|
||||||
} catch (e) {
|
|
||||||
await fs.createDir("mergeData", { dir: BaseDirectory.AppLocalData });
|
|
||||||
}
|
|
||||||
await console.log("检测到数据未加载,开始加载数据...");
|
|
||||||
TGAppDataList.AppData.map(async item => {
|
|
||||||
await fs.writeFile(
|
|
||||||
`${appStore.dataPath.app}\\${item.name}`,
|
|
||||||
JSON.stringify(item.data, null, 4)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
TGAppDataList.MergeData.map(async item => {
|
|
||||||
await fs.writeFile(
|
|
||||||
`${appStore.dataPath.merge}\\${item.name}`,
|
|
||||||
JSON.stringify(item.data, null, 4)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
appStore.loading = true;
|
|
||||||
await console.log("数据加载完成!");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
async function checkLoad() {
|
||||||
|
if (!appStore.loading) {
|
||||||
|
try {
|
||||||
|
await fs.readDir(`${appStore.dataPath.app}`);
|
||||||
|
} catch (e) {
|
||||||
|
await fs.createDir("appData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await fs.readDir(`${appStore.dataPath.user}`);
|
||||||
|
} catch (e) {
|
||||||
|
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await fs.readDir(`${appStore.dataPath.merge}`);
|
||||||
|
} catch (e) {
|
||||||
|
await fs.createDir("mergeData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
}
|
||||||
|
console.log("检测到数据未加载,开始加载数据...");
|
||||||
|
TGAppDataList.AppData.map(async item => {
|
||||||
|
await fs.writeFile(
|
||||||
|
`${appStore.dataPath.app}\\${item.name}`,
|
||||||
|
JSON.stringify(item.data, null, 4)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
TGAppDataList.MergeData.map(async item => {
|
||||||
|
await fs.writeFile(
|
||||||
|
`${appStore.dataPath.merge}\\${item.name}`,
|
||||||
|
JSON.stringify(item.data, null, 4)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
appStore.loading = true;
|
||||||
|
console.log("数据加载完成!");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -3,13 +3,11 @@
|
|||||||
<v-app-bar app>
|
<v-app-bar app>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<!-- 标题 -->
|
<!-- 标题 -->
|
||||||
<v-card-text class="text-h5">{{ title }}</v-card-text>
|
<v-card-text class="text-h5">{{ getTitle() }}</v-card-text>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<!-- 导入按钮 -->
|
<!-- 导入按钮 -->
|
||||||
<v-btn @click="importJson" prepend-icon="mdi-import" class="bg-green-accent-2">
|
<v-btn @click="importJson" prepend-icon="mdi-import" class="bg-green-accent-2"> 导入 </v-btn>
|
||||||
导入
|
|
||||||
</v-btn>
|
|
||||||
<!-- 导出按钮 -->
|
<!-- 导出按钮 -->
|
||||||
<v-btn @click="exportJson" prepend-icon="mdi-export" class="ms-2 bg-green-accent-2">
|
<v-btn @click="exportJson" prepend-icon="mdi-export" class="ms-2 bg-green-accent-2">
|
||||||
导出
|
导出
|
||||||
@@ -23,8 +21,7 @@
|
|||||||
</v-layout>
|
</v-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from "vue";
|
|
||||||
import useAppStore from "../store/modules/app";
|
import useAppStore from "../store/modules/app";
|
||||||
import useAchievementsStore from "../store/modules/achievements";
|
import useAchievementsStore from "../store/modules/achievements";
|
||||||
import UIAF_Oper from "../plugins/UIAF";
|
import UIAF_Oper from "../plugins/UIAF";
|
||||||
@@ -36,155 +33,126 @@ import {
|
|||||||
} from "../interface/Achievements";
|
} from "../interface/Achievements";
|
||||||
import TGMap from "../utils/TGMap";
|
import TGMap from "../utils/TGMap";
|
||||||
import { Map } from "../interface/Base";
|
import { Map } from "../interface/Base";
|
||||||
|
import { onMounted, ref } from "vue";
|
||||||
|
|
||||||
export default defineComponent({
|
// Store
|
||||||
name: "Achievements",
|
const appStore = useAppStore();
|
||||||
data() {
|
const achievementsStore = useAchievementsStore();
|
||||||
return {
|
|
||||||
// 标题 成就完成数/成就总数 完成率
|
// FileData
|
||||||
title: "" as string,
|
const mergeAchievementMap: TGMap<TGAchievementMap> = new TGMap<TGAchievementMap>(
|
||||||
// 成就系列列表,用于侧边栏
|
JSON.parse(await fs.readTextFile(appStore.mergePath.achievements))
|
||||||
seriesList: {} as Map<TGSeriesMap>,
|
);
|
||||||
// 成就列表-所有成就的数据
|
const mergeSeriesMap: TGMap<TGSeriesMap> = new TGMap<TGSeriesMap>(
|
||||||
achievementsList: {} as Map<TGAchievementMap>,
|
JSON.parse(await fs.readTextFile(appStore.mergePath.achievementSeries))
|
||||||
// 选中的成就系列 id,用于决定右侧显示的成就列表
|
);
|
||||||
selectedSeries: -1 as number,
|
|
||||||
};
|
// Data
|
||||||
},
|
let seriesList = ref(mergeSeriesMap.getMap() as Map<TGSeriesMap>);
|
||||||
async mounted() {
|
let achievementsList = ref(mergeAchievementMap.getMap() as Map<TGAchievementMap>);
|
||||||
await this.loadData();
|
let selectedSeries = ref(-1);
|
||||||
},
|
|
||||||
methods: {
|
onMounted(async () => {
|
||||||
// 加载数据,数据源:合并后的本地数据
|
await loadData();
|
||||||
async loadData() {
|
|
||||||
const appStore = useAppStore();
|
|
||||||
const achievementsStore = useAchievementsStore();
|
|
||||||
const localSeriesPath = appStore.mergePath.achievementSeries;
|
|
||||||
const localAchievementsPath = appStore.mergePath.achievements;
|
|
||||||
const seriesMap: TGMap<TGSeriesMap> = new TGMap<TGSeriesMap>(
|
|
||||||
JSON.parse(await fs.readTextFile(localSeriesPath))
|
|
||||||
);
|
|
||||||
const achievementsMap: TGMap<TGAchievementMap> = new TGMap<TGAchievementMap>(
|
|
||||||
JSON.parse(await fs.readTextFile(localAchievementsPath))
|
|
||||||
);
|
|
||||||
await achievementsStore.flushData(seriesMap);
|
|
||||||
this.title = this.getTitle();
|
|
||||||
this.achievementsList = achievementsMap.getMap();
|
|
||||||
this.seriesList = seriesMap.getMap();
|
|
||||||
},
|
|
||||||
// 获取标题
|
|
||||||
getTitle() {
|
|
||||||
const achievementsStore = useAchievementsStore();
|
|
||||||
const achievementsAll = achievementsStore.total_achievements;
|
|
||||||
const achievementsDone = achievementsStore.fin_achievements;
|
|
||||||
return `成就完成数:${achievementsDone}/${achievementsAll} 完成率:${(
|
|
||||||
(achievementsDone / achievementsAll) *
|
|
||||||
100
|
|
||||||
).toFixed(2)}%`;
|
|
||||||
},
|
|
||||||
// 导入 UIAF 数据,进行数据合并、刷新
|
|
||||||
async importJson() {
|
|
||||||
const appStore = useAppStore();
|
|
||||||
const localPath = appStore.userPath.achievements;
|
|
||||||
const selectedFile = await dialog.open({
|
|
||||||
multiple: false,
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: "JSON",
|
|
||||||
extensions: ["json"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
if (selectedFile && (await UIAF_Oper.importOper.checkUIAFData(<string>selectedFile))) {
|
|
||||||
const localRaw: string | false = await UIAF_Oper.importOper.readUIAFData(localPath);
|
|
||||||
const remoteRaw: string | false = await UIAF_Oper.importOper.readUIAFData(
|
|
||||||
<string>selectedFile
|
|
||||||
);
|
|
||||||
if (remoteRaw === false) {
|
|
||||||
await dialog.message("文件格式不正确,导入失败");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let remoteData: Achievements = JSON.parse(remoteRaw);
|
|
||||||
let localData: UIAF_Achievement[] = JSON.parse(localRaw || "[]");
|
|
||||||
// 因为
|
|
||||||
const mergeUIAF: UIAF_Achievement[] = await UIAF_Oper.importOper.mergeUIAFData(
|
|
||||||
localData,
|
|
||||||
remoteData
|
|
||||||
);
|
|
||||||
await fs.writeTextFile(localPath, JSON.stringify(mergeUIAF, null, 4));
|
|
||||||
// 读取本地 mergeData
|
|
||||||
const mergeAchievementMap: TGMap<TGAchievementMap> = new TGMap<TGAchievementMap>(
|
|
||||||
JSON.parse(await fs.readTextFile(appStore.mergePath.achievements))
|
|
||||||
);
|
|
||||||
const mergeSeriesMap: TGMap<TGSeriesMap> = new TGMap<TGSeriesMap>(
|
|
||||||
JSON.parse(await fs.readTextFile(appStore.mergePath.achievementSeries))
|
|
||||||
);
|
|
||||||
// 遍历 mergeUIAF,对 mergeData 进行更新
|
|
||||||
mergeUIAF.map(UIAF_Item => {
|
|
||||||
// 更新成就
|
|
||||||
if (mergeAchievementMap.has(UIAF_Item.id)) {
|
|
||||||
const achievement = mergeAchievementMap.get(UIAF_Item.id);
|
|
||||||
achievement.completed = true;
|
|
||||||
achievement.completed_time = new Date(
|
|
||||||
UIAF_Item.timestamp * 1000
|
|
||||||
).toLocaleString();
|
|
||||||
mergeAchievementMap.set(UIAF_Item.id, achievement);
|
|
||||||
// 如果成就系列中没有该成就,则添加
|
|
||||||
if (!mergeSeriesMap.has(achievement.series)) {
|
|
||||||
const series = mergeSeriesMap.get(achievement.series);
|
|
||||||
series.achievements.push(achievement.id);
|
|
||||||
mergeSeriesMap.set(achievement.series, series);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 更新成就系列
|
|
||||||
mergeSeriesMap.forEach(seriesMap => {
|
|
||||||
let completed = 0;
|
|
||||||
seriesMap.achievements.map(achievement => {
|
|
||||||
if (mergeAchievementMap.get(achievement).completed) {
|
|
||||||
completed++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
seriesMap.completed_count = completed;
|
|
||||||
seriesMap.total_count = seriesMap.achievements.length;
|
|
||||||
mergeSeriesMap.set(seriesMap.id, seriesMap);
|
|
||||||
});
|
|
||||||
// 写入数据
|
|
||||||
await fs.writeTextFile(
|
|
||||||
appStore.mergePath.achievements,
|
|
||||||
JSON.stringify(mergeAchievementMap.getMap(), null, 4)
|
|
||||||
);
|
|
||||||
await fs.writeTextFile(
|
|
||||||
appStore.mergePath.achievementSeries,
|
|
||||||
JSON.stringify(mergeSeriesMap.getMap(), null, 4)
|
|
||||||
);
|
|
||||||
// 刷新数据
|
|
||||||
await this.loadData();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 导出
|
|
||||||
async exportJson() {
|
|
||||||
const appStore = useAppStore();
|
|
||||||
const localPath = appStore.userPath.achievements;
|
|
||||||
await console.log("正在获取 UIAF 数据...");
|
|
||||||
const achievements: Achievements = await UIAF_Oper.exportOper.getAchievements(
|
|
||||||
localPath
|
|
||||||
);
|
|
||||||
await console.log("获取 UIAF 数据成功,开始导出...");
|
|
||||||
const is_save = await dialog.save({
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: "achievements",
|
|
||||||
extensions: ["json"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
if (is_save) {
|
|
||||||
await fs.writeTextFile(is_save, JSON.stringify(achievements, null, 4));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 加载数据,数据源:合并后的本地数据
|
||||||
|
async function loadData() {
|
||||||
|
await achievementsStore.flushData(mergeSeriesMap);
|
||||||
|
}
|
||||||
|
// 获取标题
|
||||||
|
async function getTitle() {
|
||||||
|
return `成就完成数:${achievementsStore.fin_achievements}/${
|
||||||
|
achievementsStore.total_achievements
|
||||||
|
} 完成率:${(
|
||||||
|
(achievementsStore.fin_achievements / achievementsStore.total_achievements) *
|
||||||
|
100
|
||||||
|
).toFixed(2)}%`;
|
||||||
|
}
|
||||||
|
// 导入 UIAF 数据,进行数据合并、刷新
|
||||||
|
async function importJson() {
|
||||||
|
const localPath = appStore.userPath.achievements;
|
||||||
|
const selectedFile = await dialog.open({
|
||||||
|
multiple: false,
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: "JSON",
|
||||||
|
extensions: ["json"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (selectedFile && (await UIAF_Oper.importOper.checkUIAFData(<string>selectedFile))) {
|
||||||
|
const localRaw: string | false = await UIAF_Oper.importOper.readUIAFData(localPath);
|
||||||
|
const remoteRaw: string | false = await UIAF_Oper.importOper.readUIAFData(<string>selectedFile);
|
||||||
|
if (remoteRaw === false) {
|
||||||
|
await dialog.message("文件格式不正确,导入失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let remoteData: Achievements = JSON.parse(remoteRaw);
|
||||||
|
let localData: UIAF_Achievement[] = JSON.parse(localRaw || "[]");
|
||||||
|
const mergeUIAF: UIAF_Achievement[] = await UIAF_Oper.importOper.mergeUIAFData(
|
||||||
|
localData,
|
||||||
|
remoteData
|
||||||
|
);
|
||||||
|
await fs.writeTextFile(localPath, JSON.stringify(mergeUIAF, null, 4));
|
||||||
|
// 遍历 mergeUIAF,对 mergeData 进行更新
|
||||||
|
mergeUIAF.map(UIAF_Item => {
|
||||||
|
// 更新成就
|
||||||
|
if (mergeAchievementMap.has(UIAF_Item.id)) {
|
||||||
|
const achievement = mergeAchievementMap.get(UIAF_Item.id);
|
||||||
|
achievement.completed = true;
|
||||||
|
achievement.completed_time = new Date(UIAF_Item.timestamp * 1000).toLocaleString();
|
||||||
|
mergeAchievementMap.set(UIAF_Item.id, achievement);
|
||||||
|
// 如果成就系列中没有该成就,则添加
|
||||||
|
if (!mergeSeriesMap.has(achievement.series)) {
|
||||||
|
const series = mergeSeriesMap.get(achievement.series);
|
||||||
|
series.achievements.push(achievement.id);
|
||||||
|
mergeSeriesMap.set(achievement.series, series);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 更新成就系列
|
||||||
|
mergeSeriesMap.forEach(seriesMap => {
|
||||||
|
let completed = 0;
|
||||||
|
seriesMap.achievements.map(achievement => {
|
||||||
|
if (mergeAchievementMap.get(achievement).completed) {
|
||||||
|
completed++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
seriesMap.completed_count = completed;
|
||||||
|
seriesMap.total_count = seriesMap.achievements.length;
|
||||||
|
mergeSeriesMap.set(seriesMap.id, seriesMap);
|
||||||
|
});
|
||||||
|
// 写入数据
|
||||||
|
await fs.writeTextFile(
|
||||||
|
appStore.mergePath.achievements,
|
||||||
|
JSON.stringify(mergeAchievementMap.getMap(), null, 4)
|
||||||
|
);
|
||||||
|
await fs.writeTextFile(
|
||||||
|
appStore.mergePath.achievementSeries,
|
||||||
|
JSON.stringify(mergeSeriesMap.getMap(), null, 4)
|
||||||
|
);
|
||||||
|
// 刷新数据
|
||||||
|
await loadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 导出
|
||||||
|
async function exportJson() {
|
||||||
|
const achievements: Achievements = await UIAF_Oper.exportOper.getAchievements(
|
||||||
|
appStore.userPath.achievements
|
||||||
|
);
|
||||||
|
const is_save = await dialog.save({
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: "achievements",
|
||||||
|
extensions: ["json"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (is_save) {
|
||||||
|
await fs.writeTextFile(is_save, JSON.stringify(achievements, null, 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css"></style>
|
<style lang="css"></style>
|
||||||
|
|||||||
@@ -29,65 +29,53 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from "vue";
|
|
||||||
import useAppStore from "../store/modules/app";
|
import useAppStore from "../store/modules/app";
|
||||||
import { dialog, fs } from "@tauri-apps/api";
|
import { dialog, fs } from "@tauri-apps/api";
|
||||||
import { BaseDirectory } from "@tauri-apps/api/fs";
|
import { BaseDirectory } from "@tauri-apps/api/fs";
|
||||||
import { TGAppDataList } from "../data";
|
import { TGAppDataList } from "../data";
|
||||||
export default defineComponent({
|
|
||||||
name: "Config",
|
// Store
|
||||||
data() {
|
const appStore = useAppStore();
|
||||||
return {
|
|
||||||
source: "本地",
|
// 打开用户数据目录
|
||||||
appStore: useAppStore(),
|
async function openMergeData() {
|
||||||
};
|
await dialog.open({
|
||||||
},
|
defaultPath: appStore.dataPath.merge,
|
||||||
methods: {
|
filters: [],
|
||||||
// 打开数据文件夹
|
});
|
||||||
async openMergeData() {
|
}
|
||||||
const appStore = useAppStore();
|
// 删除本地数据
|
||||||
const mergeDataPath = appStore.dataPath.merge;
|
async function deleteData() {
|
||||||
await dialog.open({
|
const res = await dialog.confirm("确定要删除用户数据吗?");
|
||||||
defaultPath: mergeDataPath,
|
if (res) {
|
||||||
filters: [],
|
await fs.removeDir("userData", {
|
||||||
});
|
dir: BaseDirectory.AppLocalData,
|
||||||
},
|
recursive: true,
|
||||||
// 删除数据
|
});
|
||||||
async deleteData() {
|
await fs.removeDir("mergeData", {
|
||||||
const res = await dialog.confirm("确定要删除用户数据吗?");
|
dir: BaseDirectory.AppLocalData,
|
||||||
if (res) {
|
recursive: true,
|
||||||
await fs.removeDir("userData", {
|
});
|
||||||
dir: BaseDirectory.AppLocalData,
|
await dialog.message("用户数据已删除!");
|
||||||
recursive: true,
|
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
||||||
});
|
await fs.createDir("mergeData", { dir: BaseDirectory.AppLocalData });
|
||||||
await fs.removeDir("mergeData", {
|
TGAppDataList.MergeData.map(async item => {
|
||||||
dir: BaseDirectory.AppLocalData,
|
await fs.writeFile(
|
||||||
recursive: true,
|
`${appStore.dataPath.merge}\\${item.name}`,
|
||||||
});
|
JSON.stringify(item.data, null, 4)
|
||||||
await dialog.message("用户数据已删除!");
|
);
|
||||||
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
});
|
||||||
await fs.createDir("mergeData", { dir: BaseDirectory.AppLocalData });
|
}
|
||||||
const appStore = useAppStore();
|
}
|
||||||
TGAppDataList.MergeData.map(async item => {
|
// 恢复默认配置
|
||||||
await fs.writeFile(
|
async function setDefaultConfig() {
|
||||||
`${appStore.dataPath.merge}\\${item.name}`,
|
const res = await dialog.confirm("确定要恢复默认配置吗?");
|
||||||
JSON.stringify(item.data, null, 4)
|
if (res) {
|
||||||
);
|
await appStore.init();
|
||||||
});
|
await dialog.message("已恢复默认配置!");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
// 恢复默认配置
|
|
||||||
async setDefaultConfig() {
|
|
||||||
const res = await dialog.confirm("确定要恢复默认配置吗?");
|
|
||||||
if (res) {
|
|
||||||
const appStore = useAppStore();
|
|
||||||
await appStore.init();
|
|
||||||
await dialog.message("已恢复默认配置!");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css"></style>
|
<style lang="css"></style>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<h1>开发</h1>
|
<h1>开发</h1>
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-list>
|
<v-list>
|
||||||
<v-list-item @click="initDev()" prepend-icon="mdi-refresh">
|
<v-list-item @click="devStore.init()" prepend-icon="mdi-refresh">
|
||||||
<v-list-item-title>初始化开发</v-list-item-title>
|
<v-list-item-title>初始化开发</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item @click="parseAchievement()" prepend-icon="mdi-export">
|
<v-list-item @click="parseAchievement()" prepend-icon="mdi-export">
|
||||||
@@ -15,8 +15,7 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from "vue";
|
|
||||||
import useDevStore from "../store/modules/dev";
|
import useDevStore from "../store/modules/dev";
|
||||||
import useAppStore from "../store/modules/app";
|
import useAppStore from "../store/modules/app";
|
||||||
import { dialog, fs } from "@tauri-apps/api";
|
import { dialog, fs } from "@tauri-apps/api";
|
||||||
@@ -36,204 +35,156 @@ import {
|
|||||||
import TGMap from "../utils/TGMap";
|
import TGMap from "../utils/TGMap";
|
||||||
import { TGAppData } from "../data";
|
import { TGAppData } from "../data";
|
||||||
|
|
||||||
export default defineComponent({
|
// Store
|
||||||
name: "Dev",
|
const appStore = useAppStore();
|
||||||
data() {
|
const devStore = useDevStore();
|
||||||
return {
|
|
||||||
originRaw: {
|
async function parseAchievement() {
|
||||||
Hutao: "" as string,
|
const appDataDir = appStore.devPath.app;
|
||||||
Paimon: "" as string,
|
// 读取原始数据
|
||||||
},
|
const hutaoAchievementData: HutaoAchievement[] = SnapHutaoData.Achievement.data;
|
||||||
|
const hutaoGoalData: HutaoGoal[] = SnapHutaoData.AchievementGoal.data;
|
||||||
|
const paimonSeriesMap: TGMap<PaimonSeries> = new TGMap<PaimonSeries>(
|
||||||
|
PaimonMoeData.Achievement.data
|
||||||
|
);
|
||||||
|
// 新建目标数据
|
||||||
|
const achievementSeries: TGSeries[] = [];
|
||||||
|
const achievement: TGAchievement[] = [];
|
||||||
|
// 先解析 Hutao 的成就数据
|
||||||
|
hutaoGoalData.map(hutaoGoalItem => {
|
||||||
|
const achievementSeriesItem: TGSeries = {
|
||||||
|
id: hutaoGoalItem.Id,
|
||||||
|
order: hutaoGoalItem.Order,
|
||||||
|
name: hutaoGoalItem.Name,
|
||||||
|
card: hutaoGoalItem?.FinishReward?.ID,
|
||||||
};
|
};
|
||||||
},
|
achievementSeries.push(achievementSeriesItem);
|
||||||
methods: {
|
});
|
||||||
async initDev() {
|
hutaoAchievementData.map(hutaoAchievementItem => {
|
||||||
const devStore = useDevStore();
|
const achievementItem: TGAchievement = {
|
||||||
devStore.showDev = false;
|
id: hutaoAchievementItem.Id,
|
||||||
devStore.magicCount = 0;
|
series: hutaoAchievementItem.Goal,
|
||||||
},
|
order: hutaoAchievementItem.Order,
|
||||||
async parseAchievement() {
|
name: hutaoAchievementItem.Title,
|
||||||
const appStore = useAppStore();
|
description: hutaoAchievementItem.Description,
|
||||||
const appDataDir = appStore.devPath.app;
|
reward: hutaoAchievementItem.FinishReward.ID,
|
||||||
console.log("正在读取原始数据...");
|
version: "",
|
||||||
// 读取原始数据
|
progress: hutaoAchievementItem.Progress,
|
||||||
console.log("正在读取 Snap.Hutao 数据库...");
|
};
|
||||||
const hutaoAchievementData: HutaoAchievement[] = SnapHutaoData.Achievement.data;
|
achievement.push(achievementItem);
|
||||||
console.log("读取胡桃成就数据成功!");
|
});
|
||||||
const hutaoGoalData: HutaoGoal[] = SnapHutaoData.AchievementGoal.data;
|
// 再解析 Paimon.moe 的成就数据
|
||||||
console.log("读取胡桃成就系列数据成功!");
|
paimonSeriesMap.forEach(paimonSeries => {
|
||||||
console.log("正在读取 Paimon.moe 数据库...");
|
const seriesItem: TGSeries | undefined = achievementSeries.find(
|
||||||
const paimonSeriesMap: TGMap<PaimonSeries> = new TGMap<PaimonSeries>(
|
achievementSeriesItem => achievementSeriesItem.name === paimonSeries.name
|
||||||
PaimonMoeData.Achievement.data
|
);
|
||||||
);
|
// 成就版本-暂存
|
||||||
console.log("读取 Paimon.moe 成就数据成功!");
|
let achievementVersion: string = "";
|
||||||
// 新建目标数据
|
paimonSeries.achievements.map(paimonAchievementItem => {
|
||||||
console.log("正在生成目标数据...");
|
if (Array.isArray(paimonAchievementItem)) {
|
||||||
const achievementSeries: TGSeries[] = [];
|
paimonAchievementItem.map(paimonAchievement => {
|
||||||
const achievement: TGAchievement[] = [];
|
// 查找成就中 id 相同的成就
|
||||||
// 先解析 Hutao 的成就数据
|
const achievementItem: TGAchievement | undefined = achievement.find(
|
||||||
console.log("正在解析胡桃成就系列数据...");
|
achievementItem => achievementItem.id === paimonAchievement.id
|
||||||
hutaoGoalData.map(hutaoGoalItem => {
|
);
|
||||||
const achievementSeriesItem: TGSeries = {
|
if (achievementItem) {
|
||||||
id: hutaoGoalItem.Id,
|
// 更新数据
|
||||||
order: hutaoGoalItem.Order,
|
achievementItem.version = paimonAchievement.ver;
|
||||||
name: hutaoGoalItem.Name,
|
if (seriesItem) {
|
||||||
card: hutaoGoalItem?.FinishReward?.ID,
|
if (achievementVersion === "") {
|
||||||
};
|
achievementVersion = paimonAchievement.ver;
|
||||||
achievementSeries.push(achievementSeriesItem);
|
} else {
|
||||||
});
|
// 比较 v1.1 和 v1.2 的大小
|
||||||
console.log("解析胡桃成就系列数据成功!");
|
if (achievementVersion < paimonAchievement.ver) {
|
||||||
console.log("正在解析胡桃成就数据...");
|
achievementVersion = paimonAchievement.ver;
|
||||||
hutaoAchievementData.map(hutaoAchievementItem => {
|
|
||||||
const achievementItem: TGAchievement = {
|
|
||||||
id: hutaoAchievementItem.Id,
|
|
||||||
series: hutaoAchievementItem.Goal,
|
|
||||||
order: hutaoAchievementItem.Order,
|
|
||||||
name: hutaoAchievementItem.Title,
|
|
||||||
description: hutaoAchievementItem.Description,
|
|
||||||
reward: hutaoAchievementItem.FinishReward.ID,
|
|
||||||
version: "",
|
|
||||||
progress: hutaoAchievementItem.Progress,
|
|
||||||
};
|
|
||||||
achievement.push(achievementItem);
|
|
||||||
});
|
|
||||||
console.log("解析胡桃成就数据成功!");
|
|
||||||
// 再解析 Paimon.moe 的成就数据
|
|
||||||
console.log("正在解析 Paimon.moe 成就数据...");
|
|
||||||
// 遍历 Paimon.moe 成就数据
|
|
||||||
paimonSeriesMap.forEach(paimonSeries => {
|
|
||||||
// 寻找成就系列中名称相同的成就系列
|
|
||||||
const seriesItem: TGSeries | undefined = achievementSeries.find(
|
|
||||||
achievementSeriesItem => achievementSeriesItem.name === paimonSeries.name
|
|
||||||
);
|
|
||||||
// 成就版本-暂存
|
|
||||||
let achievementVersion: string = "";
|
|
||||||
paimonSeries.achievements.map(paimonAchievementItem => {
|
|
||||||
// 判断是不是数组
|
|
||||||
if (Array.isArray(paimonAchievementItem)) {
|
|
||||||
paimonAchievementItem.map(paimonAchievement => {
|
|
||||||
// 查找成就中 id 相同的成就
|
|
||||||
const achievementItem: TGAchievement | undefined = achievement.find(
|
|
||||||
achievementItem => achievementItem.id === paimonAchievement.id
|
|
||||||
);
|
|
||||||
if (achievementItem) {
|
|
||||||
// 更新数据
|
|
||||||
achievementItem.version = paimonAchievement.ver;
|
|
||||||
if (seriesItem) {
|
|
||||||
if (achievementVersion === "") {
|
|
||||||
achievementVersion = paimonAchievement.ver;
|
|
||||||
} else {
|
|
||||||
// 比较 v1.1 和 v1.2 的大小
|
|
||||||
if (achievementVersion < paimonAchievement.ver) {
|
|
||||||
achievementVersion = paimonAchievement.ver;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 查找成就中 id 相同的成就
|
|
||||||
const achievementItem: TGAchievement | undefined = achievement.find(
|
|
||||||
achievementItem => achievementItem.id === paimonAchievementItem.id
|
|
||||||
);
|
|
||||||
if (achievementItem) {
|
|
||||||
// 更新数据
|
|
||||||
achievementItem.version = paimonAchievementItem.ver;
|
|
||||||
if (seriesItem) {
|
|
||||||
if (achievementVersion === "") {
|
|
||||||
achievementVersion = paimonAchievementItem.ver;
|
|
||||||
} else {
|
|
||||||
// 比较 v1.1 和 v1.2 的大小
|
|
||||||
if (achievementVersion < paimonAchievementItem.ver) {
|
|
||||||
achievementVersion = paimonAchievementItem.ver;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 更新成就系列版本
|
} else {
|
||||||
if (seriesItem && achievementVersion !== "") {
|
// 查找成就中 id 相同的成就
|
||||||
seriesItem.version = achievementVersion;
|
const achievementItem: TGAchievement | undefined = achievement.find(
|
||||||
|
achievementItem => achievementItem.id === paimonAchievementItem.id
|
||||||
|
);
|
||||||
|
if (achievementItem) {
|
||||||
|
// 更新数据
|
||||||
|
achievementItem.version = paimonAchievementItem.ver;
|
||||||
|
if (seriesItem) {
|
||||||
|
if (achievementVersion === "") {
|
||||||
|
achievementVersion = paimonAchievementItem.ver;
|
||||||
|
} else {
|
||||||
|
// 比较 v1.1 和 v1.2 的大小
|
||||||
|
if (achievementVersion < paimonAchievementItem.ver) {
|
||||||
|
achievementVersion = paimonAchievementItem.ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
console.log("解析 Paimon.moe 成就数据成功!");
|
});
|
||||||
// 输出数据
|
// 更新成就系列版本
|
||||||
console.log("正在输出目标数据...");
|
if (seriesItem && achievementVersion !== "") {
|
||||||
// 输出成就系列数据
|
seriesItem.version = achievementVersion;
|
||||||
console.log("正在输出成就系列数据...");
|
}
|
||||||
await fs.writeFile(
|
});
|
||||||
`${appDataDir}\\achievementSeries.json`,
|
// 输出数据
|
||||||
JSON.stringify(achievementSeries, null, 4)
|
await fs.writeFile(
|
||||||
);
|
`${appDataDir}\\achievementSeries.json`,
|
||||||
console.log("输出成就系列数据成功!");
|
JSON.stringify(achievementSeries, null, 4)
|
||||||
// 输出成就数据
|
);
|
||||||
console.log("正在输出成就数据...");
|
await fs.writeFile(`${appDataDir}\\achievements.json`, JSON.stringify(achievement, null, 4));
|
||||||
await fs.writeFile(
|
await dialog.message("文件已导出至 " + appDataDir);
|
||||||
`${appDataDir}\\achievements.json`,
|
}
|
||||||
JSON.stringify(achievement, null, 4)
|
async function mergeAchievement() {
|
||||||
);
|
const mergeDataDir = appStore.devPath.merge;
|
||||||
console.log("输出成就数据成功!");
|
// 读取原始数据
|
||||||
await dialog.message("文件已导出至 " + appDataDir);
|
const oriAchievement = TGAppData.AppData.achievements;
|
||||||
},
|
const oriSeries = TGAppData.AppData.achievementSeries;
|
||||||
async mergeAchievement() {
|
// 读取合并数据
|
||||||
const appStore = useAppStore();
|
const transSeries: TGMap<TGSeriesMap> = new TGMap<TGSeriesMap>();
|
||||||
const mergeDataDir = appStore.devPath.merge;
|
const transAchievement: TGMap<TGAchievementMap> = new TGMap<TGAchievementMap>();
|
||||||
console.log("正在读取原始数据...");
|
// 先遍历成就系列生成成就系列数据
|
||||||
const oriAchievement = TGAppData.AppData.achievements;
|
oriSeries.map(oriSeriesItem => {
|
||||||
const oriSeries = TGAppData.AppData.achievementSeries;
|
transSeries.set(oriSeriesItem.id, {
|
||||||
console.log("读取原始数据成功!");
|
id: oriSeriesItem.id,
|
||||||
console.log("正在进行处理...");
|
order: oriSeriesItem.order,
|
||||||
const transSeries: TGMap<TGSeriesMap> = new TGMap<TGSeriesMap>();
|
name: oriSeriesItem.name,
|
||||||
const transAchievement: TGMap<TGAchievementMap> = new TGMap<TGAchievementMap>();
|
achievements: [],
|
||||||
// 先遍历成就系列生成成就系列数据
|
total_count: 0,
|
||||||
oriSeries.map(oriSeriesItem => {
|
completed_count: 0,
|
||||||
transSeries.set(oriSeriesItem.id, {
|
});
|
||||||
id: oriSeriesItem.id,
|
});
|
||||||
order: oriSeriesItem.order,
|
// 遍历成就
|
||||||
name: oriSeriesItem.name,
|
oriAchievement.map(oriAchievementItem => {
|
||||||
achievements: [],
|
// 生成成就数据
|
||||||
total_count: 0,
|
transAchievement.set(oriAchievementItem.id, {
|
||||||
completed_count: 0,
|
id: oriAchievementItem.id,
|
||||||
});
|
series: oriAchievementItem.series,
|
||||||
});
|
order: oriAchievementItem.order,
|
||||||
// 遍历成就
|
name: oriAchievementItem.name,
|
||||||
oriAchievement.map(oriAchievementItem => {
|
description: oriAchievementItem.description,
|
||||||
// 生成成就数据
|
reward: oriAchievementItem.reward,
|
||||||
transAchievement.set(oriAchievementItem.id, {
|
completed: false,
|
||||||
id: oriAchievementItem.id,
|
});
|
||||||
series: oriAchievementItem.series,
|
// 默认成就系列是完备的,所以不需要判断成就系列是否存在
|
||||||
order: oriAchievementItem.order,
|
// 更新成就系列数据的 achievements 跟 total_count
|
||||||
name: oriAchievementItem.name,
|
const seriesItem = transSeries.get(oriAchievementItem.series);
|
||||||
description: oriAchievementItem.description,
|
seriesItem.achievements.push(oriAchievementItem.id);
|
||||||
reward: oriAchievementItem.reward,
|
seriesItem.total_count += 1;
|
||||||
completed: false,
|
transSeries.set(oriAchievementItem.series, seriesItem);
|
||||||
});
|
});
|
||||||
// 默认成就系列是完备的,所以不需要判断成就系列是否存在
|
// 写入文件
|
||||||
// 更新成就系列数据的 achievements 跟 total_count
|
await fs.writeTextFile(
|
||||||
const seriesItem = transSeries.get(oriAchievementItem.series);
|
`${mergeDataDir}\\achievementSeries.json`,
|
||||||
seriesItem.achievements.push(oriAchievementItem.id);
|
JSON.stringify(transSeries.getMap(), null, 4)
|
||||||
seriesItem.total_count += 1;
|
);
|
||||||
transSeries.set(oriAchievementItem.series, seriesItem);
|
await fs.writeTextFile(
|
||||||
});
|
`${mergeDataDir}\\achievements.json`,
|
||||||
console.log("处理完成!");
|
JSON.stringify(transAchievement.getMap(), null, 4)
|
||||||
// 写入文件
|
);
|
||||||
console.log("正在写入文件...");
|
await dialog.message("文件已导出至 " + mergeDataDir);
|
||||||
console.log("正在写入成就系列数据...");
|
}
|
||||||
await fs.writeTextFile(
|
|
||||||
`${mergeDataDir}\\achievementSeries.json`,
|
|
||||||
JSON.stringify(transSeries.getMap(), null, 4)
|
|
||||||
);
|
|
||||||
console.log("写入成就系列数据成功!正在写入成就数据...");
|
|
||||||
await fs.writeTextFile(
|
|
||||||
`${mergeDataDir}\\achievements.json`,
|
|
||||||
JSON.stringify(transAchievement.getMap(), null, 4)
|
|
||||||
);
|
|
||||||
console.log("写入成就数据成功!");
|
|
||||||
await dialog.message("文件已导出至 " + mergeDataDir);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css"></style>
|
<style lang="css"></style>
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
<h1>首页</h1>
|
<h1>首页</h1>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup></script>
|
||||||
import { defineComponent } from "vue";
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: "Home",
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="css"></style>
|
<style lang="css"></style>
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
</v-window>
|
</v-window>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import {
|
import {
|
||||||
MysPostType,
|
MysPostType,
|
||||||
ResponseNewsList,
|
ResponseNewsList,
|
||||||
@@ -79,121 +79,109 @@ import {
|
|||||||
// import { http,window as TauriWindow } from "@tauri-apps/api";
|
// import { http,window as TauriWindow } from "@tauri-apps/api";
|
||||||
import { http } from "@tauri-apps/api";
|
import { http } from "@tauri-apps/api";
|
||||||
|
|
||||||
const MysApi = "https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&type=";
|
// 常量
|
||||||
|
const MysNewsApi = "https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&type=";
|
||||||
|
const MysPostApi = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id=";
|
||||||
|
|
||||||
export interface CardDataType {
|
// 接口 todo:考虑放到 interface 文件夹下?
|
||||||
|
interface CardDataType {
|
||||||
title: string;
|
title: string;
|
||||||
cover: string;
|
cover: string;
|
||||||
post_id: string;
|
post_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
// 数据
|
||||||
name: "News",
|
const tab = ref("activity");
|
||||||
// 进入页面时,获取数据
|
let postData = {
|
||||||
mounted() {
|
activity: {} as CardDataType[],
|
||||||
this.getPosts();
|
news: {} as CardDataType[],
|
||||||
},
|
notice: {} as CardDataType[],
|
||||||
data() {
|
};
|
||||||
return {
|
|
||||||
tab: "activity",
|
onMounted(async () => {
|
||||||
postData: {
|
await getPosts();
|
||||||
activity: {} as CardDataType[],
|
|
||||||
news: {} as CardDataType[],
|
|
||||||
notice: {} as CardDataType[],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async getPosts() {
|
|
||||||
console.log("正在获取数据...");
|
|
||||||
console.log("正在获取活动数据...");
|
|
||||||
const activityRaw: ResponseNewsList = await http
|
|
||||||
.fetch(MysApi + EnumPostType.Activity)
|
|
||||||
.then(res => res.data as Promise<ResponseNewsList>);
|
|
||||||
console.log("正在获取新闻数据...");
|
|
||||||
const newsRaw: ResponseNewsList = await http
|
|
||||||
.fetch(MysApi + EnumPostType.News)
|
|
||||||
.then(res => res.data as Promise<ResponseNewsList>);
|
|
||||||
console.log("正在获取公告数据...");
|
|
||||||
const noticeRaw: ResponseNewsList = await http
|
|
||||||
.fetch(MysApi + EnumPostType.Notice)
|
|
||||||
.then(res => res.data as Promise<ResponseNewsList>);
|
|
||||||
console.log("数据获取完毕,正在转换数据...");
|
|
||||||
console.log("正在转换数据...");
|
|
||||||
this.postData = {
|
|
||||||
activity: this.transData(activityRaw),
|
|
||||||
news: this.transData(newsRaw),
|
|
||||||
notice: this.transData(noticeRaw),
|
|
||||||
};
|
|
||||||
console.log("数据转换完毕");
|
|
||||||
},
|
|
||||||
transData(rawData: ResponseNewsList) {
|
|
||||||
let cardData: CardDataType[] = [];
|
|
||||||
rawData.data.list.map((item: ResponseNews) => {
|
|
||||||
const postData: MysPostType = item.post;
|
|
||||||
const card: CardDataType = {
|
|
||||||
title: postData.subject,
|
|
||||||
cover: postData.images[0],
|
|
||||||
post_id: postData.post_id,
|
|
||||||
};
|
|
||||||
return cardData.push(card);
|
|
||||||
});
|
|
||||||
return cardData;
|
|
||||||
},
|
|
||||||
async toPost(post_id: string) {
|
|
||||||
// 获取帖子内容
|
|
||||||
const post: MysPostType = await this.getPost(post_id).then(res => {
|
|
||||||
return res.data.post.post;
|
|
||||||
});
|
|
||||||
// 将内容转换为 html
|
|
||||||
const postHtml = new DOMParser().parseFromString(post.content, "text/html");
|
|
||||||
// 用帖子标题替换 html 中的标题
|
|
||||||
postHtml.title = post.subject;
|
|
||||||
// 四周留白
|
|
||||||
postHtml.body.style.padding = "12%";
|
|
||||||
postHtml.querySelectorAll("img").forEach(img => {
|
|
||||||
img.style.width = "100%";
|
|
||||||
});
|
|
||||||
// 将 html 转为能够通过 window.open 打开的 url
|
|
||||||
const postUrl = URL.createObjectURL(
|
|
||||||
new Blob([postHtml.documentElement.outerHTML], { type: "text/html;charset=utf-8" })
|
|
||||||
);
|
|
||||||
// 打开新窗口,窗口位置居中
|
|
||||||
// 获取窗口宽度
|
|
||||||
const width = window.screen.width;
|
|
||||||
// 获取窗口高度
|
|
||||||
const height = window.screen.height;
|
|
||||||
// 计算窗口位置
|
|
||||||
const left = width / 2 - 480;
|
|
||||||
const top = height / 2 - 360;
|
|
||||||
// 打开窗口
|
|
||||||
window.open(postUrl, "_blank", `width=960,height=720,left=${left},top=${top}`);
|
|
||||||
// new TauriWindow.WebviewWindow("blob", {
|
|
||||||
// url: postUrl,
|
|
||||||
// title: post.subject,
|
|
||||||
// decorations: true,
|
|
||||||
// width: 960,
|
|
||||||
// x: left,
|
|
||||||
// y: top,
|
|
||||||
// height: 720,
|
|
||||||
// resizable: false,
|
|
||||||
// });
|
|
||||||
},
|
|
||||||
getPost(post_id: string): Promise<ResponsePost> {
|
|
||||||
const postUrl = `https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id=${post_id}`;
|
|
||||||
return http
|
|
||||||
.fetch(postUrl, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
referer: `https://bbs.mihoyo.com/ys/article/${post_id}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
return res.data as Promise<ResponsePost>;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function getPosts() {
|
||||||
|
const activityRaw: ResponseNewsList = await http
|
||||||
|
.fetch(MysNewsApi + EnumPostType.Activity)
|
||||||
|
.then(res => res.data as Promise<ResponseNewsList>);
|
||||||
|
const newsRaw: ResponseNewsList = await http
|
||||||
|
.fetch(MysNewsApi + EnumPostType.News)
|
||||||
|
.then(res => res.data as Promise<ResponseNewsList>);
|
||||||
|
const noticeRaw: ResponseNewsList = await http
|
||||||
|
.fetch(MysNewsApi + EnumPostType.Notice)
|
||||||
|
.then(res => res.data as Promise<ResponseNewsList>);
|
||||||
|
postData = {
|
||||||
|
activity: transData(activityRaw),
|
||||||
|
news: transData(newsRaw),
|
||||||
|
notice: transData(noticeRaw),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function transData(rawData: ResponseNewsList) {
|
||||||
|
let cardData: CardDataType[] = [];
|
||||||
|
rawData.data.list.map((item: ResponseNews) => {
|
||||||
|
const postData: MysPostType = item.post;
|
||||||
|
const card: CardDataType = {
|
||||||
|
title: postData.subject,
|
||||||
|
cover: postData.images[0],
|
||||||
|
post_id: postData.post_id,
|
||||||
|
};
|
||||||
|
return cardData.push(card);
|
||||||
|
});
|
||||||
|
return cardData;
|
||||||
|
}
|
||||||
|
async function toPost(post_id: string) {
|
||||||
|
// 获取帖子内容
|
||||||
|
const post: MysPostType = await getPost(post_id).then(res => {
|
||||||
|
return res.data.post.post;
|
||||||
|
});
|
||||||
|
// 将内容转换为 html
|
||||||
|
const postHtml = new DOMParser().parseFromString(post.content, "text/html");
|
||||||
|
// 用帖子标题替换 html 中的标题
|
||||||
|
postHtml.title = post.subject;
|
||||||
|
// 四周留白
|
||||||
|
postHtml.body.style.padding = "12%";
|
||||||
|
postHtml.querySelectorAll("img").forEach(img => {
|
||||||
|
img.style.width = "100%";
|
||||||
|
});
|
||||||
|
// 将 html 转为能够通过 window.open 打开的 url
|
||||||
|
const postUrl = URL.createObjectURL(
|
||||||
|
new Blob([postHtml.documentElement.outerHTML], { type: "text/html;charset=utf-8" })
|
||||||
|
);
|
||||||
|
// 打开新窗口,窗口位置居中
|
||||||
|
// 获取窗口宽度
|
||||||
|
const width = window.screen.width;
|
||||||
|
// 获取窗口高度
|
||||||
|
const height = window.screen.height;
|
||||||
|
// 计算窗口位置
|
||||||
|
const left = width / 2 - 480;
|
||||||
|
const top = height / 2 - 360;
|
||||||
|
// 打开窗口
|
||||||
|
window.open(postUrl, "_blank", `width=960,height=720,left=${left},top=${top}`);
|
||||||
|
// new TauriWindow.WebviewWindow("blob", {
|
||||||
|
// url: postUrl,
|
||||||
|
// title: post.subject,
|
||||||
|
// decorations: true,
|
||||||
|
// width: 960,
|
||||||
|
// x: left,
|
||||||
|
// y: top,
|
||||||
|
// height: 720,
|
||||||
|
// resizable: false,
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
async function getPost(post_id: string): Promise<ResponsePost> {
|
||||||
|
return http
|
||||||
|
.fetch(`${MysPostApi}${post_id}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
referer: `https://bbs.mihoyo.com/ys/article/${post_id}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
return res.data as Promise<ResponsePost>;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css">
|
<style lang="css">
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ export async function mergeUIAFData(
|
|||||||
// 遍历 remoteData.list
|
// 遍历 remoteData.list
|
||||||
remoteData.list.map((remoteAchievement: UIAF_Achievement) => {
|
remoteData.list.map((remoteAchievement: UIAF_Achievement) => {
|
||||||
// 查找 id 相同的 localAchievement
|
// 查找 id 相同的 localAchievement
|
||||||
const localAchievement = localData.find(
|
const localAchievement = localData.find(achievement => achievement.id === remoteAchievement.id);
|
||||||
achievement => achievement.id === remoteAchievement.id
|
|
||||||
);
|
|
||||||
// 如果没找到,就直接添加
|
// 如果没找到,就直接添加
|
||||||
if (localAchievement === undefined) {
|
if (localAchievement === undefined) {
|
||||||
localData.push(remoteAchievement);
|
localData.push(remoteAchievement);
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ const useDevStore = defineStore({
|
|||||||
magicCount: 0,
|
magicCount: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
actions: {
|
||||||
|
init() {
|
||||||
|
this.showDev = false;
|
||||||
|
this.magicCount = 0;
|
||||||
|
},
|
||||||
|
},
|
||||||
persist: true,
|
persist: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user