diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 7c63c2e..289e784 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -58,9 +58,6 @@ export default function Home() { const handleTemplateClick = async (template: Template) => { if (loading) return // 防止重复点击 - - let recordId: string | undefined - try { setLoading(true) @@ -80,64 +77,25 @@ export default function Home() { } }) - // 创建历史记录(生成中状态) - try { - recordId = await dispatch(addRecord({ - type: 'image-to-image', - templateId: template.code, - templateName: template.name, - inputImage: url, - status: 'generating' - })) - } catch (historyError) { - console.error('创建历史记录失败:', historyError) - } - // 执行模板处理 Taro.showLoading({ title: '处理图片中...', mask: true }) try { - const result = await serverSdk.executeTemplate({ + const taskId = await serverSdk.executeTemplate({ imageUrl: url, templateCode: template.code }) - // 处理完成后更新历史记录状态 - if (recordId) { - try { - await dispatch(updateRecord(recordId, { - outputResult: result || undefined, - status: 'completed' - })) - } catch (historyError) { - console.error('更新历史记录失败:', historyError) - // 历史记录更新失败不影响主流程,只记录错误 - } - } - // 隐藏loading Taro.hideLoading() // 检查处理结果 // 跳转到结果页面 - navigateTo({ - url: `/pages/result/index?images=${encodeURIComponent(JSON.stringify([result!]))}` - }) - } catch (e) { - // 处理失败时更新历史记录状态 - if (recordId) { - try { - await dispatch(updateRecord(recordId, { - status: 'failed', - errorMessage: (e as Error).message || '处理失败' - })) - } catch (historyError) { - console.error('更新失败记录到历史失败:', historyError) - } - } + // 跳转到generate页面等待loading... + } catch (e) { // 处理失败 Taro.showToast({ title: (e as Error).message || '处理失败', @@ -146,23 +104,8 @@ export default function Home() { }) } } catch (error) { - console.error('模板处理失败:', error) - - // 如果有记录ID,更新为失败状态 - if (recordId) { - try { - await dispatch(updateRecord(recordId, { - status: 'failed', - errorMessage: error instanceof Error ? error.message : '处理失败' - })) - } catch (historyError) { - console.error('更新历史记录失败:', historyError) - } - } - // 隐藏loading Taro.hideLoading() - // 显示错误提示 Taro.showToast({ title: error instanceof Error ? error.message : '处理失败', diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 6f9a686..12e13a6 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -67,6 +67,8 @@ export default function Index() { } } + + const resetToUpload = () => { setState({ step: 'upload', error: null }) } diff --git a/src/sdk/sdk-server.ts b/src/sdk/sdk-server.ts index 625ebca..129836e 100644 --- a/src/sdk/sdk-server.ts +++ b/src/sdk/sdk-server.ts @@ -198,7 +198,11 @@ export class SdkServer { } } - + /** + * 登录 + * @param params + * @returns + */ async login(params: any): Promise<{ tokens: IToken, user: IUser }> { try { const response = await this.request<{ tokens: IToken, user: IUser }>(`/api/v1/users/login`, 'POST', { @@ -214,6 +218,10 @@ export class SdkServer { } } + /** + * 获取用户信息 可检测token是否过期 + * @returns + */ async profile() { try { const response = await this.request<{ tokens: IToken }>(`/api/v1/users/profile`, 'GET', {}); @@ -243,7 +251,22 @@ export class SdkServer { return templates; } - + /** + * 获取任务执行详情 + * @param taskId + * @returns + */ + async getTaskProgress(taskId: string) { + try { + const response = await this.request<{ tokens: IToken }>(`/api/v1/templates/execution/${taskId}/progress`, 'GET', {}); + return response.data + } catch (error) { + throw error; + } + } + /** + * 获取我的执行日志 + */ async getMineLogs() { try { const userId = Taro.getStorageSync(TOKEN_UID_KEY);