feat: web通讯的处理

This commit is contained in:
2026-04-06 01:14:33 +08:00
parent c29330e03a
commit 1f75a7eab8
5 changed files with 108 additions and 16 deletions

View 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>

View 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>