Browse Source

软电话版本

吴树波 2 tháng trước cách đây
mục cha
commit
faf7a778e4

+ 53 - 16
src/components/FloatingSoftPhone/index.vue

@@ -140,22 +140,22 @@
                     :title="callStatus === 'talking' ? '发送DTMF: ' + digit : '输入: ' + digit">{{ digit }}</button>
           </div>
 
-          <!-- 呼叫按钮组 -->
+          <!-- 呼叫按钮组:空闲=绿色外呼;外呼振铃/通话中=中间挂断;来电振铃=左右接听/拒接;接通=左保持/中挂断/右转移 -->
           <div class="call-buttons">
             <button class="call-button call-left-button"
-                    :class="{ hidden: !showLeftButton, normal: leftButtonNormal }"
+                    :class="{ hidden: !showSideCallButtons, normal: callStatus === 'talking' && leftButtonNormal }"
                     @click="onLeftButtonClick"
                     :title="getLeftButtonTitle()">
               <i class="material-icons">{{ leftButtonIcon }}</i>
             </button>
             <button class="call-button call-hangup-button"
-                    :class="[getHangupButtonClass(), { hidden: callStatus === 'ringing' }]"
+                    :class="[getHangupButtonClass(), { hidden: !showCenterCallButton }]"
                     @click="onHangupClick"
                     :title="getHangupButtonTitle()">
               <i class="material-icons">{{ hangupButtonIcon }}</i>
             </button>
             <button class="call-button call-right-button"
-                    :class="{ hidden: !showRightButton, normal: rightButtonNormal, hangup: rightButtonHangup }"
+                    :class="{ hidden: !showSideCallButtons, normal: callStatus === 'talking' && rightButtonNormal, hangup: isIncomingRinging }"
                     @click="onRightButtonClick"
                     :title="getRightButtonTitle()">
               <i class="material-icons">{{ rightButtonIcon }}</i>
