2025-07-10 19:05:38 +08:00
|
|
|
|
<template>
|
2025-08-04 11:42:24 +08:00
|
|
|
|
<div class="px-4px h-full overflow-hidden">
|
|
|
|
|
|
<div class="back-wap cursor-pointer mb-17px mt--3px !w-fit" @click="goChatIndex">
|
|
|
|
|
|
<icon-left size="16" class="color-#737478 mr-4px" />
|
|
|
|
|
|
<span class="cs">返回空间</span>
|
2025-07-30 12:00:14 +08:00
|
|
|
|
</div>
|
2025-07-29 17:59:55 +08:00
|
|
|
|
<div class="workflow-container">
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<div class="left-wap mr-24px" v-if="isCollapsed == false">
|
2025-08-04 13:55:46 +08:00
|
|
|
|
<div class="w-full w-100% mb-15px h-160px rounded-8px" v-image-main-color="cozeInfo.image_url">
|
2025-08-04 11:42:24 +08:00
|
|
|
|
<img v-if="cozeInfo?.image_url" :src="cozeInfo?.image_url" class="w-full h-full object-contain" />
|
2025-07-30 14:07:18 +08:00
|
|
|
|
</div>
|
2025-08-04 13:55:46 +08:00
|
|
|
|
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<div class="content mb-15px">
|
2025-07-29 17:59:55 +08:00
|
|
|
|
<div class="title-body">
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<div class="text mr-4px">{{ cozeInfo?.name }}</div>
|
|
|
|
|
|
<div class="tag-body">
|
2025-07-29 17:59:55 +08:00
|
|
|
|
<div class="">
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<SvgIcon size="12" name="svg-chatbot" class="color-#6D4CFE" />
|
2025-07-29 17:59:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="text">对话式</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<div class="use-body flex items-center">
|
|
|
|
|
|
<div class="num mr-2px">{{ formatNumberShow({ value: cozeInfo?.views, showExactValue: true }) }}</div>
|
2025-07-29 17:59:55 +08:00
|
|
|
|
<div class="text">次使用</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="description">
|
|
|
|
|
|
<div class="text">
|
|
|
|
|
|
{{ cozeInfo?.description }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="right-wap">
|
|
|
|
|
|
<div class="header">
|
|
|
|
|
|
<div class="body">
|
|
|
|
|
|
<div class="">
|
2025-07-30 12:00:14 +08:00
|
|
|
|
<div class="toggle-btn cursor-pointer" @click="toggleCollapse">
|
2025-07-28 19:59:54 +08:00
|
|
|
|
<a-tooltip :content="isCollapsed ? '展开' : '折叠'">
|
|
|
|
|
|
<img class="status-icon" :src="isCollapsed ? menuUnfold : menuFold" />
|
|
|
|
|
|
</a-tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-29 17:59:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-31 11:19:53 +08:00
|
|
|
|
<div class="coze-content" id="coze-chat-container"></div>
|
2025-07-29 17:59:55 +08:00
|
|
|
|
</div>
|
2025-07-15 15:16:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-10 19:05:38 +08:00
|
|
|
|
</template>
|
2025-07-15 15:16:03 +08:00
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-07-18 10:11:13 +08:00
|
|
|
|
import { ref, onMounted } from 'vue';
|
2025-07-15 15:16:03 +08:00
|
|
|
|
import { getChatAgent } from '@/api/all/agent';
|
2025-07-16 18:49:28 +08:00
|
|
|
|
import { useRouter } from 'vue-router';
|
2025-07-28 16:08:02 +08:00
|
|
|
|
import menuFold from '@/assets/svg/menu-fold.svg';
|
|
|
|
|
|
import menuUnfold from '@/assets/svg/menu-unfold.svg';
|
2025-08-04 11:42:24 +08:00
|
|
|
|
import { formatNumberShow } from '@/utils/tools';
|
2025-07-17 19:32:47 +08:00
|
|
|
|
|
2025-07-16 18:49:28 +08:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
2025-07-15 15:16:03 +08:00
|
|
|
|
// 存储认证令牌
|
2025-07-24 19:07:46 +08:00
|
|
|
|
const authToken = ref('');
|
2025-07-28 16:08:02 +08:00
|
|
|
|
const isCollapsed = ref(false);
|
|
|
|
|
|
|
|
|
|
|
|
// 切换折叠状态
|
|
|
|
|
|
const toggleCollapse = () => {
|
|
|
|
|
|
isCollapsed.value = !isCollapsed.value;
|
|
|
|
|
|
};
|
2025-07-15 15:16:03 +08:00
|
|
|
|
|
|
|
|
|
|
// 模拟从API获取token
|
|
|
|
|
|
const fetchToken = async () => {
|
|
|
|
|
|
// 实际开发中应替换为真实的 API 请求
|
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
resolve('pat_' + Math.random().toString(36).substring(2, 15));
|
|
|
|
|
|
}, 500);
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新token
|
|
|
|
|
|
const refreshToken = async () => {
|
|
|
|
|
|
authToken.value = await fetchToken();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-16 18:49:28 +08:00
|
|
|
|
const goChatIndex = async () => {
|
|
|
|
|
|
router.push({
|
|
|
|
|
|
path: '/agent/index',
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-15 15:16:03 +08:00
|
|
|
|
// 动态加载脚本函数
|
|
|
|
|
|
const loadScript = (src) =>
|
|
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
|
|
const script = document.createElement('script');
|
|
|
|
|
|
script.src = src;
|
|
|
|
|
|
script.onload = resolve;
|
|
|
|
|
|
script.onerror = reject;
|
|
|
|
|
|
document.head.appendChild(script);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
2025-07-16 18:49:28 +08:00
|
|
|
|
const id = route.query.id;
|
2025-07-15 15:16:03 +08:00
|
|
|
|
const query = reactive({
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-04 13:55:46 +08:00
|
|
|
|
const cozeInfo = ref({
|
2025-07-15 15:16:03 +08:00
|
|
|
|
title: '',
|
|
|
|
|
|
description: '',
|
2025-08-04 13:55:46 +08:00
|
|
|
|
image_url: '',
|
2025-07-18 10:11:13 +08:00
|
|
|
|
bot_id: '',
|
|
|
|
|
|
auth: {},
|
2025-07-15 15:16:03 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-07-18 10:11:13 +08:00
|
|
|
|
let cozeWebSDK = null;
|
2025-07-15 15:16:03 +08:00
|
|
|
|
const initChat = async () => {
|
|
|
|
|
|
const { code, data } = await getChatAgent(query.id);
|
2025-07-29 16:00:24 +08:00
|
|
|
|
if (code !== 200) {
|
2025-07-15 15:16:03 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-07-18 10:11:13 +08:00
|
|
|
|
|
2025-08-04 13:55:46 +08:00
|
|
|
|
Object.assign(cozeInfo.value, data.info);
|
2025-07-28 19:59:54 +08:00
|
|
|
|
await loadScript('https://lf-cdn.coze.cn/obj/unpkg/flow-platform/chat-app-sdk/1.2.0-beta.17/libs/cn/index.js');
|
2025-07-28 13:47:40 +08:00
|
|
|
|
let cozeConfig = await cozeWebSdkConfig(data.info.bot_id, data.info.name, data.info.auth, data.info.user_info);
|
2025-07-18 10:11:13 +08:00
|
|
|
|
cozeWebSDK = cozeWebSDK = new CozeWebSDK.WebChatClient(cozeConfig);
|
2025-07-15 15:16:03 +08:00
|
|
|
|
showChatPage();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-28 13:47:40 +08:00
|
|
|
|
const cozeWebSdkConfig = (botId, name, auth, userInfo) => {
|
2025-07-18 10:11:13 +08:00
|
|
|
|
auth.onRefreshToken = function () {
|
2025-07-24 19:07:46 +08:00
|
|
|
|
return '';
|
2025-07-18 10:11:13 +08:00
|
|
|
|
};
|
2025-07-17 19:32:47 +08:00
|
|
|
|
let config = {
|
|
|
|
|
|
config: {
|
2025-07-18 10:11:13 +08:00
|
|
|
|
botId: botId,
|
2025-07-17 19:32:47 +08:00
|
|
|
|
},
|
|
|
|
|
|
ui: {
|
|
|
|
|
|
chatBot: {
|
|
|
|
|
|
el: document.getElementById('coze-chat-container'),
|
2025-07-29 16:00:24 +08:00
|
|
|
|
width: '100%',
|
2025-07-17 19:32:47 +08:00
|
|
|
|
height: '100%',
|
2025-07-18 10:11:13 +08:00
|
|
|
|
title: name,
|
2025-07-17 19:32:47 +08:00
|
|
|
|
isNeedFunctionCallMessage: true,
|
2025-08-04 11:42:24 +08:00
|
|
|
|
isNeedAudio: false,
|
2025-07-29 16:00:24 +08:00
|
|
|
|
feedback: {
|
|
|
|
|
|
isNeedFeedback: true,
|
|
|
|
|
|
feedbackPanel: {
|
|
|
|
|
|
title: '您对这个回答有什么看法?请告诉我们',
|
|
|
|
|
|
placeholder: '请详细描述您的问题...',
|
|
|
|
|
|
tags: [
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '信息不正确',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '涉及敏感信息',
|
|
|
|
|
|
isNeedDetail: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-07-17 19:32:47 +08:00
|
|
|
|
},
|
2025-07-25 14:49:38 +08:00
|
|
|
|
base: {
|
|
|
|
|
|
icon: '',
|
2025-08-04 14:07:24 +08:00
|
|
|
|
zIndex: 100,
|
2025-07-29 16:00:24 +08:00
|
|
|
|
lang: 'zh-CN',
|
2025-07-25 14:49:38 +08:00
|
|
|
|
},
|
2025-07-28 13:47:40 +08:00
|
|
|
|
footer: {
|
|
|
|
|
|
expressionText: '内容由AI生成,无法确保真实准确,仅供参考。',
|
2025-07-24 19:07:46 +08:00
|
|
|
|
},
|
2025-07-28 19:59:54 +08:00
|
|
|
|
header: {
|
2025-08-04 11:42:24 +08:00
|
|
|
|
isShow: false,
|
|
|
|
|
|
isNeedClose: false,
|
2025-07-28 19:59:54 +08:00
|
|
|
|
},
|
|
|
|
|
|
conversations: {
|
|
|
|
|
|
isNeed: true,
|
2025-07-29 16:00:24 +08:00
|
|
|
|
isNeedAddNewConversation: true,
|
|
|
|
|
|
isNeedQuote: true,
|
|
|
|
|
|
},
|
2025-07-16 18:49:28 +08:00
|
|
|
|
},
|
2025-07-18 10:11:13 +08:00
|
|
|
|
auth: auth,
|
2025-07-28 13:47:40 +08:00
|
|
|
|
userInfo: userInfo,
|
2025-07-16 18:49:28 +08:00
|
|
|
|
header: {
|
2025-08-04 11:42:24 +08:00
|
|
|
|
isShow: false,
|
2025-07-29 09:55:58 +08:00
|
|
|
|
isNeedClose: false,
|
2025-07-16 18:49:28 +08:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2025-07-18 10:11:13 +08:00
|
|
|
|
return config;
|
2025-07-16 18:49:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-15 15:16:03 +08:00
|
|
|
|
const showChatPage = () => {
|
|
|
|
|
|
cozeWebSDK.showChatBot();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
initChat();
|
|
|
|
|
|
});
|
2025-07-17 19:32:47 +08:00
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
cozeWebSDK.destroy();
|
|
|
|
|
|
});
|
2025-07-15 15:16:03 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
@import './style.scss';
|
|
|
|
|
|
</style>
|