fix: 主体图片预览防止形态提示词和模型参数切换后显示旧结果
This commit is contained in:
1 parent
8c14efcfe4
commit
49fb9c7a27
1 file changed
+18
-2
@@ -29,6 +29,18 @@ const acknowledged = ref(false)
|
||||
const preview = ref<SubjectImageGenerationPreview | null>(null)
|
||||
const previewError = ref('')
|
||||
const previewPending = ref(false)
|
||||
/** 预览与当前形态、提示词及模型配置绑定,避免显示过期结果。 */
|
||||
const previewKey = computed(() => JSON.stringify([
|
||||
props.form?.id,
|
||||
prompt.value,
|
||||
provider.value,
|
||||
generationOptions.value
|
||||
]))
|
||||
watch(previewKey, () => {
|
||||
preview.value = null
|
||||
previewError.value = ''
|
||||
})
|
||||
|
||||
|
||||
/** 每次打开重新建立表单,避免把另一形态的 Prompt 或尺寸带入请求。 */
|
||||
watch(
|
||||
@@ -64,17 +76,21 @@ async function loadPreview() {
|
||||
if (!props.form || previewPending.value) return
|
||||
previewPending.value = true
|
||||
previewError.value = ''
|
||||
const requestKey = previewKey.value
|
||||
try {
|
||||
const result = await subjectImagesApi.preview(props.form.id, {
|
||||
...(prompt.value.trim() ? { prompt: prompt.value.trim() } : {}),
|
||||
provider: provider.value,
|
||||
generationOptions: generationOptions.value
|
||||
})
|
||||
if (requestKey !== previewKey.value || !open.value) return
|
||||
if (!result || result.subjectFormId !== props.form.id) throw new Error('预览结果与当前形态不匹配。')
|
||||
preview.value = result
|
||||
} catch (cause) {
|
||||
preview.value = null
|
||||
previewError.value = errorMessage(cause)
|
||||
if (requestKey === previewKey.value && open.value) {
|
||||
preview.value = null
|
||||
previewError.value = errorMessage(cause)
|
||||
}
|
||||
} finally {
|
||||
previewPending.value = false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user