index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /** 绘画 - start */
  60. const handleDrawStart = async (type) => {
  61. }
  62. /** 绘画 - complete */
  63. const handleDrawComplete = async (type) => {
  64. await imageTaskRef.value.getImageList()
  65. }
  66. /** 绘画 - 重新生成 */
  67. const handleRegeneration = async (imageDetail: ImageVO) => {
  68. // 切换平台
  69. selectPlatform.value = imageDetail.platform
  70. console.log('切换平台', imageDetail.platform)
  71. // 根据不同平台填充 imageDetail
  72. if (imageDetail.platform === AiPlatformEnum.MIDJOURNEY) {
  73. await nextTick(async () => {
  74. midjourneyRef.value.settingValues(imageDetail)
  75. })
  76. } else if (imageDetail.platform === AiPlatformEnum.OPENAI) {
  77. await nextTick(async () => {
  78. dall3Ref.value.settingValues(imageDetail)
  79. })
  80. } else if (imageDetail.platform === AiPlatformEnum.STABLE_DIFFUSION) {
  81. await nextTick(async () => {
  82. stableDiffusionRef.value.settingValues(imageDetail)
  83. })
  84. }
  85. }
  86. </script>
  87. <style scoped lang="scss">
  88. .ai-image {
  89. position: absolute;
  90. left: 0;
  91. right: 0;
  92. bottom: 0;
  93. top: 0;
  94. display: flex;
  95. flex-direction: row;
  96. height: 100%;
  97. width: 100%;
  98. .left {
  99. display: flex;
  100. flex-direction: column;
  101. padding: 20px;
  102. width: 350px;
  103. .segmented {
  104. }
  105. .segmented .el-segmented {
  106. --el-border-radius-base: 16px;
  107. --el-segmented-item-selected-color: #fff;
  108. background-color: #ececec;
  109. width: 350px;
  110. }
  111. .modal-switch-container {
  112. height: 100%;
  113. overflow-y: auto;
  114. margin-top: 30px;
  115. }
  116. }
  117. .main {
  118. flex: 1;
  119. background-color: #fff;
  120. }
  121. .right {
  122. width: 350px;
  123. background-color: #f7f8fa;
  124. }
  125. }
  126. </style>