ComplianceServer/oldcode/WEB/Scripts/ChatCore.js

1892 lines
93 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
@Name: Fangsi WebIM 1.0.0
@Author锋哥@Fangsi.net
@Date: 2015-01-01
@Blog: http://www.fangsi.net
*/
var face = [{ name: "[微笑]", code: "/::)", imgpath: "0.png" }, { name: "[撇嘴]", code: "/::~", imgpath: "1.png" }, { name: "[色]", code: "/::B", imgpath: "2.png" }, { name: "[发呆]", code: "/::|", imgpath: "3.png" },
{ name: "[得意]", code: "/:8-)", imgpath: "4.png" }, { name: "[流泪]", code: "/::<", imgpath: "5.png" }, { name: "[害羞]", code: "/::$", imgpath: "6.png" }, { name: "[闭嘴]", code: "/::X", imgpath: "7.png" },
{ name: "[睡]", code: "/::Z", imgpath: "8.png" }, { name: "[大哭]", code: "/::'(", imgpath: "9.png" }, { name: "[尴尬]", code: "/::-|", imgpath: "10.png" }, { name: "[发怒]", code: "/::@", imgpath: "11.png" },
{ name: "[调皮]", code: "/::P", imgpath: "12.png" },
{ name: "[呲牙]", code: "/::D", imgpath: "13.png" }, { name: "[惊讶]", code: "/::O", imgpath: "14.png" }, { name: "[难过]", code: "/::(", imgpath: "15.png" },
{ name: "[囧]", code: "[囧]", imgpath: "17.png" }, { name: "[抓狂]", code: "/::Q", imgpath: "18.png" }, { name: "[吐]", code: "/::T", imgpath: "19.png" }, { name: "[偷笑]", code: "/:,@P", imgpath: "20.png" },
{ name: "[愉快]", code: "/:,@-D", imgpath: "21.png" }, { name: "[白眼]", code: "/::d", imgpath: "22.png" }, { name: "[傲慢]", code: "/:,@o", imgpath: "23.png" },
{ name: "[困]", code: "/:|-)", imgpath: "25.png" }, { name: "[惊恐]", code: "/::!", imgpath: "26.png" },
{ name: "[流汗]", code: "/::L", imgpath: "27.png" }, { name: "[憨笑]", code: "/::>", imgpath: "28.png" }, { name: "[悠闲]", code: "/::,@", imgpath: "29.png" }, { name: "[奋斗]", code: "/:,@f", imgpath: "30.png" },
{ name: "[咒骂]", code: "/::-S", imgpath: "31.png" }, { name: "[疑问]", code: "/:?", imgpath: "32.png" }, { name: "[嘘]", code: "/:,@x", imgpath: "33.png" }, { name: "[晕]", code: "/:,@@", imgpath: "34.png" },
{ name: "[衰]", code: "/:,@!", imgpath: "36.png" }, { name: "[骷髅]", code: "/:!!!", imgpath: "37.png" },
{ name: "[敲打]", code: "/:xx", imgpath: "38.png" }, { name: "[再见]", code: "/:bye", imgpath: "39.png" }, { name: "[擦汗]", code: "/:wipe", imgpath: "40.png" },
{ name: "[抠鼻]", code: "/:dig", imgpath: "41.png" }, { name: "[鼓掌]", code: "/:handclap", imgpath: "42.png" },
{ name: "[坏笑]", code: "/:B-)", imgpath: "44.png" }, { name: "[左哼哼]", code: "/:<@", imgpath: "45.png" },
{ name: "[右哼哼]", code: "/:@>", imgpath: "46.png" }, { name: "[哈欠]", code: "/::-O", imgpath: "47.png" },
{ name: "[鄙视]", code: "/:>-|", imgpath: "48.png" }, { name: "[委屈]", code: "/:P-(", imgpath: "49.png" },
{ name: "[快哭了]", code: "/::'|", imgpath: "50.png" }, { name: "[阴险]", code: "/:X-)", imgpath: "51.png" },
{ name: "[亲亲]", code: "/::*", imgpath: "52.png" },
{ name: "[可怜]", code: "/:8*", imgpath: "54.png" }, { name: "[菜刀]", code: "/:pd", imgpath: "55.png" },
{ name: "[西瓜]", code: "/:<W>", imgpath: "56.png" }, { name: "[啤酒]", code: "/:beer", imgpath: "57.png" },
{ name: "[咖啡]", code: "/:coffee", imgpath: "60.png" },
{ name: "[猪头]", code: "/:pig", imgpath: "62.png" }, { name: "[玫瑰]", code: "/:rose", imgpath: "63.png" },
{ name: "[凋谢]", code: "/:fade", imgpath: "64.png" }, { name: "[嘴唇]", code: "/:showlove", imgpath: "65.png" },
{ name: "[爱心]", code: "/:heart", imgpath: "66.png" }, { name: "[心碎]", code: "/:break", imgpath: "67.png" },
{ name: "[蛋糕]", code: "/:cake", imgpath: "68.png" }, { name: "[炸弹]", code: "/:bome", imgpath: "70.gif" }, { name: "[便便]", code: "/:shit", imgpath: "71.gif" },
{ name: "[月亮]", code: "/:moon", imgpath: "72.gif" }, { name: "[太阳]", code: "/:sun", imgpath: "73.gif" }, { name: "[拥抱]", code: "/:hug", imgpath: "74.png" }, { name: "[强]", code: "/:strong", imgpath: "75.gif" },
{ name: "[弱]", code: "/:weak", imgpath: "76.gif" },
{ name: "[握手]", code: "/:share", imgpath: "77.gif" }, { name: "[胜利]", code: "/:v", imgpath: "78.gif" }, { name: "[抱拳]", code: "/:@)", imgpath: "79.gif" }, { name: "[勾引]", code: "/:jj", imgpath: "80.gif" },
{ name: "[拳头]", code: "/:@@", imgpath: "81.gif" }, { name: "[OK]", code: "/:ok", imgpath: "82.gif" }, { name: "[跳跳]", code: "/:jump", imgpath: "83.gif" }, { name: "[发抖]", code: "/:shake", imgpath: "84.gif" },
{ name: "[怄火]", code: "/:<O>", imgpath: "85.png" }, { name: "[转圈]", code: "/:circle", imgpath: "86.gif" }, { name: "😄", code: "😄", imgpath: "87.png" },
{ name: "😷", code: "😷", imgpath: "90.png" }, { name: "😂", code: "😂", imgpath: "91.png" }, { name: "😝", code: "😝", imgpath: "92.png" }, { name: "😳", code: "😳", imgpath: "93.png" },
{ name: "[嘿哈]", code: "[Hey]", imgpath: "97.png" }, { name: "[捂脸]", code: "[Facepalm]", imgpath: "98.png" }, { name: "[奸笑]", code: "[Smirk]", imgpath: "99.png" },
{ name: "[机智]", code: "[Smart]", imgpath: "100.png" }, { name: "[皱眉]", code: "[Concerned]", imgpath: "101.png" }, { name: "[耶]", code: "[Yeah!]", imgpath: "102.png" },
{ name: "[红包]", code: "[Packet]", imgpath: "108.png" }, { name: "[红包]", code: "[Chick]", imgpath: "109.png" }
];
var openIdMsgCount = {};//存储未读消息
var openIdMsg = {};//存储未读消息数据
var isTwinkleNow = 0;//正在闪烁(信息)
var timerArr;
var Alivetimer;
var aliveTime = new Date();
//var AllMssgeCount = 0;
$.connection.hub.url = signalrService + "/signalr";
//$.connection.hub.start({ xdomain: true });
!function (win, undefined) {
var config = {
msgurl: 'Message',
chatlogurl: '聊天记录url前缀',
aniTime: 200,
right: 290,
left: -290,
api: {
friend: 'friend.json', //好友列表接口
group: 'group.json', //群组列表接口
chatlog: 'chatlog.json', //聊天记录接口
groups: 'groups.json', //群组成员接口
sendurl: '' //发送消息接口
},
user: { //当前用户信息
name: username,
dept: deptname,
face: "/Content/Images/avatar.jpg"
},
//自动回复内置文案,也可动态读取数据库配置
autoReplay: [
'您好,我现在有事不在,一会再和您联系。',
'你没发错吧?',
'洗澡中,请勿打扰,偷窥请购票,个体四十,团体八折,订票电话:一般人我不告诉他!',
'你好,我是主人的美女秘书,有什么事就跟我说吧,等他回来我会转告他的。',
'我正在拉磨,没法招呼您,因为我们家毛驴去动物保护协会把我告了,说我剥夺它休产假的权利。',
'<@ ̄︶ ̄@>',
'你要和我说话?你真的要和我说话?你确定自己想说吗?你一定非说不可吗?那你说吧,这是自动回复。',
'主人正在开机自检,键盘鼠标看好机会出去凉快去了,我是他的电冰箱,我打字比较慢,你慢慢说,别急……',
'(*^__^*) 嘻嘻,是胖子吗?'
],
chating: {},
hosts: (function () {
var dk = location.href.match(/\:\d+/);
dk = dk ? dk[0] : '';
return 'http://' + document.domain + dk + '/';
})(),
json: function (url, data, callback, error) {
return $.ajax({
type: 'POST',
url: url,
data: data,
dataType: 'json',
success: callback,
error: error
});
},
stopMP: function (e) {
e ? e.stopPropagation() : e.cancelBubble = true;
}
},
dom = [$(window), $(document), $('html'), $('body')],
ChatCore = {},
systemHub = $.connection.chatHub,
onlinenum = 0;//在线人数
//主界面tab
ChatCore.tabs = function (index) {
var node = ChatCore.node;
node.tabs.eq(index).addClass('ChatCore_tabnow').siblings().removeClass('ChatCore_tabnow');
node.list.eq(index).show().siblings('.ChatCore_list').hide();
if (node.list.eq(index).find('li').length === 0) {
ChatCore.getDates(index);
}
};
//节点
ChatCore.renode = function () {
var node = ChatCore.node = {
tabs: $('#ChatCore_tabs>span'),
list: $('.ChatCore_list'),
online: $('.ChatCore_online'),
setonline: $('.ChatCore_setonline'),
onlinetex: $('#ChatCore_onlinetex'),
ChatCoreon: $('#ChatCore_on'),
ChatCoreFooter: $('#ChatCore_bottom'),
ChatCoreHide: $('#ChatCore_hide'),
ChatCoreSearch: $('#ChatCore_searchkey'),
searchMian: $('#ChatCore_searchmain'),
closeSearch: $('#ChatCore_closesearch'),
ChatCoreMin: $('#ChatCore_min')
};
};
//主界面缩放
ChatCore.expend = function () {
var node = ChatCore.node;
if (ChatCore.ChatCoreNode.attr('state') !== '1') {
ChatCore.ChatCoreNode.stop().animate({ left: config.left }, config.aniTime, function () {
node.ChatCoreon.addClass('ChatCore_off');
try {
localStorage.ChatCoreState = 1;
} catch (e) { }
ChatCore.ChatCoreNode.attr({ state: 1 });
node.ChatCoreFooter.addClass('ChatCore_expend').stop().animate({ marginLeft: -config.left }, config.aniTime / 2);
node.ChatCoreHide.addClass('ChatCore_show');
});
} else {
ChatCore.ChatCoreNode.stop().animate({ left: 1 }, config.aniTime, function () {
node.ChatCoreon.removeClass('ChatCore_off');
try {
localStorage.ChatCoreState = 2;
} catch (e) { }
ChatCore.ChatCoreNode.removeAttr('state');
node.ChatCoreFooter.removeClass('ChatCore_expend');
node.ChatCoreHide.removeClass('ChatCore_show');
});
node.ChatCoreFooter.stop().animate({ marginLeft: 0 }, config.aniTime);
}
};
//初始化窗口格局
ChatCore.FangsiInit = function () {
var node = ChatCore.node;
//主界面
try {
/*
if(!localStorage.ChatCoreState){
config.aniTime = 0;
localStorage.ChatCoreState = 1;
}
*/
if (localStorage.ChatCoreState === '1') {
ChatCore.ChatCoreNode.attr({ state: 1 }).css({ left: config.left });
node.ChatCoreon.addClass('ChatCore_off');
node.ChatCoreFooter.addClass('ChatCore_expend').css({ marginLeft: -config.left });
node.ChatCoreHide.addClass('ChatCore_show');
}
} catch (e) {
//layer.msg(e.message, 5, -1);
}
};
//获取消息记录
ChatCore.getmessage = function (param, dangQianYuefen, isNeedShowErro) {
var url = "http://192.168.1.132:808/MessageGh/" + accountnum + "/" + param.id + "/" + dangQianYuefen + ".json?i=" + GetGuid();
var selfParam = {
name: config.user.name,
face: config.user.face
};
$.ajax({
type: "GET",
url: url,
dataType: "text",
async: false,
success: function (data) {
var json = JSON.parse("[" + data + "]");
json.sort(sortBy('CreateTime', false, parseInt));
var imare = $("#ChatCore_areaone" + param.id);
var nbpkid = 0;
$(json).each(function (i, da) {
//var dataStr = getNowFormatDate(newDate);//聊天时间
var html = ChatCore.GetMsgLiHtml(param, da.CreateTime, da.IsSend, da.MsgType, da.Content, da.EID, da.Path, da.ID, da.MediaId);
imare.append(html);
if (nbpkid < da.ID)
nbpkid = da.ID;
});
imare.scrollTop(imare[0].scrollHeight);
//ChatCore.GetNewAndIsReadMsg(nbpkid, param.id);
if (nbpkid > 0) {
$.ajax({
url: signalrService + '/WxMessageSvr/GetNewAndIsReadMsg',
type: 'POST',
data: { eid: userid, accountnum: accountnum, openid: param.id, pkid: nbpkid },
dataType: 'JSON',
cache: false,
}).done(function (ret2) {
$(ret2).each(function (i, da2) {
//var dataStr = getNowFormatDate(newDate);//聊天时间
//alert(da2.Content);
var html = ChatCore.GetMsgLiHtml(param, da2.createtime, da2.issend, da2.msgtype, da2.content, da2.eid, da2.filepath, da2.id, da2.mediaid);
imare.append(html);
});
imare.scrollTop(imare[0].scrollHeight);
});
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (isNeedShowErro != null && isNeedShowErro == true)
ShowErroMsg("没有数据了!");
}
});
}
ChatCore.ShowAllHisMsg = function (openid) {
//-----查找所有的消息文件------
var url = signalrService + "/WxMessageSvr/GetHisMsgFile";
var param = {
name: $('.ChatCore_names').text(), //用户名
face: $('.ChatCore_face>img').attr('src'), //用户头像
}
$.ajax({
type: "POST",
url: url,
data: { openid: openid, accountnum: accountnum },
dataType: "JSON",
async: false,
success: function (da) {
if (da.result == 0) {
ShowErroMsg(da.erro);
return;
}
//$("#AllHisMsg").html("");
var hxhtml = "<ul class='ChatCore_chatview ChatCore_chatthis'></ul>";
var xxhtml = '<div id="tt" class="easyui-tabs" fit="true" >';
$(da.data).each(function (xx, wmm) {
var mnmnn = wmm.replace('.json', '').replace(/^(\d{4})(\d{2})$/, "$1年$2月");
//alert(mnmnn);
xxhtml += ('<div title="' + mnmnn + '" jsonName="' + wmm + '" style="padding:5px;"> '
+ "<ul class='ChatCore_chatview ChatCore_chatthis' style='height:auto;width:auto;'></ul>"
+ '</div> ')
});
xxhtml += '</div> ';
layer.open({
id: "AllHisMsg",
title: param.name + " 聊天记录",
type: 1,
//skin: 'layui-layer-rim',
area: ['400px', '600px'],
icon: 5,
offset: 'rt',
resize: true,
shade: 0,
content: xxhtml
});
$('#tt').tabs({
border: false,
onSelect: function (title, index) {
var tab = $('#tt').tabs('getSelected');
//console.log(tab.html());
var jsonName = title.replace('年', '').replace('月', '');
var selfParam = {
name: config.user.name,
face: config.user.face
};
var url = "http://192.168.1.132:808/MessageGh/" + accountnum + "/" + openid + "/" + jsonName + ".json?i=" + GetGuid();
$.ajax({
type: "GET",
url: url,
dataType: "text",
async: false,
success: function (data) {
var json = JSON.parse("[" + data + "]");
json.sort(sortBy('CreateTime', false, parseInt));
var imare = tab.find(".ChatCore_chatview");
imare.html("");
var nbpkid = 0;
$(json).each(function (i, da) {
//var dataStr = getNowFormatDate(newDate);//聊天时间
var html = ChatCore.GetMsgLiHtml(param, da.CreateTime, da.IsSend, da.MsgType, da.Content, da.EID, da.Path, da.ID, da.MediaId);
imare.append(html);
});
imare.parent().scrollTop(imare.parent()[0].scrollHeight);
}
});
}
});
}
});
};
ChatCore.GetMsgLiHtml = function (param, CreateTime, IsSend, MsgType, Content, EID, Path, ID, MediaId) {
var newDate = new Date();
newDate.setTime("" + CreateTime + "000");
var html = "";
var type = "me";
if (IsSend == 0) {
type = "customer";
}
var ncontent = "";
if (MsgType == "image") {
ncontent = "<img style='max-width:250px;' src='http://192.168.1.132/weappfile/" + Path + "' />"
} else if (MsgType == "voice") {
//ncontent = '<button class="layui-btn"><i class="layui-icon"></i></button>';
//ncontent = '<span class="layui-icon" style="font-size: 30px; color: #1E9FFF;">&#xe60c;</span>';
ncontent = '<span vco="wc" voice="' + MediaId + '" onClick="ShowVoice(\'' + MediaId + '\')" class=\"layui-icon\" style="color:#f30c55;font-weight:bold;cursor:pointer;"></span>';
} else {
ncontent = ChatCore.replaceFace(Content);
}
html = '<li class="' + (type === 'me' ? 'ChatCore_chateme' : '') + '">'
+ '<div class="ChatCore_chatuser">'
+ (
(type === 'me') ?
('<span class="ChatCore_chattime">' + newDate.toLocaleString() + '</span>'
+ '<span class="ChatCore_chatname">' + config.user.name + "(" + EID + ")" + '</span>'
+ '<img src="' + config.user.face + '" >') :
('<img src="' + param.face + '" >'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<span class="ChatCore_chattime">' + newDate.toLocaleString() + '</span>')
)
+ '</div>'
+ '<div class="ChatCore_chatsay" msgId="' + ID + '">' + ncontent + '<em class="ChatCore_zero"></em></div>'
+ '</li>';
return html;
}
//获取未读消息(数据库读取)
ChatCore.GetUnReadMsg = function () {
$.ajax({
url: signalrService + '/WxMessageSvr/GetUnReadMsg',
type: 'POST',
data: { eid: userid, accountnum: accountnum },
dataType: 'JSON',
cache: false,
}).done(function (ret) {
if (ret != null && ret.length > 0) {
$(ret).each(function (w, n) {
var fromUserId = n.openId;
var message = n.content;
if (n.msgtype == "image")
message = "[imagepath]:" + n.filepath;
else if (n.msgtype == "voice")
message = "[voice]:" + n.MediaId;
var newDate = new Date();
newDate.setTime("" + n.createtime + "000");
if (openIdMsgCount[fromUserId] == null)
openIdMsgCount[fromUserId] = 1;
else
openIdMsgCount[fromUserId]++;
if (openIdMsg[fromUserId] == null) {
openIdMsg[fromUserId] = new Array();
openIdMsg[fromUserId][0] = { msg: message, id: n.id, createtime: newDate.toLocaleString() };
} else {
var ncount = openIdMsg[fromUserId].length;
openIdMsg[fromUserId][ncount] = { msg: message, id: n.id, createtime: newDate.toLocaleString() };
}
$("[nid='msgcount_" + fromUserId + "']").attr("style", "").html("" + openIdMsgCount[fromUserId]);
});
ChatCore.NewsTwinkle();
}
});
}
//显示表情,并发送表情
ChatCore.showFace = function (type) {
var nhtml = "<ul id=\"layimFace\" class='layui-clear layim-face-list'>";
$(face).each(function (e, x) {
nhtml += "<li title=\"" + x.name + "\" code=\"" + x.code + "\" ><img src=\"/Face/" + x.imgpath + "\"></li>";
});
nhtml += "</ul>";
layer.open({
title: '选择表情',
type: 1,
skin: 'layui-layer-rim',
area: ['410px', '400px'],
content: nhtml
});
$(".layim-face-list li").mouseover(function () {
$(this).attr("style", "border: 1px solid red;");
}).mouseout(function () {
$(this).removeAttr("style");
}).click(function () {
var imwriht = null;
if (type == "batch") {
imwriht = $("#QFChatCore_write");
} else {
imwriht = $("#ChatCore_write");
}
imwriht.val(imwriht.val() + $(this).attr("code"));
var indexs = $("#layimFace").parent().parent().attr("times");
layer.close(indexs);
});
}
ChatCore.replaceFace = function (cotent) {
var txt = cotent;
$(face).each(function (i, n) {
while (txt.indexOf(n.code) > -1) {
txt = txt.replace(n.code, "<img src=\"/Face/" + n.imgpath + "\">");
}
});
return txt;
}
ChatCore.GetSuCai = function (type) {
var sendType = type;
if (sendType == "mpnews") {
sendType = "news";
}
$.ajax({
url: signalrService + '/WxMessageSvr/GetSuCai',
type: 'POST',
data: { 'type': sendType, 'count': imgshowCount, 'offset': 0, 'accountnum': accountnum },
dataType: 'JSON',
cache: false
}).done(function (ret) {
if (ret.result == 0) {
ShowErroMsg(ret.msg);
//alert(ret.msg);//错误提示
} else {
var nhtml = "<table id=\"sucaitab\" class=\"WoCao\" border='0'>";
if (type == "mpnews") {
var xxx = JSON.parse(ret.dataResult);
//console.log(xxx);
$(xxx.item).each(function (wz, wa) {
nhtml += "<tr>";
nhtml += "<td><button class=\"layui-btn layui-btn-normal layui-btn-mini \" >" + wa.content.news_item[0].title + "</button></td>";
nhtml += "<td><button class=\"layui-btn layui-btn-mini \" onClick=\"SendSucai('" + wa.content.news_item[0].title + "','" + type + "','" + wa.media_id + "','')\">发送</button></td>";
nhtml += "</tr>";
});
//alert(xxx.item_count);
} else {
$(ret.item).each(function (i, el) {
nhtml += "<tr>";
nhtml += "<td><button class=\"layui-btn layui-btn-normal layui-btn-mini \" >" + el.name + "</button></td>";
nhtml += "<td><button class=\"layui-btn layui-btn-mini \" onClick=\"SendSucai('" + el.name + "','" + type + "','" + el.media_id + "','" + el.url + "')\">发送</button></td>";
if (type == "image")
nhtml += "<td><a href=\"javascript:ImgPreview('" + el.media_id + "','" + el.url + "','" + el.name + "')\" class=\"layui-btn layui-btn-primary layui-btn-mini\">查看</a></td>";
nhtml += "</tr>";
});
}
nhtml += "</table>";
nhtml += "<div id=\"demo1\"></div>";
var ntitle = "选择图片素材";
if (type == "image") {
ntitle = "选择图片素材";
} else if (type == "video") {
ntitle = "选择视频素材";
} else if (type == "voice") {
ntitle = "选择语音素材";
} else if (type == "mpnews") {
ntitle = "选择图文素材";
}
layer.open({
title: ntitle,
type: 1,
skin: 'layui-layer-rim',
area: ['600px', '370px'],
content: nhtml
});
var showIndex = 0;
layui.use(['laypage', 'layer'], function () {
var laypage = layui.laypage
, layer = layui.layer;
laypage({
cont: 'demo1'
, pages: Math.ceil(ret.total_count / imgshowCount) //总页数
, groups: 5 //连续显示分页数
, jump: function (obj) {
showIndex++;
if (showIndex > 1) {
var offset = (obj.curr - 1) * imgshowCount
//alert(obj.curr);
$.ajax({
url: signalrService + '/WxMessageSvr/GetSuCai',
type: 'POST',
data: { 'type': "image", 'count': imgshowCount, 'offset': offset, 'accountnum': accountnum },
dataType: 'JSON',
cache: false
}).done(function (ret2) {
$(".WoCao").html("");
if (ret2.result == 0) {
alert(ret2.erro);//错误提示
} else {
var nhtml2 = "";
$(ret2.item).each(function (i, el) {
nhtml2 += "<tr>";
nhtml2 += "<td><button class=\"layui-btn layui-btn-normal layui-btn-mini \" >" + el.name + "</button></td>";
nhtml2 += "<td><button class=\"layui-btn layui-btn-mini \" onClick=\"SendSucai('" + el.name + "','image','" + el.media_id + "','" + el.url + "')\">发送</button></td>";
if (type == "image")
nhtml2 += "<td><a href=\"javascript:ImgPreview('" + el.media_id + "','" + el.url + "','" + el.name + "')\" class=\"layui-btn layui-btn-primary layui-btn-mini\">查看</a></td>";
nhtml2 += "</tr>";
});
$(".WoCao").html(nhtml2);
}
});
}
}
});
});
}
});
}
//读取未读消息(从本地缓存中读取)
ChatCore.GetNotReadMsg = function (openId) {
if (openIdMsg[openId] == null)
return;
$(openIdMsg[openId]).each(function (x, n) {
var log = {};
log.html = function (param, type) {
return '<li class="' + (type === 'me' ? 'ChatCore_chateme' : '') + '">'
+ '<div class="ChatCore_chatuser">'
+ function () {
if (type === 'me') {
return '<span class="ChatCore_chattime">' + param.time + '</span>'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<img src="' + param.face + '" >';
} else {
return '<img src="' + param.face + '" >'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<span class="ChatCore_chattime">' + param.time + '</span>';
}
}()
+ '</div>'
+ '<div class="ChatCore_chatsay">' + ChatCore.replaceFace(param.content) + '<em class="ChatCore_zero"></em></div>'
+ '</li>';
};
var othis = $("#ChatCore_friend_list li[data-id=" + openId + "]");
var keys = "one" + openId;
log.imarea = ChatCore.chatbox.find('#ChatCore_area' + keys);
if (n.id != null) {
var ncount = log.imarea.find("[msgId='" + n.id + "']").length;
if (ncount > 0)
return true;//相当于continure
}
var nmessage = n.msg;
//alert(nmessage);
if (nmessage.indexOf("[imagepath]:") > -1) {
nmessage = "<img style='max-width:250px;' src='http://192.168.1.132/weappfile" + nmessage.replace("[imagepath]:", "") + "' />"
} else if (nmessage.indexOf("[voice]:") > -1) {
//ncontent = '<button class="layui-btn"><i class="layui-icon"></i></button>';
//ncontent = '<span class="layui-icon" style="font-size: 30px; color: #1E9FFF;">&#xe60c;</span>';
var MediaId = nmessage.replace("[voice]:", "");
ncontent = '<span voice="' + MediaId + '" onClick="ShowVoice(\'' + MediaId + '\')" class=\"layui-icon\" style="color:#f30c55;font-weight:bold;cursor:pointer;"></span>';
}
log.imarea.append(log.html({
time: n.createtime,
name: othis.find('.ChatCore_onename').text(),
face: othis.find('.ChatCore_oneface').attr('src'),
content: nmessage,
}));
log.imarea.scrollTop(log.imarea[0].scrollHeight);//聊天界面滚动到最底下
});
openIdMsg[openId] = null;//移除数据
openIdMsgCount[openId] = 0;
$("[nid='msgcount_" + openId + "']").attr("style", "display:none;").html("");
ChatCore.UpdateIsAlreadyRead(openId);//读取完数据后修改数据状态
ChatCore.NewsTwinkle();
}
//新消息闪烁功能
ChatCore.NewsTwinkle = function () {
var shuxinCount = 0;
for (var name in openIdMsgCount) {
if (openIdMsgCount[name] != null) {
//alert("name:" + name);
var xx = $("#ChatCore_friend_list").find("[data-id='" + name + "']").not(".Hidden").length;
if (xx > 0)
shuxinCount += openIdMsgCount[name];
}
}
//alert(shuxinCount);
if (shuxinCount > 0) {
if (isTwinkleNow == 0) {//需要进行闪烁
timerArr = $.blinkTitle.show();
isTwinkleNow = 1;
}
} else {
if (isTwinkleNow == 1) {//需要停止闪烁
$.blinkTitle.clear(timerArr);
isTwinkleNow = 0;
}
}
}
//修改读取状态
ChatCore.UpdateIsAlreadyRead = function (openId) {
$.ajax({
url: signalrService + '/WxMessageSvr/UpdateIsAlreadyRead',
type: 'POST',
data: { eid: userid, openId: openId, accountnum: accountnum },
dataType: 'JSON',
cache: false
}).done(function (ret) {
});
}
//客户转接
//ChatCore.Transfer = Transfer();
//ChatCore.BindPhone = BindPhone();
//管理分组
ChatCore.ManagerGroup = function () {
$.r_ajax({
url: signalrService + '/WxGroupSvr/GetGroup',
type: "Post",
data: { accountNum: accountnum, eId: parseInt(userid) },
dataType: "json",
loading: true,
success: function (ret) {
if (ret.type == 0) {
ShowErroMsg(ret.message);
return;
}
var getRowHtml = function (gid, gname) {
fenzuid++;
var rowHtml = '<tr fenzuid="' + fenzuid + '" wx_gid="' + gid + '" ><td width="40%" style="height:35px;"><input name="title" gid="' + gid + '" gname="' + gname + '" style="height:30px;width:200px;" lay-verify="title" autocomplete="off" placeholder="请输入组名称" class="layui-input" type="text" value="' + gname + '"></td>';
rowHtml += '<td width="10%">&nbsp;</td>';
rowHtml += '<td style=""><button class="layui-btn layui-btn-small" onclick="SaveGroup(\'' + fenzuid + '\')">保存</button>&nbsp;<button btn_remove="delete" onclick="RemoveRow(\'' + fenzuid + '\')" class="layui-btn layui-btn-danger layui-btn-small">删除</button></td>';
rowHtml += "</tr>";
return rowHtml;
}
var html = "<table id='grouptable' width='100%'>";
$(ret.data).each(function (x, n) {
html += getRowHtml(n.PKID, n.GROUPNAME);
});
html += "</table>";
layer.open({
title: '管理分组',
type: 1,
skin: 'layui-layer-rim',
area: ['450px', '400px'],
btn: ["新增一条"],
content: '<div style="padding: 5px 5px;">' + html + '</div>',
yes: function () {
var nrow = getRowHtml(0, "");
$("#grouptable").append(nrow);
return false;
}
});
}
});
//$.ajax({
// url: 'http://192.168.1.132:709/WxGroupSvr/GetUserGroup',
// type: 'POST',
// data: { accountNum: accountnum, eId: parseInt(userid) },
// dataType: 'JSON',
// cache: false
//}).done(function (ret) {
//});
}
//初始化好友和分组
ChatCore.InitFriendAndGroup = function () {
$.r_ajax({
url: signalrService + '/WxGroupSvr/GetUserGroup',
type: "Get",
data: { accountNum: accountnum, eId: userid },
dataType: "json",
loading: true,
success: function (ret) {
if (ret.type == 0) {
ShowErroMsg(ret.message);
return;
}
$("#Chat_FriendList>li").not(":first").remove();
$(ret.data).each(function (x, nn) {
var style = "";
var isNotSys = "";
isNotSys = 'NotSysGroup="true"';
if (nn.GroupType == 0) {
style = 'style="color:#ad9327;"';
isNotSys = "";
}
var xhtml = '<li class="ChatCore_parentnode" ' + isNotSys + ' groupName="' + nn.GroupName + '" wxxGid="' + nn.GroupId + '"><h5><i></i><span class="ChatCore_parentname" ngid="' + nn.GroupId + '" ' + style + '>' + nn.GroupName + '</span><em class="ChatCore_nums">' + nn.UserGroupList.length + '</em></h5><ul id="ChatCore_friend_list_' + nn.GroupId + '" class="ChatCore_chatlist" style="">';
$(nn.UserGroupList).each(function (ss, mm) {
xhtml += $("#ChatCore_friend_list [data-id='" + mm.OpenId + "']").prop("outerHTML");
});
xhtml += "</ul></li>";
$("#Chat_FriendList").append(xhtml);
});
$("#Chat_FriendList>li").not(":first").not("[notsysgroup='true']").find(".Hidden").removeClass("Hidden").removeAttr("hidden");
$(".ChatCore_childnode").on('contextmenu', function (e) {
menuChooseId = $(this).attr("data-id");
$('#tab_menu').menu('show', {
left: e.pageX,
top: e.pageY
});
return false;
});
}
});
}
//初始化聊天窗口
ChatCore.popchat = function (param) {
var node = ChatCore.node, log = {};
log.success = function (layero) {
layer.setMove();
ChatCore.chatbox = layero.find('#ChatCore_chatbox');
log.chatlist = ChatCore.chatbox.find('.ChatCore_chatmore>ul');
log.chatlist.html('<li data-id="' + param.id + '" type="' + param.type + '" id="ChatCore_user' + param.type + param.id + '"><span>' + param.name + '</span><div nid="msgcount_' + param.id + '" class="MsgCount" style="display:none;"></div><em>×</em></li>')
ChatCore.tabchat(param, ChatCore.chatbox);
//最小化聊天窗
ChatCore.chatbox.find('.layer_setmin').on('click', function () {
var indexs = layero.attr('times');
layero.hide();
node.ChatCoreMin.text(ChatCore.nowchat.name).show();
});
//关闭窗口
ChatCore.chatbox.find('.ChatCore_close').on('click', function () {
var indexs = layero.attr('times');
//alert(indexs);
//layer.closeAll();
layer.close(indexs);
//layero.close();
ChatCore.chatbox = null;
config.chating = {};
config.chatings = 0;
$("[times='" + indexs + "']").remove();
});
//转接,弹出转接窗口
ChatCore.chatbox.find("#Transfer").on("click", function () {
var openid = $(this).attr("n_openid");
if (openid == null || openid == "") {
ShowErroMsg("参数错误");
return;
}
Transfer(openid, ChatCore.chatbox.find(".ChatCore_names").text());
});
ChatCore.chatbox.find("#BindPhone").on("click", function () {
var openid = $(this).attr("n_openid");
if (openid == null || openid == "") {
ShowErroMsg("参数错误");
return;
}
BindPhone(openid, ChatCore.chatbox.find(".ChatCore_names").text());
});
//关闭某个聊天
log.chatlist.on('mouseenter', 'li', function () {
$(this).find('em').show();
}).on('mouseleave', 'li', function () {
$(this).find('em').hide();
});
log.chatlist.on('click', 'li em', function (e) {
var parents = $(this).parent(), dataType = parents.attr('type');
var dataId = parents.attr('data-id'), index = parents.index();
var chatlist = log.chatlist.find('li'), indexs;
config.stopMP(e);
delete config.chating[dataType + dataId];
config.chatings--;
parents.remove();
$('#ChatCore_area' + dataType + dataId).remove();
if (dataType === 'group') {
$('#ChatCore_group' + dataType + dataId).remove();
}
if (parents.hasClass('ChatCore_chatnow')) {
if (index === config.chatings) {
indexs = index - 1;
} else {
indexs = index + 1;
}
ChatCore.tabchat(config.chating[chatlist.eq(indexs).attr('type') + chatlist.eq(indexs).attr('data-id')]);
}
if (log.chatlist.find('li').length === 1) {
log.chatlist.parent().hide();
}
});
//聊天选项卡
log.chatlist.on('click', 'li', function () {
//alert("聊天选项卡");
var othis = $(this), dataType = othis.attr('type'), dataId = othis.attr('data-id');
ChatCore.tabchat(config.chating[dataType + dataId]);
});
//发送热键切换
log.sendType = $('#ChatCore_sendtype'), log.sendTypes = log.sendType.find('span');
$('#ChatCore_enter').on('click', function (e) {
config.stopMP(e);
log.sendType.show();
});
log.sendTypes.on('click', function () {
log.sendTypes.find('i').text('')
$(this).find('i').text('√');
});
$("#ChatCore_addface").on('click', function (e) {
//alert("你麻痹,点我干哈");
//layer.alert('你好么,体验者');
ChatCore.showFace("one");
});
$("#ChatCore_addimage").on('click', function (e) {
sendType = "plain";
//$("#nbtouser").val($(this).attr("nid"));
//$("#nbname").val($(this).attr("nname"));
$("#uploadFile").trigger("click");
})
//发送素材图片
$("#ChatCore_addimage2").on('click', function (e) {
sendType = "plain";
ChatCore.GetSuCai('image');
});
//发送语音
$("#ChatCore_addvoice").on('click', function (e) {
sendType = "plain";
ChatCore.GetSuCai('voice');
});
//发送视频
$("#ChatCore_addvedio").on('click', function (e) {
sendType = "plain";
ChatCore.GetSuCai('video');
});
$("#ChatCore_addfile").on("click", function (e) {
sendType = "plain";
ChatCore.GetSuCai('mpnews');
});
$("#ChatCore_seechatlog").on("click", function (e) {
ChatCore.ShowAllHisMsg($(this).attr("openid"));
});
ChatCore.transmit();
};
log.html = '<div class="ChatCore_chatbox" id="ChatCore_chatbox">'
+ '<h6>'
+ '<span class="ChatCore_move"></span>'
+ ' <a href="javascript:void(0);" class="ChatCore_face" ><img src="' + param.face + '" ></a>'
+ ' <a href="javascript:void(0);" class="ChatCore_names" >' + param.name + '</a>'
+ ' <span class="ChatCore_rightbtn">'
+ ' <i id="Transfer" class="layui-icon" title="转接" style="margin-right:10px;font-style: normal;background:none;color: #8f3434;/*! font-weight: bold; */"></i>'
+ ' <i id="BindPhone" class="layui-icon" title="绑定手机号码" style="margin-right:10px;font-style: normal;background:none;color: #a53d62;/*! font-weight: bold; */"></i>'
+ ' <i class="layer_setmin"></i>'
+ ' <i class="ChatCore_close"></i>'
+ ' </span>'
+ '</h6>'
+ '<div class="ChatCore_chatmore" id="ChatCore_chatmore">'
+ ' <ul class="ChatCore_chatlist"></ul>'
+ '</div>'
+ '<div class="ChatCore_groups" id="ChatCore_groups"></div>'
+ '<div class="ChatCore_chat">'
+ ' <div class="ChatCore_chatarea" id="ChatCore_chatarea">'
+ ' <ul class="ChatCore_chatview ChatCore_chatthis" id="ChatCore_area' + param.type + param.id + '"></ul>'
+ ' </div>'
//+ ' <div class="ChatCore_tool" style="color:#666;">注Web聊天中请勿发送过长的文本.</div>'//增加内容
+ ' <div class="ChatCore_tool" style="">'
+ ' <i class="ChatCore_addface" id="ChatCore_addface" title="发送表情"></i>'
+ ' <a href="javascript:;"><i class="ChatCore_upImg" id="ChatCore_addimage" nid="' + param.id + '" nname="' + param.name + '" title="本地图片"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addimage" id="ChatCore_addimage2" nid="' + param.id + '" nname="' + param.name + '" title="发送图片"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addvoice" id="ChatCore_addvoice" title="发送语音"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addvedio" id="ChatCore_addvedio" title="发送视频"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addfile" id="ChatCore_addfile" title="发送图文"></i></a>'
+ ' <a href="javascript:;" class="ChatCore_seechatlog" id="ChatCore_seechatlog" openId=""><i></i>聊天记录</a>'
+ ' </div>'
+ ' <textarea class="ChatCore_write" id="ChatCore_write"></textarea>'
+ ' <div class="ChatCore_send">'
+ ' <div class="ChatCore_sendbtn" id="ChatCore_sendbtn">发送<span class="ChatCore_enter" id="ChatCore_enter"><em class="ChatCore_zero"></em></span></div>'
+ ' <div class="ChatCore_sendtype" id="ChatCore_sendtype">'
+ ' <span><i>√</i>按Enter键发送</span>'
+ ' <span><i></i>按Ctrl+Enter键发送</span>'
+ ' </div>'
+ ' </div>'
+ '</div>'
+ '</div>';
//alert("点击了客户:" + param.id);
if (config.chatings < 1) {//还没有聊天窗口,进行初始化
$.layer({
type: 1,
border: [0],
title: false,
shade: [0],
area: ['620px', '493px'],
move: '.ChatCore_chatbox .ChatCore_move',
moveType: 1,
closeBtn: false,
offset: [(($(window).height() - 493) / 2) + 'px', ''],
page: {
html: log.html
}, success: function (layero) {
log.success(layero);
}
});
//GetUserInfo(param.id);//获取客户信息
} else {//已有聊天窗口增加tab面板和聊天界面
log.chatmore = ChatCore.chatbox.find('#ChatCore_chatmore');
log.chatarea = ChatCore.chatbox.find('#ChatCore_chatarea');
log.chatmore.show();
log.chatmore.find('ul>li').removeClass('ChatCore_chatnow');
log.chatmore.find('ul').append('<li data-id="' + param.id + '" type="' + param.type + '" id="ChatCore_user' + param.type + param.id + '" class="ChatCore_chatnow"><span>' + param.name + '</span><div nid="msgcount_' + param.id + '" class="MsgCount" style="display:none;"></div><em>×</em></li>');
log.chatarea.find('.ChatCore_chatview').removeClass('ChatCore_chatthis');
log.chatarea.append('<ul class="ChatCore_chatview ChatCore_chatthis" id="ChatCore_area' + param.type + param.id + '"></ul>');//
param.IsNeedReadMsg = false;
ChatCore.tabchat(param);
//GetUserInfo(param.id);//获取客户信息
}
var imare2 = $("#ChatCore_areaone" + param.id);
var d = new Date();
var yyy = "" + (d.getMonth() + 1);
if (d.getMonth() < 9) {
yyy = "0" + (d.getMonth() + 1).toString();
}
var dangQianYuefen = d.getFullYear() + yyy;
ChatCore.getmessage(param, dangQianYuefen, false);//加载聊天记录
param.IsNeedReadMsg = true;
ChatCore.GetNotReadMsg(param.id);//加载未读消息
//群组
log.chatgroup = ChatCore.chatbox.find('#ChatCore_groups');
if (param.type === 'group') {
log.chatgroup.find('ul').removeClass('ChatCore_groupthis');
log.chatgroup.append('<ul class="ChatCore_groupthis" id="ChatCore_group' + param.type + param.id + '"></ul>');
ChatCore.getGroups(param);
}
//点击群员切换聊天窗
log.chatgroup.on('click', 'ul>li', function () {
ChatCore.popchatbox($(this));
});
};
//定位到某个聊天队列
ChatCore.tabchat = function (param) {
var node = ChatCore.node, log = {}, keys = param.type + param.id;
ChatCore.nowchat = param;
$("#nbtouser").val(param.id);
ChatCore.chatbox.find('#ChatCore_user' + keys).addClass('ChatCore_chatnow').siblings().removeClass('ChatCore_chatnow');
ChatCore.chatbox.find('#ChatCore_area' + keys).addClass('ChatCore_chatthis').siblings().removeClass('ChatCore_chatthis');
ChatCore.chatbox.find('#ChatCore_group' + keys).addClass('ChatCore_groupthis').siblings().removeClass('ChatCore_groupthis');
var nbclass = "nEmpty";
if (param.isGuanzu == "unsubscribe") {
nbclass = "Imggray";
} else {
ChatCore.chatbox.find('.ChatCore_face>img').removeClass("Imggray");
}
ChatCore.chatbox.find('.ChatCore_face>img').attr('src', param.face).addClass(nbclass);
//ChatCore.chatbox.find('.ChatCore_face, .ChatCore_names').attr('href', param.href);
ChatCore.chatbox.find('.ChatCore_names').text(param.name);
ChatCore.chatbox.find('.ChatResId').remove();
if (param.resid != null && param.resid != '') {
ChatCore.chatbox.find('.ChatCore_names').after("<a class='ChatResId' href='javascript:OpenWindResId(\"" + param.resid + "\")'>" + param.resid + "</a>");
}
ChatCore.chatbox.find('#Transfer').attr("n_openid", param.id);
ChatCore.chatbox.find('#BindPhone').attr("n_openid", param.id);
ChatCore.chatbox.find('.ChatCore_seechatlog').attr('openid', param.id);
log.groups = ChatCore.chatbox.find('.ChatCore_groups');
if (param.type === 'group') {
log.groups.show();
} else {
log.groups.hide();
}
//alert(param.IsNeedReadMsg);
if (param.IsNeedReadMsg == null || param.IsNeedReadMsg == true)
ChatCore.GetNotReadMsg(param.id);//加载未读消息
$('#ChatCore_write').focus();
};
//弹出聊天窗
ChatCore.popchatbox = function (othis) {
var node = ChatCore.node, userId = othis.attr('id'), dataId = othis.attr('data-id'), param = {
id: dataId, //用户ID
userid: userId,
type: othis.attr('type'),
name: othis.find('.ChatCore_onename').text(), //用户名
face: othis.find('.ChatCore_oneface').attr('src'), //用户头像
isGuanzu: othis.find('.ChatCore_oneface').attr('guanzu'), //用户头像
resid: othis.attr('resid'),//resid
href: ''//config.hosts + 'user/' + dataId //用户主页
}, key = param.type + dataId;
if (!config.chating[key]) {//当前没有打开这个界面,需要初始化
ChatCore.popchat(param);
config.chatings++;
} else {
ChatCore.tabchat(param);//已经有这个界面,直接选中
}
config.chating[key] = param;
var chatbox = $('#ChatCore_chatbox');
if (chatbox[0]) {
node.ChatCoreMin.hide();
chatbox.parents('.xubox_layer').show();
}
};
//请求群员
ChatCore.getGroups = function (param) {
var keys = param.type + param.id, str = '',
groupss = ChatCore.chatbox.find('#ChatCore_group' + keys);
groupss.addClass('loading');
config.json(config.api.groups, {}, function (datas) {
if (datas.status === 1) {
var ii = 0, lens = datas.data.length;
if (lens > 0) {
for (; ii < lens; ii++) {
str += '<li data-id="' + datas.data[ii].id + '" type="one"><img src="' + datas.data[ii].face + '" class="ChatCore_oneface"><span class="ChatCore_onename">' + datas.data[ii].name + '</span></li>';
}
} else {
str = '<li class="ChatCore_errors">没有群员</li>';
}
} else {
str = '<li class="ChatCore_errors">' + datas.msg + '</li>';
}
groupss.removeClass('loading');
groupss.html(str);
}, function () {
groupss.removeClass('loading');
groupss.html('<li class="ChatCore_errors">请求异常</li>');
});
};
//消息传输
ChatCore.transmit = function () {
var node = ChatCore.node, log = {};
node.sendbtn = $('#ChatCore_sendbtn');
node.imwrite = $('#ChatCore_write');
//发送
log.send = function () {
var data = {
content: node.imwrite.val(),
id: ChatCore.nowchat.id,
sign_key: '', //密匙
_: +new Date
};
var imgmsg = $("#imgmsg").val();
var sucaicontent = $("#sucaiContent").val();
if (data.content.replace(/\s/g, '') === '' && (imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null")) {
layer.tips('说点啥呗!', '#ChatCore_write', 2);
node.imwrite.focus();
} else {
//此处皆为模拟
var keys = ChatCore.nowchat.type + ChatCore.nowchat.id;
//聊天模版
log.html = function (param, type) {
return '<li class="' + (type === 'me' ? 'ChatCore_chateme' : '') + '">'
+ '<div class="ChatCore_chatuser">'
+ function () {
if (type === 'me') {
return '<span class="ChatCore_chattime">' + param.time + '</span>'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<img src="' + param.face + '" >';
} else {
return '<img src="' + param.face + '" >'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<span class="ChatCore_chattime">' + param.time + '</span>';
}
}()
+ '</div>'
+ '<div class="ChatCore_chatsay">' + ChatCore.replaceFace(param.content) + '<em class="ChatCore_zero"></em></div>'
+ '</li>';
};
log.imarea = ChatCore.chatbox.find('#ChatCore_area' + keys);
var nmessage = data.content;
if ((imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null")) {
nmessage = data.content
}
else if (imgmsg != null && imgmsg != '') {
nmessage = "<img style='max-width:250px;' src='http://192.168.1.132/weappfile/" + imgmsg + "' />";
}
else if (sucaicontent != null && sucaicontent != '' && sucaicontent != "null") {
nmessage = sucaicontent;
}
log.imarea.append(log.html({
time: new Date().toLocaleString(),
name: config.user.name,
dept: config.user.dept,
face: config.user.face,
content: nmessage
}, 'me'));
node.imwrite.val('').focus();
log.imarea.scrollTop(log.imarea[0].scrollHeight);
//setTimeout(function () {
// log.imarea.append(log.html({
// time: '2014-04-26 0:38',
// name: ChatCore.nowchat.name,
// face: ChatCore.nowchat.face,
// content: config.autoReplay[(Math.random() * config.autoReplay.length) | 0]
// }));
// log.imarea.scrollTop(log.imarea[0].scrollHeight);
//}, 500);
/*
that.json(config.api.sendurl, data, function(datas){
});
*/
if ((imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null"))
systemHub.server.sendPrivateMessage(ChatCore.nowchat.id, data.content, parseInt(userid), accountnum);
else {
$("#imgmsg").val("");
$("#sucaitype").val("");
$("#sucaiContent").val("");
}
}
};
node.sendbtn.on('click', log.send);
node.imwrite.keyup(function (e) {
if (e.keyCode === 13) {
log.send();
}
});
};
//事件,系统事件
ChatCore.event = function () {
var node = ChatCore.node;
//主界面tab
node.tabs.eq(0).addClass('ChatCore_tabnow');
node.tabs.on('click', function () {
var othis = $(this), index = othis.index();
ChatCore.tabs(index);
});
//列表展收
node.list.on('click', 'h5', function () {
var othis = $(this), chat = othis.siblings('.ChatCore_chatlist'), parentss = othis.parent();
if (parentss.hasClass('ChatCore_liston')) {
chat.hide();
parentss.removeClass('ChatCore_liston');
} else {
chat.show();
parentss.addClass('ChatCore_liston');
}
});
//设置在线隐身
node.online.on('click', function (e) {
config.stopMP(e);
node.setonline.show();
});
node.setonline.find('span').on('click', function (e) {
var index = $(this).index();
config.stopMP(e);
if (index === 0) {
node.onlinetex.html('在线');
node.online.removeClass('ChatCore_offline');
} else if (index === 1) {
node.onlinetex.html('隐身');
node.online.addClass('ChatCore_offline');
}
node.setonline.hide();
});
node.ChatCoreon.on('click', ChatCore.expend);
node.ChatCoreHide.on('click', ChatCore.expend);
//搜索
node.ChatCoreSearch.keyup(function () {
var val = $(this).val().replace(/\s/g, '');
if (val !== '') {
node.searchMian.show();
node.closeSearch.show();
//此处的搜索ajax参考ChatCore.getDates
//node.list.eq(3).html('<li class="ChatCore_errormsg">没有符合条件的结果</li>');
var nx = 0;
var nhtml = "";
$("#ChatCore_friend_list .ChatCore_onename").each(function (x, n) {
if ($(this).html().indexOf(val) > -1) {
nx++;
nhtml += $(this).parent().prop("outerHTML");
}
});
if (nx == 0)
node.list.eq(3).html('<li class="ChatCore_errormsg">没有符合条件的结果</li>');
else
node.list.eq(3).html(nhtml);
$("#ChatCore_searchmain .ChatCore_childnode").on('contextmenu', function (e) {
menuChooseId = $(this).attr("data-id");
$('#tab_menu').menu('show', {
left: e.pageX,
top: e.pageY
});
return false;
});
} else {
node.searchMian.hide();
node.closeSearch.hide();
}
});
node.closeSearch.on('click', function () {
$(this).hide();
node.searchMian.hide();
node.ChatCoreSearch.val('').focus();
});
//弹出聊天窗
config.chatings = 0;
node.list.on('click', '.ChatCore_childnode', function () {
//alert("ChatCore_childnode");
var othis = $(this);
ChatCore.popchatbox(othis);
});
//点击最小化栏
node.ChatCoreMin.on('click', function () {
$(this).hide();
$('#ChatCore_chatbox').parents('.xubox_layer').show();
});
//document事件
dom[1].on('click', function () {
node.setonline.hide();
$('#ChatCore_sendtype').hide();
});
//连接IM服务器成功
systemHub.client.onConnected = function (id, userName, allUsers) {
var node = ChatCore.node, myf = node.list.eq(0), str = '', i = 0;
myf.addClass('loading');
onlinenum = allUsers.length;
//if (onlinenum > 0) {
str += '<li class="ChatCore_parentnode ChatCore_liston">'
+ '<h5><i></i><span class="ChatCore_parentname" style="color:#381e0bcc;">全部客户</span><em class="ChatCore_nums">' + onlinenum + '</em></h5>'
+ '<ul id="ChatCore_friend_list" class="ChatCore_chatlist">';
for (; i < onlinenum; i++) {
//allfriends.add(allUsers[i].OpenId, allUsers[i]);
var cunickname = allUsers[i].NickName;
if (cunickname == null || cunickname == "") {
cunickname = "未知";
}
if (allUsers[i].Remarks != null && allUsers[i].Remarks != "" && allUsers[i].Remarks != cunickname) {
cunickname = allUsers[i].Remarks + "(" + cunickname + ")";
}
var huidu = "";
var Guanzu = "subscribe";
var title = "已关注";
var disPaly = "";
//alert(allUsers[i].ChatTime);
if (allUsers[i].subscribe != 1) {
huidu = " Imggray";
Guanzu = "unsubscribe";//取消了关注
title = "取消关注";
disPaly = ' Hidden ';
}
var aa = "display: block;height: 25px;padding: 0px;margin: 0px;";
var vv = "display:block;height:25px;width:55px;line-height:14px;padding:2px 0px 0px 0px;margin:0px;color:gray";
var wcontent = "";
if (allUsers[i].Hours >= 48)
wcontent = "会话过期";
else if (allUsers[i].Hours >= 24 && allUsers[i].Hours < 48) {
wcontent = "" + allUsers[i].Hours + "小时";
}
str += '<li title="' + title + '" ' + disPaly + ' id="userid-' + allUsers[i].OpenId + '" nickname="' + allUsers[i].NickName + '" ResId="' + allUsers[i].resid + '" Remarks="' + allUsers[i].Remarks + '" data-id="' + allUsers[i].ConnectionId + '" class="ChatCore_childnode ' + disPaly + '" type="one"><img src="' + allUsers[i].HeaderUrl + "?i=" //+ GetGuid()
+ '" class="ChatCore_oneface ' + huidu + '" guanzu="' + Guanzu + '"><span class="ChatCore_onename">' + cunickname + '</span><ul style="width:55px;"><li style="' + aa + '"><div nid="msgcount_' + allUsers[i].OpenId + '" class="MsgCount" style="display:none;"></div></li><li xtype="guoqi" style="' + vv + '">' + wcontent + '</li></ul></li>';
}
str += '</ul></li>';
myf.html(str);
//} else {
// myf.html('<li class="ChatCore_errormsg">没有任何数据</li>');
//}
ChatCore.InitFriendAndGroup();//初始化好友数据
openIdMsgCount = {};//存储未读消息
openIdMsg = {};//存储未读消息数据
ChatCore.GetUnReadMsg();
myf.removeClass('loading');
/*为选项卡绑定右键*/
};
//新用户上线
systemHub.client.onNewUserConnected = function (id, userID, userName, deptName, HeaderUrl, loginTime) {
//alert("id:"+id+",userid:"+userID);
onlinenum = onlinenum + 1;
//$(".ChatCore_nums").html("" + onlinenum + "");
var myf = $('#ChatCore_friend_list'), str = '';
var aa = "display: block;height: 25px;padding: 0px;margin: 0px;";
var vv = "display:block;height:25px;width:40px;line-height:14px;padding:2px 0px 0px 0px;margin:0px;color:gray";
var wcontent = "";
str += '<li title="已关注" id="userid-' + userID + '" nickname="' + userName + '" Remarks="" data-id="' + id + '" class="ChatCore_childnode" type="one"><img src="' + HeaderUrl + "?i=" + GetGuid() + '" class="ChatCore_oneface" guanzu="subscribe"><span class="ChatCore_onename">' + userName + '</span><ul style="width:50px;"><li style="' + aa + '"><div nid="msgcount_' + userID + '" class="MsgCount" style="display:none;"></div></li><li xtype="guoqi" style="' + vv + '">' + wcontent + '</li></ul></li>';
var oldLi = myf.find("[data-id='" + id + "']");
if (oldLi.length > 0) {
oldLi.removeClass("Hidden").removeAttr("hidden");
} else {
myf.append(str);
$("[data-id='" + id + "']").on('contextmenu', function (e) {
menuChooseId = $(this).attr("data-id");
$('#tab_menu').menu('show', {
left: e.pageX,
top: e.pageY
});
return false;
});
}
$("#ChatCore_friend_list").parent().find(".ChatCore_nums").html("" + $("#ChatCore_friend_list >li").length + "");
};
//用户离线
systemHub.client.onUserDisconnected = function (id, userName) {
//alert("用户离线?");
//onlinenum = onlinenum - 1;
////$(".ChatCore_nums").html("" + onlinenum + "");
//$(".ChatCore_nums").html("" + $("#ChatCore_friend_list >li").length + "");
//$("#ChatCore_friend_list li[data-id=" + id + "]").remove();
};
//发送消息时,对方已不在线
systemHub.client.absentSubscriber = function () {
alert("对方已不在线,请采用其它方式沟通!");
//$.gritter.add({
// title: "系统提醒",
// text: "对方已不在线,请采用其它方式沟通!",
// class_name: "gritter-info gritter-center"
//});
};
//接收消息
systemHub.client.receivePrivateMessage = function (fromUserId, message, msgType) {
window.focus();
if (msgType == "subscribe") {//公众号关注
$("#Chat_FriendList>li").not("[wxxgid]").find("[data-id='" + fromUserId + "']").remove("Hidden").removeAttr("hidden");//给除了系统分组显示出来
$("[data-id='" + fromUserId + "'] .ChatCore_oneface ").removeClass("Imggray").attr("guanzu", "subscribe").parent().attr("title", "已关注");
var xxx = $("#ChatCore_friend_list [data-id='" + fromUserId + "']").prop("outerHTML");//取消关注
$("#Chat_FriendList [groupname='新关注']>ul").prepend(xxx);//新关注里面新增一条记录
$("#Chat_FriendList [groupname='取消关注']>ul").find("[data-id='" + fromUserId + "']").remove();//取消关注里面的移除
$("#Chat_FriendList [wxxgid]").find("[data-id]").removeClass("Hidden").removeAttr("hidden");
} else if (msgType == "unsubscribe") {//取消了关注
$("#Chat_FriendList>li").not("[wxxgid]").find("[data-id='" + fromUserId + "']").addClass("Hidden");//给除了系统分组影藏
$("#ChatCore_friend_list [data-id='" + fromUserId + "']").prop("outerHTML");
$("[data-id='" + fromUserId + "'] .ChatCore_oneface ").addClass("Imggray").attr("guanzu", "unsubscribe").parent().attr("title", "取消关注");
var xxx = $("#ChatCore_friend_list [data-id='" + fromUserId + "']").prop("outerHTML");//取消关注
$("#Chat_FriendList [groupname='取消关注']>ul").prepend(xxx);//取消关注里面新增一条记录
$("#Chat_FriendList [groupname='新关注']>ul").find("[data-id='" + fromUserId + "']").remove();//将新关注里面的移除
$("#Chat_FriendList [wxxgid]").find("[data-id]").removeClass("Hidden").removeAttr("hidden");
}
$("[nid='msgcount_" + fromUserId + "']").parent().parent().find("[xtype='guoqi']").html("");
$("#ChatCore_friend_list").prepend($("#Chat_FriendList #ChatCore_friend_list [nid='msgcount_" + fromUserId + "']").parent().parent().parent());
var node = ChatCore.node, log = {}, othis = $("#ChatCore_friend_list li[data-id=" + fromUserId + "]");
//聊天模版
log.html = function (param, type) {
return '<li class="' + (type === 'me' ? 'ChatCore_chateme' : '') + '">'
+ '<div class="ChatCore_chatuser">'
+ function () {
if (type === 'me') {
return '<span class="ChatCore_chattime">' + param.time + '</span>'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<img src="' + param.face + '" >';
} else {
return '<img src="' + param.face + '" >'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<span class="ChatCore_chattime">' + param.time + '</span>';
}
}()
+ '</div>'
+ '<div class="ChatCore_chatsay">' + ChatCore.replaceFace(param.content) + '<em class="ChatCore_zero"></em></div>'
+ '</li>';
};
//ChatCore.popchatbox(othis);
var tabCount = $(".xubox_layer").length;
if (tabCount > 0 && ChatCore.nowchat != null && ChatCore.nowchat.id == fromUserId) {//已经是当前打开的聊天窗口,直接加入数据
//var keys = ChatCore.nowchat.type + ChatCore.nowchat.id;
var keys = "one" + fromUserId;
log.imarea = ChatCore.chatbox.find('#ChatCore_area' + keys);
var nmessage = message;
if (nmessage.indexOf("[imagepath]:") > -1) {
nmessage = "<img style='max-width:250px;' src='http://192.168.1.132/weappfile" + message.replace("[imagepath]:", "") + "' />"
} else if (nmessage.indexOf("[voice]:") > -1) {
var voicemedia = message.replace("[voice]:", "");
nmessage = '<span voice="' + voicemedia + '" onclick="ShowVoice(\'' + voicemedia + '\')" class="layui-icon" style="color:#f30c55;font-weight:bold;cursor:pointer;"></span>';
}
log.imarea.append(log.html({
time: new Date().toLocaleString(),
name: othis.find('.ChatCore_onename').text(),
face: othis.find('.ChatCore_oneface').attr('src'),
content: nmessage
}));
log.imarea.scrollTop(log.imarea[0].scrollHeight);//聊天界面滚动到最底下
ChatCore.UpdateIsAlreadyRead(fromUserId);//直接在所在界面的,直接修改状态
} else {//将离线消息存入 变量中,等点击后再读取
if (openIdMsgCount[fromUserId] == null)
openIdMsgCount[fromUserId] = 1;
else
openIdMsgCount[fromUserId]++;
if (openIdMsg[fromUserId] == null) {
openIdMsg[fromUserId] = new Array();
openIdMsg[fromUserId][0] = { msg: message, createtime: new Date().toLocaleString() };
} else {
var ncount = openIdMsg[fromUserId].length;
openIdMsg[fromUserId][ncount] = { msg: message, createtime: new Date().toLocaleString() };
}
$("[nid='msgcount_" + fromUserId + "']").attr("style", "").html("" + openIdMsgCount[fromUserId]);
ChatCore.NewsTwinkle();
}
};
//心跳回执信息
systemHub.client.getAlive = function (eid) {
aliveTime = new Date();
};
};
//请求列表数据
ChatCore.getDates = function (index) {
var api = [config.api.friend, config.api.group, config.api.chatlog],
node = ChatCore.node, myf = node.list.eq(index);
myf.addClass('loading');
config.json(api[index], {}, function (datas) {
if (datas.status === 1) {
var i = 0, myflen = datas.data.length, str = '', item;
if (myflen > 1) {
if (index !== 2) {
for (; i < myflen; i++) {
str += '<li data-id="' + datas.data[i].id + '" class="ChatCore_parentnode">'
+ '<h5><i></i><span class="ChatCore_parentname">' + datas.data[i].name + '</span><em class="ChatCore_nums">' + datas.data[i].nums + '</em></h5>'
+ '<ul class="ChatCore_chatlist">';
item = datas.data[i].item;
for (var j = 0; j < item.length; j++) {
str += '<li data-id="' + item[j].id + '" class="ChatCore_childnode" type="' + (index === 0 ? 'one' : 'group') + '"><img src="' + item[j].face + '" class="ChatCore_oneface" ><span class="ChatCore_onename">' + item[j].name + '</span></li>';
}
str += '</ul></li>';
}
} else {
str += '<li class="ChatCore_liston">'
+ '<ul class="ChatCore_chatlist">';
for (; i < myflen; i++) {
str += '<li data-id="' + datas.data[i].id + '" class="ChatCore_childnode" type="one"><img src="' + datas.data[i].face + '" class="ChatCore_oneface"><span class="ChatCore_onename">' + datas.data[i].name + '</span><em class="ChatCore_time">' + datas.data[i].time + '</em></li>';
}
str += '</ul></li>';
}
myf.html(str);
} else {
myf.html('<li class="ChatCore_errormsg">没有任何数据</li>');
}
myf.removeClass('loading');
} else {
myf.html('<li class="ChatCore_errormsg">' + datas.msg + '</li>');
}
}, function () {
myf.html('<li class="ChatCore_errormsg">请求失败</li>');
myf.removeClass('loading');
});
};
//渲染骨架
ChatCore.view = (function () {
var ChatCoreNode = ChatCore.ChatCoreNode = $('<div id="ChatCoremm" class="ChatCore_main">'
+ '<div class="ChatCore_top" id="ChatCore_top">'
+ ' <div class="ChatCore_search"><i></i><input id="ChatCore_searchkey" /><span id="ChatCore_closesearch">×</span></div>'
+ ' <div class="ChatCore_tabs" id="ChatCore_tabs"><span class="ChatCore_tabfriend" title="好友"><i></i></span><span class="ChatCore_tabgroup" title="群组" style="display:none;"><i></i></span><span class="ChatCore_latechat" title="最近聊天" style="display:none;"><i></i></span></div>'
+ ' <ul class="ChatCore_list" id="Chat_FriendList" style="display:block"></ul>'
+ ' <ul class="ChatCore_list"></ul>'
+ ' <ul class="ChatCore_list"></ul>'
+ ' <ul class="ChatCore_list ChatCore_searchmain ChatCore_chatlist" id="ChatCore_searchmain"></ul>'
+ '</div>'
+ '<ul class="ChatCore_bottom" id="ChatCore_bottom" style="width:290px;">'
+ '<li class="ChatCore_online" id="ChatCore_online">'
+ '<i class="ChatCore_nowstate"></i><span id="ChatCore_onlinetex">在线</span>'
+ '<div class="ChatCore_setonline">'
+ '<span><i></i>在线</span>'
+ '<span class="ChatCore_setoffline"><i></i>隐身</span>'
+ '</div>'
+ '</li>'
+ '<li class="ChatCore_mymsg" id="ChatCore_mymsg" title="批量消息"><i></i></a></li>'
+ '<li class="ChatCore_group" id="ChatCore_group" title="设置分组">'
+ '<i></i>'
+ '<div class="">'
+ '</div>'
+ '</li>'
+ '<li class="ChatCore_hide" id="ChatCore_hide"><i></i></li>'
+ '<li id="ChatCore_on" class="ChatCore_icon ChatCore_on"></li>'
+ '<div class="ChatCore_min" id="ChatCore_min"></div>'
+ '</ul>'
+ '</div>');
dom[3].append(ChatCoreNode);
ChatCore.renode();
ChatCore.event();
$.connection.hub.start().done(function () {
systemHub.server.connect(userid, username, deptname, accountnum);
//$("#nimalegechoubixx").click(function () {
// systemHub.server.connect(userid, username, deptname, accountnum);
//});
Alivetimer = setInterval(function () {//每十秒跳动一次
var nowDate = new Date();
var timespan = (nowDate.getTime() - aliveTime.getTime()) / 1000;//相差秒数
if (timespan > 60) {
$.connection.hub.start().done(function () {
systemHub.server.connect(userid, username, deptname, accountnum);
});
} else {
//console.log("alive");
systemHub.server.alive(userid, accountnum);
}
//aliveTime = new Date();
}, 10000);
});
//ChatCore.getDates(0);
ChatCore.FangsiInit();
var Qf = {};
Qf.send = function () {
var chooseUser = "";
$("#ChooseFriendUL li").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
chooseUser = chooseUser.substr(0, chooseUser.length - 1);
Qf.imwrite = $("#QFChatCore_write");
var data = {
content: Qf.imwrite.val(),
//id: ChatCore.nowchat.id,
sign_key: '', //密匙
_: +new Date
};
var imgmsg = $("#imgmsg").val();
var sucaicontent = $("#sucaiContent").val();
if (data.content.replace(/\s/g, '') === '' && (imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null")) {
layer.tips('说点啥呗!', '#QFChatCore_write', 2);
Qf.imwrite.focus();
} else {
//此处皆为模拟
//var keys = ChatCore.nowchat.type + ChatCore.nowchat.id;
//聊天模版
Qf.html = function (param, type) {
return '<li class="' + (type === 'me' ? 'ChatCore_chateme' : '') + '">'
+ '<div class="ChatCore_chatuser">'
+ function () {
if (type === 'me') {
return '<span class="ChatCore_chattime">' + param.time + '</span>'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<img src="' + param.face + '" >';
} else {
return '<img src="' + param.face + '" >'
+ '<span class="ChatCore_chatname">' + param.name + '</span>'
+ '<span class="ChatCore_chattime">' + param.time + '</span>';
}
}()
+ '</div>'
+ '<div class="ChatCore_chatsay">' + ChatCore.replaceFace(param.content) + '<em class="ChatCore_zero"></em></div>'
+ '</li>';
};
Qf.imarea = $('#QFChatCore_area');
var nmessage = data.content;
if ((imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null")) {
nmessage = data.content
}
else if (imgmsg != null && imgmsg != '') {
nmessage = "<img style='max-width:250px;' src='http://192.168.1.132/weappfile/" + imgmsg + "' />";
}
else if (sucaicontent != null && sucaicontent != '' && sucaicontent != "null") {
nmessage = sucaicontent;
}
Qf.imarea.append(Qf.html({
time: new Date().toLocaleString(),
name: config.user.name,
dept: config.user.dept,
face: config.user.face,
content: nmessage
}, 'me'));
Qf.imwrite.val('').focus();
Qf.imarea.scrollTop(Qf.imarea[0].scrollHeight);
if ((imgmsg == null || imgmsg == '') && (sucaicontent == null || sucaicontent == '' || sucaicontent == "null"))
systemHub.server.sendQFMessage(chooseUser, data.content, parseInt(userid), accountnum);
else {
$("#imgmsg").val("");
$("#sucaitype").val("");
$("#sucaiContent").val("");
}
}
};
$("#ChatCore_mymsg").click(function () {
//alert($("#Chat_FriendList").html());
var fff = "<ul id=\"wfqf\" class=\"ChatCore_list\" style='display:block;height:auto'>" + $("#Chat_FriendList").html() + "</ul>";
var sendQunFaHtml = '<div class="ChatCore_chatbox" id="ChatCore_chatbox22">'
+ '<div class="ChatCore_chatmore" id="ChooseFriend" style="display: block;width:240px;">'
+ ' <ul class="ChatCore_chatlist" id="ChooseFriendUL"></ul>'
+ '</div>'
+ '<div class="ChatCore_groups" id="ChatCore_groups"></div>'
+ '<div class="ChatCore_chat">'
+ ' <div class="ChatCore_chatarea" id="ChatCore_chatarea">'
+ ' <ul class="ChatCore_chatview ChatCore_chatthis" id=\"QFChatCore_area\" ></ul>'
+ ' </div>'
//+ ' <div class="ChatCore_tool" style="color:#666;">注Web聊天中请勿发送过长的文本.</div>'//增加内容
+ ' <div class="ChatCore_tool" style="">'
+ ' <i class="ChatCore_addface" id="QFChatCore_addface" title="发送表情"></i>'
+ ' <a href="javascript:;"><i class="ChatCore_upImg" id="QFChatCore_addimage" title="本地图片"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addimage" id="QFChatCore_addimage2" title="发送图片"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addvoice" id="QFChatCore_addvoice" title="发送语音"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addvedio" id="QFChatCore_addvedio" title="发送视频"></i></a>'
+ ' <a href="javascript:;"><i class="ChatCore_addfile" id="QFChatCore_addfile" title="发送图文"></i></a>'
+ ' </div>'
+ ' <textarea class="ChatCore_write" id="QFChatCore_write"></textarea>'
+ ' <div class="ChatCore_send">'
+ ' <div class="ChatCore_sendbtn" id="QFChatCore_sendbtn">发送<span class="ChatCore_enter" id="ChatCore_enter"><em class="ChatCore_zero"></em></span></div>'
+ ' <div class="ChatCore_sendtype" id="ChatCore_sendtype">'
+ ' <span><i>√</i>按Enter键发送</span>'
+ ' <span><i></i>按Ctrl+Enter键发送</span>'
+ ' </div>'
+ ' </div>'
+ '</div>'
+ '</div>';
//左边的选择界面
layer.open({
title: '批量发送管理',
type: 1,
offset: "l",
btn: ['选中', '清除', '关闭'], //只是为了演示
skin: 'layui-layer-rim',
area: ['330px', '600px'],
shade: 0,
content: fff,
closeBtn: 0,
yes: function (index, layero) {
$("#ChooseFriendUL").html("");
//$("#ChooseFriendUL").append($("#wfqf").html());
$("#wfqf .ChatCore_chatlist li :checked").each(function (x, n) {
var choosebox = $(this).parent();
var dataid = choosebox.attr("data-id");
if ($("#ChooseFriendUL [data-id='" + dataid + "']").attr("data-id") == null) {
$("#ChooseFriendUL").append($(this).parent().prop("outerHTML"));
}
});
$("#ChooseFriendUL").find("input").remove();//移除多余的em
$("#ChooseFriendUL .ChatCore_childnode").append("<em style=\"display: none;\">×</em>");
$("#ChooseFriendUL .ChatCore_childnode").on('mouseenter', function () {
$(this).find('em').show();
}).on('mouseleave', function () {
$(this).find('em').hide();
}).on('click', 'em', function (e) {
$(this).parent().remove();
});
},
btn2: function (index, layero) {
$("#ChooseFriendUL").html("");
return false;
},
btn3: function (index, layero) {
layer.closeAll();
}
});
$("#wfqf .ChatCore_childnode").find("em").remove();//移除多余的em
$("#wfqf>li").not("[wxxgid]").find(".Hidden").remove();
$("#wfqf .ChatCore_parentnode").on('click', 'h5', function () {
var othis = $(this), chat = othis.siblings('.ChatCore_chatlist'), parentss = othis.parent();
if (parentss.hasClass('ChatCore_liston')) {
chat.hide();
parentss.removeClass('ChatCore_liston');
} else {
chat.show();
parentss.addClass('ChatCore_liston');
}
});
$("#wfqf .ChatCore_childnode").prepend("<input type='checkbox' slt='false' style='margin: 12px;'>");
$("#wfqf .ChatCore_parentnode h5 i").after("<input type='checkbox' slt='false' style='width:26px;'>");
$("#wfqf .ChatCore_childnode").click(function () {//选择列表点击事件
var dataid = $(this).attr("data-id");
var wxx = $(this).find("[type='checkbox']");
//alert();
//wxx.prop("checked");
var ischeck = wxx.attr("slt");
if (ischeck == "false") {
wxx.prop("checked", true);
wxx.attr("slt", "true");
}
else {
wxx.removeAttr("checked");
wxx.attr("slt", "false");
}
//if ($("#ChooseFriendUL [data-id='" + dataid + "']").attr("data-id") == null) {
// $("#ChooseFriendUL").append($(this).prop("outerHTML"));
// $("#ChooseFriendUL [data-id='" + dataid + "']").append("<em style=\"display: none;\">×</em>").on('mouseenter', function () {
// $(this).find('em').show();
// }).on('mouseleave', function () {
// $(this).find('em').hide();
// }).on('click', 'em', function (e) {
// $(this).parent().remove();
// });
//}
});
$("#wfqf .ChatCore_parentnode h5 input").click(function (e) {
var fd = $(this);
var ischeck = fd.attr("slt");
if (ischeck == "false") {
fd.parent().parent().find(".ChatCore_chatlist input").prop("checked", true);
fd.attr("slt", "true");
}
else {
fd.parent().parent().find(".ChatCore_chatlist input").removeAttr("checked");
fd.attr("slt", "false");
}
e.stopPropagation();
});
//右边选择界面
layer.open({
title: '批量发送',
type: 1,
skin: 'layui-layer-rim',
area: ['700px', '500px'],
shade: 0,
closeBtn: 0,
content: sendQunFaHtml
});
$("#QFChatCore_addimage").click(function () {//本地图片发送
sendType = "batch";
var chooseUser = "";
$("#ChooseFriendUL .ChatCore_childnode").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择一个客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
$("#nbtouser").val(chooseUser);
$("#uploadFile").trigger("click");
});
$("#QFChatCore_addimage2").click(function () {//本地图片发送
sendType = "batch";
var chooseUser = "";
$("#ChooseFriendUL .ChatCore_childnode").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择一个客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
$("#nbtouser").val(chooseUser);
ChatCore.GetSuCai('image');
});
//发送语音
$("#QFChatCore_addvoice").on('click', function (e) {
sendType = "batch";
var chooseUser = "";
$("#ChooseFriendUL .ChatCore_childnode").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择一个客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
$("#nbtouser").val(chooseUser);
ChatCore.GetSuCai('voice');
});
//发送视频
$("#QFChatCore_addvedio").on('click', function (e) {
sendType = "batch";
var chooseUser = "";
$("#ChooseFriendUL .ChatCore_childnode").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择一个客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
$("#nbtouser").val(chooseUser);
ChatCore.GetSuCai('video');
});
$("#QFChatCore_addfile").on('click', function (e) {
sendType = "batch";
var chooseUser = "";
$("#ChooseFriendUL .ChatCore_childnode").each(function () {
chooseUser += $(this).attr("data-id") + ",";
});
if (chooseUser == "") {
layer.msg('请至少选择一个客户!', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
return;
}
$("#nbtouser").val(chooseUser);
ChatCore.GetSuCai('mpnews');
});
$("#QFChatCore_sendbtn").click(function () {
Qf.send();
});
//关闭某个聊天
$("#QFChatCore_write").keyup(function (e) {
if (e.keyCode === 13) {
Qf.send();
}
});
$("#QFChatCore_addface").click(function () {
ChatCore.showFace("batch");
});
});
$("#ChatCore_group").click(function () {
ChatCore.ManagerGroup();
});
}());
}(window);
/**
* Created by Leo on 2015/4/26.
*/