/* @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: "/:", 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: "/:", 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 = ""; var xxhtml = '
'; $(da.data).each(function (xx, wmm) { var mnmnn = wmm.replace('.json', '').replace(/^(\d{4})(\d{2})$/, "$1年$2月"); //alert(mnmnn); xxhtml += ('
' + "
    " + '
    ') }); xxhtml += '
    '; 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 = "" } else if (MsgType == "voice") { //ncontent = ''; //ncontent = ''; ncontent = ''; } else { ncontent = ChatCore.replaceFace(Content); } html = '
  • ' + '
    ' + ( (type === 'me') ? ('' + newDate.toLocaleString() + '' + '' + config.user.name + "(" + EID + ")" + '' + '') : ('' + '' + param.name + '' + '' + newDate.toLocaleString() + '') ) + '
    ' + '
    ' + ncontent + '
    ' + '
  • '; 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 = ""; 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, ""); } }); 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 = ""; if (type == "mpnews") { var xxx = JSON.parse(ret.dataResult); //console.log(xxx); $(xxx.item).each(function (wz, wa) { nhtml += ""; nhtml += ""; nhtml += ""; nhtml += ""; }); //alert(xxx.item_count); } else { $(ret.item).each(function (i, el) { nhtml += ""; nhtml += ""; nhtml += ""; if (type == "image") nhtml += ""; nhtml += ""; }); } nhtml += "
    查看
    "; nhtml += "
    "; 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 += ""; nhtml2 += ""; nhtml2 += ""; if (type == "image") nhtml2 += "查看"; nhtml2 += ""; }); $(".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 '
  • ' + '
    ' + function () { if (type === 'me') { return '' + param.time + '' + '' + param.name + '' + ''; } else { return '' + '' + param.name + '' + '' + param.time + ''; } }() + '
    ' + '
    ' + ChatCore.replaceFace(param.content) + '
    ' + '
  • '; }; 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 = "" } else if (nmessage.indexOf("[voice]:") > -1) { //ncontent = ''; //ncontent = ''; var MediaId = nmessage.replace("[voice]:", ""); ncontent = ''; } 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) { 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 = ''; rowHtml += ' '; rowHtml += ' '; rowHtml += ""; return rowHtml; } var html = ""; $(ret.data).each(function (x, n) { html += getRowHtml(n.PKID, n.GROUPNAME); }); html += "
    "; layer.open({ title: '管理分组', type: 1, skin: 'layui-layer-rim', area: ['450px', '400px'], btn: ["新增一条"], content: '
    ' + html + '
    ', 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 = '
  • ' + nn.GroupName + '(' + nn.UserGroupList.length + ')
      '; $(nn.UserGroupList).each(function (ss, mm) { xhtml += $("#ChatCore_friend_list [data-id='" + mm.OpenId + "']").prop("outerHTML"); }); xhtml += "
  • "; $("#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('
  • ' + param.name + '×
  • ') 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 = '
    ' + '
    ' + '' + ' ' + ' ' + param.name + '' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
    ' + '
    ' + '
      ' + '
      ' + '
      ' + '
      ' + '
      ' + '
        ' + '
        ' //+ '
        注:Web聊天中请勿发送过长的文本.
        '//增加内容 + '
        ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' 聊天记录' + '
        ' + ' ' + '
        ' + '
        发送
        ' + '
        ' + ' 按Enter键发送' + ' 按Ctrl+Enter键发送' + '
        ' + '
        ' + '
        ' + '
        '; //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('
      • ' + param.name + '×
      • '); log.chatarea.find('.ChatCore_chatview').removeClass('ChatCore_chatthis'); log.chatarea.append('');// 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(''); 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("" + param.resid + ""); } 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 += '
      • ' + datas.data[ii].name + '
      • '; } } else { str = '
      • 没有群员
      • '; } } else { str = '
      • ' + datas.msg + '
      • '; } groupss.removeClass('loading'); groupss.html(str); }, function () { groupss.removeClass('loading'); groupss.html('
      • 请求异常
      • '); }); }; //消息传输 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 '
      • ' + '
        ' + function () { if (type === 'me') { return '' + param.time + '' + '' + param.name + '' + ''; } else { return '' + '' + param.name + '' + '' + param.time + ''; } }() + '
        ' + '
        ' + ChatCore.replaceFace(param.content) + '
        ' + '
      • '; }; 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 = ""; } 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('
      • 没有符合条件的结果
      • '); 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('
      • 没有符合条件的结果
      • '); 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 += '
      • ' + '
        全部客户(' + onlinenum + ')
        ' + '
          '; 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 += '
        • ' + cunickname + '
          • ' + wcontent + '
        • '; } str += '
      • '; myf.html(str); //} else { // myf.html('
      • 没有任何数据
      • '); //} 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 += '
      • ' + userName + '
        • ' + wcontent + '
      • '; 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='" + menuChooseId + "']").prop("outerHTML");//取消关注 $("#Chat_FriendList [groupname='新关注']>ul").prepend(xxx);//新关注里面新增一条记录 $("#Chat_FriendList [groupname='取消关注']>ul").find("[data-id='" + fromUserId + "']").remove();//取消关注里面的移除 } 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='" + menuChooseId + "']").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 '
      • ' + '
        ' + function () { if (type === 'me') { return '' + param.time + '' + '' + param.name + '' + ''; } else { return '' + '' + param.name + '' + '' + param.time + ''; } }() + '
        ' + '
        ' + ChatCore.replaceFace(param.content) + '
        ' + '
      • '; }; //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 = "" } else if (nmessage.indexOf("[voice]:") > -1) { var voicemedia = message.replace("[voice]:", ""); nmessage = ''; } 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 += '
      • ' + '
        ' + datas.data[i].name + '(' + datas.data[i].nums + ')
        ' + '
          '; item = datas.data[i].item; for (var j = 0; j < item.length; j++) { str += '
        • ' + item[j].name + '
        • '; } str += '
      • '; } } else { str += '
      • ' + '
          '; for (; i < myflen; i++) { str += '
        • ' + datas.data[i].name + '' + datas.data[i].time + '
        • '; } str += '
      • '; } myf.html(str); } else { myf.html('
      • 没有任何数据
      • '); } myf.removeClass('loading'); } else { myf.html('
      • ' + datas.msg + '
      • '); } }, function () { myf.html('
      • 请求失败
      • '); myf.removeClass('loading'); }); }; //渲染骨架 ChatCore.view = (function () { var ChatCoreNode = ChatCore.ChatCoreNode = $('
        ' + '
        ' + ' ' + '
        ' + '
          ' + '
            ' + '
              ' + '
                ' + '
                ' + '
                  ' + '
                • ' + '在线' + '
                  ' + '在线' + '隐身' + '
                  ' + '
                • ' + '
                • ' + '
                • ' + '' + '
                  ' + '
                  ' + '
                • ' + '
                • ' + '
                • ' + '
                  ' + '
                ' + '
                '); 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 '
              • ' + '
                ' + function () { if (type === 'me') { return '' + param.time + '' + '' + param.name + '' + ''; } else { return '' + '' + param.name + '' + '' + param.time + ''; } }() + '
                ' + '
                ' + ChatCore.replaceFace(param.content) + '
                ' + '
              • '; }; 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 = ""; } 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 = ""; var sendQunFaHtml = '
                ' + '
                ' + '
                  ' + '
                  ' + '
                  ' + '
                  ' + '
                  ' + '
                    ' + '
                    ' //+ '
                    注:Web聊天中请勿发送过长的文本.
                    '//增加内容 + '
                    ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
                    ' + ' ' + '
                    ' + '
                    发送
                    ' + '
                    ' + ' 按Enter键发送' + ' 按Ctrl+Enter键发送' + '
                    ' + '
                    ' + '
                    ' + '
                    '; //左边的选择界面 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("×"); $("#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(""); $("#wfqf .ChatCore_parentnode h5 i").after(""); $("#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("×").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. */