CzRger 3 weeks ago
parent
commit
bfae63df25

+ 9 - 0
src/api/modules/app/chat.ts

@@ -11,3 +11,12 @@ export const appTextToAudio = (params) =>
     },
     proxy,
   )
+// 查询应用的会话列表
+export const appConversationsSearch = (params) =>
+  post(`/app/conversations/search`, params, {}, proxy)
+// x
+export const appConversations = (id, params) =>
+  get(`/app/conversations/${id}`, params, {}, proxy)
+// 对话重命名
+export const appConversationsRename = (params) =>
+  post(`/app/conversations/rename`, params, {}, proxy)

File diff suppressed because it is too large
+ 5 - 0
src/assets/svg/msg.svg


+ 2 - 0
src/types/chat.ts

@@ -11,4 +11,6 @@ export type AnswerStruct = {
   feedback: 'good' | 'bad'
   finished?: boolean
   error?: boolean
+  messageId?: string
+  taskId?: string
 }

+ 14 - 3
src/views/chat/normal.vue

@@ -101,6 +101,8 @@ const state: any = reactive({
     appId: props.ID,
     query: '',
     modelConfig: {},
+    conversationId: '',
+    parentMessageId: '',
   },
   isWaiting: false,
   isStop: false,
@@ -245,17 +247,26 @@ const onSend = (text = '', isSet = false) => {
       text: '',
       loading: true,
       error: false,
+      messageId: '',
+      taskId: '',
     })
     state.chats.push(answer)
     scrollToEnd()
     state.isWaiting = true
     state.isStop = true
-    chatMessage(state.params, {
+    const p = {}
+    for (const [k, v] of Object.entries(state.params)) {
+      if (isValue(v)) {
+        p[k] = v
+      }
+    }
+    chatMessage(p, {
       onData: (text, data) => {
         console.log(text, data)
         state.isWaiting = false
-        // answer.messageId = messageId
-        // answer.taskId = taskId
+        state.params.conversationId = data.conversation_id
+        answer.messageId = data.message_id
+        answer.taskId = data.task_id
         answer.loading = false
         answer.text += text
         scrollToEnd()

+ 54 - 15
src/views/manage/home/app/index.vue

@@ -9,11 +9,19 @@
     <div class="bm-main-box" style="flex-direction: row">
       <div class="flex w-104 flex-col p-4">
         <div class="flex border-b border-gray-300 pb-4">
-          <img src="@/assets/images/app/app-default-logo.png" class="size-15" />
+          <template v-if="state.detail.icon">
+            <img :src="state.detail.icon" class="size-15" />
+          </template>
+          <template v-else>
+            <img
+              src="@/assets/images/app/app-default-logo.png"
+              class="size-15"
+            />
+          </template>
           <div class="ml-2 flex flex-1 flex-col justify-around">
             <div class="flex justify-between">
               <div class="text-xl font-bold text-[#303133]" v-title>
-                应用名称
+                {{ state.detail.name }}
               </div>
               <el-tooltip
                 :content="false ? '取消收藏' : '收藏'"
@@ -34,6 +42,11 @@
             </div>
           </div>
         </div>
+        <div
+          class="__hover mt-4 flex h-10.5 w-full items-center justify-center gap-2 rounded-lg bg-[#EAF1FF] text-[var(--czr-main-color)]"
+        >
+          <SvgIcon name="msg" :active="true" />开启新对话
+        </div>
         <div class="__czr-title_2 mt-4">
           记录
           <div
@@ -68,18 +81,25 @@
       </div>
       <div
         class="m-1 flex-1 rounded-lg border-1 border-[var(--czr-main-color)]/5 shadow"
+        v-loading="state.chat.loading"
       >
-        <chat :online="state.isOnline" :ID="state.ID" />
+        <chat :online="state.chat.isOnline" :ID="state.ID" ref="ref_chat" />
       </div>
     </div>
   </div>
 </template>
 
 <script setup lang="ts">
-import { onMounted, reactive } from 'vue'
+import { nextTick, onMounted, reactive, ref } from 'vue'
 import toBackCom from '@/views/manage/components/to-back.vue'
 import { useRoute, useRouter } from 'vue-router'
 import chat from '@/views/chat/index.vue'
+import {
+  appConversations,
+  appConversationsSearch,
+  appHistory,
+} from '@/api/modules/app/chat'
+import { appDetail } from '@/api/modules/app'
 
 const router = useRouter()
 const route = useRoute()
@@ -88,8 +108,12 @@ const state: any = reactive({
   ID: route.params.id,
   detail: {},
   history: [],
-  isOnline: true,
+  chat: {
+    isOnline: false,
+    loading: false,
+  },
 })
+const ref_chat = ref()
 const initHistory = () => {
   const arr = []
   for (let i = 0; i < 20; i++) {
@@ -97,7 +121,13 @@ const initHistory = () => {
       name: '水水水水水水水水水水水水水水水水水水水水水水水水水水水水水',
     })
   }
-  state.history = arr
+  appConversationsSearch({
+    appId: state.ID,
+    page: 1,
+    size: 100000,
+  }).then(({ data }: any) => {
+    state.history = data.records
+  })
 }
 onMounted(() => {
   initDictionary()
@@ -105,16 +135,25 @@ onMounted(() => {
 })
 const initDetail = () => {
   if (state.ID) {
-    state.detail = {}
-    // pluginDetail(state.ID)
-    //   .then(({ data }: any) => {
-    //     state.detail = data
-    //   })
-    //   .catch(() => {})
-    //   .finally(() => {})
-    initHistory()
+    state.chat.loading = true
+    appDetail(state.ID)
+      .then(({ data }: any) => {
+        console.log(2222)
+        state.detail = data
+        document.title = state.detail.name
+        state.chat.isOnline = state.detail.userInputMethod == 1
+        state.chat.loading = false
+        nextTick(() => {
+          ref_chat.value?.init()
+        })
+        initHistory()
+      })
+      .catch(() => {
+        console.log(3333)
+        // router.push({ name: '4806d051-e037-4d9d-99a0-78aa2f2f362b' })
+      })
   } else {
-    router.push({ name: 'd446bfb3-4605-477f-a0f4-b7a0a1aa78fe' })
+    router.push({ name: '4806d051-e037-4d9d-99a0-78aa2f2f362b' })
   }
 }
 const initDictionary = () => {