forked from natuka/web.puabadge.com
修改:京东端下单不考虑效果图导入
This commit is contained in:
1 parent
6c55986337
commit
1887e8b2b3
3 files changed
+9
-73
No files matched your search
@@ -46,10 +46,6 @@ export const jingdongConfig = {
|
|||||||
placeholder: '描述你想要的手办,例如:橘猫,戴黄色围巾...',
|
placeholder: '描述你想要的手办,例如:橘猫,戴黄色围巾...',
|
||||||
placeholderNeedPhoto: '请先点击左侧按钮上传照片',
|
placeholderNeedPhoto: '请先点击左侧按钮上传照片',
|
||||||
placeholderEditing: '说说想怎么改,例如:换成蓝色围巾、表情更开心…',
|
placeholderEditing: '说说想怎么改,例如:换成蓝色围巾、表情更开心…',
|
||||||
/** 识别为卡通效果图时 */
|
|
||||||
placeholderCartoon: '已识别为效果图,可直接发送;也可补充想调整的地方',
|
|
||||||
/** 卡通效果图且用户未补充提示词时的气泡文案 */
|
|
||||||
cartoonDirectPrompt: '这是我在别的平台生成的卡通效果图,不用再调整了,直接帮我下单吧~',
|
|
||||||
defaultPrompt: '按所选产品、风格生成手办效果图~',
|
defaultPrompt: '按所选产品、风格生成手办效果图~',
|
||||||
editingHint: '正在编辑效果图 · 描述想调整的地方后发送',
|
editingHint: '正在编辑效果图 · 描述想调整的地方后发送',
|
||||||
exitEdit: '退出编辑',
|
exitEdit: '退出编辑',
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ const props = withDefaults(
|
|||||||
placeholder?: string
|
placeholder?: string
|
||||||
placeholderNeedPhoto?: string
|
placeholderNeedPhoto?: string
|
||||||
placeholderEditing?: string
|
placeholderEditing?: string
|
||||||
placeholderCartoon?: string
|
|
||||||
previewUrl?: string
|
previewUrl?: string
|
||||||
tags?: ComposerTag[]
|
tags?: ComposerTag[]
|
||||||
editing?: boolean
|
editing?: boolean
|
||||||
@@ -120,8 +119,6 @@ const props = withDefaults(
|
|||||||
canSend?: boolean
|
canSend?: boolean
|
||||||
/** 图片识别 / 主体识别进行中 */
|
/** 图片识别 / 主体识别进行中 */
|
||||||
inspecting?: boolean
|
inspecting?: boolean
|
||||||
/** 当前预览图是否为卡通效果图 */
|
|
||||||
cartoonEffect?: boolean
|
|
||||||
/** 底部状态提示 */
|
/** 底部状态提示 */
|
||||||
statusTip?: string
|
statusTip?: string
|
||||||
tipWarn?: boolean
|
tipWarn?: boolean
|
||||||
@@ -136,7 +133,6 @@ const props = withDefaults(
|
|||||||
placeholder: '',
|
placeholder: '',
|
||||||
placeholderNeedPhoto: '请先点击左侧按钮上传照片',
|
placeholderNeedPhoto: '请先点击左侧按钮上传照片',
|
||||||
placeholderEditing: '说说想怎么改…',
|
placeholderEditing: '说说想怎么改…',
|
||||||
placeholderCartoon: '已识别为效果图,可直接发送',
|
|
||||||
previewUrl: '',
|
previewUrl: '',
|
||||||
tags: () => [],
|
tags: () => [],
|
||||||
editing: false,
|
editing: false,
|
||||||
@@ -145,7 +141,6 @@ const props = withDefaults(
|
|||||||
disabled: false,
|
disabled: false,
|
||||||
canSend: false,
|
canSend: false,
|
||||||
inspecting: false,
|
inspecting: false,
|
||||||
cartoonEffect: false,
|
|
||||||
statusTip: '',
|
statusTip: '',
|
||||||
tipWarn: false,
|
tipWarn: false,
|
||||||
titleSpec: null,
|
titleSpec: null,
|
||||||
@@ -185,7 +180,6 @@ const tagItems = computed(() =>
|
|||||||
const resolvedPlaceholder = computed(() => {
|
const resolvedPlaceholder = computed(() => {
|
||||||
if (props.editing) return props.placeholderEditing || props.placeholder
|
if (props.editing) return props.placeholderEditing || props.placeholder
|
||||||
if (!props.previewUrl) return props.placeholderNeedPhoto || props.placeholder
|
if (!props.previewUrl) return props.placeholderNeedPhoto || props.placeholder
|
||||||
if (props.cartoonEffect) return props.placeholderCartoon || props.placeholder
|
|
||||||
return props.placeholder
|
return props.placeholder
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,6 @@
|
|||||||
:placeholder="config.messages.placeholder"
|
:placeholder="config.messages.placeholder"
|
||||||
:placeholder-need-photo="config.messages.placeholderNeedPhoto"
|
:placeholder-need-photo="config.messages.placeholderNeedPhoto"
|
||||||
:placeholder-editing="config.messages.placeholderEditing"
|
:placeholder-editing="config.messages.placeholderEditing"
|
||||||
:placeholder-cartoon="config.messages.placeholderCartoon"
|
|
||||||
:preview-url="pendingPreview"
|
:preview-url="pendingPreview"
|
||||||
:tags="composerTags"
|
:tags="composerTags"
|
||||||
:editing="isEditing"
|
:editing="isEditing"
|
||||||
@@ -97,7 +96,6 @@
|
|||||||
:exit-edit-label="config.messages.exitEdit"
|
:exit-edit-label="config.messages.exitEdit"
|
||||||
:disabled="isBusy"
|
:disabled="isBusy"
|
||||||
:inspecting="inspecting"
|
:inspecting="inspecting"
|
||||||
:cartoon-effect="isPendingCartoon"
|
|
||||||
:can-send="canSend"
|
:can-send="canSend"
|
||||||
:status-tip="composerStatusTip"
|
:status-tip="composerStatusTip"
|
||||||
:tip-warn="composerTipWarn"
|
:tip-warn="composerTipWarn"
|
||||||
@@ -128,7 +126,6 @@ import { jingdongConfig as config } from '@/config/jingdong'
|
|||||||
import {
|
import {
|
||||||
InspectCancelled,
|
InspectCancelled,
|
||||||
inspectImage,
|
inspectImage,
|
||||||
isCartoonImage,
|
|
||||||
type ImageInspect,
|
type ImageInspect,
|
||||||
} from '@/services/jingdong/image-inspect'
|
} from '@/services/jingdong/image-inspect'
|
||||||
import { flyImageToRect, rectFromElement, type FlyRect } from '@/utils/fly-image'
|
import { flyImageToRect, rectFromElement, type FlyRect } from '@/utils/fly-image'
|
||||||
@@ -275,9 +272,6 @@ const composerRef = ref<{
|
|||||||
} | null>(null)
|
} | null>(null)
|
||||||
|
|
||||||
const isEditing = computed(() => !!editingResultId.value)
|
const isEditing = computed(() => !!editingResultId.value)
|
||||||
const isPendingCartoon = computed(
|
|
||||||
() => Boolean(pendingPreview.value && photoInspect.value && isCartoonImage(photoInspect.value)),
|
|
||||||
)
|
|
||||||
|
|
||||||
/** 统计已消耗的生图次数:成功 task + 对话里已出的结果卡 */
|
/** 统计已消耗的生图次数:成功 task + 对话里已出的结果卡 */
|
||||||
function countUsedGenerations() {
|
function countUsedGenerations() {
|
||||||
@@ -527,12 +521,7 @@ async function runPhotoRecognize(file: File) {
|
|||||||
// 标签仍展示订单主体;识别结果只用于校验
|
// 标签仍展示订单主体;识别结果只用于校验
|
||||||
if (subjectNameFromStat.value) subjectName.value = subjectNameFromStat.value
|
if (subjectNameFromStat.value) subjectName.value = subjectNameFromStat.value
|
||||||
|
|
||||||
const matched = checkSubjectMatch(inspectResult)
|
checkSubjectMatch(inspectResult)
|
||||||
if (!matched) return
|
|
||||||
|
|
||||||
if (isCartoonImage(inspectResult)) {
|
|
||||||
showToast('已识别为效果图,可直接发送;也可补充想调整的地方')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (serial !== inspectSerial || error instanceof InspectCancelled) return
|
if (serial !== inspectSerial || error instanceof InspectCancelled) return
|
||||||
showToast(friendlyError(error, 'inspect'))
|
showToast(friendlyError(error, 'inspect'))
|
||||||
@@ -741,7 +730,6 @@ async function startGenerate(opts: {
|
|||||||
userImage?: string
|
userImage?: string
|
||||||
mode: 'generate' | 'edit'
|
mode: 'generate' | 'edit'
|
||||||
file?: File | null
|
file?: File | null
|
||||||
useCartoonEffect?: boolean
|
|
||||||
sceneProp?: string
|
sceneProp?: string
|
||||||
}) {
|
}) {
|
||||||
if (remainCount.value <= 0) {
|
if (remainCount.value <= 0) {
|
||||||
@@ -793,46 +781,16 @@ async function startGenerate(opts: {
|
|||||||
if (!opts.file) {
|
if (!opts.file) {
|
||||||
throw new Error(opts.mode === 'edit' ? '缺少可编辑的效果图' : '请先上传照片')
|
throw new Error(opts.mode === 'edit' ? '缺少可编辑的效果图' : '请先上传照片')
|
||||||
}
|
}
|
||||||
// 编辑效果图也要重新上传图片
|
// 卡通 / 真人统一走生图:上传 purpose=origin,再 imagegen/submit
|
||||||
const purpose = opts.useCartoonEffect ? 'external_effect' : 'origin'
|
|
||||||
const uploaded = await jingdongApi.uploadOriginal(opts.file, {
|
const uploaded = await jingdongApi.uploadOriginal(opts.file, {
|
||||||
session_id: sid,
|
session_id: sid,
|
||||||
purpose,
|
purpose: 'origin',
|
||||||
})
|
})
|
||||||
uploadId = uploaded.uploadId
|
uploadId = uploaded.uploadId
|
||||||
lastUploadId.value = uploadId
|
lastUploadId.value = uploadId
|
||||||
|
|
||||||
const styleId = resolveStyleId()
|
const styleId = resolveStyleId()
|
||||||
let taskId = ''
|
|
||||||
let imageId = ''
|
|
||||||
let resultUrl = ''
|
|
||||||
|
|
||||||
const sceneProp = String(opts.sceneProp || '').trim()
|
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({
|
const task = await jingdongApi.submitImageGen({
|
||||||
session_id: sid,
|
session_id: sid,
|
||||||
upload_id: uploadId,
|
upload_id: uploadId,
|
||||||
@@ -844,15 +802,14 @@ async function startGenerate(opts: {
|
|||||||
mode: opts.mode,
|
mode: opts.mode,
|
||||||
scene_prop: sceneProp,
|
scene_prop: sceneProp,
|
||||||
})
|
})
|
||||||
taskId = task.task_id
|
let taskId = task.task_id
|
||||||
if (!taskId) throw new Error('提交生成失败')
|
if (!taskId) throw new Error('提交生成失败')
|
||||||
const done = await pollImageGen(taskId)
|
const done = await pollImageGen(taskId)
|
||||||
const image = [...(done.images ?? [])].sort((a, b) => a.index - b.index)[0]
|
const image = [...(done.images ?? [])].sort((a, b) => a.index - b.index)[0]
|
||||||
if (!image?.url) throw new Error(done.error || '没有生成结果')
|
if (!image?.url) throw new Error(done.error || '没有生成结果')
|
||||||
resultUrl = image.url
|
const resultUrl = image.url
|
||||||
imageId = image.image_id || ''
|
const imageId = image.image_id || ''
|
||||||
taskId = done.task_id || taskId
|
taskId = done.task_id || taskId
|
||||||
}
|
|
||||||
|
|
||||||
pendingFinish.value = {
|
pendingFinish.value = {
|
||||||
generatingId,
|
generatingId,
|
||||||
@@ -951,18 +908,8 @@ function onSend() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const useCartoonEffect = Boolean(photoInspect.value && isCartoonImage(photoInspect.value))
|
const sendText = text || config.messages.defaultPrompt
|
||||||
// 卡通效果图:无文案 → 直接提交;有文案 → 按效果图编辑(传 mode=edit)
|
const sendImage = image || undefined
|
||||||
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
|
|
||||||
// 本地 blob 预览会进气泡,提交后不能 revoke,否则裂图
|
// 本地 blob 预览会进气泡,提交后不能 revoke,否则裂图
|
||||||
const keepObjectUrl = Boolean(sendImage && String(sendImage).startsWith('blob:'))
|
const keepObjectUrl = Boolean(sendImage && String(sendImage).startsWith('blob:'))
|
||||||
|
|
||||||
@@ -971,9 +918,8 @@ function onSend() {
|
|||||||
void startGenerate({
|
void startGenerate({
|
||||||
userText: sendText,
|
userText: sendText,
|
||||||
userImage: sendImage,
|
userImage: sendImage,
|
||||||
mode,
|
mode: 'generate',
|
||||||
file,
|
file,
|
||||||
useCartoonEffect,
|
|
||||||
sceneProp,
|
sceneProp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user