index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. <Common
  10. v-if="selectPlatform === 'common'"
  11. ref="commonRef"
  12. :models="models"
  13. @on-draw-complete="handleDrawComplete"
  14. />
  15. <Dall3
  16. v-if="selectPlatform === AiPlatformEnum.OPENAI"
  17. ref="dall3Ref"
  18. :models="models"
  19. @on-draw-start="handleDrawStart"
  20. @on-draw-complete="handleDrawComplete"
  21. />
  22. <Midjourney
  23. v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY"
  24. ref="midjourneyRef"
  25. :models="models"
  26. />
  27. <StableDiffusion
  28. v-if="selectPlatform === AiPlatformEnum.STABLE_DIFFUSION"
  29. ref="stableDiffusionRef"
  30. :models="models"
  31. @on-draw-complete="handleDrawComplete"
  32. />
  33. </div>
  34. </div>
  35. <div class="main">
  36. <ImageList ref="imageListRef" @on-regeneration="handleRegeneration" />
  37. </div>
  38. </div>
  39. </template>
  40. <script setup lang="ts">
  41. import ImageList from './components/ImageList.vue'
  42. import { AiPlatformEnum } from '@/views/ai/utils/constants'
  43. import { ImageVO } from '@/api/ai/image'
  44. import Dall3 from './components/dall3/index.vue'
  45. import Midjourney from './components/midjourney/index.vue'
  46. import StableDiffusion from './components/stableDiffusion/index.vue'
  47. import Common from './components/common/index.vue'
  48. import { ModelApi, ModelVO } from '@/api/ai/model/model'
  49. import { AiModelTypeEnum } from '@/views/ai/utils/constants'
  50. const imageListRef = ref<any>() // image 列表 ref
  51. const dall3Ref = ref<any>() // dall3(openai) ref
  52. const midjourneyRef = ref<any>() // midjourney ref
  53. const stableDiffusionRef = ref<any>() // stable diffusion ref
  54. const commonRef = ref<any>() // stable diffusion ref
  55. // 定义属性
  56. const selectPlatform = ref('common') // 选中的平台
  57. const platformOptions = [
  58. {
  59. label: '通用',
  60. value: 'common'
  61. },
  62. {
  63. label: 'DALL3 绘画',
  64. value: AiPlatformEnum.OPENAI
  65. },
  66. {
  67. label: 'MJ 绘画',
  68. value: AiPlatformEnum.MIDJOURNEY
  69. },
  70. {
  71. label: 'SD 绘图',
  72. value: AiPlatformEnum.STABLE_DIFFUSION
  73. }
  74. ]
  75. const models = ref<ModelVO[]>([]) // 模型列表
  76. /** 绘画 start */
  77. const handleDrawStart = async (platform: string) => {}
  78. /** 绘画 complete */
  79. const handleDrawComplete = async (platform: string) => {
  80. await imageListRef.value.getImageList()
  81. }
  82. /** 重新生成:将画图详情填充到对应平台 */
  83. const handleRegeneration = async (image: ImageVO) => {
  84. // 切换平台
  85. selectPlatform.value = image.platform
  86. // 根据不同平台填充 image
  87. await nextTick()
  88. if (image.platform === AiPlatformEnum.MIDJOURNEY) {
  89. midjourneyRef.value.settingValues(image)
  90. } else if (image.platform === AiPlatformEnum.OPENAI) {
  91. dall3Ref.value.settingValues(image)
  92. } else if (image.platform === AiPlatformEnum.STABLE_DIFFUSION) {
  93. stableDiffusionRef.value.settingValues(image)
  94. }
  95. // TODO @fan:貌似 other 重新设置不行?
  96. }
  97. /** 组件挂载的时候 */
  98. onMounted(async () => {
  99. // 获取模型列表
  100. models.value = await ModelApi.getModelSimpleList(AiModelTypeEnum.IMAGE)
  101. })
  102. </script>
  103. <style scoped lang="scss">
  104. .ai-image {
  105. position: absolute;
  106. left: 0;
  107. right: 0;
  108. bottom: 0;
  109. top: 0;
  110. display: flex;
  111. flex-direction: row;
  112. height: 100%;
  113. width: 100%;
  114. .left {
  115. display: flex;
  116. flex-direction: column;
  117. padding: 20px;
  118. width: 390px;
  119. .segmented .el-segmented {
  120. --el-border-radius-base: 16px;
  121. --el-segmented-item-selected-color: #fff;
  122. background-color: #ececec;
  123. width: 350px;
  124. }
  125. .modal-switch-container {
  126. height: 100%;
  127. overflow-y: auto;
  128. margin-top: 30px;
  129. }
  130. }
  131. .main {
  132. flex: 1;
  133. background-color: #fff;
  134. }
  135. .right {
  136. width: 350px;
  137. background-color: #f7f8fa;
  138. }
  139. }
  140. </style>