topfans/frontend/pages/castlove/laser/laser-thinking.vue

76 lines
1.7 KiB
Vue

<template>
<view class="laser-thinking-page">
<LaserThinkingShell :progress="progress" />
<LaserBatchCanvasHost />
</view>
</template>
<script setup>
import { onMounted } from 'vue'
import LaserThinkingShell from '@/components/laser/LaserThinkingShell.vue'
import LaserBatchCanvasHost from '@/components/laser/LaserBatchCanvasHost.vue'
import { useLaserBatchGenerate } from '@/composables/useLaserBatchGenerate.js'
import {
consumeGenerationFlowPayload,
LASER_RESULT_URL,
} from '@/utils/castloveGenerationFlow.js'
const { progress, simulateProgress, setFlowStartedAt, run } = useLaserBatchGenerate()
const revertAndBack = () => {
uni.showToast({ title: '已取消', icon: 'none' })
setTimeout(() => {
uni.navigateBack()
}, 500)
}
const revertProgress = () => {
let p = progress.value
const revertInterval = setInterval(() => {
if (p > 0) {
p = Math.max(0, p - 10)
progress.value = p
} else {
clearInterval(revertInterval)
revertAndBack()
}
}, 100)
}
const handleSuccess = () => {
uni.showToast({ title: '生成成功', icon: 'success', duration: 1200 })
setTimeout(() => {
uni.navigateTo({ url: LASER_RESULT_URL })
}, 1200)
}
onMounted(async () => {
const startedAt = Date.now()
setFlowStartedAt(startedAt)
simulateProgress()
try {
const flow = consumeGenerationFlowPayload()
if (!flow) {
throw new Error('缺少生成流程数据')
}
await run({ flow })
handleSuccess()
} catch (err) {
console.error('[laser-thinking]', err)
uni.showToast({
title: err?.message || '镭射生成失败',
icon: 'none',
})
revertProgress()
}
})
</script>
<style scoped>
.laser-thinking-page {
width: 100%;
height: 100vh;
}
</style>