yinbangzhong
2024-09-12 ff0ae974a1c561eaf2915988dac63cd066af189f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<template>
  <div class="layoutHisCenter">
    <a-button
      type="primary"
      status="danger"
      style="
        position: absolute;
        top: 10px;
        left: -40px;
        font-size: 30px;
        z-index: 99;
        cursor: pointer;
      "
      @click="emit('changeAgentType', '1')"
    >
      <template #icon>
        <icon-close style="font-size: 20px" />
      </template>
    </a-button>
 
    <a-scrollbar
      ref="scrollRef"
      class="left-list"
      style="
        height: calc(100vh - 160px);
        overflow-y: scroll;
        overflow-x: hidden;
      "
      v-if="isReached"
      @scroll="handleScroll"
    >
      <div class="historyTitle___F_iam">历史会话</div>
 
      <div class="search">
        <a-input-search @change="querySessionList('')"   v-model="searchValue" class="search-box" placeholder="按下Enter键,搜索会话名称">
 
        </a-input-search>
      </div>
 
      <div class="historyCenter">
        <div
          class="item historyCenter-box"
          v-for="session in sessionList"
          @click="querySessionDetail(session)"
          @mouseenter="handleMouseEnter(session)"
          @mouseleave="handleMouseLeave(session)"
        >
          <div class="text">
            <img
              :style="{ width: '16px' }"
              alt="dessert"
              :src="session.icon ? httpUrl + session.icon : imgSrc"
            />
            {{ session.name }}
          </div>
          <div class="time">
            <span v-show="session.showtype == 1" style="font-size: 14px">
              {{
                moment(new Date(session.create_time)).format(
                  'YYYY-MM-DD HH:mm:ss'
                )
              }}
            </span>
          </div>
          <a-button
            type="text"
            @click.stop="deleteSession(session)"
            style="color: red; position: absolute; right: 10px; top: 10px"
            v-show="session.showtype == 2"
          >
            <icon-delete style="font-size: 14px" />
          </a-button>
        </div>
      </div>
    </a-scrollbar>
  </div>
</template>
<script setup lang="ts">
import { IconClose, IconSearch } from "@arco-design/web-vue/es/icon";
import { nextTick, onBeforeMount, onBeforeUnmount, onMounted, reactive, ref } from "vue";
 
import { Message, Modal } from "@arco-design/web-vue";
import EventBus from "@/utils/EventBus";
import moment from "moment";
import { deleteSessionApi, sessionListApiPage } from "@/api/session";
import logo from "@/assets/images/model.png";
 
const emit = defineEmits(['querySessionDetail', 'changeAgentType']);
const sessionList = ref([]); //会话列表
  const activeSessionId = ref('');
  const fieldNames = { value: 'id', label: 'name' };
  const dialogs = ref([]);
  const dialogObj = reactive({});
  const agentObj = reactive({});
  const agentList = ref([]);
  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 querySessionList = async (id) => {
    const { code, data } = await sessionListApiPage({
      dialog_id: id,
      searchParam: searchValue.value,
      ...queryPage,
    });
    if (code === 200) {
      sessionList.value = data.map((item) => {
        return {
          ...item,
          showtype: 1,
        };
      });
      isReached.value = false;
      setTimeout(() => {
        isReached.value = true;
      }, 100);
      // total.value = sessionList.value.length;
    } else {
      Message.warning('查询失败');
    }
  };
 
  //根据会话id删除会话
  const deleteSession = async (session) => {
    Modal.confirm({
      title: '提示信息',
      content: '确认删除吗',
      okText: '确定',
      cancelText: '取消',
      hideTitle: true,
      onOk: async () => {
        const { code } = await deleteSessionApi([session.id]);
        if (code === 200) {
          Message.success('删除成功');
          querySessionList('');
        }
      },
      onCancel: () => {},
    });
  };
 
  const querySessionDetail = async (session) => {
    console.log(session, 'session');
    // 查询历史记录 app_type 1:智能体 2:agent
    if (!session.base) {
      // 生成智能体新的对话
      emit('changeAgentType', '1');
      emit('querySessionDetail', session);
    } else if (session.base == 'agent') {
      // 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');
    } else if (session.base == 'advanced-agent') {
      EventBus.emit('queryAgentSessionDetails', session);
      emit('changeAgentType', '5');
    }
  };
 
  const handleMouseEnter = (session) => {
    session.showtype = 2;
  };
 
  const handleMouseLeave = (session) => {
    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) {
        if (data.length == 0) {
          isReached.value = true;
          return;
        }
        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('');
  });
 
  onMounted(() => {
    console.log(httpUrl, '当前地址');
    EventBus.on('history', () => {
      emit('changeAgentType', '3');
      queryPage.page = 1;
      querySessionList('');
    });
    // 添加滚动事件监听器
    scrollRef.value.$el.addEventListener('scroll', handleScroll);
 
    // 清理函数
    return () => {
      scrollRef.value.$el.removeEventListener('scroll', handleScroll);
    };
  });
  onBeforeUnmount(() => {
    EventBus.off('history');
  });
</script>
<style scoped lang="less">
  .layoutHisCenter {
    width: 100%;
    //background: #999999;
    position: absolute;
    left: 0;
    top: 0;
    .historyTitle___F_iam {
      font-size: 36px;
      line-height: 50px;
      font-weight: 700;
      text-align: center;
    }
    .search {
      width: 100%;
      .search-box {
        width: 70%;
        margin-left: 15%;
        border: 1px solid var(--color-text-4);
        padding: 10px;
        border-radius: 12px;
        background: var(--color-bg-2);
        margin-top: 20px;
        margin-bottom: 20px;
        :deep(.arco-input-wrapper) {
          border: none;
          background: var(--color-bg-2);
        }
      }
    }
    .historyCenter {
      width: 100%;
      margin-top: 30px;
      .historyCenter-box {
        position: relative;
        display: flex;
        width: 70%;
        margin-left: 15%;
        //border: 1px solid var(--color-neutral-3);
        padding: 16px;
        border-radius: 12px;
        background: var(--color-bg-1);
        margin-top: 10px;
        cursor: pointer;
        justify-content: space-between;
        align-items: center;
        color: var(--color-text-2);
      }
      .historyCenter-box:hover {
        color: var(--color-text-2);
        //border: 1px solid var(--color-neutral-3);
        background: var(--color-bg-3);
        box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16),
          0 3px 6px 0 rgba(0, 0, 0, 0.12), 0 5px 12px 4px rgba(0, 0, 0, 0.09);
      }
    }
  }
</style>