refactor(vue): 重构代码,采用setup语法

This commit is contained in:
BTMuli
2023-03-09 16:19:26 +08:00
parent 817ccaf18a
commit 5bf45c6080
8 changed files with 455 additions and 564 deletions

View File

@@ -11,53 +11,51 @@
</v-layout>
</template>
<script lang="ts">
import { defineComponent } from "vue";
<script lang="ts" setup>
import TSidebar from "./components/t-sidebar.vue";
import useAppStore from "./store/modules/app";
import { TGAppDataList } from "./data";
import { fs } from "@tauri-apps/api";
import { BaseDirectory } from "@tauri-apps/api/fs";
import { onMounted } from "vue";
export default defineComponent({
name: "App",
components: {
TSidebar,
},
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("数据加载完成!");
}
},
const appStore = useAppStore();
onMounted(async () => {
await checkLoad();
});
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>