feat(wordcloud): 前端 R4 类型/api/词云页真实接口 + stickerEdit 线稿真实地址

This commit is contained in:
2026-08-12 19:10:41 +08:00
parent 85356e7a39
commit 73fac0cb9c
4 changed files with 252 additions and 54 deletions
+17 -27
View File
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef, useCallback } from 'react'
import './index.scss'
import { getProductById } from '../../../utils/productConfig'
import { getDesignList, setDesignList, updateDesign, type DesignItem, type StickerItem } from '../../../utils/store'
import { sketchImage } from '../../../utils/api'
import { useThemeContext } from '../../../context/ThemeContext'
import { useSafeArea } from '../../../hooks/useSafeArea'
import { useStatusBar } from '../../../hooks/useStatusBar'
@@ -263,36 +264,25 @@ export default function StickerEditPage() {
})
}
/** 线稿:预留后端AI接口 */
const API_BASE = 'https://your-api-domain.com' // ← 填入你的服务器地址
const handleSketch = () => {
/** 线稿:调真实后端接口(POST /api/sketch,带 token);失败降级前端灰度 */
const handleSketch = async () => {
if (!sticker) return
setLoading(true)
Taro.uploadFile({
url: `${API_BASE}/api/sketch`,
filePath: sticker.src,
name: 'image',
success: (res) => {
try {
const data = JSON.parse(res.data)
if (data.url) {
const newSticker = { ...sticker, src: data.url, edits: { ...sticker.edits, sketchSrc: data.url } }
setSticker(newSticker)
setTimeout(() => redraw(), 200)
Taro.showToast({ title: '线稿生成成功', icon: 'success' })
} else {
throw new Error('no url')
}
} catch {
// 如果接口不可用,降级为前端灰度+边缘检测
applyFrontendSketch()
}
},
fail: () => {
applyFrontendSketch()
try {
const res = await sketchImage(sticker.src)
if (res?.imageUrl) {
const newSticker = { ...sticker, src: res.imageUrl, edits: { ...sticker.edits, sketchSrc: res.imageUrl } }
setSticker(newSticker)
setLoading(false)
setTimeout(() => redraw(), 200)
Taro.showToast({ title: '线稿生成成功', icon: 'success' })
} else {
throw new Error('no imageUrl')
}
})
} catch {
// 如果接口不可用/失败,降级为前端灰度+边缘检测
applyFrontendSketch()
}
}
/** 前端线稿降级方案:灰度+反相高对比 */