diff --git a/src/views/home/index.vue b/src/views/home/index.vue index a813ead..9c79459 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -131,22 +131,35 @@ const uploadImage = () => { } } -window.onUploadResult = function(imageUrl) { - console.log('上传结果:', imageUrl); - - if (!imageUrl || imageUrl === 'error') { - showFailToast('获取图片地址失败,请重试。'); - return; +window.addEventListener('hashchange', () => { + const imageUrl = getHashParam('imageUrl') + console.log('从 hash 中获取的 imageUrl:', imageUrl) + if (imageUrl) { + sendGeneratorPhotoTask(imageUrl) } +}) - sendGeneratorPhotoTask(imageUrl); -}; +const getHashParam = (key) => { + const hash = window.location.hash + console.log('hash URL:', hash) + + const queryStr = hash.split('?')[1] || '' + const params = queryStr.split('&') + + for (let i = 0; i < params.length; i++) { + const [k, v] = params[i].split('=') + if (k === key) { + return decodeURIComponent(v || '') + } + } + return null +} /// 发送生成任务 const sendGeneratorPhotoTask = async (photoUrl: string) => { const photoUrlList = [photoUrl]; try { - const response = await createGeneratorPhotoTask({ photoUrlList: photoUrlList, sceneId: activeScene.value.sceneCode }); + const response = await createGeneratorPhotoTask({ photoUrlList: photoUrlList, sceneId: activeScene.value.sceneStyleId }); if (response) { showSuccessToast('生成任务创建成功!'); router.push('/generate');