| | |
| | | |
| | | <!-- 呼叫按钮 --> |
| | | <button |
| | | :class="['call-btn', { calling: isCalling }]" |
| | | :class="[ |
| | | 'call-btn', |
| | | { |
| | | calling: isCalling, |
| | | registering: isRegistering, |
| | | }, |
| | | ]" |
| | | @click="startCall" |
| | | :disabled="isCalling || sipStatus !== '已注册'" |
| | | :disabled="isButtonDisabled" |
| | | > |
| | | <i v-if="isRegistering" class="el-icon-loading"></i> |
| | | {{ callButtonText }} |
| | | </button> |
| | | |
| | |
| | | const randomNum = Math.floor(Math.random() * 20) + 1000; // 定义随机分机号 |
| | | return { |
| | | isCalling: false, |
| | | isRegistering: true, // 初始为注册中状态 |
| | | randomNum: randomNum, |
| | | randomID: null, |
| | | callStatus: "idle", // idle, calling, connected, ended |
| | |
| | | } |
| | | return ""; |
| | | }, |
| | | callStatusClass() { |
| | | return `status-${this.callStatus}`; |
| | | isButtonDisabled() { |
| | | return ( |
| | | this.isCalling || this.sipStatus !== "已注册" || this.isRegistering |
| | | ); |
| | | }, |
| | | callButtonText() { |
| | | if (this.isRegistering) return "注册中..."; |
| | | return this.isCalling ? "通话中..." : "一键呼叫"; |
| | | }, |
| | | callStatusClass() { |
| | | return `status-${this.callStatus}`; |
| | | }, |
| | | }, |
| | | created() { |
| | |
| | | |
| | | async mounted() { |
| | | await this.CallgetList(); |
| | | this.isRegistering = true; // 开始注册 |
| | | sipService.init(this.sipConfig); |
| | | // 设置状态回调 |
| | | sipService.onStatusChange = (status) => { |
| | | this.sipStatus = status.text; |
| | | this.sipStatusClass = `status-${status.type}`; |
| | | |
| | | // 注册成功或失败时取消加载状态 |
| | | if (status.type === "registered" || status.type === "failed") { |
| | | this.isRegistering = false; |
| | | } |
| | | // 注册成功 |
| | | if (status.type === "registered") { |
| | | this.startCallsetState(); |
| | | } |
| | | // 处理注册失败和断开连接情况 |
| | | if (status.type === "failed" || status.type === "disconnected") { |
| | | this.overCallsetState(); // 释放分机号 |
| | | this.isRegistering = false; |
| | | } |
| | | }; |
| | | |
| | |
| | | // 通知父组件通话状态变化 |
| | | this.$emit("call-status-change", status); |
| | | }; |
| | | // 添加注册超时处理 |
| | | setTimeout(() => { |
| | | if (this.isRegistering && this.sipStatus !== "已注册") { |
| | | this.isRegistering = false; |
| | | this.$message.warning("SIP注册超时,请检查网络连接"); |
| | | } |
| | | }, 10000); // 10秒超时 |
| | | }, |
| | | methods: { |
| | | async startCall() { |
| | |
| | | this.randomID = res.data[0].id; |
| | | // 正确设置 sipUri |
| | | this.sipConfig.sipUri = `${this.randomNum}@192.168.10.124`; |
| | | this.startCallsetState(); |
| | | } catch (error) { |
| | | console.error("获取分机号失败:", error); |
| | | // this.updateStatus("failed", "获取分机号失败"); |