diff --git a/src/views/ai/image/index/components/ImageCard.vue b/src/views/ai/image/index/components/ImageCard.vue index 8b23f001..4ba78cac 100644 --- a/src/views/ai/image/index/components/ImageCard.vue +++ b/src/views/ai/image/index/components/ImageCard.vue @@ -2,53 +2,53 @@
- + 生成中 - + 已完成 - + 异常
+
- - + +
- - -
- {{ imageDetail?.errorMessage }} + +
+ {{ detail?.errorMessage }}
- +
{{ button.label }}{{ button.emoji }} @@ -62,28 +62,47 @@ import { PropType } from 'vue' import { ElLoading, LoadingOptionsResolved } from 'element-plus' import { AiImageStatusEnum } from '@/views/ai/utils/constants' -const cardImageRef = ref() // 卡片 image ref -const cardImageLoadingInstance = ref() // 卡片 image ref -const message = useMessage() +const message = useMessage() // 消息 + const props = defineProps({ - imageDetail: { + detail: { type: Object as PropType, require: true } }) -/** 按钮 - 点击事件 */ -const handleBtnClick = async (type, imageDetail: ImageVO) => { - emits('onBtnClick', type, imageDetail) +const cardImageRef = ref() // 卡片 image ref +const cardImageLoadingInstance = ref() // 卡片 image ref + +/** 处理点击事件 */ +const handleButtonClick = async (type, detail: ImageVO) => { + emits('onBtnClick', type, detail) } +/** 处理 Midjourney 按钮点击事件 */ +const handleMidjourneyBtnClick = async (button: ImageMidjourneyButtonsVO) => { + // 确认窗体 + await message.confirm(`确认操作 "${button.label} ${button.emoji}" ?`) + emits('onMjBtnClick', button, props.detail) +} + +const emits = defineEmits(['onBtnClick', 'onMjBtnClick']) // emits + +/** 监听详情 */ +const { detail } = toRefs(props) +watch(detail, async (newVal, oldVal) => { + await handleLoading(newVal.status as string) +}) + +/** 处理加载状态 */ const handleLoading = async (status: number) => { - // TODO @芋艿:这个搞成 Loading 组件,然后通过数据驱动,这样搞可以哇? + // 情况一:如果是生成中,则设置加载中的 loading if (status === AiImageStatusEnum.IN_PROGRESS) { cardImageLoadingInstance.value = ElLoading.service({ target: cardImageRef.value, text: '生成中...' } as LoadingOptionsResolved) + // 情况二:如果已经生成结束,则移除 loading } else { if (cardImageLoadingInstance.value) { cardImageLoadingInstance.value.close() @@ -92,25 +111,9 @@ const handleLoading = async (status: number) => { } } -/** mj 按钮 click */ -const handleMjBtnClick = async (button: ImageMidjourneyButtonsVO) => { - // 确认窗体 - await message.confirm(`确认操作 "${button.label} ${button.emoji}" ?`) - emits('onMjBtnClick', button, props.imageDetail) -} - -// watch -const { imageDetail } = toRefs(props) -watch(imageDetail, async (newVal, oldVal) => { - await handleLoading(newVal.status as string) -}) - -// emits -const emits = defineEmits(['onBtnClick', 'onMjBtnClick']) - -// +/** 初始化 */ onMounted(async () => { - await handleLoading(props.imageDetail.status as string) + await handleLoading(props.detail.status as string) }) diff --git a/src/views/ai/image/index/components/ImageDetail.vue b/src/views/ai/image/index/components/ImageDetail.vue index 73e58ba6..c4b90b6c 100644 --- a/src/views/ai/image/index/components/ImageDetail.vue +++ b/src/views/ai/image/index/components/ImageDetail.vue @@ -107,8 +107,6 @@ watch(id, async (newVal, oldVal) => { }) // const emits = defineEmits(['handleDrawerClose']) -// -onMounted(async () => {})