543 lines
15 KiB
JavaScript
543 lines
15 KiB
JavaScript
/*
|
||
* 艾讯新接口-运维开发的新接口
|
||
* 可以同时登录同一分机
|
||
*/
|
||
// 对Date的扩展,将 Date 转化为指定格式的String
|
||
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
|
||
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
|
||
// 例子:
|
||
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
|
||
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
|
||
var enableconsole = true;
|
||
Date.prototype.Format = function (fmt) { //author: meizz
|
||
var o = {
|
||
"M+": this.getMonth() + 1, //月份
|
||
"d+": this.getDate(), //日
|
||
"h+": this.getHours(), //小时
|
||
"m+": this.getMinutes(), //分
|
||
"s+": this.getSeconds(), //秒
|
||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||
"S": this.getMilliseconds() //毫秒
|
||
};
|
||
if (/(y+)/.test(fmt))
|
||
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||
for (var k in o)
|
||
if (new RegExp("(" + k + ")").test(fmt))
|
||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
||
return fmt;
|
||
}
|
||
window.console = window.console || (function () {
|
||
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
|
||
= c.clear = c.exception = c.trace = c.assert = function () { };
|
||
return c;
|
||
})();
|
||
if (!enableconsole)
|
||
{
|
||
window.console = (function () {
|
||
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
|
||
= c.clear = c.exception = c.trace = c.assert = function () { return; };
|
||
return c;
|
||
})();
|
||
}
|
||
|
||
|
||
if (!Array.prototype.indexOf) {
|
||
Array.prototype.indexOf = function (elt /*, from*/) {
|
||
var len = this.length >>> 0;
|
||
var from = Number(arguments[1]) || 0;
|
||
from = (from < 0)
|
||
? Math.ceil(from)
|
||
: Math.floor(from);
|
||
if (from < 0)
|
||
from += len;
|
||
for (; from < len; from++) {
|
||
if (from in this &&
|
||
this[from] === elt)
|
||
return from;
|
||
}
|
||
return -1;
|
||
};
|
||
}
|
||
|
||
$(function () {
|
||
__Login();
|
||
});
|
||
|
||
function __LoginCallback() {
|
||
if (strFJH == '') {
|
||
return;
|
||
}
|
||
document.all.lblFJH.innerText = strFJH;
|
||
fleshstatus();
|
||
}
|
||
/*********************************************
|
||
方法封装
|
||
*********************************************/
|
||
//移动坐席登录
|
||
function __Login() {
|
||
if (strFJH == '') {
|
||
return;
|
||
}
|
||
this.socket.emit('login', { agentId: strFJH, eid: strGH });
|
||
}
|
||
socket.on('req' + strFJH, function (o) {
|
||
if (o.action == "login") {
|
||
if (o.ret.indexOf("+OK") >= 0) {
|
||
funEnabledBtn("btnLogout", true);
|
||
__LoginCallback();
|
||
}
|
||
}
|
||
|
||
if (o.action == "logout") {
|
||
if (o.ret.indexOf("+OK") >= 0) {
|
||
$("#btnLogout").val("登录");
|
||
$('#btnLogout').unbind();
|
||
$("#btnLogout").bind("click", function () {
|
||
__Login();
|
||
});
|
||
}
|
||
}
|
||
|
||
if (o.action == "makeCall") {
|
||
if (o.ret+''=="true") {
|
||
__DialCallback();
|
||
}
|
||
}
|
||
|
||
if (o.action == "callDown") {
|
||
if (o.ret.indexOf("+OK") >= 0) {
|
||
__HangupCallback(strFJH, o);
|
||
}
|
||
}
|
||
|
||
if (o.action == "transferCall") {
|
||
if (o.ret.indexOf("+OK") >= 0) {
|
||
__getDND(strFJH);
|
||
clearTransfer();
|
||
}
|
||
}
|
||
|
||
if (o.action == "monitor") {
|
||
if (o.ret.indexOf("+OK") >= 0) {
|
||
__ChanspyCallback(strFJH, o);
|
||
}
|
||
}
|
||
});
|
||
|
||
socket.on('state' + strFJH, function (o) {
|
||
if (strFJH == '') {
|
||
return;
|
||
}
|
||
__getDNDCallback(strFJH, o);
|
||
__getStatusCallback(strFJH, o.state);
|
||
});
|
||
socket.on('alarm' + strFJH, function (o) {
|
||
if (strFJH == '') {
|
||
return;
|
||
}
|
||
if (o.action == "CallIn") {
|
||
mixcallback({ type: 1, dst: o.dstNumber, src: o.srcNumber });
|
||
}
|
||
if (o.action == "CallOut") {
|
||
mixcallback({ type: 2, dst: o.dstNumber, src: o.srcNumber });
|
||
}
|
||
//回调处理
|
||
});
|
||
socket.on('callend', function (o) {
|
||
__HangupCallback(strFJH, o);
|
||
//回调处理
|
||
});
|
||
|
||
//移动坐席退出
|
||
function __Loginout() {
|
||
$.ajaxSettings.async = false;
|
||
this.socket.emit('logout', { agentId: strFJH });
|
||
$.ajaxSettings.async = true;
|
||
return true;
|
||
}
|
||
|
||
//分机示闲/示忙
|
||
function __setDND(exten, dnd) {
|
||
if (exten == '') {
|
||
return;
|
||
}
|
||
if (dnd == 1) {//示忙
|
||
this.socket.emit('busy', { agentId: exten });
|
||
}
|
||
else {
|
||
this.socket.emit('available', { agentId: exten });
|
||
}
|
||
}
|
||
|
||
//获取分机示闲状态
|
||
function __getDND(exten) {
|
||
if (exten == '') {
|
||
return;
|
||
}
|
||
this.socket.emit('listState', { agentid: exten });
|
||
}
|
||
|
||
//获取示闲回调
|
||
function __getDNDCallback(exten, res) {
|
||
if (exten == '') {
|
||
return;
|
||
}
|
||
try {
|
||
if (res.state == "Available") {//闲
|
||
document.all.btnDND.value = "示忙";
|
||
document.all.btnDND.style.color = 'black';
|
||
if (strIsAdmin == "1")
|
||
funEnabledBtn("btnListen", true);
|
||
$('#btnDND').unbind("click").bind("click", function () {
|
||
//示忙
|
||
clearToListen();
|
||
clearTransfer();
|
||
cleartimer();
|
||
__setDND(strFJH, '1');
|
||
});
|
||
} else {
|
||
document.all.btnDND.value = "示闲";
|
||
document.all.btnDND.style.color = 'red';
|
||
funEnabledBtn("btnListen", false);
|
||
$('#btnDND').unbind("click").bind("click", function () {
|
||
//示闲
|
||
clearToListen();
|
||
clearTransfer();
|
||
cleartimer();
|
||
__setDND(strFJH, '-1');
|
||
});
|
||
}
|
||
}
|
||
catch (e) { showstatus("系统错误", "err", e); }
|
||
}
|
||
|
||
//获取分机状态回调
|
||
function __getStatusCallback(exten, onstatus) {
|
||
if (exten == "") {
|
||
return;
|
||
}
|
||
try {
|
||
if (onstatus == "Logged Out" || onstatus == 4) {//未注册或不存在
|
||
cleartimer();
|
||
funEnabledBtn("btnDND", false);
|
||
funEnabledBtn("btnListen", false);
|
||
funEnabledBtn("btnHangup", false);
|
||
funEnabledBtn("btnTransfer", false);
|
||
}
|
||
if (onstatus == "Available") {//0: 空闲
|
||
cleartimer();
|
||
blTimer = false;
|
||
funEnabledBtn("btnTransfer", false);
|
||
funEnabledBtn("btnHangup", false);
|
||
funEnabledBtn("btnDND", true);
|
||
if (strIsAdmin == "1") {
|
||
funEnabledBtn("btnListen", true);
|
||
}
|
||
}
|
||
if (onstatus == "CALLING") {//1: 通话中
|
||
funEnabledBtn("btnDND", false);
|
||
funEnabledBtn("btnHangup", true);
|
||
funEnabledBtn("btnTransfer", true);
|
||
funEnabledBtn("btnListen", false);
|
||
}
|
||
if (onstatus == "RINGING") {//8: 振铃中
|
||
clearToListen(); clearTransfer();
|
||
funEnabledBtn("btnDND", false);
|
||
funEnabledBtn("btnTransfer", false);
|
||
funEnabledBtn("btnHangup", false);
|
||
funEnabledBtn("btnListen", false);
|
||
funEnabledBtn("btnHangup", true);
|
||
}
|
||
blLogined = true;
|
||
|
||
var lblexstatus = $("#divAction");
|
||
var strstats = getstatus(onstatus);
|
||
lblexstatus.html(strstats);
|
||
}
|
||
catch (e) {
|
||
showstatus("系统错误", "err", e);
|
||
}
|
||
}
|
||
|
||
//挂断
|
||
function __Hangup(exten) {
|
||
if (exten == "") {
|
||
return;
|
||
}
|
||
this.socket.emit('callDown', { agentId: exten });
|
||
}
|
||
|
||
//挂机回调
|
||
function __HangupCallback(exten) {
|
||
if (exten == "") {
|
||
return;
|
||
}
|
||
__getDND(exten);
|
||
document.getElementById("txtTelNO").value = ""; //清除号码框
|
||
funEnabledBtn("btnHangup", false);
|
||
cleartimer();
|
||
}
|
||
|
||
//外拨
|
||
function __Dial(exten, dst) {
|
||
if (exten == "") {
|
||
return;
|
||
}
|
||
var callout = $("#txtCallingNo").val();
|
||
if (callout && callout.length > 0) {
|
||
this.socket.emit('makeCall', { agentId: exten, number: dst, type: callout });
|
||
}
|
||
else
|
||
this.socket.emit('makeCall', { agentId: exten, number: dst });
|
||
}
|
||
|
||
//外拨回调
|
||
function __DialCallback() {
|
||
blCallOut = true; //设置外拨状态
|
||
blTimer = true;
|
||
funEnabledBtn("btnHangup", true);
|
||
funEnabledBtn("btnTransfer", true);
|
||
setTimer();
|
||
}
|
||
|
||
//刷新状态
|
||
function fleshstatus() {
|
||
__getDND(strFJH);
|
||
}
|
||
|
||
//转接
|
||
function __Transfer(exten, dst) {
|
||
if (exten == "" || dst == "") {
|
||
return;
|
||
}
|
||
this.socket.emit('transferCall', { agentId: exten, otherAgentId: dst });
|
||
}
|
||
|
||
//监听
|
||
function __Chanspy(exten, dst) {
|
||
if (exten == "" || dst == "") {
|
||
return;
|
||
}
|
||
this.socket.emit('monitor', { agentId: exten, otherAgentId: dst });
|
||
}
|
||
|
||
//监听回调
|
||
function __ChanspyCallback(exten) {
|
||
if (exten == "") {
|
||
return;
|
||
}
|
||
clearToListen();
|
||
blTimer = true;
|
||
funEnabledBtn("btnHangup", true);
|
||
funEnabledBtn("btnTransfer", false);
|
||
funEnabledBtn("btnListen", false);
|
||
setTimer();
|
||
fleshstatus(exten);
|
||
}
|
||
|
||
//清除转接状态
|
||
function clearTransfer() {
|
||
document.all.lfjh.style.display = "none";
|
||
}
|
||
//清除监听状态
|
||
function clearToListen() {
|
||
document.all.lfjh.style.display = "none";
|
||
}
|
||
//清除定时器
|
||
function cleartimer() {
|
||
nTimer = 0;
|
||
window.clearTimeout(timer2);
|
||
}
|
||
/*********************************************
|
||
功能代码
|
||
*********************************************/
|
||
//退出
|
||
function btnLogout() {
|
||
__Loginout();
|
||
}
|
||
|
||
//软挂机
|
||
function funBtnSoftHook() {
|
||
clearTransfer();
|
||
clearToListen();
|
||
__Hangup(strFJH);
|
||
blTimer = false;
|
||
nTimer = 0;
|
||
}
|
||
|
||
//外拨
|
||
function funBtnCall() {
|
||
try {
|
||
clearToListen(); clearTransfer();
|
||
var dst = document.all.txtTelNO.value.Trim();
|
||
if (dst.length == 0) {
|
||
showstatus("号码为空!", "err");
|
||
return;
|
||
}
|
||
if (strGH == "") {
|
||
showstatus("登录超时,请重新登录。", "err");
|
||
return;
|
||
}
|
||
__Dial(strFJH, dst);
|
||
}
|
||
catch (e) { showstatus("系统错误", "err", e); }
|
||
}
|
||
|
||
// 转接
|
||
function funBtnTrans() {
|
||
transfer();
|
||
}
|
||
|
||
function transfer() {
|
||
var strTransfer = document.all.txtTelNO.value.Trim();
|
||
if (strTransfer == "") {
|
||
alert('请选择要转接到的分机号。');
|
||
return;
|
||
}
|
||
__Transfer(strFJH, strTransfer);
|
||
}
|
||
|
||
//监听
|
||
function funBtnToListen() {
|
||
tolisten();
|
||
}
|
||
|
||
//监听
|
||
function tolisten() {
|
||
var strToLisFJH = document.all.txtTelNO.value.Trim();
|
||
if (strToLisFJH == "") {
|
||
alert('请选择要监听的分机号。');
|
||
return;
|
||
}
|
||
__Chanspy(strFJH, strToLisFJH);
|
||
}
|
||
//监控
|
||
function btnAgentmonitor() {
|
||
ChildAddTab("坐席监控", '/CallRecord/AgentMonitor?strFJH=' + strFJH);
|
||
}
|
||
//弹屏
|
||
//mixcallback:Event=Popscreen&Poptime=Ring&Callerid=8026&CallerIDName=<unknown>&CID=69837518&Calleeid=015305816689&CalleeIDName=&Recordfile=OUT8026-015305816689-20150603-171646
|
||
|
||
-1433323005.359020.WAV&Uniqueid=1433323005.359020&DateTime=2015-06-03 17:16:46&Server=localhost&Method=Dialout
|
||
function mixcallback(data) {
|
||
funEnabledBtn("btnSoftHook", true);
|
||
|
||
var State = data.type;//1呼入,2呼出
|
||
var call = "";//主叫
|
||
var called = "";//被叫
|
||
var srid = "";
|
||
if (State == 1) {//1呼入
|
||
State = 0;
|
||
call = data.src;
|
||
called = data.dst;
|
||
}
|
||
else {//2呼出
|
||
State = 1;
|
||
call = data.src;
|
||
called = data.dst;
|
||
}
|
||
|
||
var vStrUrl = "/Call/CallLog?State=" + State + "&CallType=1&DNIS=" + called + "&Tel=" + call + "&SRID=" + srid + "&AGENTID=" + strGH;
|
||
if (State == 0)//呼入
|
||
{
|
||
blCallin = true;
|
||
blTimer = true;
|
||
setTimer();
|
||
ShowResDetial(vStrUrl);
|
||
document.all.txtTelNO.value = call;
|
||
}
|
||
}
|
||
|
||
function getstatus(stats) {
|
||
if (stats == "Logged Out")
|
||
return "未登录";
|
||
if (stats == "Available") {
|
||
return "空闲";
|
||
}
|
||
if (stats == "CALLING") {
|
||
var call = document.all.txtTelNO.value;
|
||
call = confusedTel(call);
|
||
if (call.length > 0)
|
||
return "通话中(" + call + ")";
|
||
else
|
||
return "通话中";
|
||
}
|
||
if (stats == "Available (On Demand)") {
|
||
return "小结";
|
||
} if (stats == "RINGING") {
|
||
return "振铃";
|
||
}
|
||
if (stats == "On Break")
|
||
return "小休";
|
||
return stats;
|
||
}
|
||
var timer2;
|
||
//设置计时器
|
||
function setTimer() {
|
||
if (!blTimer) return;
|
||
var nHour = parseInt(nTimer / 3600);
|
||
var nTmp = nTimer % 3600;
|
||
var nMintue = parseInt(nTmp / 60);
|
||
var nSecond = nTmp % 60;
|
||
var strTimer = funAddZero(nHour) + ":" + funAddZero(nMintue) + ":" + funAddZero(nSecond);
|
||
var objTimer = document.getElementById('lblTimer');
|
||
if (objTimer) objTimer.innerText = strTimer;
|
||
nTimer++;
|
||
timer2 = window.setTimeout("setTimer()", 1000);
|
||
}
|
||
|
||
//设置按钮是否显示
|
||
function funDisplayBtn(vStrBtnID, vBlDisplay) {
|
||
var objBtn = document.getElementById(vStrBtnID);
|
||
if (objBtn) {
|
||
if (vBlDisplay)
|
||
objBtn.style.display = "block";
|
||
else
|
||
objBtn.style.display = "none";
|
||
}
|
||
}
|
||
// 设置按钮状态
|
||
function funEnabledBtn(vStrBtnID, vBlEnabled) {
|
||
var objBtn = document.getElementById(vStrBtnID);
|
||
if (objBtn) objBtn.disabled = !vBlEnabled;
|
||
}
|
||
function showstatus(errmsg, typ, err) {
|
||
document.all.divAction.innerHTML = errmsg;
|
||
if (typ == "err")
|
||
document.all.divAction.innerHTML = "<font color='red'>" + errmsg + "</font>";
|
||
}
|
||
function funAddZero(vIntValue) {
|
||
var strRevalue = '0000' + vIntValue;
|
||
return strRevalue.substr(strRevalue.length - 2, strRevalue.length);
|
||
}
|
||
String.prototype.Trim = function () {
|
||
return this.replace(/(^\s*)|(\s*$)/g, "");
|
||
}
|
||
function confusedTel(tel) {
|
||
var telstr = tel;
|
||
if (tel.length >= 4) {
|
||
telstr = tel.substr(tel.length - 4);
|
||
telstr = "****" + telstr;
|
||
if (tel.length < 8)
|
||
telstr = telstr.substr(telstr.length - tel.length);
|
||
if (tel.length > 8)
|
||
telstr = tel.substr(0, tel.length - telstr.length) + telstr;
|
||
}
|
||
|
||
return telstr;
|
||
}
|
||
|
||
$.extend({
|
||
getUrlVars: function (url) {
|
||
var vars = [], hash;
|
||
var hashes = url.slice(url.indexOf('?') + 1).split('&');
|
||
for (var i = 0; i < hashes.length; i++) {
|
||
hash = hashes[i].split('=');
|
||
vars.push(hash[0]);
|
||
vars[hash[0]] = hash[1];
|
||
}
|
||
return vars;
|
||
},
|
||
getUrlVar: function (url, name) {
|
||
return $.getUrlVars(url)[name];
|
||
}
|
||
}); |