From 57c1e943c1e20c57ff69945216a133a5ec2127f7 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期四, 11 九月 2025 11:51:04 +0800
Subject: [PATCH] 测试完成

---
 src/utils/sipService.js             |   47 ++++++++++++++++++++---
 src/components/CallButton/index.vue |   15 +++++++
 2 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/src/components/CallButton/index.vue b/src/components/CallButton/index.vue
index 87660b2..a49edff 100644
--- a/src/components/CallButton/index.vue
+++ b/src/components/CallButton/index.vue
@@ -61,6 +61,15 @@
       };
       return statusMap[this.callStatus];
     },
+    countdownText() {
+      if (this.sipStatus !== "宸叉敞鍐�") return "";
+
+      const { canCall, reason } = sipService.canMakeCall();
+      if (!canCall && reason.includes("绛夊緟")) {
+        return reason;
+      }
+      return "";
+    },
     callStatusClass() {
       return `status-${this.callStatus}`;
     },
@@ -94,6 +103,12 @@
       }
 
       try {
+        // 鍏堟鏌ユ槸鍚﹀彲浠ュ懠鍙�
+        const { canCall, reason } = sipService.canMakeCall();
+        if (!canCall) {
+          this.$message.warning(reason);
+          return;
+        }
         this.callStatus = "calling";
         this.isCalling = true;
 
diff --git a/src/utils/sipService.js b/src/utils/sipService.js
index cd9c265..ed49275 100644
--- a/src/utils/sipService.js
+++ b/src/utils/sipService.js
@@ -7,6 +7,8 @@
     this.onStatusChange = null;
     this.onCallStatusChange = null;
     this.onIncomingCall = null;
+    this.isRegistered = false; // 鏂板娉ㄥ唽鐘舵�佹爣蹇�
+    this.registrationTime = null; // 鏂板娉ㄥ唽鎴愬姛鏃堕棿鎴�
   }
 
   init(config) {
@@ -28,12 +30,22 @@
       this.ua.start();
 
       // 浜嬩欢鐩戝惉
-      this.ua.on("registered", () =>
-        this.updateStatus("registered", "宸叉敞鍐�56")
-      );
-      this.ua.on("registrationFailed", (e) =>
-        this.updateStatus("failed", `娉ㄥ唽澶辫触11: ${e.cause}`)
-      );
+      // 浜嬩欢鐩戝惉
+      this.ua.on("registered", () => {
+        this.isRegistered = true;
+        this.registrationTime = Date.now(); // 璁板綍娉ㄥ唽鎴愬姛鏃堕棿
+        this.updateStatus("registered", "宸叉敞鍐�");
+      });
+
+      this.ua.on("registrationFailed", (e) => {
+        this.isRegistered = false;
+        this.updateStatus("failed", `娉ㄥ唽澶辫触: ${e.cause}`);
+      });
+
+      this.ua.on("unregistered", () => {
+        this.isRegistered = false;
+        this.updateStatus("disconnected", "宸叉敞閿�");
+      });
       this.ua.on("disconnected", () =>
         this.updateStatus("disconnected", "杩炴帴鏂紑")
       );
@@ -49,8 +61,31 @@
       throw error;
     }
   }
+  // 鏂板鏂规硶锛氭鏌ユ槸鍚﹀彲浠ュ懠鍙�
+  canMakeCall(minDelay = 2000) {
+    if (!this.isRegistered) {
+      return { canCall: false, reason: "SIP鏈敞鍐岋紝鏃犳硶鍛煎彨" };
+    }
+
+    const now = Date.now();
+    const timeSinceRegistration = now - this.registrationTime;
+
+    if (timeSinceRegistration < minDelay) {
+      const remaining = minDelay - timeSinceRegistration;
+      return {
+        canCall: false,
+        reason: `娉ㄥ唽鎴愬姛锛岃绛夊緟 ${Math.ceil(remaining / 1000)} 绉掑悗鍐嶅懠鍙玚
+      };
+    }
+
+    return { canCall: true, reason: "" };
+  }
 
   makeCall(targetNumber) {
+     const { canCall, reason } = this.canMakeCall();
+    if (!canCall) {
+      return Promise.reject(new Error(reason));
+    }
     return new Promise((resolve, reject) => {
       try {
         if (!this.ua) {

--
Gitblit v1.9.3