Browse Source

feat: 外呼接口联调

sunxiao 4 months ago
parent
commit
4036763c94

File diff suppressed because it is too large
+ 12 - 0
hs-cti.es6.umd.prod.js


+ 3 - 2
index.html

@@ -6,12 +6,13 @@
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <meta name="renderer" content="webkit">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
-  <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
+  <!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> -->
   <!-- <script src="./public/socket.io.min.js" type="text/javascript"></script>
   <script src="./public/SIP.min.js" type="text/javascript"></script> -->
   <script src="http://cdn.socket.io/4.0.0/socket.io.min.js"></script>
   <script src="http://static.fuxicarbon.com/hs-cti/SIP.min.js"></script>
-  <script src="http://static.fuxicarbon.com/hs-cti/hs-cti.es6.umd.prod.js" type="text/javascript"></script>
+  <!-- <script src="http://static.fuxicarbon.com/hs-cti/hs-cti.es6.umd.prod.js" type="text/javascript"></script> -->
+   <script src="./hs-cti.es6.umd.prod.js"></script>
   <link rel="icon" href="/favicon.ico">
   <title>佳木斯智能语音客服</title>
   <!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->

+ 5 - 4
src/layout/components/HeaderGroup/index.vue

@@ -11,8 +11,8 @@ const voiceStore = useVoiceStore();
 const usePermission = usePermissionStore();
 const { proxy } = getCurrentInstance();
 
-const { callAnswered } = storeToRefs(voiceStore);
-const systemState = ref(false);
+const { callAnswered, systemState } = storeToRefs(voiceStore);
+// const systemState = ref(false);
 const userStore = useUserStore();
 const isShowCallPanel = ref(false); 
 
@@ -29,7 +29,7 @@ watchEffect(() => {
 // 修改在线状态
 const handlePopoverItem = async ({ state, label }) => {
   state ? await voiceStore.setIdle() : await voiceStore.setBusy();
-  systemState.value = state;
+  // systemState.value = state;
   proxy.$modal[state ? 'msgSuccess' : 'msgWarning']('当前坐席状态: ' + label);
 }
 
@@ -49,7 +49,8 @@ const logout = () => {
     confirmButtonText: '确定',
     cancelButtonText: '取消',
     type: 'warning'
-  }).then(() => {
+  }).then(async () => {
+    await voiceStore.unInit();
     userStore.logOut().then(() => {
       location.href = '/index';
     })

+ 2 - 2
src/layout/index.vue

@@ -18,11 +18,11 @@ onMounted(() => {
       useVoice.HS_CTI_INSTANCE(data.outId);
       setTimeout(() => {
         try {
-          useVoice.setBusy();
+          useVoice.setIdle();
         } catch(error) {
           console.log(error);
         }
-      }, 1000);
+      }, 3000);
     })
   }
 })

+ 37 - 13
src/store/modules/voice.js

@@ -58,7 +58,7 @@ const useVoiceStore = defineStore('voice', () => {
 
     callAnswered.value = true;
 
-    const { data } = await makeCall();
+    const { data } = await makeCall(phoneNum);
 
     sessionId.value = data;
 
@@ -70,22 +70,24 @@ const useVoiceStore = defineStore('voice', () => {
   }
 
   // 接听电话
-  const onCallAnswered = () => {
+  const onCallAnswered =  async () => {
     callDialing.value = true;
+    callAnswered.value = true;
+    await answer();
     timer.start();
     // TODO 这里需要补充其他逻辑
   }
 
   // 挂断电话
-  const onCallDisconnected = () => {
+  const onCallDisconnected = async () => {
     noiceBarVisibleState.value = false;
     noiceBoxVisibleState.value = false;
     callAnswered.value = false;
     timer.resetTimer();
-    const currentTimer = timer.updateDisplay();
+    // const currentTimer = timer.updateDisplay();
     
     // 挂断
-    bye();
+    await bye();
 
     ElMessage({
       message: '通话已经结束,挂断成功',
@@ -122,18 +124,18 @@ const useVoiceStore = defineStore('voice', () => {
   }
 
   // 挂断电话
-  const bye = () => {
-    HS_CTI.bye().then(res => { console.log(res) })
+  const bye = async () => {
+    return await HS_CTI.serverBye().then(res => { console.log(res) })
   }
 
   // 卸载实例
-  const unInit = () => {
-    HS_CTI.unInit()
+  const unInit = async () => {
+    return await HS_CTI.unInit()
   }
 
   // 下面开始事件监听
   const listenScoketEvent = (CTIEvent) => {
-    HS_CTI.on(CTIEvent.OnAgentWorkReport, ({ workStatus, description }) => {
+    HS_CTI.on(CTIEvent.OnAgentWorkReport, ({ workStatus, description, callId, phone }) => {
 
       console.log( "workStatus", workStatus );
 
@@ -184,13 +186,31 @@ const useVoiceStore = defineStore('voice', () => {
 
       // 座席振铃
       if ( workStatus === 5 ) {
-        // console.log("座席振铃");
+
+        sessionId.value = callId;
+
+        telephoneNumber.value = phone;
+
+        isMakingCall.value = false;
+
+        noiceBarVisibleState.value = true;
+
         ElMessage({
-          message: '当前坐席状态:置忙',
+          message: '来电话了',
           type: 'warning',
           plain: true,
         })
       }
+
+      // 挂断 任意一方挂断
+      if ( workStatus === 7 ) {
+        
+        // ElMessage({
+        //   message: '当前坐席状态:置忙',
+        //   type: 'warning',
+        //   plain: true,
+        // })
+      }
     })
   }
 
@@ -234,10 +254,14 @@ const useVoiceStore = defineStore('voice', () => {
     // 电话号码
     telephoneNumber,
 
+    // 系统状态
+    systemState,
+
     // 通话相关
     HS_CTI_INSTANCE,
     setBusy,
-    setIdle
+    setIdle,
+    unInit
   }
 })
 

Some files were not shown because too many files changed in this diff