index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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
  16. v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY"
  17. ref="midjourneyRef"
  18. />
  19. <StableDiffusion
  20. v-if="selectPlatform === AiPlatformEnum.STABLE_DIFFUSION"
  21. ref="stableDiffusionRef"
  22. @on-draw-complete="handleDrawComplete"
  23. />
  24. </div>
  25. </div>
  26. <div class="main">
  27. <ImageTask ref="imageTaskRef" @on-regeneration="handleRegeneration" />
  28. </div>
  29. </div>
  30. </template>
  31. <script setup lang="ts">
  32. // TODO @fan:在整个挪到 /views/ai/image/index 目录。因为我想在 /views/ai/image/manager 做管理的功能,进行下区分!
  33. import Dall3 from './dall3/index.vue'
  34. import Midjourney from './midjourney/index.vue'
  35. import StableDiffusion from './stable-diffusion/index.vue'
  36. import ImageTask from './ImageTask.vue'
  37. import { AiPlatformEnum } from '@/views/ai/utils/constants'
  38. import {ImageVO} from "@/api/ai/image";
  39. const imageTaskRef = ref<any>() // image task ref
  40. const dall3Ref = ref<any>() // openai ref
  41. const midjourneyRef = ref<any>() // midjourney ref
  42. const stableDiffusionRef = ref<any>() // stable diffusion ref
  43. // 定义属性
  44. const selectPlatform = ref('StableDiffusion')
  45. const platformOptions = [
  46. {
  47. label: 'DALL3 绘画',
  48. value: AiPlatformEnum.OPENAI
  49. },
  50. {
  51. label: 'MJ 绘画',
  52. value: AiPlatformEnum.MIDJOURNEY
  53. },
  54. {
  55. label: 'Stable Diffusion',
  56. value: AiPlatformEnum.STABLE_DIFFUSION
  57. }
  58. ]
  59. const drawIn = ref<boolean>(false) // 生成中
  60. /** 绘画 - start */
  61. const handleDrawStart = async (type) => {
  62. // todo @fan:这个是不是没用啦?
  63. drawIn.value = true
  64. }
  65. /** 绘画 - complete */
  66. const handleDrawComplete = async (type) => {
  67. drawIn.value = false
  68. // todo
  69. await imageTaskRef.value.getImageList()
  70. }
  71. /** 绘画 - 重新生成 */
  72. const handleRegeneration = async (imageDetail: ImageVO) => {
  73. // 切换平台
  74. selectPlatform.value = imageDetail.platform
  75. console.log('切换平台', imageDetail.platform)
  76. // 根据不同平台填充 imageDetail
  77. if (imageDetail.platform === AiPlatformEnum.MIDJOURNEY) {
  78. await nextTick(async () => {
  79. midjourneyRef.value.settingValues(imageDetail)
  80. })
  81. } else if (imageDetail.platform === AiPlatformEnum.OPENAI) {
  82. await nextTick(async () => {
  83. dall3Ref.value.settingValues(imageDetail)
  84. })
  85. } else if (imageDetail.platform === AiPlatformEnum.STABLE_DIFFUSION) {
  86. await nextTick(async () => {
  87. stableDiffusionRef.value.settingValues(imageDetail)
  88. })
  89. }
  90. }
  91. </script>
  92. <style scoped lang="scss">
  93. .ai-image {
  94. position: absolute;
  95. left: 0;
  96. right: 0;
  97. bottom: 0;
  98. top: 0;
  99. display: flex;
  100. flex-direction: row;
  101. height: 100%;
  102. width: 100%;
  103. .left {
  104. display: flex;
  105. flex-direction: column;
  106. padding: 20px;
  107. width: 350px;
  108. .segmented {
  109. }
  110. .segmented .el-segmented {
  111. --el-border-radius-base: 16px;
  112. --el-segmented-item-selected-color: #fff;
  113. background-color: #ececec;
  114. width: 350px;
  115. }
  116. .modal-switch-container {
  117. height: 100%;
  118. overflow-y: auto;
  119. margin-top: 30px;
  120. }
  121. }
  122. .main {
  123. flex: 1;
  124. background-color: #fff;
  125. }
  126. .right {
  127. width: 350px;
  128. background-color: #f7f8fa;
  129. }
  130. }
  131. </style>