@@ -340,6 +340,7 @@ export default {
       isRegistered: false,
       isConnected: false,
       callStatus: UI_STATE.IDLE,
+      isIncomingCall: false,  // 振铃阶段是否为来电(非外呼)
       incomingCaller: '',  // 来电号码
 
       // ===== 音频控制 =====
@@ -492,8 +493,22 @@ export default {
       if (this.fabX === null) return false;
       return this.fabX + 28 < window.innerWidth / 2;
     },
+    /** 来电振铃(左右接听/拒接,隐藏中间按钮) */
+    isIncomingRinging() {
+      return this.callStatus === UI_STATE.RINGING && this.isIncomingCall;
+    },
+    /** 中间按钮:空闲外呼 / 外呼振铃挂断 / 通话中挂断 */
+    showCenterCallButton() {
+      return this.callStatus === UI_STATE.IDLE
+        || (this.callStatus === UI_STATE.RINGING && !this.isIncomingCall)
+        || this.callStatus === UI_STATE.TALKING;
+    },
+    /** 左右侧按钮:来电振铃 或 通话中 */
+    showSideCallButtons() {
+      return this.isIncomingRinging || this.callStatus === UI_STATE.TALKING;
+    },
     leftButtonIcon() {
-      if (this.callStatus === 'ringing') return 'phone';
+      if (this.isIncomingRinging) return 'phone';
       if (this.callStatus === 'talking') {
         if (this.ccPhoneBar && this.ccSocketConnected) {
           return this.isOnHold ? 'play_arrow' : 'pause';
@@ -503,7 +518,7 @@ export default {
       return '';
     },
     rightButtonIcon() {
-      if (this.callStatus === 'ringing') return 'call_end';
+      if (this.isIncomingRinging) return 'call_end';
       if (this.callStatus === 'talking') return 'call_split';
       return '';
     }
@@ -880,7 +895,7 @@ export default {
 
     // ==================== UI事件 ====================
     getLeftButtonTitle() {
-      if (this.callStatus === 'ringing') return '接听来电';
+      if (this.isIncomingRinging) return '接听来电';
       if (this.callStatus === 'talking') return this.isOnHold ? '恢复通话' : '保持通话';
       return '';
     },
@@ -892,7 +907,7 @@ export default {
       return '未就绪';
     },
     getRightButtonTitle() {
-      if (this.callStatus === 'ringing') return '拒绝来电';
+      if (this.isIncomingRinging) return '拒绝来电';
       if (this.callStatus === 'talking') return '呼叫转移';
       return '';
     },
@@ -1095,6 +1110,10 @@ export default {
         if (!this.ccSocketConnected && this.ccConnectingReject) this.ccConnectingReject(new Error('服务器错误'));
       });
       this.ccPhoneBar.on(EventList.OUTBOUND_START, (msg) => {
+        this.isIncomingCall = false;
+        this.callStatus = UI_STATE.RINGING;
+        this.showLeftButton = false;
+        this.showRightButton = false;
         this.showStatus('拨号中...', 'info');
         if (msg?.object?.uuid) {
           this.currentCallUuid = msg.object.uuid;
@@ -1102,7 +1121,10 @@ export default {
         }
       });
       this.ccPhoneBar.on(EventList.CALLEE_RINGING, () => {
+        this.isIncomingCall = false;
         this.callStatus = UI_STATE.RINGING;
+        this.showLeftButton = false;
+        this.showRightButton = false;
         this.showStatus('振铃中...', 'info');
         if (this.currentCallUuid && this.callUuidMap[this.currentCallUuid]) {
           this.callUuidMap[this.currentCallUuid].status = 'ringing';
@@ -1123,6 +1145,7 @@ export default {
           }
         }
         this.callStatus = UI_STATE.TALKING;
+        this.isIncomingCall = false;
         this.showLeftButton = true;
         this.showRightButton = true;
         this.leftButtonNormal = true;
@@ -1309,6 +1332,7 @@ export default {
     },
     onRing(event) {
       if (!event.outgoing) {
+        this.isIncomingCall = true;
         this.incomingJsipCall = true;
         this.incomingCaller = event.caller || '';
         this.callStatus = UI_STATE.RINGING;
@@ -1323,6 +1347,7 @@ export default {
       }
     },
     onAnswered() {
+      this.isIncomingCall = false;
       this.callStatus = UI_STATE.TALKING;
       this.showLeftButton = true;
       this.showRightButton = true;
@@ -1334,6 +1359,7 @@ export default {
     _resetCallState() {
       if (this.callStatus !== UI_STATE.IDLE) {
         this.callStatus = UI_STATE.IDLE;
+        this.isIncomingCall = false;
         this.isOnHold = false;
         this.province = '';
         this.callDuration = '00:00';
@@ -1363,15 +1389,18 @@ export default {
     onCallTimer(time) { this.callDuration = time; },
 
     // ==================== 弹窗通话状态同步 ====================
-    onDialogCallRinging() {
+    onDialogCallRinging(payload) {
+      const incoming = !!(payload && payload.incoming);
+      this.isIncomingCall = incoming;
       this.callStatus = UI_STATE.RINGING;
-      this.showLeftButton = true;
-      this.showRightButton = true;
-      this.rightButtonHangup = true;
-      this.delegatedCallActive = true;  // 来电由弹窗phoneBar处理,标记为委托通话
-      this.showStatus('振铃中...', 'info');
+      this.showLeftButton = incoming;
+      this.showRightButton = incoming;
+      this.rightButtonHangup = incoming;
+      this.delegatedCallActive = true;
+      this.showStatus(incoming ? '来电振铃中...' : '振铃中...', 'info');
     },
     onDialogCallTalking() {
+      this.isIncomingCall = false;
       this.callStatus = UI_STATE.TALKING;
       this.showLeftButton = true;
       this.showRightButton = true;
@@ -1414,6 +1443,10 @@ export default {
       if (window.__floatingPhoneCallDelegateActive) {
         this.$root.$emit('floating-softphone-call-triggered', phoneNumber);
         this.delegatedCallActive = true;
+        this.isIncomingCall = false;
+        this.callStatus = UI_STATE.RINGING;
+        this.showLeftButton = false;
+        this.showRightButton = false;
         this.showStatus('拨号中...', 'info');
         return;
       }
@@ -1421,6 +1454,10 @@ export default {
       // 普通页面:使用浮动软电话自身的 ccPhoneBar 直接外呼
       try {
         this.delegatedCallActive = false;
+        this.isIncomingCall = false;
+        this.callStatus = UI_STATE.RINGING;
+        this.showLeftButton = false;
+        this.showRightButton = false;
         this.ccPhoneBar.call(phoneNumber, 'audio', VideoLevels.HD.levelId);
       } catch (err) {
         console.error('[FloatingSoftPhone] 外呼失败:', err);
@@ -1467,7 +1504,7 @@ export default {
       else this.makeCall();
     },
     onLeftButtonClick() {
-      if (this.callStatus === UI_STATE.RINGING) {
+      if (this.isIncomingRinging) {
         if (this.phone) this.phone.Answer();
       } else if (this.callStatus === UI_STATE.TALKING) {
         // 委托通话时,通知弹窗执行保持/恢复
@@ -1484,7 +1521,7 @@ export default {
       }
     },
     onRightButtonClick() {
-      if (this.callStatus === UI_STATE.RINGING) this.endCall();
+      if (this.isIncomingRinging) this.endCall();
       else if (this.callStatus === UI_STATE.TALKING) this.showStatus('呼叫转移功能暂未实现', 'info');
     },
 

+ 2 - 2
src/views/aiSipCall/aiSipCallManualOutbound.vue

@@ -1018,8 +1018,8 @@ export default {
                 console.log('被叫振铃事件:' + msg.content);
                 this.updatePhoneBar(msg, EventList.CALLEE_RINGING);
                 this.markExecuteSuccess();
-                // 同步状态到浮动软电话
-                this.$root.$emit('dialog-call-ringing');
+                // 同步状态到浮动软电话(外呼被叫振铃,非来电)
+                this.$root.$emit('dialog-call-ringing', { incoming: false });
             });
 
             this._phoneBarOn(EventList.CALLER_ANSWERED, (msg) => {