refactor(agent): 重构智能体聊天页面

- 修改 HistoryChat组件中显示智能体名称而非标题
- 优化 Chat 页面初始化逻辑,添加组件卸载时的销毁操作
- 更新 Index 页面中智能体产品的展示方式
This commit is contained in:
林志军
2025-07-17 19:32:47 +08:00
parent b3af007dd2
commit af147625ae
3 changed files with 60 additions and 13 deletions

View File

@ -6,7 +6,7 @@
<a-menu mode="inline" theme="light">
<a-menu-item key="1">
<span class="menu-title">{{ cozeInfo.title }}</span>
<span class="menu-title">{{ cozeInfo.name }}</span>
<span style="color: #8492ff; font-size: 12px">{{ cozeInfo.type == 1 ? '智能体' : '对话式' }}</span>
<span style="float: right">{{ cozeInfo.views }}次使用</span>
<p>{{ cozeInfo.description }}</p>

View File

@ -23,10 +23,11 @@
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, onUnmounted } from 'vue';
import { getChatAgent } from '@/api/all/agent';
import HistoryChat from './components/HistoryChat.vue';
import { useRouter } from 'vue-router';
const router = useRouter();
// 存储认证令牌
@ -82,7 +83,7 @@ const cozeInfo = reactive({
icon_url: '',
});
let cozeWebSDK = null;
const cozeWebSDK = null;
const initChat = async () => {
console.log(2323);
const { code, data } = await getChatAgent(query.id);
@ -93,15 +94,57 @@ const initChat = async () => {
Object.assign(cozeInfo, data.info);
console.log(cozeWebSDKConfig?.config?.bot_id, 'cozeWebSDKConfig?.config?.bot_id');
await loadScript('https://lf-cdn.coze.cn/obj/unpkg/flow-platform/chat-app-sdk/1.2.0-beta.10/libs/cn/index.js');
let config = data.cozeConfig;
let config = await getChatAgent(data.info.bot_id, data.info.title);
config.ui = editUi(data);
config.auth.onRefreshToken = function () {
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
};
cozeWebSDK = cozeWebSDK = new CozeWebSDK.WebChatClient(config);
cozeWebSDK = new CozeWebSDK.WebChatClient(config);
showChatPage();
};
//扣子配置
const cozeWebSdkConfig = (botId, title) => {
let config = {
config: {
bot_id: botId,
},
ui: {
chatBot: {
el: document.getElementById('coze-chat-container'),
width: '70%',
height: '100%',
title: title,
isNeedFunctionCallMessage: true,
},
base: {
icon: '',
zIndex: 1000,
},
header: {
isShow: true,
isNeedClose: false,
},
feedback: {
isNeedFeedback: true,
feedbackPanel: {
title: '您对这个回答有什么看法?请告诉我们',
placeholder: '请详细描述您的问题...',
tags: [
{
label: '信息不正确',
},
{
label: '敏感涉及 信息',
},
],
},
},
},
};
return config;
};
const editUi = (config) => {
let uiConfig = {
chatBot: {
@ -130,6 +173,10 @@ const showChatPage = () => {
onMounted(() => {
initChat();
});
//销毁组件
onUnmounted(() => {
cozeWebSDK.destroy();
});
</script>
<style scoped lang="scss">