zhengnaiwen_citu 1 tuần trước cách đây
mục cha
commit
821b81e6c4
2 tập tin đã thay đổi với 106 bổ sung5 xóa
  1. 10 0
      src/api/dataChart.js
  2. 96 5
      src/views/dataChart/dataChartEditChat.vue

+ 10 - 0
src/api/dataChart.js

@@ -45,3 +45,13 @@ export function addFeedback (data) {
 export function getFeedbackStats (data) {
   return http.get('/vanna/v0/qa_feedback/stats', data)
 }
+
+// 获取指定用户user_id的最近N次的会话信息
+export function getConversations (data) {
+  return http.get('/vanna/v0/user/guest/conversations', data)
+}
+
+// 获取指定用户user_id的最近N次的会话信息
+export function getConversationsById (id) {
+  return http.get(`/vanna/v0/conversation/${id}/messages`)
+}

+ 96 - 5
src/views/dataChart/dataChartEditChat.vue

@@ -1,5 +1,13 @@
 <template>
-  <div class="chart-content-chat heightFull d-flex flex-column">
+  <div class="chart-content-chat heightFull d-flex flex-column position-relative overflow-hidden">
+    <v-btn
+      class="history"
+      color="indigo lighten-1"
+      dark
+      @click.stop="drawer = !drawer"
+    >
+      最近会话
+    </v-btn>
     <div class="chart-content-chat-title mb-3">
       <v-tabs>
         <v-tab>AI 取数</v-tab>
@@ -222,19 +230,49 @@
         </div>
       </div>
     </div>
+    <v-navigation-drawer
+      v-model="drawer"
+      absolute
+      temporary
+      right
+      width="300"
+      overlay-opacity="0"
+    >
+      <v-list dense>
+        <v-list-item-group
+          v-model="selected"
+          color="primary"
+          @change="onSelectConversation"
+        >
+          <v-list-item
+            v-for="(conversation) in conversationList"
+            :key="conversation.conversation_id"
+          >
+            <v-list-item-content>
+              <v-list-item-title>{{ conversation.conversation_title }}</v-list-item-title>
+            </v-list-item-content>
+          </v-list-item>
+        </v-list-item-group>
+      </v-list>
+    </v-navigation-drawer>
   </div>
 </template>
 
 <script>
 import {
   getAsk,
-  addFeedback
+  addFeedback,
+  getConversations,
+  getConversationsById
 } from '@/api/dataChart'
 import { mapGetters } from 'vuex'
 export default {
   name: 'dataChartEditChat',
   data () {
     return {
+      selected: null,
+      lastSelected: null,
+      drawer: false,
       routingMode: undefined,
       chips: [
         { text: '聊天模式', value: 'chat_direct' },
@@ -256,13 +294,17 @@ export default {
         }
       ],
       abortController: null,
-      conversationId: undefined
+      conversationId: undefined,
+      conversationList: []
       // trueData: false
     }
   },
   computed: {
     ...mapGetters(['userInfo'])
   },
+  created () {
+    this.getConversationList()
+  },
   methods: {
     onNew () {
       this.abortController.abort('')
@@ -366,10 +408,53 @@ export default {
       }
       const { typeAxis, dataAxis } = model
       const data = {
-        type: typeAxis ? content.rows.map(e => e[typeAxis]) : [],
-        data: dataAxis ? dataAxis.map(e => content.rows.map(r => r[e])) : []
+        type: typeAxis ? content.records.rows.map(e => e[typeAxis]) : [],
+        data: dataAxis ? dataAxis.map(e => content.records.rows.map(r => r[e])) : []
       }
       this.$emit('render', data)
+    },
+    async getConversationList () {
+      try {
+        const { data } = await getConversations({ limit: 5 })
+        this.conversationList = data.conversations
+      } catch (error) {
+        this.$snackbar.error(error)
+      }
+    },
+    async onSelectConversation (index) {
+      if (!index) {
+        setTimeout(() => {
+          this.selected = this.lastSelected
+        })
+        return
+      }
+      this.lastSelected = index
+      try {
+        const { data } = await getConversationsById(this.conversationList[index].conversation_id)
+        this.items.splice(1, this.items.length - 1, ...data.messages.map(e => {
+          if (e.role === 'user') {
+            return {
+              type: 2,
+              user: '游客',
+              content: e.content
+            }
+          }
+          return {
+            type: 1,
+            content: e.metadata,
+            showSnackbar: false,
+            dataValidation: false,
+            question: e.content, // 记录当前问题
+            showMenu: false,
+            model: {
+              dataAxis: null,
+              typeAxis: null
+            }
+          }
+        }))
+      } catch (error) {
+        this.$snackbar.error(error)
+      }
     }
   }
 }
@@ -446,4 +531,10 @@ export default {
 .element::-webkit-scrollbar {
   display: none; /* Chrome/Safari/Opera */
 }
+.history {
+  position: absolute;
+  right: 20px;
+  top: 20px;
+  z-index: 1;
+}
 </style>