|
@@ -582,7 +582,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="telControl">
|
|
|
-import { reactive, ref, computed, watch, onUnmounted, defineAsyncComponent } from 'vue';
|
|
|
+import { reactive, ref, computed, watch, onUnmounted, defineAsyncComponent,onMounted } from 'vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
import { ElMessageBox, ElNotification, ElMessage } from 'element-plus';
|
|
|
import { storeToRefs } from 'pinia';
|
|
@@ -595,6 +595,7 @@ import { formatDuration } from '/@/utils/formatTime';
|
|
|
import { commonEnum } from '/@/utils/tools';
|
|
|
import { Local } from '/@/utils/storage';
|
|
|
import other from '/@/utils/other';
|
|
|
+import { userState } from '/@/api/login';
|
|
|
import {
|
|
|
onDuty,
|
|
|
offDuty,
|
|
@@ -843,43 +844,35 @@ const idleFn = ()=>{
|
|
|
const callQueueFv = (data:any)=>{
|
|
|
console.log(data,'排队事件')
|
|
|
}
|
|
|
-// 如果当前是已经签入状态 监听消息事件
|
|
|
-if (telStatusInfo.value.isDutyOn) {
|
|
|
- if (
|
|
|
- ['onCall', 'oneCallHold', 'onMute', 'onConference', 'oneHoldOneCall'].includes(telStatusInfo.value.phoneControlState) &&
|
|
|
- telStatusInfo.value.onCallArr.length >= 1
|
|
|
- ) {
|
|
|
- //如果当前状态是通话中 刷新继续计时
|
|
|
- // 开始计时
|
|
|
- startTime();
|
|
|
- }
|
|
|
- signalR.start();
|
|
|
- signalR.SR.on('Ring', (data: any) => {
|
|
|
- // 接收来电消息
|
|
|
- console.log(data, '来电消息');
|
|
|
- ringFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('Alert', (data: any) => {
|
|
|
- // 接受alert事件 将通话加入到本地通话列表
|
|
|
- console.log(data, 'alert事件');
|
|
|
- alertFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('Answered', (data: any) => {
|
|
|
- //接收接听消息
|
|
|
- console.log(data, '接听消息');
|
|
|
- answerFn();
|
|
|
- });
|
|
|
-
|
|
|
- signalR.SR.on('Bye', (data: any) => {
|
|
|
- // 接收挂断消息
|
|
|
- console.log(data, '挂断消息');
|
|
|
- byeFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('RestApplyPass', (data: any) => {
|
|
|
- // 小休审批通过消息
|
|
|
- console.log(data, '小休审批通过消息');
|
|
|
- RestApplyPassFn();
|
|
|
- });
|
|
|
+// 监听消息
|
|
|
+const signalRStart=()=>{
|
|
|
+ // 开启 signalr 链接
|
|
|
+ signalR.start();
|
|
|
+ signalR.SR.on('Ring', (data: any) => {
|
|
|
+ // 接收来电消息
|
|
|
+ console.log(data, '来电消息');
|
|
|
+ ringFn(data);
|
|
|
+ });
|
|
|
+ signalR.SR.on('Alert', (data: any) => {
|
|
|
+ // 接受alert事件 将通话加入到本地通话列表
|
|
|
+ console.log(data, 'alert事件');
|
|
|
+ alertFn(data);
|
|
|
+ });
|
|
|
+ signalR.SR.on('Bye', (data: any) => {
|
|
|
+ // 接收挂断消息
|
|
|
+ console.log(data, '挂断消息');
|
|
|
+ byeFn(data);
|
|
|
+ });
|
|
|
+ signalR.SR.on('Answered', (data: any) => {
|
|
|
+ //接收接听消息
|
|
|
+ console.log(data, '接听消息');
|
|
|
+ answerFn();
|
|
|
+ });
|
|
|
+ signalR.SR.on('RestApplyPass', (data: any) => {
|
|
|
+ // 小休审批通过消息
|
|
|
+ console.log(data, '小休审批通过消息');
|
|
|
+ RestApplyPassFn();
|
|
|
+ });
|
|
|
signalR.SR.on('Idle', (data: any) => {
|
|
|
// 小休审批通过消息
|
|
|
console.log(data, '空闲事件消息');
|
|
@@ -890,6 +883,55 @@ if (telStatusInfo.value.isDutyOn) {
|
|
|
callQueueFv(data);
|
|
|
});
|
|
|
}
|
|
|
+// 检查用户状态
|
|
|
+const checkUserState = async ()=>{
|
|
|
+ const {result} = await userState();
|
|
|
+ if(result.isOnDuty !== telStatusInfo.value.isDutyOn && result.telNo !== telStatusInfo.value.telsNo){ // 发现状态不一致时
|
|
|
+ await offDuty();// 先签出
|
|
|
+ signalR.SR.off('Ring');
|
|
|
+ signalR.SR.off('Answered');
|
|
|
+ signalR.SR.off('Bye');
|
|
|
+ signalR.SR.off('RestApplyPass');
|
|
|
+ // 断开链接
|
|
|
+ signalR.stop();
|
|
|
+ // 重置所有状态
|
|
|
+ useTelStatusStore.resetState();
|
|
|
+
|
|
|
+ onDuty(result.telNo) // 再签入
|
|
|
+ .then(() => {
|
|
|
+ // 设置分机号
|
|
|
+ useTelStatusStore.setTelsNo(result.telNo);
|
|
|
+ // 设置签入状态
|
|
|
+ useTelStatusStore.setDutyState(true);
|
|
|
+ // 设置电话状态
|
|
|
+ useTelStatusStore.setPhoneControlState(TelStates.dutyOn);
|
|
|
+ signalRStart(); //开启消息监听
|
|
|
+ // 重置表单
|
|
|
+ dutyFormRef.value?.resetFields();
|
|
|
+ state.showDutyDialog = false;
|
|
|
+ state.loading = false;
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.log(err, '签入出现错误');
|
|
|
+ state.showDutyDialog = false;
|
|
|
+ state.loading = false;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ // 如果当前是已经签入状态 监听消息事件
|
|
|
+ if (telStatusInfo.value.isDutyOn) {
|
|
|
+ if (
|
|
|
+ ['onCall', 'oneCallHold', 'onMute', 'onConference', 'oneHoldOneCall'].includes(telStatusInfo.value.phoneControlState) &&
|
|
|
+ telStatusInfo.value.onCallArr.length >= 1
|
|
|
+ ) {
|
|
|
+ //如果当前状态是通话中 刷新继续计时
|
|
|
+ // 开始计时
|
|
|
+ startTime();
|
|
|
+ }
|
|
|
+ signalRStart(); //开启消息监听
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(result,'检查用户状态',telStatusInfo.value)
|
|
|
+}
|
|
|
// 设置当前可用的按钮
|
|
|
const activeArr = computed(() => {
|
|
|
const switchCases = {
|
|
@@ -1020,42 +1062,7 @@ const clickOnDuty = () => {
|
|
|
useTelStatusStore.setDutyState(true);
|
|
|
// 设置电话状态
|
|
|
useTelStatusStore.setPhoneControlState(TelStates.dutyOn);
|
|
|
- // 开启 signalr 链接
|
|
|
- signalR.start();
|
|
|
- signalR.SR.on('Ring', (data: any) => {
|
|
|
- // 接收来电消息
|
|
|
- console.log(data, '来电消息');
|
|
|
- ringFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('Alert', (data: any) => {
|
|
|
- // 接受alert事件 将通话加入到本地通话列表
|
|
|
- console.log(data, 'alert事件');
|
|
|
- alertFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('Bye', (data: any) => {
|
|
|
- // 接收挂断消息
|
|
|
- console.log(data, '挂断消息');
|
|
|
- byeFn(data);
|
|
|
- });
|
|
|
- signalR.SR.on('Answered', (data: any) => {
|
|
|
- //接收接听消息
|
|
|
- console.log(data, '接听消息');
|
|
|
- answerFn();
|
|
|
- });
|
|
|
- signalR.SR.on('RestApplyPass', (data: any) => {
|
|
|
- // 小休审批通过消息
|
|
|
- console.log(data, '小休审批通过消息');
|
|
|
- RestApplyPassFn();
|
|
|
- });
|
|
|
- signalR.SR.on('Idle', (data: any) => {
|
|
|
- // 小休审批通过消息
|
|
|
- console.log(data, '空闲事件消息');
|
|
|
- idleFn();
|
|
|
- });
|
|
|
- signalR.SR.on('CallQueue', (data: any) => {
|
|
|
- // 排队事件
|
|
|
- callQueueFv(data);
|
|
|
- });
|
|
|
+ signalRStart(); //开启消息监听
|
|
|
ElNotification({
|
|
|
title: '成功',
|
|
|
message: '签入成功',
|
|
@@ -1804,6 +1811,9 @@ watch(
|
|
|
console.log(`状态改变了:${oldVal}=====>${newVal}`);
|
|
|
}
|
|
|
);
|
|
|
+onMounted(()=>{
|
|
|
+ checkUserState();
|
|
|
+})
|
|
|
// 清理定时器
|
|
|
onUnmounted(() => {
|
|
|
removeTimer();
|