feat: web通讯的处理
This commit is contained in:
32
src/pages-bridge/SaveImage.vue
Normal file
32
src/pages-bridge/SaveImage.vue
Normal file
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
<script setup>
|
||||
import { onMounted } from "vue";
|
||||
import { saveImageToAlbum } from '@/pages/webview/bridge.js'
|
||||
|
||||
onMounted(() => {
|
||||
// 获取页面参数
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const options = currentPage.options;
|
||||
|
||||
if (options.imageUrl) {
|
||||
const imageUrl = decodeURIComponent(options.imageUrl);
|
||||
saveImage(imageUrl);
|
||||
}
|
||||
});
|
||||
|
||||
const saveImage = async (imageUrl) => {
|
||||
try {
|
||||
await saveImageToAlbum(imageUrl)
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
</script>
|
||||
27
src/pages-bridge/UploadImage.vue
Normal file
27
src/pages-bridge/UploadImage.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { chooseAndUploadImage } from '@/pages/webview/bridge.js'
|
||||
|
||||
onLoad(() => {
|
||||
handleChoose()
|
||||
})
|
||||
|
||||
const sendResult = (imageUrl) => {
|
||||
// 触发全局事件
|
||||
uni.$emit('UPLOAD_RESULT', imageUrl)
|
||||
}
|
||||
const handleChoose = async () => {
|
||||
try {
|
||||
const imageUrl = await chooseAndUploadImage()
|
||||
sendResult(imageUrl)
|
||||
} catch (e) {
|
||||
sendResult('error')
|
||||
}
|
||||
|
||||
uni.navigateBack()
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user