index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!-- image -->
  2. <template>
  3. <div class="ai-image">
  4. <div class="left">
  5. <div class="segmented">
  6. <el-segmented v-model="selectPlatform" :options="platformOptions" />
  7. </div>
  8. <div class="modal-switch-container">
  9. <Dall3
  10. v-if="selectPlatform === AiPlatformEnum.OPENAI"
  11. ref="dall3Ref"
  12. @on-draw-start="handleDrawStart"
  13. @on-draw-complete="handleDrawComplete"
  14. />
  15. <Midjourney v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY" ref="midjourneyRef" />
  16. <StableDiffusion
  17. v-if="selectPlatform === AiPlatformEnum.STABLE_DIFFUSION"
  18. ref="stableDiffusionRef"
  19. @on-draw-complete="handleDrawComplete"
  20. />
  21. </div>
  22. </div>
  23. <div class="main">
  24. <ImageList ref="imageListRef" @on-regeneration="handleRegeneration" />
  25. </div>
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import ImageList from './components/ImageList.vue'
  30. import { AiPlatformEnum } from '@/views/ai/utils/constants'
  31. import { ImageVO } from '@/api/ai/image'
  32. import Dall3 from './components/dall3/index.vue'
  33. import Midjourney from './components/midjourney/index.vue'
  34. import StableDiffusion from './components/stableDiffusion/index.vue'
  35. const imageListRef = ref<any>() // image 列表 ref
  36. const dall3Ref = ref<any>() // dall3(openai) ref
  37. const midjourneyRef = ref<any>() // midjourney ref
  38. const stableDiffusionRef = ref<any>() // stable diffusion ref
  39. // 定义属性
  40. const selectPlatform = ref(AiPlatformEnum.MIDJOURNEY)
  41. const platformOptions = [
  42. {
  43. label: 'DALL3 绘画',
  44. value: AiPlatformEnum.OPENAI
  45. },
  46. {
  47. label: 'MJ 绘画',
  48. value: AiPlatformEnum.MIDJOURNEY
  49. },
  50. {
  51. label: 'Stable Diffusion',
  52. value: AiPlatformEnum.STABLE_DIFFUSION
  53. }
  54. ]
  55. /** 绘画 start */
  56. const handleDrawStart = async (platform: string) => {}
  57. /** 绘画 complete */
  58. const handleDrawComplete = async (platform: string) => {
  59. await imageListRef.value.getImageList()
  60. }
  61. /** 重新生成:将画图详情填充到对应平台 */
  62. const handleRegeneration = async (image: ImageVO) => {
  63. // 切换平台
  64. selectPlatform.value = image.platform
  65. // 根据不同平台填充 image
  66. await nextTick()
  67. if (image.platform === AiPlatformEnum.MIDJOURNEY) {
  68. midjourneyRef.value.settingValues(image)
  69. } else if (image.platform === AiPlatformEnum.OPENAI) {
  70. dall3Ref.value.settingValues(image)
  71. } else if (image.platform === AiPlatformEnum.STABLE_DIFFUSION) {
  72. stableDiffusionRef.value.settingValues(image)
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .ai-image {
  78. position: absolute;
  79. left: 0;
  80. right: 0;
  81. bottom: 0;
  82. top: 0;
  83. display: flex;
  84. flex-direction: row;
  85. height: 100%;
  86. width: 100%;
  87. .left {
  88. display: flex;
  89. flex-direction: column;
  90. padding: 20px;
  91. width: 350px;
  92. .segmented {
  93. }
  94. .segmented .el-segmented {
  95. --el-border-radius-base: 16px;
  96. --el-segmented-item-selected-color: #fff;
  97. background-color: #ececec;
  98. width: 350px;
  99. }
  100. .modal-switch-container {
  101. height: 100%;
  102. overflow-y: auto;
  103. margin-top: 30px;
  104. }
  105. }
  106. .main {
  107. flex: 1;
  108. background-color: #fff;
  109. }
  110. .right {
  111. width: 350px;
  112. background-color: #f7f8fa;
  113. }
  114. }
  115. </style>