ImageTaskCard.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <el-card body-class="" class="image-card">
  3. <div class="image-operation">
  4. <div>
  5. <el-button type="" text bg v-if="imageDetail.status === 'in_progress'">生成中</el-button>
  6. <el-button type="" text bg v-else-if="imageDetail.status === 'fail'">已完成</el-button>
  7. <el-button type="" text bg v-else-if="imageDetail.status === 'complete'">已完成</el-button>
  8. </div>
  9. <div>
  10. <el-button class="btn" text :icon="Download"
  11. @click="handlerBtnClick('download', imageDetail)"/>
  12. <el-button class="btn" text :icon="Delete" @click="handlerBtnClick('delete', imageDetail)"/>
  13. <el-button class="btn" text :icon="More" @click="handlerBtnClick('more', imageDetail)"/>
  14. </div>
  15. </div>
  16. <div class="image-wrapper" ref="cardImageRef">
  17. <img class="image" :src="imageDetail?.picUrl"/>
  18. </div>
  19. </el-card>
  20. </template>
  21. <script setup lang="ts">
  22. import {Delete, Download, More} from "@element-plus/icons-vue";
  23. import {ImageDetailVO} from "@/api/ai/image";
  24. import {PropType} from "vue";
  25. import {ElLoading} from "element-plus";
  26. const cardImageRef = ref<any>() // 卡片 image ref
  27. const cardImageLoadingInstance = ref<any>() // 卡片 image ref
  28. const props = defineProps({
  29. imageDetail: {
  30. type: Object as PropType<ImageDetailVO>,
  31. require: true
  32. }
  33. })
  34. /**
  35. * 按钮 - 点击事件
  36. */
  37. const handlerBtnClick = async (type, imageDetail: ImageDetailVO) => {
  38. emits('onBtnClick', type, imageDetail)
  39. }
  40. // emits
  41. const emits = defineEmits(['onBtnClick'])
  42. //
  43. onMounted(async () => {
  44. if (props.imageDetail.status === 'in_progress') {
  45. cardImageLoadingInstance.value = ElLoading.service({
  46. target: cardImageRef.value,
  47. text: '生成中...'
  48. })
  49. } else {
  50. if (cardImageLoadingInstance.value) {
  51. cardImageLoadingInstance.value.close();
  52. cardImageLoadingInstance.value = null;
  53. }
  54. }
  55. })
  56. </script>
  57. <style scoped lang="scss">
  58. .image-card {
  59. width: 320px;
  60. max-height: 370px;
  61. border-radius: 10px;
  62. position: relative;
  63. display: flex;
  64. flex-direction: column;
  65. .image-operation {
  66. display: flex;
  67. flex-direction: row;
  68. justify-content: space-between;
  69. .btn {
  70. //border: 1px solid red;
  71. padding: 10px;
  72. margin: 0;
  73. }
  74. }
  75. .image-wrapper {
  76. overflow: hidden;
  77. margin-top: 20px;
  78. height: 280px;
  79. flex: 1;
  80. .image {
  81. width: 100%;
  82. border-radius: 10px;
  83. }
  84. }
  85. }
  86. </style>