瀏覽代碼

处理获取绘画结果记录

liyanbo 10 月之前
父節點
當前提交
94ad075e8a
共有 2 個文件被更改,包括 18 次插入35 次删除
  1. 5 6
      src/api/questions.js
  2. 13 29
      src/views/AIPainting.vue

+ 5 - 6
src/api/questions.js

@@ -62,12 +62,11 @@ export function CreatePainting (data){
   })
 }
 // 绘画
-export function PaintingGetMys (ids){
-  const convertedIds = ids.map(id => String(Number(id)));
-  console.log(convertedIds);
-  return axios({
+export async function PaintingGetMys(ids) {
+  return await axios({
     url: "bjdxWeb/ai/painting-get-mys",
     method: 'get',
-    params: { ids: convertedIds.join(',') }
+    data: {ids: ids.join(',')}
   })
-}
+}
+

+ 13 - 29
src/views/AIPainting.vue

@@ -19,15 +19,11 @@
           <div class="message-list">
             <div v-for="(item, index) in imageAllList" :key="index">
 
-              <!-- AI消息 -->
-              <div class="ai-message" v-if="item.type !== 'user'">
-                {{ item.content }}
-              </div>
-
               <!-- 用户消息 -->
               <div class="user-message" v-if="item.type === 'user'">
                 {{ item.content }}
               </div>
+
               <!-- AI生成图片对话框 -->
               <div class="ai-message" v-if="item.type !== 'user'">
 
@@ -125,7 +121,7 @@ const inputMessage = ref('')
 // 发送消息函数
 const sendMessage = () => {
   if (inputMessage.value.trim()) {
-    messages.value.push(inputMessage.value.trim())
+    // messages.value.push(inputMessage.value.trim())
     inputMessage.value = ''
 
     let content = inputMessage.value.trim();
@@ -142,7 +138,6 @@ const sendMessage = () => {
       content: "正在为您生成图片,请稍等...",
     })
 
-
     CreatePainting({
       "modelId": 56,
       "prompt":content,
@@ -151,8 +146,8 @@ const sendMessage = () => {
     }).then(res=>{
       console.log("生成图片",res)
       //目前写死调用已生成的图片,全部通了后再改
-      // inProgressImageMap.value[res.data] = {}
-      inProgressImageMap.value[260] = {}
+      inProgressImageMap.value[res.data] = {id:res.data,status:AiImageStatusEnum.IN_PROGRESS}
+      // inProgressImageMap.value[260] = {id:260,status:AiImageStatusEnum.IN_PROGRESS}
     })
   }
 }
@@ -171,12 +166,6 @@ import {
   ZoomOut,
 } from '@element-plus/icons-vue'
 
-const url =
-  'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg'
-const srcList = [
-  'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
-]
-
 
 const imageAllList = ref([]) // 对话的消息列表
 const imageList = ref([]) // image 列表
@@ -187,11 +176,11 @@ const inProgressTimer = ref() // 生成中的 image 定时器,轮询生成进
 
 /** 轮询生成中的 image 列表 */
 const refreshWatchImages = async () => {
-  const imageIds = Object.keys(inProgressImageMap.value)
-  if (imageIds.length == 0) {
+  const imageIds = Object.keys(inProgressImageMap.value).map(Number)
+  if (imageIds.length === 0) {
     return
   }
-  console.log("轮询生成中的 image 列表",imageIds)
+  console.log("轮询生成中的 image 列表",imageIds,imageIds.join(','))
   const list = await PaintingGetMys(imageIds)
   console.log("轮询生成中的 image 列表",list)
   const newWatchImages = {}
@@ -199,18 +188,13 @@ const refreshWatchImages = async () => {
     if (image.status === AiImageStatusEnum.IN_PROGRESS) {
       newWatchImages[image.id] = image
     } else {
-    //   const index = imageList.value.findIndex((oldImage) => image.id === oldImage.id)
-    //   if (index >= 0) {
-        // 更新 imageList
-        // imageList.value[index] = image
 
-        imageAllList.value.pop();
-        imageAllList.value.push({
-          type: 'ai',
-          content: "已为您生成图片:",
-          imageList: image.picUrl,
-        })
-      // }
+      imageAllList.value.pop();
+      imageAllList.value.push({
+        type: 'ai',
+        content: "已为您生成图片:",
+        imageList: image.picUrl,
+      })
     }
   })
   console.log("================",imageAllList)