liudong
2024-08-16 ab731748ca873ce980d10001fdb12ae319191ab3
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
<template>
  <div class="layoutAgentCenter">
              <a-scrollbar
                style="
                  height: calc(100vh - 100px);
                  overflow-y: auto;
                  overflow-x: hidden;
                "
              >
                <div class="search">
                  <!--                  查询框-->
                  <img src="@/assets/images/his.png"
                       style="width: 100%"
                       alt="">
 
                </div>
                <div class="agentMainCenter">
                  <a-row class="agentCenter">
                    <a-col :span="8" v-for="item in dialogs">
                      <div
                        class="item agentCenter-box"
                        @click="createNewSession(item)"
                      >
                        <div class="text" >
                          <a-avatar>
                            <img
                              :style="{ width: '100%' }"
                              alt="dessert"
                              :src="item.avatar || imgSrc"
                            />
                          </a-avatar>
                          <span style="margin-left: 10px;font-weight: 500;color: var(--color-text-1)">
                            {{ item.name }}
                          </span>
                        </div>
                        <div class="time"
                        >
                        </div>
                      </div>
                    </a-col>
                  </a-row>
                </div>
              </a-scrollbar>
  </div>
</template>
<script setup lang="ts">
import {
  IconClose,
  IconSearch,
  IconTiktokColor
} from "@arco-design/web-vue/es/icon";
import { useAppStore, useUserStore } from "@/store";
import { computed, nextTick, onMounted, watch, reactive, ref, onBeforeMount, onBeforeUnmount } from "vue";
 
import { Message } from "@arco-design/web-vue";
import EventBus from '@/utils/EventBus';
import moment from "moment";
import {
  addSessionApi,
  chatApi,
  getDialogListApi,
  getSessionDetailsApi,
  sessionListApi
} from "@/api/session";
import { queryCanvasList } from "@/api/Agent";
const emit = defineEmits(["querySessionDetail","changeAgentType","createSession"]);
import logo from "@/assets/images/model.png";
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 imgSrc = ref(logo);
const DialogList = async () => {
  const { code, data } = await getDialogListApi();
  if (code === 200) {
    if (data) {
      selectValue.value = data[0].id;
      dialogs.value = data.map((item) => {
        return {
          ...item,
          type: 1 //智能体
        };
      });
      // console.log(data, "dialogs");
      queryCanvas();
    }
  }
};
 
const queryCanvas = async (params = {}) => {
  try {
    const { data } = await queryCanvasList(params);
    console.log(data, "agent");
    agentList.value = data.map((item) => {
      return {
        ...item,
        name: item.title,
        type: 2 //agent
      };
    });
    // 合并数组
    dialogs.value = dialogs.value.concat(agentList.value);
 
 
  } catch (err) {
    // you can report use errorHandler or other
  } finally {
  }
};
 
 
// 查询会话列表
const querySessionList = async (id) => {
  const { code, data } = await sessionListApi(id);
  if (code === 200) {
    sessionList.value = data;
 
 
 
  } else {
    Message.warning("查询失败");
  }
};
 
const createNewSession = async (session) => {
  console.log(session, 'session');
  // 查询历史记录
  // emit('querySessionDetail',session);
  if (session.type == '1') {
    // 生成智能体新的对话
    emit('createSession',session.id);
    emit('changeAgentType','1');
  } else {
    // 生成agent新的对话
    EventBus.emit("createAgent",session);
    emit('changeAgentType','2');
  }
 
 
 
}
onBeforeMount(()=>{
  DialogList()
})
 
onMounted(() => {
  EventBus.on("smartAi", () => {
    emit('changeAgentType','4');
    DialogList();
  });
})
onBeforeUnmount(() => {
  EventBus.off("smartAi");
});
 
 
</script>
<style scoped lang="less">
  .layoutAgentCenter{
    width: 100%;
    //background: #999999;
    position: absolute;
    left: 0;
    top: 0;
    .agentTitle___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);
        }
      }
    }
    .agentMainCenter{
      width: 70%;
      margin: 0 auto;
      .agentCenter{
        width: 100%;
        margin-top: 30px;
        .agentCenter-box{
          display: flex;
          width: 90%;
          margin: 0 auto;
          //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);
        }
        .agentCenter-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>