forked from natuka/web.puabadge.com
修改:京东端下单不考虑效果图导入
This commit is contained in:
1 parent
6c55986337
commit
1887e8b2b3
3 files changed
+25
-89
No files matched your search
@@ -89,7 +89,6 @@
|
||||
:placeholder="config.messages.placeholder"
|
||||
:placeholder-need-photo="config.messages.placeholderNeedPhoto"
|
||||
:placeholder-editing="config.messages.placeholderEditing"
|
||||
:placeholder-cartoon="config.messages.placeholderCartoon"
|
||||
:preview-url="pendingPreview"
|
||||
:tags="composerTags"
|
||||
:editing="isEditing"
|
||||
@@ -97,7 +96,6 @@
|
||||
:exit-edit-label="config.messages.exitEdit"
|
||||
:disabled="isBusy"
|
||||
:inspecting="inspecting"
|
||||
:cartoon-effect="isPendingCartoon"
|
||||
:can-send="canSend"
|
||||
:status-tip="composerStatusTip"
|
||||
:tip-warn="composerTipWarn"
|
||||
@@ -128,7 +126,6 @@ import { jingdongConfig as config } from '@/config/jingdong'
|
||||
import {
|
||||
InspectCancelled,
|
||||
inspectImage,
|
||||
isCartoonImage,
|
||||
type ImageInspect,
|
||||
} from '@/services/jingdong/image-inspect'
|
||||
import { flyImageToRect, rectFromElement, type FlyRect } from '@/utils/fly-image'
|
||||
@@ -275,9 +272,6 @@ const composerRef = ref<{
|
||||
} | null>(null)
|
||||
|
||||
const isEditing = computed(() => !!editingResultId.value)
|
||||
const isPendingCartoon = computed(
|
||||
() => Boolean(pendingPreview.value && photoInspect.value && isCartoonImage(photoInspect.value)),
|
||||
)
|
||||
|
||||
/** 统计已消耗的生图次数:成功 task + 对话里已出的结果卡 */
|
||||
function countUsedGenerations() {
|
||||
@@ -527,12 +521,7 @@ async function runPhotoRecognize(file: File) {
|
||||
// 标签仍展示订单主体;识别结果只用于校验
|
||||
if (subjectNameFromStat.value) subjectName.value = subjectNameFromStat.value
|
||||
|
||||
const matched = checkSubjectMatch(inspectResult)
|
||||
if (!matched) return
|
||||
|
||||
if (isCartoonImage(inspectResult)) {
|
||||
showToast('已识别为效果图,可直接发送;也可补充想调整的地方')
|
||||
}
|
||||
checkSubjectMatch(inspectResult)
|
||||
} catch (error) {
|
||||
if (serial !== inspectSerial || error instanceof InspectCancelled) return
|
||||
showToast(friendlyError(error, 'inspect'))
|
||||
@@ -741,7 +730,6 @@ async function startGenerate(opts: {
|
||||
userImage?: string
|
||||
mode: 'generate' | 'edit'
|
||||
file?: File | null
|
||||
useCartoonEffect?: boolean
|
||||
sceneProp?: string
|
||||
}) {
|
||||
if (remainCount.value <= 0) {
|
||||
@@ -793,66 +781,35 @@ async function startGenerate(opts: {
|
||||
if (!opts.file) {
|
||||
throw new Error(opts.mode === 'edit' ? '缺少可编辑的效果图' : '请先上传照片')
|
||||
}
|
||||
// 编辑效果图也要重新上传图片
|
||||
const purpose = opts.useCartoonEffect ? 'external_effect' : 'origin'
|
||||
// 卡通 / 真人统一走生图:上传 purpose=origin,再 imagegen/submit
|
||||
const uploaded = await jingdongApi.uploadOriginal(opts.file, {
|
||||
session_id: sid,
|
||||
purpose,
|
||||
purpose: 'origin',
|
||||
})
|
||||
uploadId = uploaded.uploadId
|
||||
lastUploadId.value = uploadId
|
||||
|
||||
const styleId = resolveStyleId()
|
||||
let taskId = ''
|
||||
let imageId = ''
|
||||
let resultUrl = ''
|
||||
|
||||
const sceneProp = String(opts.sceneProp || '').trim()
|
||||
|
||||
if (opts.useCartoonEffect && opts.mode === 'generate') {
|
||||
const effect = await jingdongApi.submitExternalEffect({
|
||||
session_id: sid,
|
||||
upload_id: uploadId,
|
||||
product_id: productId,
|
||||
product_name: String(orderStat.value?.prod_name || orderStat.value?.product_name || ''),
|
||||
user_message: opts.userText,
|
||||
style_id: styleId,
|
||||
prompt: opts.userText,
|
||||
scene_prop: sceneProp,
|
||||
})
|
||||
taskId = effect.task_id
|
||||
resultUrl = effect.url || effect.images[0]?.url || ''
|
||||
imageId = effect.image_id || effect.images[0]?.image_id || ''
|
||||
if (!resultUrl && taskId) {
|
||||
const done = await pollImageGen(taskId)
|
||||
const image = [...(done.images ?? [])].sort((a, b) => a.index - b.index)[0]
|
||||
if (!image?.url) throw new Error(done.error || '没有生成结果')
|
||||
resultUrl = image.url
|
||||
imageId = image.image_id || imageId
|
||||
taskId = done.task_id || taskId
|
||||
}
|
||||
if (!resultUrl) throw new Error(effect.error || '没有生成结果')
|
||||
} else {
|
||||
const task = await jingdongApi.submitImageGen({
|
||||
session_id: sid,
|
||||
upload_id: uploadId,
|
||||
product_id: productId,
|
||||
product_name: String(orderStat.value?.prod_name || orderStat.value?.product_name || ''),
|
||||
style_id: styleId,
|
||||
prompt: opts.userText,
|
||||
n: 1,
|
||||
mode: opts.mode,
|
||||
scene_prop: sceneProp,
|
||||
})
|
||||
taskId = task.task_id
|
||||
if (!taskId) throw new Error('提交生成失败')
|
||||
const done = await pollImageGen(taskId)
|
||||
const image = [...(done.images ?? [])].sort((a, b) => a.index - b.index)[0]
|
||||
if (!image?.url) throw new Error(done.error || '没有生成结果')
|
||||
resultUrl = image.url
|
||||
imageId = image.image_id || ''
|
||||
taskId = done.task_id || taskId
|
||||
}
|
||||
const task = await jingdongApi.submitImageGen({
|
||||
session_id: sid,
|
||||
upload_id: uploadId,
|
||||
product_id: productId,
|
||||
product_name: String(orderStat.value?.prod_name || orderStat.value?.product_name || ''),
|
||||
style_id: styleId,
|
||||
prompt: opts.userText,
|
||||
n: 1,
|
||||
mode: opts.mode,
|
||||
scene_prop: sceneProp,
|
||||
})
|
||||
let taskId = task.task_id
|
||||
if (!taskId) throw new Error('提交生成失败')
|
||||
const done = await pollImageGen(taskId)
|
||||
const image = [...(done.images ?? [])].sort((a, b) => a.index - b.index)[0]
|
||||
if (!image?.url) throw new Error(done.error || '没有生成结果')
|
||||
const resultUrl = image.url
|
||||
const imageId = image.image_id || ''
|
||||
taskId = done.task_id || taskId
|
||||
|
||||
pendingFinish.value = {
|
||||
generatingId,
|
||||
@@ -951,18 +908,8 @@ function onSend() {
|
||||
return
|
||||
}
|
||||
|
||||
const useCartoonEffect = Boolean(photoInspect.value && isCartoonImage(photoInspect.value))
|
||||
// 卡通效果图:无文案 → 直接提交;有文案 → 按效果图编辑(传 mode=edit)
|
||||
const hasUserPrompt = text.length > 0
|
||||
const mode: 'generate' | 'edit' =
|
||||
useCartoonEffect && hasUserPrompt ? 'edit' : 'generate'
|
||||
const sendText = hasUserPrompt
|
||||
? text
|
||||
: useCartoonEffect
|
||||
? config.messages.cartoonDirectPrompt
|
||||
: config.messages.defaultPrompt
|
||||
// 与 detail 一致:origin 右侧显示图;external_effect 只显示提示词
|
||||
const sendImage = useCartoonEffect ? undefined : image || undefined
|
||||
const sendText = text || config.messages.defaultPrompt
|
||||
const sendImage = image || undefined
|
||||
// 本地 blob 预览会进气泡,提交后不能 revoke,否则裂图
|
||||
const keepObjectUrl = Boolean(sendImage && String(sendImage).startsWith('blob:'))
|
||||
|
||||
@@ -971,9 +918,8 @@ function onSend() {
|
||||
void startGenerate({
|
||||
userText: sendText,
|
||||
userImage: sendImage,
|
||||
mode,
|
||||
mode: 'generate',
|
||||
file,
|
||||
useCartoonEffect,
|
||||
sceneProp,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user