mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
feat(config): 配置文件的导入\读取\删除草创
* 后续只保留 appData,userData 默认清空
This commit is contained in:
10859
src/data/app/achievements.json
Normal file
10859
src/data/app/achievements.json
Normal file
File diff suppressed because it is too large
Load Diff
10
src/data/app/index.ts
Normal file
10
src/data/app/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import achievements from "./achievements.json?raw";
|
||||||
|
|
||||||
|
const appData = [
|
||||||
|
{
|
||||||
|
name: "achievements.json",
|
||||||
|
data: achievements,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default appData;
|
||||||
8
src/data/index.ts
Normal file
8
src/data/index.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import appData from "./app";
|
||||||
|
import userDate from "./user";
|
||||||
|
|
||||||
|
const TauriGenshinData = {
|
||||||
|
appData: appData,
|
||||||
|
userData: userDate,
|
||||||
|
};
|
||||||
|
export default TauriGenshinData;
|
||||||
5302
src/data/user/achievements.json
Normal file
5302
src/data/user/achievements.json
Normal file
File diff suppressed because it is too large
Load Diff
10
src/data/user/index.ts
Normal file
10
src/data/user/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import achievements from "./achievements.json?raw";
|
||||||
|
|
||||||
|
const userDate = [
|
||||||
|
{
|
||||||
|
name: "achievements.json",
|
||||||
|
data: achievements,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default userDate;
|
||||||
@@ -1,12 +1,108 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>设置页面</h1>
|
<v-card>
|
||||||
|
<v-card-title>配置</v-card-title>
|
||||||
|
<v-list>
|
||||||
|
<v-list-item @click="checkData" prepend-icon="mdi-folder">
|
||||||
|
<v-list-item-title>检测数据</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
<v-list-item @click="setAppData" prepend-icon="mdi-folder">
|
||||||
|
<v-list-item-title>导入数据</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
<v-list-item @click="openUserData" prepend-icon="mdi-folder">
|
||||||
|
<v-list-item-title>打开用户数据目录</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
<v-list-item @click="deleteUserData" prepend-icon="mdi-delete">
|
||||||
|
<v-list-item-title>删除用户数据</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
<v-list-item @click="setDefaultConfig" prepend-icon="mdi-cog">
|
||||||
|
<v-list-item-title>恢复默认配置</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
</v-list>
|
||||||
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
import useAppStore from "../store/modules/app";
|
||||||
|
import { dialog, fs, path, notification } from "@tauri-apps/api";
|
||||||
|
import { BaseDirectory } from "@tauri-apps/api/fs";
|
||||||
|
import TauriGenshinData from "../data";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "Config",
|
name: "Config",
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
source: "本地",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 检测本地数据
|
||||||
|
async checkData() {
|
||||||
|
if (await this.checkDir()) {
|
||||||
|
await notification.sendNotification("数据目录不为空,检测成功");
|
||||||
|
} else {
|
||||||
|
await notification.sendNotification("数据目录为空,正在导入数据...");
|
||||||
|
await this.setAppData();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 检查数据目录是否为空
|
||||||
|
async checkDir() {
|
||||||
|
const appStore = useAppStore();
|
||||||
|
try {
|
||||||
|
await fs.readDir(`${appStore.dataPath.app}`);
|
||||||
|
await fs.readDir(`${appStore.dataPath.user}`);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
await fs.createDir("appData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 导入数据
|
||||||
|
async setAppData() {
|
||||||
|
const appStore = useAppStore();
|
||||||
|
TauriGenshinData.appData.map(async item => {
|
||||||
|
await fs.writeFile(`${appStore.dataPath.app}\\${item.name}`, item.data);
|
||||||
|
});
|
||||||
|
TauriGenshinData.userData.map(async item => {
|
||||||
|
await fs.writeFile(`${appStore.dataPath.user}\\${item.name}`, item.data);
|
||||||
|
});
|
||||||
|
await dialog.message("数据导入成功");
|
||||||
|
},
|
||||||
|
// 打开数据文件夹
|
||||||
|
async openUserData() {
|
||||||
|
const appStore = useAppStore();
|
||||||
|
const appDataPath = appStore.dataPath.user;
|
||||||
|
await dialog.open({
|
||||||
|
defaultPath: appDataPath,
|
||||||
|
filters: [],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 删除数据
|
||||||
|
async deleteUserData() {
|
||||||
|
const res = await dialog.confirm("确定要删除用户数据吗?");
|
||||||
|
if (res) {
|
||||||
|
await fs.removeDir("userData", {
|
||||||
|
dir: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await dialog.message("用户数据已删除!");
|
||||||
|
await fs.createDir("userData", { dir: BaseDirectory.AppLocalData });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 恢复默认配置
|
||||||
|
async setDefaultConfig() {
|
||||||
|
const res = await dialog.confirm("确定要恢复默认配置吗?");
|
||||||
|
if (res) {
|
||||||
|
const appStore = useAppStore();
|
||||||
|
const appLocalDataDir = await path.appLocalDataDir();
|
||||||
|
appStore.dataPath = {
|
||||||
|
app: `${appLocalDataDir}appData`,
|
||||||
|
user: `${appLocalDataDir}userData`,
|
||||||
|
};
|
||||||
|
await dialog.message("已恢复默认配置!");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ const useAppStore = defineStore({
|
|||||||
sidebar: {
|
sidebar: {
|
||||||
expand: true,
|
expand: true,
|
||||||
},
|
},
|
||||||
dataPath: "",
|
dataPath: {
|
||||||
|
app: "",
|
||||||
|
user: "",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
actions: {
|
|
||||||
setDataPath(path: string) {
|
|
||||||
this.dataPath = path;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
persist: true,
|
persist: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user