ImageTaskCard.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <el-card body-class="" class="image-card">
  3. <div class="image-operation">
  4. <div>
  5. <el-button type="primary" text bg v-if="imageDetail?.status === 10">生成中</el-button>
  6. <el-button text bg v-else-if="imageDetail?.status === 20">已完成</el-button>
  7. <el-button type="danger" text bg v-else-if="imageDetail?.status === 30">异常</el-button>
  8. </div>
  9. <!-- TODO @fan:1)按钮要不调整成详情、下载、再次生成、删除?;2)如果是再次生成,就把当前的参数填写到左侧的框框里? -->
  10. <div>
  11. <el-button class="btn" text :icon="Download"
  12. @click="handlerBtnClick('download', imageDetail)"/>
  13. <el-button class="btn" text :icon="Delete" @click="handlerBtnClick('delete', imageDetail)"/>
  14. <el-button class="btn" text :icon="More" @click="handlerBtnClick('more', imageDetail)"/>
  15. </div>
  16. </div>
  17. <div class="image-wrapper" ref="cardImageRef">
  18. <!-- TODO @fan:要不加个点击,大图预览? -->
  19. <img class="image" :src="imageDetail?.picUrl"/>
  20. <div v-if="imageDetail?.status === 30">{{imageDetail?.errorMessage}}</div>
  21. </div>
  22. </el-card>
  23. </template>
  24. <script setup lang="ts">
  25. import {Delete, Download, More} from "@element-plus/icons-vue";
  26. import {ImageDetailVO} from "@/api/ai/image";
  27. import {PropType} from "vue";
  28. import {ElLoading} from "element-plus";
  29. const cardImageRef = ref<any>() // 卡片 image ref
  30. const cardImageLoadingInstance = ref<any>() // 卡片 image ref
  31. const props = defineProps({
  32. imageDetail: {
  33. type: Object as PropType<ImageDetailVO>,
  34. require: true
  35. }
  36. })
  37. /** 按钮 - 点击事件 */
  38. const handlerBtnClick = async (type, imageDetail: ImageDetailVO) => {
  39. emits('onBtnClick', type, imageDetail)
  40. }
  41. const handlerLoading = async (status: number) => {
  42. // TODO @fan:这个搞成 Loading 组件,然后通过数据驱动,这样搞可以哇?
  43. if (status === 10) {
  44. cardImageLoadingInstance.value = ElLoading.service({
  45. target: cardImageRef.value,
  46. text: '生成中...'
  47. })
  48. } else {
  49. if (cardImageLoadingInstance.value) {
  50. cardImageLoadingInstance.value.close();
  51. cardImageLoadingInstance.value = null;
  52. }
  53. }
  54. }
  55. // watch
  56. const { imageDetail } = toRefs(props)
  57. watch(imageDetail, async (newVal, oldVal) => {
  58. await handlerLoading(newVal.status as string)
  59. })
  60. // emits
  61. const emits = defineEmits(['onBtnClick'])
  62. //
  63. onMounted(async () => {
  64. await handlerLoading(props.imageDetail.status as string)
  65. })
  66. </script>
  67. <style scoped lang="scss">
  68. .image-card {
  69. width: 320px;
  70. height: auto;
  71. border-radius: 10px;
  72. position: relative;
  73. display: flex;
  74. flex-direction: column;
  75. .image-operation {
  76. display: flex;
  77. flex-direction: row;
  78. justify-content: space-between;
  79. .btn {
  80. //border: 1px solid red;
  81. padding: 10px;
  82. margin: 0;
  83. }
  84. }
  85. .image-wrapper {
  86. overflow: hidden;
  87. margin-top: 20px;
  88. height: 280px;
  89. flex: 1;
  90. .image {
  91. width: 100%;
  92. border-radius: 10px;
  93. }
  94. }
  95. }
  96. </style>