diff --git a/src/views/home/index.vue b/src/views/home/index.vue index a5fbaf4..a813ead 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -59,7 +59,7 @@ import AgreementTip from '../components/AgreementTip.vue'; // @ts-ignore import { getAigcSceneList, AigcSceneListItem, AigcSceneStyleItem } from '@api'; // @ts-ignore -import { createGeneratorPhotoTask, updateImageFile } from '@api'; +import { createGeneratorPhotoTask } from '@api'; import { showFailToast, showSuccessToast } from 'vant'; // --- 测试数据 --- @@ -115,27 +115,32 @@ const onStartSelect = () => { // 调用上传 const uploadImage = () => { - wx.miniProgram.postMessage({ - data: { action: 'chooseAndUpload' } - }); + // 测试保存图片逻辑 + // if (window.wx && wx.miniProgram) { + // wx.miniProgram.navigateTo({ + // url: `/pages-bridge/SaveImage?imageUrl=${encodeURIComponent(activeScene.value.sceneCoverUrl)}` + // }); + // } + // return + + /// 调用小程序上传接口 + if (window.wx && wx.miniProgram) { + wx.miniProgram.navigateTo({ + url: '/pages-bridge/UploadImage' + }); + } } -// 监听 hash 变化,获取结果 -window.addEventListener('hashchange', function() { - const hash = window.location.hash; - if (hash.startsWith('#uploadResult=')) { - const imageUrl = decodeURIComponent(hash.substring('#uploadResult='.length)); - console.log('上传成功,图片地址:', imageUrl); - // 这里就可以使用 imageUrl 了,比如赋值给某个变量或调用业务逻辑 - if (!imageUrl || imageUrl === 'error') { - showFailToast('获取图片地址失败,请重试。'); - return; - } - sendGeneratorPhotoTask(imageUrl); - // 可选:清除 hash,避免重复触发 - history.replaceState(null, null, window.location.pathname + window.location.search); +window.onUploadResult = function(imageUrl) { + console.log('上传结果:', imageUrl); + + if (!imageUrl || imageUrl === 'error') { + showFailToast('获取图片地址失败,请重试。'); + return; } -}); + + sendGeneratorPhotoTask(imageUrl); +}; /// 发送生成任务 const sendGeneratorPhotoTask = async (photoUrl: string) => { diff --git a/src/views/prepicture/index.vue b/src/views/prepicture/index.vue index f51802a..6510695 100644 --- a/src/views/prepicture/index.vue +++ b/src/views/prepicture/index.vue @@ -78,14 +78,12 @@ const saveImage = () => { showToast('图片地址无效,无法保存'); return; } - - // 发送消息给小程序 - wx.miniProgram.postMessage({ - data: { - action: 'saveImage', - imageUrl: imageUrl - } - }); + + if (window.wx && wx.miniProgram) { + wx.miniProgram.navigateTo({ + url: `/pages-bridge/SaveImage?imageUrl=${encodeURIComponent(imageUrl.value)}` + }); + } };