filesbox/web/dist/design/designstatic/newJS/chatroom/wap/chatroom.js

3 lines
37 KiB
JavaScript
Raw Normal View History

2024-07-26 06:10:54 +00:00
layui.define(["layer","laytpl","upload"],function(X){var Z="2.0.0",n=layui.jquery,v=layui.layer,y=layui.laytpl,U=0,w=null,$a="layim-show",M="layim-this",Y=50,S=1e3,c={},h={},p={},f=function(){this.v=Z,n(document).on("click","*[chatroom-event]",function(a){var e=n(this),i=e.attr("chatroom-event");g[i]&&g[i].call(this,e,a)}),n(window).ready(function(){n("body").on("change",".group_chat_img",function(){La(this)}),n("#group-msg-input").on("blur",function(){setTimeout(function(){var a=document.documentElement.scrollTop||document.body.scrollTop||0;window.scrollTo(0,Math.max(a-1,0))},300)})}),n(window).resize(function(){setTimeout(function(){var a=document.documentElement.scrollTop||document.body.scrollTop||0;window.scrollTo(0,Math.max(a-1,0))},300)})};window.coverError=function(){var a=event.target;if(parseInt(a.dataset.errorcount)==0){var e=a.dataset.source;a.setAttribute("data-errorcount",1),a.src=e}},layui.data.substr=function(a,e){return a==""||a==null||typeof a!="string"?"":a.length<e?a:a.substring(0,e)+"..."},layui.data.avatar=function(a,e,i){if(a.indexOf("http://")>-1||a.indexOf("https://")>-1)return a;var t="";return e==1?t=a.replace(/([^.]*).([^.]*)$/g,"$1!large.$2"):e==2?t=a.replace(/([^.]*).([^.]*)$/g,"$1!medium.$2"):e==3?i?t=a.replace(/([^.]*).([^.]*)$/g,"$1!small.$2"):t=a.replace(/([^.]*).([^.]*)$/g,"$1!80_80.$2"):t=a,(window.cdnPath||"")+""+t},layui.data.escape=function(a){var e=document.createElement("div"),i=document.createTextNode(a);return e.appendChild(i),e.innerHTML},layui.data.img2str=function(a){var e=a.replace(/img\[([^\s]+?)\]/g,function(i){return"[\u56FE\u7247]"});return e},layui.data.content=function(a,e){var i="",t="audio[";if(a.indexOf(t)>-1){var r=a.split(",");a=r[0],i=r[1]||0}var s=function(l){return new RegExp("\\n*\\["+(l||"")+"(pre|div|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h2|h3|h4|h5)([\\s\\S]*?)\\]\\n*","g")};return a=(a||"").replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;").replace(/@(\S+)(\s+?|$)/g,'@<a href="javascript:;">$1</a>$2').replace(/\s{2}/g,"&nbsp").replace(/img\[([^\s]+?)\]/g,function(l){var o=(window.cdnPath||"")+""+l.replace(/(^img\[)|(\]$)/g,""),d=o.replace("!medium",""),m=d.replace(/([^.]*).([^.]*)$/g,"$1!small.$2");return'<img class="layui-layim-photos" chatroom-event="showimg" src="'+m+'" data-errorcount="0" onerror="coverError()" data-source="'+o+'" />'}).replace(/audio\[([^\s]+?)\]/g,function(l){var o=(window.cdnPath||"")+""+l.replace(/(^audio\[)|(\]$)/g,"");return'<div class="group_msg_audio js_msg_audio">'+i+'<audio ><source onended="audioPlayEnd(this)" src="'+o+'" type="audio/mpeg"></audio></div>'}).replace(/file\([\s\S]+?\)\[[\s\S]*?\]/g,function(l){var o=(l.match(/file\(([\s\S]+?)\)\[/)||[])[1],d=(l.match(/\)\[([\s\S]*?)\]/)||[])[1];return o?'<a class="layui-layim-file" href="'+o+'" target="_blank"><i class="layui-icon">&#xe61e;</i><cite>'+(d||o)+"</cite></a>":l}).replace(/face\[([^\s\[\]]+?)\]/g,function(l){var o=l.replace(/^face/g,"");return'<img style="max-width:24px;" alt="'+o+'" title="'+o+'" src="'+O[o]+'">'}).replace(/a\([\s\S]+?\)\[[\s\S]*?\]/g,function(l){var o=(l.match(/a\(([\s\S]+?)\)\[/)||[])[1],d=(l.match(/\)\[([\s\S]*?)\]/)||[])[1];return o?'<a href="'+o+'" target="_blank">'+(d||o)+"</a>":l}).replace(s(),"<$1 $2>").replace(s("/"),"</$1>").replace(/\n/g,"<br>"),a},layui.data.date=function(a){var e=new Date(a||new Date);return e.getFullYear()+"-"+b(e.getMonth()+1)+"-"+b(e.getDate())+" "+b(e.getHours())+":"+b(e.getMinutes())+":"+b(e.getSeconds())},layui.data.datetotime=function(a){var e=new Date(a||new Date);return b(e.getHours())+":"+b(e.getMinutes())+":"+b(e.getSeconds())},layui.data.humanitytime=function(a){var e=1e3*60,i=e*60,t=i*24,r=t*15,s=t*30,l=new Date().getTime(),o=l-a;o<0;var d=o/s,m=o/(7*t),u=o/t,k=o/i,_=o/e;return d>=1?result=parseInt(d)+"\u4E2A\u6708\u524D":m>=1?result=parseInt(m)+"\u4E2A\u661F\u671F\u524D":u>=1?result=parseInt(u)+"\u5929\u524D":k>=1?result=parseInt(k)+"\u4E2A\u5C0F\u65F6\u524D":_>=1?result=parseInt(_)+"\u5206\u949F\u524D":result="\u52
`);if(i.shiftKey)return;i.preventDefault(),H()}})},O=function(){var a=["[\u7231\u4F60]","[\u767D\u773C]","[\u9F3B\u6D95]","[\u95ED\u5634]","[\u5472\u7259]","[\u5927\u7B11]","[\u5F97\u610F]","[\u6076\u5FC3]","[\u53D1\u70E7]","[\u5C34\u5C2C]","[\u9B3C\u8138]","[\u597D\u5403]","[\u778C\u7761]","[\u53E3\u6C34]","[\u53E3\u7F69]","[\u5BBD\u6170]","[\u51B7]","[\u96BE\u8FC7]","[\u4FCF\u76AE]","[\u4EB2\u4EB2]","[\u70ED]","[\u53D7\u4F24]","[\u7761\u7740\u4E86]","[\u8BF4\u8C0E]","[\u601D\u8003]","[\u5410\u4E86]","[\u5410\u820C]","[\u54C7\u585E]","[\u5FAE\u7B11]","[\u559C\u6B22]","[\u7B11\u54ED]","[\u865A\u5F31]","[\u5618]","[\u6655\u7729]","[100\u5206]","[\u7231\u5FC3]","[\u62DC\u6258]","[\u5927\u54ED]","[\u62C5\u5FE7]","[\u9F13\u638C]","[\u54C8\u6B20]","[\u52A0\u6CB9]","[\u60CA\u6050]","[\u60CA\u8BB6]","[\u6CAE\u4E27]","[\u805A\u4F1A]","[\u6073\u6C42]","[\u54ED\u6CE3]","[\u8138\u7EA2]","[\u73AB\u7470]","[\u8FF7\u60D1]","[\u58A8\u955C]","[\u725B\u4ED4]","[\u75B2\u60EB]","[\u5F3A\u58EE]","[\u751F\u6C14]","[\u80DC\u5229]","[\u5C0F\u4E11]","[\u5FC3\u788E]","[\u773C\u955C]","[\u8D5E]","[\u5492\u9A82]","[OK]"],e={};return layui.each(a,function(i,t){e[t]=layui.cache.dir+"images/emoji/"+i+".png"}),e}(),C=layui.stope,J=function(a,e){var i,t=a.value;a.focus(),document.selection?(i=document.selection.createRange(),document.selection.empty(),i.text=e):(i=[t.substring(0,a.selectionStart),e,t.substr(a.selectionEnd)],a.focus(),a.value=i.join(""))},R=function(a){var e=new RegExp("(^|&)"+a+"=([^&]*)(&|$)"),i=window.location.search.substr(1).match(e);return i!=null?unescape(i[2]):null},La=function(a){var e=n(a).val(),i=n(a).attr("isfriend"),t=e.substr(e.lastIndexOf(".")).toLowerCase(),r=n(a)[0].files[0],s=Math.round(r.size/1024*100)/100;if(t!=".jpg"&&t!=".png"){v.msg("\u4E0D\u652F\u6301\u8BE5\u6587\u4EF6\u683C\u5F0F",{icon:2});return}else if(s>2048)if(s>20480){v.msg("\u56FE\u7247\u4E0D\u5F97\u8FC7\u5927",{icon:2});return}else new Compressor(r,{quality:.4,success(l){K(2,l,i,r)}});else K(1,r,i)},K=function(a,e,i,t){var r=R("key")==null?n.cookie("token"):R("key"),s=new FormData;s.append("busType","chat_image"),a==1?s.append("file",e):s.append("file",e,t.name),n.ajax({url:"/api/common/upload",type:"POST",cache:!1,processData:!1,contentType:!1,headers:{token:r},data:s,dataType:"json",success:function(l){var o=l.success;if(o){n(".group_chat_img").val("");var d=l.data.sourcePath;if(i=="0"){var m=R("cwid"),u="img["+(d||"")+"]",k={type:"groupMsg",from:c,to:m,content:u,timestamp:new Date().getTime()};N(u,function(){layui.each(h.sendGroupMessage,function(_,W){W&&W(k)})})}else N(u,function(){var _=T();J(_.textarea[0],u)})}else n(".group_chat_img").val(""),v.msg(l.message,{icon:2})}})},N=function(a,e){a.replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;").replace(/@(\S+)(\s+?|$)/g,'@<a href="javascript:;">$1</a>$2').replace(/\s{2}/g,"&nbsp").replace(/img\[([^\s]+?)\]/g,function(i){var t=(window.cdnPath||"")+""+i.replace(/(^img\[)|(\]$)/g,""),r=t.replace("!medium",""),s=r.replace(/([^.]*).([^.]*)$/g,"$1!small.$2"),l="";l+='<img class="preloadingImg" src="'+s+'" data-errorcount="0" onerror="coverError()" data-source="'+t+'" style="width:0px;height:0;" />',n("body").append(l),setTimeout(function(){e(),n("body").find(".preloadingImg").remove()},2e3)})},B="layui-anim-up",g={sendGroup:function(){E()},send:function(){H()},chat:function(a){return;var e,i;if(i=="1")var t;else if(i=="2")var t=a.parents(".privatecha_list_once");else var t=a;var r},setSend:function(a,e){var i=a.siblings(".layim-menu-box"),t=function(){i.hide().removeClass(B)},r=a.attr("lay-type");if(r==="show")C(e),i.show().addClass(B),n(document).off("click",t).on("click",t);else{a.addClass(M).siblings().removeClass(M);var s=layui.data("layim")[c.uid]||{};s.sendHotKey=r,layui.data("layim",{key:c.uid,value:s})}},face:function(a,e){var i="",t=T(),r=function(){v.close(g.face.index)};for(var s in O)i+='<li title="'+s+'"><img src="'+O[s]+'"></li>';i='<ul class="layui-clear layim-face-list">'+i+"</ul>",g.face.index=v.tips(i,a,{tips:1,ti