-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/create-evoker/template-example/src/pages/API/File.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<template> | ||
<img class="w-full" mode="widthFix" :src="src" /> | ||
<button type="primary" @click="chooseImage">+</button> | ||
<button :disabled="!tempFilePath" @click="saveFile">保存文件</button> | ||
<button :disabled="!savedFilePath" @click="removeFile">删除文件</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, computed } from "vue" | ||
import { usePage } from "evoker" | ||
const fs = ek.getFileSystemManager() | ||
const KEY = "savedFilePath" | ||
const tempFilePath = ref("") | ||
const savedFilePath = ref("") | ||
const src = computed(() => { | ||
return savedFilePath.value || tempFilePath.value | ||
}) | ||
const { onLoad } = usePage() | ||
onLoad(async () => { | ||
savedFilePath.value = await ek.getStorage({ key: KEY }) | ||
}) | ||
const chooseImage = async () => { | ||
try { | ||
const res = await ek.chooseImage({ count: 1 }) | ||
const path = res.tempFilePaths[0] | ||
tempFilePath.value = path | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
const saveFile = async () => { | ||
if (!tempFilePath.value) { | ||
return | ||
} | ||
try { | ||
savedFilePath.value = fs.saveFileSync(tempFilePath.value) | ||
tempFilePath.value = "" | ||
ek.setStorage({ key: KEY, data: savedFilePath.value }) | ||
ek.showToast({ title: "保存成功, 退出应用后不会被删除", icon: "none" }) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
const removeFile = async () => { | ||
if (!savedFilePath.value) { | ||
return | ||
} | ||
try { | ||
await fs.removeSavedFile({ filePath: savedFilePath.value }) | ||
ek.removeStorage({ key: KEY }) | ||
savedFilePath.value = "" | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters