zhangxiao
2024-08-22 04f37dbc48f29b48ba65e8ad259240937f0e4e0a
src/views/sessionManager/components/historySession.vue
@@ -18,12 +18,15 @@
              </a-button>
              <a-scrollbar
                ref="scrollRef"
                class="left-list"
                style="
                  height: calc(100vh - 100px);
                  overflow-y: auto;
                  height: calc(100vh - 160px);
                  overflow-y: scroll;
                  overflow-x: hidden;
                "
                v-if="isReached"
                @scroll="handleScroll"
              >
                <div class="historyTitle___F_iam">历史会话</div>
@@ -54,7 +57,7 @@
                      <img
                        :style="{ width: '16px' }"
                        alt="dessert"
                        :src="session.avatar || imgSrc"
                        :src="session.icon ? httpUrl + session.icon : imgSrc"
                      />
                      {{ session.name }}
                    </div>
@@ -94,13 +97,14 @@
  getDialogListApi,
  getSessionDetailsApi,
  deleteSessionApi,
  sessionListApi
  sessionListApiPage
} from "@/api/session";
import { queryCanvasList } from "@/api/Agent";
const emit = defineEmits(["querySessionDetail","changeAgentType"]);
import logo from "@/assets/images/model.png";
import { deleteKnow } from "@/api/kbList";
import { getAgentSessionDetailsApi } from "@/api/agentSession";
const sessionList = ref([]); //会话列表
const activeSessionId = ref("");
const fieldNames = { value: "id", label: "name" };
@@ -111,7 +115,18 @@
const searchValue = ref("");
const selectValue = ref("");
const sectionList = ref({});
const scrollRef = ref(null);
const httpUrl = localStorage.getItem('httpUrl');
const imgSrc = ref(logo);
let scrollTopVal = ref(0);
let queryPage = reactive({
  page: 1,
  page_size: 50
})
let total = ref(0);
let sessionScrollList = ref([]);
let isReached = ref(true);
const DialogList = async () => {
  const { code, data } = await getDialogListApi();
  if (code === 200) {
@@ -161,7 +176,10 @@
// 查询会话列表
const querySessionList = async (id) => {
  const { code, data } = await sessionListApi(id);
  const { code, data } = await sessionListApiPage({
    dialog_id: id,
    ...queryPage
  });
  if (code === 200) {
    sessionList.value = data.map((item) => {
      return {
@@ -169,7 +187,11 @@
        showtype: 1
      }
    });
    isReached.value = false;
    setTimeout(()=>{
      isReached.value = true;
    },100)
    // total.value = sessionList.value.length;
  } else {
@@ -198,8 +220,25 @@
const querySessionDetail = async (session) => {
  console.log(session, 'session');
  emit('changeAgentType','1');
  emit('querySessionDetail',session);
  // 查询历史记录 app_type 1:智能体 2:agent
  if (session.app_type == '1') {
    // 生成智能体新的对话
    emit('changeAgentType','1');
    emit('querySessionDetail',session);
  } else  if (session.app_type == '2'){
    // agent对象数据封装
    // const { code, data } = await getAgentSessionDetailsApi(session.dialog_id);
    // if (code == 0) {
    //   console.log(data,'会话详情');
    //   // let sessionObj = {
    //   //   id: session.app_id,
    //   //   dsl: data.dsl,
    //   //   title: session.name,
    //   // }
    // }
    EventBus.emit("queryAgentSessionDetail",session);
    emit('changeAgentType','2');
  }
}
@@ -211,6 +250,58 @@
  session.showtype = 1;
};
const handleScroll = async (e: any) => {
  scrollTopVal.value = e.target.scrollTop;
  let offsetHeight = e.target.offsetHeight;
  let scrollHeight = e.target.scrollHeight;
  if (scrollTopVal.value + offsetHeight >= scrollHeight-1) {
    console.log(scrollTopVal.value);
    // console.log(offsetHeight);
    // console.log(scrollHeight);
    //滚动条到达底部
    // if (sessionList.value.length < total.value) {
    //   //数据为加载完,继续赋值
    //   // queryPage.page++
    //
    //
    //
    // }
    queryPage.page++
    const { code, data } = await sessionListApiPage({
      dialog_id: '',
      ...queryPage
    });
    if (code === 200) {
       sessionScrollList.value = data.map((item) => {
        return {
          ...item,
          showtype: 1
        }
      });
      // total.value = sessionList.value.length;
      sessionList.value = [...sessionList.value,...sessionScrollList.value];
      isReached.value = false;
      setTimeout(()=>{
        isReached.value = true;
        nextTick(()=>{
          scrollRef.value.scrollTop(scrollTopVal.value);
          // console.log(scrollRef.value.$el.scrollTop,'scrollTopVal');
          // console.log(scrollTopVal.value,'scrollTopVal');
        })
      },100)
    } else {
      Message.warning("查询失败");
    }
  }
}
onBeforeMount(()=>{
  // DialogList()
  querySessionList('');
@@ -220,9 +311,20 @@
  EventBus.on("history", () => {
    emit('changeAgentType','3');
    // DialogList()
    queryPage.page = 1;
    querySessionList('');
  });
  // 添加滚动事件监听器
  scrollRef.value.$el.addEventListener('scroll', handleScroll);
  // 清理函数
  return () => {
    scrollRef.value.$el.removeEventListener('scroll', handleScroll);
  };
})
onBeforeUnmount(() => {
  EventBus.off("history");