余尚辉 2 ヶ月 前
コミット
65eaa349b7
3 ファイル変更30 行追加15 行削除
  1. 3 3
      src/layout/index.vue
  2. 26 11
      src/store/modules/voice.js
  3. 1 1
      src/utils/request.js

+ 3 - 3
src/layout/index.vue

@@ -27,9 +27,9 @@ onMounted(() => {
       if (!data) return;
       useVoice.HS_CTI_INSTANCE(data.outId);
 
-      const voiceStatus = localStorage.getItem('VOICE_STATUS');
+      const voiceStatus = sessionStorage.getItem('VOICE_STATUS');
 
-      if ( voiceStatus ) {
+      if ( voiceStatus && [1,2].includes(useVoice.AGENTSTATUS)) {
         if ( voiceStatus === 'busy' ) {
           setTimeout(() => useVoice.setBusy(), 1000);
         } else {
@@ -39,7 +39,7 @@ onMounted(() => {
       } else {
         setTimeout(() => {
           try {
-            useVoice.setIdle();
+            useVoice.AGENTSTATUS!=0 && useVoice.setIdle();
           } catch(error) {
             console.log(error);
           }

+ 26 - 11
src/store/modules/voice.js

@@ -26,6 +26,11 @@ const useVoiceStore = defineStore('voice', () => {
   // 接听中
   const callDialing = ref(false);
 
+  // SDK 错误码
+  const HSCTIERRORCODE = ref('');
+
+  const AGENTSTATUS = ref(0);
+
   // 横条来电显示
   const noiceBarVisibleState = ref(false);
   // 盒子来电显示
@@ -121,7 +126,7 @@ const useVoiceStore = defineStore('voice', () => {
   // 置忙
   const setBusy = () => {
     if ( HS_CTI ) {
-      localStorage.setItem('VOICE_STATUS', 'busy');
+      sessionStorage.setItem('VOICE_STATUS', 'busy');
       systemState.value = false;
       HS_CTI.setBusy().then(res => { console.log(res) });
     }
@@ -130,7 +135,7 @@ const useVoiceStore = defineStore('voice', () => {
   // 置闲
   const setIdle = () => {
     if ( HS_CTI ) {
-      localStorage.setItem('VOICE_STATUS', 'idle');
+      sessionStorage.setItem('VOICE_STATUS', 'idle');
       systemState.value = true;
       HS_CTI.setIdle().then(res => { console.log(res) });
     }
@@ -138,7 +143,9 @@ const useVoiceStore = defineStore('voice', () => {
 
   // 获取坐席状态
   const getAgentStatus = () => {
-    HS_CTI.getAgentStatus().then(res => { console.log(res) })
+    HS_CTI.getAgentStatus().then(res => { 
+      AGENTSTATUS.value = res.data;
+    })
   }
 
   // 主动外呼
@@ -156,15 +163,20 @@ const useVoiceStore = defineStore('voice', () => {
 
   // 卸载实例
   const unInit = async () => {
-    if ( HS_CTI ) {
-      const res = await HS_CTI.unInit();
-      HS_CTI = null;
-      return res
-    }
+    AGENTSTATUS.value != 0 && await HS_CTI.unInit()
   }
 
   // 下面开始事件监听
   const listenScoketEvent = (CTIEvent) => {
+    HS_CTI.on(CTIEvent.OnCtiError,(res)=>{
+      HSCTIERRORCODE.value = res.code;
+      switch (res.code) {
+        case '100002':
+          ElMessage({message: res.msg, type: 'error',})
+          break;
+      }
+    })
+
     HS_CTI.on(CTIEvent.OnAgentWorkReport, async ({ workStatus, description, callId, phone }) => {
 
       // console.log( "-----------------------" );
@@ -181,8 +193,8 @@ const useVoiceStore = defineStore('voice', () => {
           type: 'success',
           plain: true,
         })
-        await unInit();
-        localStorage.removeItem('VOICE_STATUS');
+        unInit();
+        sessionStorage.removeItem('VOICE_STATUS');
         userStore.logOut().then(() => {
           location.href = '/index';
         })
@@ -242,6 +254,7 @@ const useVoiceStore = defineStore('voice', () => {
       //   reset();
       // }
     })
+    
   }
 
   // 初始化 通话实例
@@ -265,7 +278,7 @@ const useVoiceStore = defineStore('voice', () => {
     // HS_CTI.domainName = VITE_HS_CTI_BASE_URL
 
     HS_CTI.init();
-
+    getAgentStatus()
     listenScoketEvent(CTIEvent);
   }
 
@@ -284,6 +297,8 @@ const useVoiceStore = defineStore('voice', () => {
     callDialing,
     noiceBarVisibleState,
     noiceBoxVisibleState,
+    HSCTIERRORCODE,
+    AGENTSTATUS,
 
     // 电话号码
     telephoneNumber,

+ 1 - 1
src/utils/request.js

@@ -83,7 +83,7 @@ service.interceptors.response.use(res => {
       return res.data
     }
     if (code === 401) {
-      localStorage.removeItem('VOICE_STATUS');
+      sessionStorage.removeItem('VOICE_STATUS');
       if (!isRelogin.show) {
         isRelogin.show = true;
         ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(async () => {