From dd58c1d3a27ba48a5df050aab7c586bb9b988914 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 09 四月 2025 18:01:22 +0800 Subject: [PATCH] activeTopMenuStyle --- src/components/chat/components/playBar/hook/useDigitalHuman.ts | 66 +++++++++++++++++++++++++-------- 1 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/components/chat/components/playBar/hook/useDigitalHuman.ts b/src/components/chat/components/playBar/hook/useDigitalHuman.ts index 7f0b096..6d48b3b 100644 --- a/src/components/chat/components/playBar/hook/useDigitalHuman.ts +++ b/src/components/chat/components/playBar/hook/useDigitalHuman.ts @@ -1,10 +1,12 @@ -import { nextTick, onDeactivated, onMounted, ref } from 'vue'; import { SignJWT } from 'jose'; +import { nextTick, onDeactivated, onMounted, ref } from 'vue'; +import { markdownToTxt } from 'markdown-to-txt'; import './libs/duix.js'; import { questionStreamByPost } from '/@/api/ai/chat'; import { activeGroupType, activeRoomId } from '/@/stores/chatRoom'; -import { markdownToTxt } from 'markdown-to-txt'; +import axios from 'axios'; +import { ElMessage } from 'element-plus'; export type UseDigitalHumanProps = { container: string; @@ -29,6 +31,32 @@ const closeDigitalHuman = () => { digitalHumanIsShow.value = false; resetDuixStatus(); + }; + /** + * 妫�鏌ユ暟瀛椾汉鏄惁鍙敤 + */ + const checkIsUseable = async () => { + const config = { + method: 'get', + url: `https://duix.guiji.ai/duix-openapi-v2/v1/getconcurrentNumber?appId=${duixConfig.appId}`, + headers: { + priority: 'u=1, i', + sig: duixConfig.sign, + }, + }; + + const response = await axios(config); + const data = response.data.data; + const total = data.totalConcurrentNumber; + const user = data.userConcurrentNumber; + if (total === null || total === 0) { + return false; + } + if (total !== null && total === user) { + return false; + } + + return true; }; const resetDuixStatus = () => { @@ -69,15 +97,18 @@ }); }; - const startDuix = () =>{ + const startDuix = () => { const conversationId = duixConfig.conversationId; // duix骞冲彴浼氳瘽id - duix.start({ conversationId, openAsr: true,wipeGreen:true }).then((res) => { - console.info('start', res); - }).catch((err)=>{ - console.error('start error', err); - }); - } + duix + .start({ conversationId, openAsr: true, wipeGreen: true }) + .then((res) => { + console.info('start', res); + }) + .catch((err) => { + console.error('start error', err); + }); + }; const initDuix = () => { const sign = duixConfig.sign; // sign鐢辨湇鍔$鐢熸垚 @@ -118,8 +149,7 @@ duix.on('speakEnd', (data) => { if (!isWaitingSpeak) { isReceiveRes.value = false; - duix.openAsr().then((...a) => { - }); + duix.openAsr().then((...a) => {}); } }); duix.on('speakSection', (data) => { @@ -133,8 +163,7 @@ if (isReceiveRes.value) { return; } - duix.closeAsr().then((...a) => { - }); + duix.closeAsr().then((...a) => {}); let hasResult = false; isReceiveRes.value = true; @@ -192,11 +221,16 @@ let hasInitDuix = false; let duix: any; - const openDigitalHuman = () => { + const openDigitalHuman = async () => { + duixConfig.sign = await createSig(duixConfig.appId, duixConfig.appKey, 60 * 60 * duixConfig.expired); + const isUsable = await checkIsUseable(); + if (!isUsable) { + ElMessage.warning('"璧勬簮鍗犵敤涓紝璇锋鏌ュ悗鍐嶈瘯~"'); + return; + } digitalHumanIsShow.value = true; - nextTick(async () => { - duixConfig.sign = await createSig(duixConfig.appId, duixConfig.appKey, 60 * 60 * duixConfig.expired); + nextTick(() => { if (!hasInitDuix) { hasInitDuix = true; -- Gitblit v1.9.3