Skip to content

Commit

Permalink
feat(create): example 增加 File
Browse files Browse the repository at this point in the history
  • Loading branch information
yizhi996 committed Aug 29, 2022
1 parent 7dd227e commit 172451a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
"avatarUrl": "https://file.lilithvue.com/lilith-test-assets/avatar-new.png"]
bridge.invokeCallbackSuccess(args: args, result: ["userInfo": userInfo])
}

config.hooks.app.shareAppMessage = { appService, content in
NotifyType.success("title: \(content.title)\npath: \(content.path)\n请在 Native 自行实现转发界面").show()
}

config.dev.useDevServer = true
Engine.shared.connectDevService()
Expand Down
6 changes: 6 additions & 0 deletions packages/create-evoker/template-example/src/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@
"style": {
"navigationBarTitleText": "WebSocket"
}
},
{
"path": "pages/API/File",
"style": {
"navigationBarTitleText": "File"
}
}
]
}
67 changes: 67 additions & 0 deletions packages/create-evoker/template-example/src/pages/API/File.vue
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>
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const list = reactive([
{ name: "音频", url: "./Audio" },
{ name: "录音", url: "./Voice" },
{ name: "背景音频", url: "not supported" },
{ name: "文件", url: "not supported" },
{ name: "文件", url: "./File" },
{ name: "视频", url: "./Video" },
{ name: "动态加载字体", url: "./LoadFontFace" }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const list = reactive([
}
])
const { onLoad, onShow, onReady, onHide, onUnload } = usePage()
const { onLoad, onShow, onReady, onHide, onUnload, onShareAppMessage } = usePage()
onLoad(options => {
console.log("Page onLoad: ", options)
Expand All @@ -101,4 +101,8 @@ onHide(() => {
onUnload(() => {
console.log("Page onUnload")
})
onShareAppMessage(() => {
return { title: "!! Evoker !!" }
})
</script>

0 comments on commit 172451a

Please sign in to comment.