UNPKG

fcc-core

Version:

Fusion communication center.

359 lines (357 loc) 10.1 kB
import agentApi from '../api/agentApi' import { debounce } from '../util/util' import {hex_hmac_md5} from '../../md5' import EventBus, { OnConfjoinSuccess, OnConfjoinFail, OnTransferSuccess, OnTransferFail, OnHoldSuccess, OnHoldFail, OnUnHoldSuccess, OnUnHoldFail, OnSayFreeFailure, OnSayFreeSuccess, OnSayBusyFailure, OnSayBusySuccess, OnBeginMuteFail, OnBeginMuteSuccess, OnCancelMuteFail, OnCancelMuteSuccess} from '../../event-bus' import { Message, MessageBox } from 'element-ui' export default { /** * 签入方法 * @returns {Promise<void>} */ async signIn ($this) { const { result: { status } } = await agentApi.queryagentstatusandskill() return new Promise((resolve, reject)=> { if (status === 2 || status === 0) { // 根据参数判断是否支持强制签入 agentApi .sign({ agenttype: 4, autoanswer: this.autoAnswer, autoenteridle: this.autoEnterIdle, password: hex_hmac_md5(this.userInfo.AGENT_ID, this.userInfo.SIGNIN_PWD), phonenum: this.userInfo.SIGNIN_CODE, releasephone: this.releasephone, status: 4 }) .then(code => { this.isClickSignBtn = false this.eventctrl.init() this.sayFree() this.executeEvent('OnSignInSuccess') resolve() }).catch(e => { reject() }) } else { const self = this self.forceSignIn().then( function (res) { window.xw.userInfo.vdnId = res.result.vdnId self.isClickSignBtn = false self.eventctrl.init() // self.sayFree() self.autoanswer(true) self.executeEvent('OnSignInSuccess') resolve() }, () => { reject() } ) } }) }, /** * 强制签入 */ forceSignIn () { return agentApi.forceSignIn({ agenttype: 4, autoanswer: this.autoAnswer, autoenteridle: this.autoEnterIdle, password: hex_hmac_md5(this.userInfo.AGENT_ID, this.userInfo.SIGNIN_PWD), // password: '71a231668314cc71d113d4aba041801d', phonenum: this.userInfo.SIGNIN_CODE || '8001', releasephone: this.releasephone, status: 4 }) }, /** * 签出方法 * @returns {Promise<void>} */ signOut: debounce(function () { // this.changeButtonStaus('signIn') this.isClickSignoutBtn = false agentApi.signOut().then(code => { this.isClickSignoutBtn = false // 强制签出标识改为false this.isforceOut = false // 主动签出发射事件 this.eventctrl.executeChangebtn('OnSignOutSuccess') // 发射签出成功事件到各个组件 this.eventctrl.emitEventToComponent('OnSignOutSuccess') return '签出成功' }).catch(e => { // this.recoverBtnStatus('signIn') return '签出失败' }) }, 300, true), /** * 示忙 */ sayBusy: debounce(function () { this.isshowBusyDialog = false agentApi.sayBusy().then(code => { this.isClickBusyBtn = false // 如果处于工作态 则调用退出工作态的方法 if (this.isWorking === true) { agentApi.agentEnterIdle().then(() => { this.isWorking = false this.executeEvent('OnSayBusySuccess') }) } else { this.executeEvent('OnSayBusySuccess') } EventBus.$emit(OnSayBusySuccess, code) }).catch(e => { EventBus.$emit(OnSayBusyFailure, e) }) }, 300, true), /** * 示闲 */ sayFree: debounce(function () { // this.changeButtonStaus('busy') agentApi.sayFree().then((res) => { this.executeEvent('OnSayFreeSuccess') EventBus.$emit(OnSayFreeSuccess, res) }).catch(e => { EventBus.$emit(OnSayFreeFailure, e) // this.recoverBtnStatus('busy') }) }, 300, true), /** * 退出工作态 */ agentEnterIdle: debounce(function () { // this.changeButtonStaus('await') agentApi.agentEnterIdle().then(code => { this.executeEvent('OnCancelWorkSuccess') }).catch(e => { // this.recoverBtnStatus('await') }) }), /** * 设置签入的技能队列 */ changeAgentSkill (params) { agentApi.changeAgentSkill(params) }, /** * 设置自动应答 */ autoanswer (params) { agentApi.autoanswer(params) }, /** * 坐席挂机 * @param params */ release: debounce( async function (params) { const transType = this.getEventData('onAnswerSuccess', 'transType') || this.transType // 手动点击挂机按钮则每次挂断最后建立的那通通话 if (this.isClickHangup && ['4', '7'].indexOf(this.transType) < 0) { /* if (this.transData && (this.transType === '2' || this.transType === '5')) { await this.addCallForward(this.transData) } */ const index = this.callids.length - 1 return agentApi.releaseCall({ callid: this.callids[index] }) } // 三方转满意度 if (transType && this.transToIvr) { } return agentApi.hangUp() }, 300, true ), /** * 保持 * @param params */ hold: debounce(function (params) { if (this.isMute) { return } this.isHold = true agentApi.hold(params) .then((res) => { EventBus.$emit(OnHoldSuccess, res) }, (err) => { EventBus.$emit(OnHoldFail, err) this.isHold = false }) }), /** * 取保持 * @param params */ unhold: debounce(function (params) { if (!this.isHold) { return } const callId = this.getEventData('OnPhoneAlerting', 'callId') || '' agentApi.getHold({ callId }).then((res) => { EventBus.$emit(OnUnHoldSuccess, res) this.isHold = false }).catch(err => { EventBus.$emit(OnUnHoldFail, err) }) }), /** * 三方通话 */ innerhelp: debounce(function (params) { agentApi.innerhelp(params).then((res) => { EventBus.$emit(OnConfjoinSuccess, res) }).catch(err => { EventBus.$emit(OnConfjoinFail, err) }) }), /** * 申请通话 */ requestcall: function (params) { return agentApi.requestcall(params) }, /** * 呼叫转移 */ transfer: function (params) { agentApi.transfer(params).then((res) => { EventBus.$emit(OnTransferSuccess, res) }).catch(err => { EventBus.$emit(OnTransferFail, err) }) }, /** * 静音 * @param params */ mute: debounce(function (params) { if (this.isHold) { return } agentApi.beginMute(params) .then((res) => { this.isMute = true this.eventctrl.emitEvent('OnBeginMuteUserSuccess', null) EventBus.$emit(OnBeginMuteSuccess, res) }).catch(err => { EventBus.$emit(OnBeginMuteFail, err) }) }), /** * 取消静音 * @param params */ cancleMute: debounce(function (params) { if (!this.isMute) { return } agentApi.endMute(params).then((res) => { this.isMute = false this.eventctrl.emitEvent('OnEndMuteUserSuccess', null) EventBus.$emit(OnCancelMuteSuccess, res) }).catch(err => { EventBus.$emit(OnCancelMuteFail, res) }) }), /** * 发送便签 * @param params */ sendNote (params) { params.content = JSON.stringify(params.content) return agentApi.sendNote(params) }, /** * 根据操作类型执行监听.插入.拦截操作 * 1.监听 * 2.插入 * 3.接管通话 -拦截 * @param params * @returns {Promise<void>} */ async listenOrInset (params) { const { result: { status } } = await agentApi.queryAgentbyWorkNo(params) if (status !== '7' && params.type !== 1) { // this.components.$callbar.$message({ // type: 'warning', // message: window.app.$t('坐席不在通话中') // }) return false } let data = null let message = '' // 1 表示监听 2表示插入 3接管通话 if (params.type === 1) { data = await agentApi.listen(params) // message = window.app.$t('监听通话成功') } else if (params.type === 2) { data = await agentApi.switch(params) // message = window.app.$t('加入通话成功') } else { data = await agentApi.intercept(params) // message = window.app.$t('接管通话成功') } // this.components.$callbar.$message({ // type: 'success', // message // }) return data }, /** * 批量查询指定坐席的信息 * * @params座席工号列表。数组最大500。 */ getAgentInfoNoSkills (params) { const arr = [] for (let i = 0; i * 500 < params.length; i++) { arr.push(params.slice(i * 500, (i + 1) * 500)) } const promises = arr.map(function (agentlist) { return agentApi.getAgentInfoNoSkills({ agentlist }) }) return Promise.all(promises) }, /** * 外呼 * * @params 外呼号码 */ callOut (params) { return new Promise((resolve, reject) => { agentApi.callOutDefault(params).then(data => { const content = data if (content.retcode === '0') { // 呼叫类型-外呼 15 或者16 this.transType = '15' // 绑定外呼号码 this.callOutData.callOutNum = params.called resolve({status: 200}) } else { reject({status: 500}) } }) }) }, /** * 应答 * @params 应答 */ answer (params) { agentApi.answer(params).then(data => { this.isAnswerButton = true }) } }