| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- var userAgent = navigator.userAgent.toLowerCase();
- var isIE = window.ActiveXObject && userAgent.indexOf('msie') != -1 && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
- function flashTitle() {
- clearInterval(tttt);
- flashtitle_step = 1;
- tttt = setInterval(function() {
- if (flashtitle_step == 1) {
- window.parent.document.title = '【新消息】' + pagetitle;
- flashtitle_step = 2
- } else {
- window.parent.document.title = '【 】' + pagetitle;
- flashtitle_step = 1
- }
- }, 50);
- }
- function toLink(url){
- window.open(url,'_blank');
- }
- function stopFlashTitle() {
- flashtitle_step = 0;
- clearInterval(tttt);
- if (flashtitle_step != 0) {
- flashtitle_step = 0;
- clearInterval(tttt);
- window.parent.document.title = pagetitle;
- }
- window.parent.document.title = pagetitle;
- }
- function getLocalTime() {
- var c = new Date();
- function addZeros(a, b) {
- var i;
- a = "" + a;
- if (a.length < b) {
- for (i = 0; i < (b - a.length); i++) a = "0" + a
- }
- return a
- }
- return addZeros(c.getHours(), 2) + ':' + addZeros(c.getMinutes(), 2) + ':' + addZeros(c.getSeconds(), 2)
- }
- /* 解析表情表 */
- function getFace(){
- var emojis=document.getElementsByClassName('i');
- for(var i in emojis){
- if(emojis[i].innerHTML==undefined) return;
- if(emojis[i].innerHTML.indexOf('[]')==-1){
- $(emojis[i]).parseEmotion();
- }
- }
- }
- /* 获取聊天记录 */
- function getchatForm(fromId){
- var chatHTML="";
- $.ajax({
- type: "POST",
- url : "/home/service/messageLog",
- data: {to_id:fromId,page:1},
- success: function(msg){
- var myData=msg;
- myData.data.map((item,index)=>{
- if(item.who_is!==1){
- chatHTML+= '<div class="msg l"><div class="sper-img"><img src="'+welive.vistorImg+'"></div><b></b><div class="b"><div class="i">' + item.content + '</div></div><i>' + item.create_time + '</i></div>';
- }else{
- chatHTML+= '<div class="msg r"><div class="mper-img"><img src="'+default_s_avatar+'"></div><b></b><div class="b"><div class="i">' + item.content + '</div></div><i>' +item.create_time + '</i></div>';
- }
- })
- $('.history').find(".overview").html(chatHTML);
- if(parseInt($('.history').find(".viewport").css('height'))<parseInt($('.history').find(".overview").css('height'))){
- $('.scb_scrollbar').css('visibility','visible');
- window.setTimeout(function(){
- $('.history').welivebar_update('bottom');
- },200)
- }else{
- $('.history').find(".overview").css('top','0px');
- $('.scb_scrollbar').css('visibility','hidden');
- }
- getFace();
- }
- });
-
- }
- function openWin(fromId) {
- /* 展示新的聊天窗口 */
- /* 获取当前的访客 from_id */
- /* 查询当前用户的聊天记录 */
- $('.history').find('.overview').css('visibility','visible');
- /* 消息条数清零并隐藏 */
- var guestList=$('.visit_content');
- $('.visit_content').removeClass('active');
- guestList.map((item,index)=>{
- if($(index).attr('id').split("g")[1]==fromId){
- /* 删除消息条数dom元素 */
- $($(index).find('.messCount')).css('display','none');
- $($(index).find('.messCount')).html(0);
- welive.vistorImg=$(index).find('img').attr('src');
- console.log($(index).attr('data-isonline'))
- if($(index).attr('data-isonline')!==undefined){
- $(index).attr('data-isonline')=='0'?$('#guest_status').html('离线'):$('#guest_status').html('在线');
- }
- $(index).attr('data-isonline')=='0'?$('#guest_status').html('离线'):$('#guest_status').html('在线');
- $(index).addClass('active');
- $('#from').html($(index).attr('data-address'));
- $('#guest_source').html($(index).attr('data-source'));
- }
- })
- getchatForm(fromId);
- /* 同时更新访客资料 */
- $('#guest_id').html(fromId);
- }
- function getURL(a, b) {
- if (a.substr(0, 5).toLowerCase() == 'href=') return a;
- if (!b) b = 60;
- var c = '<a href="' + (a.substr(0, 4).toLowerCase() == 'www.' ? 'http://' + a : a) + '" target="_blank" title="' + a + '">';
- if (a.length > b) {
- a = a.substr(0, 30) + ' ... ' + a.substr(a.length - 18)
- }
- c += a + '</a>';
- return c
- }
- function welive_link() {
- welive.ws = new WebSocket(node.address);
- welive.ws.onopen = function() {
- setTimeout(welive_verify, 100)
- };
- welive.ws.onclose = function() {
- welive_close()
- };
- /* websocket服务端接收到消息后做处理 */
- welive.ws.onmessage = function(a) {
- welive_parseOut(a.data)
- }
- }
- function TitleSound() {
- sounder.html(welive.sound1);
- /* if (welive.flashTitle && x) {
- flashTitle();
- if (welive.sound) sounder.html(welive.sound1);
- welive.flashTitle = 0
- } else if (welive.flashTitle) {
- if (welive.sound) sounder.html(welive.sound2);
- welive.flashTitle = 0
- } */
- }
- function welive_clear() {
- var a = s_history.children("div");
- var b = a.length;
- if (b >= 100) {
- a.slice(0, b - 50).remove();
- s_hwrap.welivebar_update('bottom')
- }
- }
- function admins_update(n) {
- var x = parseInt(s_admins.html());
- x = x + n;
- if (x < 0) x = 0;
- s_admins.html(x)
- }
- /* 绑定客服 */
- function bindAvtar(){
- $.ajax({
- type: "POST",
- url : "/home/service/bind",
- data: {client_id:welive.client_id},
- success: function(msg){
- /* 订阅成功 */
-
- }
- });
- }
- function replyForSs(){
- welive.ws.send(JSON.stringify({"method":"pong", "data": "{}"}))
- }
- /* 获取用户的订阅信息 */
- /* 改变访客状态-在线 */
- function changeStatusOn(index){
- var guestList=$('.visit_content');
- /* 获取当前聊天的访客id */
- for(var i=0;i<guestList.length;i++){
- if($(guestList[i]).attr('id').split("g")[1]===index){
- /* 跳转到该用户的聊天窗口 */
- /* 并改变访客的状态 */
- $(guestList[i]).attr('data-isonline','1');
- $(guestList[i]).removeClass('offline');
- }
- }
- }
- /* 显示消息条数 */
- function showMessCount(index){
- var guestList=$('.visit_content');
- var count;
- /* 获取当前聊天的访客id */
- for(var i=0;i<guestList.length;i++){
- if($(guestList[i]).attr('id').split("g")[1]===index){
- /* 跳转到该用户的聊天窗口 */
- $($(guestList[i]).find('.messCount')).css('display','block');
- count=$($(guestList[i]).find('.messCount')).html();
- count++
- $($(guestList[i]).find('.messCount')).html(count);
- }
- }
- }
- /* 改变访客状态-离线 */
- function changeStatusOff(index){
- var guestList=$('.visit_content');
- /* 获取当前聊天的访客id */
- for(var i=0;i<guestList.length;i++){
- if($(guestList[i]).attr('id').split("g")[1]===index){
- /* 跳转到该用户的聊天窗口 */
- /* 并改变访客的状态 */
- $(guestList[i]).attr('data-isonline','0');
- $(guestList[i]).addClass('offline');
- }
- }
- }
- /* 获取商品信息 */
- /* 接收消息 */
- function welive_parseOut(b) {
- var isOther=false;
- var isEqual=false;
- var c = 0,
- b = JSON.parse(b);
- welive.client_id=b.data.client_id;
- welive.loginTime=b.data.time;
- if(b.method=='bind'){
- bindAvtar();
- }
- switch(b.method){
- case "chat":
- /* 接收到来自客户端的消息后,展示消息 */
- $('.history').find('.overview').css('visibility',' hidden');
- changeStatusOn(b.data.from_id);
- TitleSound();
- flashTitle();
- if($('#showusername .active').length!==0){
- welive.index=$('#showusername .active').attr('id').split('g')[1];
- var guestList=$('.visit_content');
- /* 获取当前聊天的访客id */
- for(var i=0;i<guestList.length;i++){
- if($(guestList[i]).attr('id').split("g")[1]===welive.index){
- if(b.data.from_id==welive.index){
- isEqual=true;
- }
- /* 并改变访客的状态 */
- $(guestList[i]).addClass('active');
- $('.history').find('.overview').css('visibility',' visible');
-
- }
- else{
- /* 不是被选中的人发消息时 */
- isOther=true;
- }
- }
- }else{
- /*没有被选中时 显示消息条数 */
- showMessCount(b.data.from_id);
- }
- if(isOther){
- showMessCount(b.data.from_id);
- isOther=false;
- }
- if(isEqual){
- guest_output(b.data.content,5,1);
- getFace();
- isEqual=false;
- }
- break;
- case "ping":
- replyForSs();
- break;
- case "subscribe":
- /* 使该用户上线 */
- changeStatusOn(b.data.from_id);
- b.data.visitor.avatar!==""?welive.vistorImg=b.data.visitor.avatar:welive.vistorImg=default_v_avatar;
- var isequal=false;
- guest=$('.visit_content');
- welive.vistorLog_id=b.data.log_id;
- welive.vistorName=b.data.visitor.name;
- welive.vistorFram_id=b.data.from_id;
- welive.vistorAddress=b.data.visitor.address;
- welive.vistorSource=b.data.visitor.source;
- if(v_ids.indexOf(b.data.from_id)==-1){
- isequal=true;
- if(isequal){
- guest.push({
- log_id:b.data.log_id,
- name:b.data.visitor.name,
- form_id:b.data.from_id,
- source:b.data.visitor.source,
- address:b.data.visitor.address
- })
- v_ids.push(b.data.from_id)
- guest_create(welive.vistorImg);
- isequal=false;
- }
- }
- if(v_ids.length==0||guest.length==0){
-
- guest.push({
- log_id:b.data.log_id,
- name:b.data.visitor.name,
- form_id:b.data.from_id,
- source:b.data.visitor.source,
- address:b.data.visitor.address
- })
- v_ids.push(b.data.from_id)
- guest_create(welive.vistorImg);
- isequal=false;
- }else{
- if(guest.length>1&&isequal){
- for (var j=0;j<guest.length;j++) {
- if(guest[j].form_id!==b.data.from_id){
- isequal=true;
- if(isequal){
- guest.push({
- log_id:b.data.log_id,
- name:b.data.visitor.name,
- form_id:b.data.from_id,
- source:b.data.visitor.source,
- address:b.data.visitor.address
- })
- v_ids.push(b.data.from_id)
- guest_create(welive.vistorImg);
- isequal=false;
- }
- }
- }
- }
- }
- break;
- case "logout":
- /* 监测用户登出 */
- changeStatusOff(b.data.from_id)
- break;
- }
- }
- /* 创建聊天 */
- function guest_create(avatar) {
- g_online.prepend('<div class="visit_content" id="g'+welive.vistorFram_id+'" onclick="openWin(\''+welive.vistorFram_id+'\')" class="g" title="' + welive.vistorName + '" data-source="'+welive.vistorSource+'" data-address="'+welive.vistorAddress+'">'+
- '<img class="guest-headerImg" src="'+avatar+'" width="50px">'+
- '<span class="guest_name">'+welive.vistorName+'</span>'+
- '<button class="delBtn" title="删除" onclick="delGuest(\''+welive.vistorFram_id+'\')">✕</button>'+
- '<div id="messCount" class="messCount">0</div>'+
- '</div>');
- }
- /* 消息展示 */
- function guest_output(d, a, b) {
- if (!d || !a || !b) return;
- var o = $(".history");
- switch (b) {
- case 1:
- d = '<div class="msg l"><div class="sper-img"><img src="'+welive.vistorImg+'"></div><b></b><div class="b"><div class="i">' + d + '</div></div><i>' + getLocalTime() + '</i></div>';
- break;
- case 2:
- d = '<div class="msg r"><div class="mper-img"><img src="'+default_s_avatar+'"></div><b></b><div class="b"><div class="i" id="result">' + d + '</div></div><i>' + getLocalTime() + '</i></div>';
- break;
- case 3:
- d = '<div class="msg s"><div class="b"><div class="ico"></div><div class="i">' + d + '</div></div></div>';
- break;
- case 4:
- d = '<div class="msg e"><div class="b"><div class="ico"></div><div class="i">' + d + '</div></div></div>';
- break;
- case 5:
- d='<div class="product-form"><div class="proImg"><img src="../public/img/pro1.jpg"></div><div class="proDesc"><p class="proTit">终身学习:哈佛毕业的第六堂课<p><p class="proPri">35.00<p></div></div>';
- break;
- }
- o.find(".overview").append(d);
- window.setTimeout(function(){
- $('.history').welivebar_update('bottom');
- },200)
- }
- function welive_output(d, a, b) {
- if (a) {
- guest_output(d, a, b)
- } else {
- if (d === false) return;
- s_history.append(d);
- s_history.welivebar_update('bottom')
- }
- }
- function welive_verify() {
- welive.status = 1;
- welive_send(JSON.stringify({"method":"login","data":{"site_code":site.code,"type":"service"}}))
- $(".set_serving").hide();
- $(".set_busy").show()
- }
- function welive_close() {
- if (welive.status) {
- s_online.html("");
- s_admins.html(0)
- }
- welive.status = 0;
- $("#websocket1212").remove();
- welive_output('<div class="i"><b></b>连接失败, 3秒后自动重试 ...</div>');
- welive.ttt = setTimeout(welive_link, 3000)
- }
- /* 发送消息 */
- function welive_send(d) {
- s_send.addClass('loading2');
- if (welive.status) {
- welive.ws.send(d);
- s_msg.val('')
- } else {
- welive_output('<div class=i><b></b>服务器连接中, 请等待 ...</div>')
- }
- s_msg.focus();
- s_send.removeClass('loading2');
- localStorage.clear();
- }
- /* 发送消息 */
- function guest_send(e) {
- var o = $('#sendTxt')||$('.content');
- var ltly = o.val()||$('.publish').serializeArray()[0].value;//获取聊天数据
- console.log();
- if(ltly.length>0){
- if($('#guest_id').html()==''){
- /* 还未选择任何访客 提示 */
- layer.msg('还未选择访客!')
- }else{
- $.ajax({
- type: "POST",
- url : "/home/service/chat",
- data: {to_id:$('#guest_id').html(),type:1,content:ltly},
- success: function(msg){
- if(msg.status==200){
- guest_output(ltly,5,2);
- getFace();
- $('#sendTxt').val('');
- $('.content').val('');
- }else{
- layer.msg("发送失败!");
- }
- }
- });
- }
- }
- o.focus();
- return false;
- }
- function guest_kickout() {
- if ($.inArray(CurrentId, offline) < 0) welive.ws.send('x=6&a=6&g=' + CurrentId);
- guest_delete(CurrentId);
- CurrentId = 0;
- $("#tiptip_holder").hide();
- showNext()
- }
- /* 删除访客 */
- function delGuest(index){
- var guests=$('.visit_content');
- var delStatus=false;
- var curTab;
- for(var j=0;j<v_ids.length;j++){
- if(v_ids[j]==index){
- v_ids.splice(j, 1);
- }
- }
- guest=guests;
- for(var i=0;i<guests.length;i++){
- if($(guests[i]).attr('id').split("g")[1]==index){
- /* 删除guest列表中的元素 */
- curTab=$(guests[i]);
- $.ajax({
- type: "POST",
- url : "/home/service/delChatList",
- data: {to_id:index},
- success: function(msg){
- var myData=msg;
- if(myData.status==200){
- delStatus=true;
- if(delStatus){
- curTab.remove();
- guest.splice(i,1);
- delStatus=false;
- layer.msg('删除成功!');
- /* 并清空聊天记录 */
- $('.history .overview').css('visibility','hidden');
- }
- }else{
- layer.msg('删除失败,稍后重新操作!');
- }
- }
- });
- }
- }
- }
- function welive_runtime(a, b) {
- if (!a || !b) return;
- b = format_output(b) + ' <img src="' + SYSDIR + 'public/img/writting.gif">';
- var o = $(".history");
- var c = o.find(".overview>div.updating");
- if (c.length) {
- c.find(".i").html(b)
- } else {
- b = '<div class="msg updating"><b></b><div class="b"><div class="i">' + b + '</div></div></div>';
- o.find(".overview").append(b)
- }
- o.welivebar_update('bottom')
- }
- /* 聊天时初始化 */
- function welive_init() {
- guest = new Array();
- offline = new Array();
- g_online = $("#showusername"); /* 客户列表*/
- s_chat = $("#s_chat");
- s_msg = s_chat.find(".s_msg");
- s_send = s_chat.find(".s_send");
- s_admins = s_chat.find(".s_admins");
- s_title = s_chat.find(".s_title").children(".l");
- s_hwrap = $(".history");
- s_owrap = s_chat.find("#s_owrap");
- s_history = s_hwrap.find(".overview");
- s_online = s_owrap.find(".overview");
- sounder = $("#wl_sounder");
- welive_link();
- myWin88;
- var b = s_hwrap.find(".viewport"),
- s_onlineViewport = s_owrap.find(".viewport"),
- xHeight = $(window).height() - 88;
- g_online.height(xHeight);
- s_hwrap.welivebar();
- s_owrap.welivebar();
-
- /* $(window).resize(function() {
- s_hwrap.welivebar_update('bottom');
- }); */
- s_msg.keyup(function(e) {
- /* if (e.keyCode == 13) s_send.trigger("click"); */
- }).focus(function() {
- welive.where = 0;
- });
- /* 发送消息 */
- s_send.click(function(e) {
- var a = $.trim(s_msg.val());
- if (a) {
- welive_output('<div class=i><b></b>抱歉, WeLive4免费版功能受限!</div>')
- } else {
- s_msg.focus()
- }
- e.preventDefault()
- });
- /* tab切换 */
- $('.right-menunav').click(function(e){
- var dataFor=e.target.getAttribute('for');
- $('.right-menunav li').removeClass('active');
- $(e.target).addClass('active');
- $('.tab-content div').removeClass('show');
- $('.tab-content').find('div[id^="'+dataFor+'"]').addClass("show");
- })
- /* 快捷回复 */
- $('#reply-List').click(function(e){
- var obj=$(e.target).html();
- $.ajax({
- type: "POST",
- url : "/home/service/chat",
- data: {to_id:$('#guest_id').html(),type:1,content:obj},
- success: function(msg){
- if(msg.status==200){
- guest_output(obj,5,2);
- getFace();
- $('#sendTxt').val('');
- $('.content').val('');
- }else{
- layer.msg("发送失败!");
- }
- }
- });
- })
- $("#wl_ring").click(function(e) {
- if (welive.sound) {
- welive.sound = 0;
- $(this).addClass("s_ringoff").removeClass("s_ring")
- } else {
- welive.sound = 1;
- $(this).addClass("s_ring").removeClass("s_ringoff")
- }
- s_msg.focus();
- e.preventDefault()
- });
- pagetitle = window.parent.document.title;
- $(document,window.parent.document).mousedown(function(){
- stopFlashTitle();
- })
- $(document,window.parent.document).keydown(function() {
- stopFlashTitle();
- });
- /* welive.sound1 = '<audio src="'+path+'/admin/sound1.swf" autoplay>该浏览器不支持audio属性</audio>';
- welive.sound2 = '<audio src="../sound2.swf" autoplay>该浏览器不支持audio属性</audio>'; */
- window.onbeforeunload = function(a) {
- welive.status = 0;
- clearTimeout(welive.ttt);
- return " "
- };
- $(window).unload(function() {
- welive.status = 0;
- clearTimeout(welive.ttt)
- })
- }
- var tttt = 0,
- pagetitle, flashtitle_step = 0,
- sounder, towhere = 0;
- var guest, offline, g_online, s_chat, s_msg, s_history, s_online, s_send, s_hwrap, s_owrap, s_admins, s_title;
- var welive = {
- ws: {},
- index: '',
- status: 0,
- ttt: 0,
- flashTitle: 0,
- sound: 1,
- sound1: '',
- sound2: '',
- where: 0,
- client_id:'',
- loginTime:'',
- vistorFram_id:'',
- vistorLog_id:'',
- vistorName:'',
- vistorImg:'',
- vistorAddress:'',
- vistorSource:'',
- avatar:default_v_avatar, /* 客服头像*/
- messageCount:0,
- messContent:'',
- recordPermission:false,
- product:{}
-
- };
- var admin ={
- id: '',
- type: '',
- sid: '',
- fullname: '',
- post: '',
- agent: ''};
- var myWin88, CurrentId = 0,//<a class="t_picture" type="file" title="发送图片">
- zIndex = 2000;
- $(function() {
- var isFile=false;
- var File=null;
- var recorder=null;
- var audio_context='';
- welive_init();
- $(".logout").click(function(e) {
- showDialog('确定退出 WeLive 在线客服系统吗?', '', function() {
- document.location = 'index.php?a=logout'
- });
- e.preventDefault()
- })
- /* 初始化商品 */
-
- /* 加载录音模块 */
- try {
- // webkit shim
- window.AudioContext = window.AudioContext || window.webkitAudioContext;
- navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
- window.URL = window.URL || window.webkitURL;
-
- welive.audio_context = new AudioContext;
- console.log('Audio context set up.');
- console.log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!'));
- } catch (e) {
- console.log('No web audio support in this browser!');
- }
-
- navigator.getUserMedia({audio: true}, startUserMedia, function(e) {
- console.log('No live audio input: ' + e);
- });
- });
- $(function(){
- $("input").bind("input propertychange", function() {
- var ltly = $("#ltly").val();
- });
- });
- /* 发送图片 */
- $('#chooseImg').click(function(){
- $('#inp-file').click();
- })
- $('#inp-file').change(function(){
- imgUp();
- });
- /* 发送视频 */
- $('#chooseVideo').click(function(){
- $('#inp-video').click();
- })
- $('#inp-video').change(function(){
- utils.fileChange(this,"video","视频",/video\/\w+/);
- })
- /* 选择录音文件 */
- $('#inp-record').change(function(){
- utils.fileChange(this,"audio","音频",/audio\/\w+/);
- })
- /* 发送其他文件 */
- $('#chooseFile').click(function(){
- $('#inp-ohter').click();
- })
- $('#inp-ohter').change(function(){
- utils.fileChange(this,"file","","");
- })
- function imgUp(){
- var formData = new FormData();
- formData.append('image', $('#inp-file')[0].files[0]); //添加图片信息的参数
- formData.append('type','image'); //添加其他参数
- //获取文件
- var file = $('#inp-file')[0].files[0];
- var imageType = /^image\//;
- var imgHTML="";
- //是否是图片
- if(!imageType.test(file.type)) {
- alert("请选择图片!");
- return;
- }else{
- $.ajax({
- url: '/home/upload/upFile',
- type: 'POST',
- cache: false, //上传文件不需要缓存
- data: formData,
- processData: false, // 告诉jQuery不要去处理发送的数据
- contentType: false, // 告诉jQuery不要去设置Content-Type请求头
- success: function (data) {
- if(data.status==200){
- imgHTML+="<img src='"+data.data.path+"' class='trans_img' >";
- $.ajax({
- type: "POST",
- url : "/home/service/chat",
- data: {to_id:$('#guest_id').html(),type:1,content:imgHTML},
- success: function(msg){
- if(msg.status==200){
- welive_output(imgHTML,5,2);
- getFace();
- $('#sendTxt').val('');
- $('.content').val('');
- }else{
- layer.msg('上传失败');
- }
- }
- });
- }
-
- },
- error: function (data) {
- alert("上传失败");
- }
- })
- }
- }
- /* 创建文件,并且写入数据内容 */
- function CreateFile(fileObj)
- {
- var fso, tf;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- tf = fso.CreateTextFile("../imgFile/testfile.json", true);
- // 写一行,并且带有新行字符。
- tf.WriteLine(fileObj) ;
- tf.Close();
- }
- /* 录音模块 */
- function startUserMedia(stream) {
- if(stream!==undefined){
- welive.recordPermission=true;
- }
- var input = audio_context.createMediaStreamSource(stream);
- console.log('Media stream created.');
-
- // Uncomment if you want the audio to feedback directly
- //input.connect(audio_context.destination);
- //__log('Input connected to audio context destination.');
-
- recorder = new Recorder(input);
- console.log('Recorder initialised.');
- }
- function startRecording(button) {
- if(welive.recordPermission==false){
- /* 自动触发选择录音文件 */
- /* 当录音功能被禁止时 */
- layer.alert("网页录音功能已被禁止,请选择音频文件!",function(){
- $('#inp-record').click();
- });
- }
- else{
- welive.recorder && welive.recorder.record();
- layer.open({
- type: 1,
- content: '正在录音……,点击完成,发送录音,取消取消发送',
- btn: ['完成', '取消'],
- yes:function(){
- stopRecording();
- },
- btn1:function(){
- console.log('取消发送')
- }
- });
- console.log('Recording...');
- }
- }
- function stopRecording(button) {
- recorder && recorder.stop();
- //button.disabled = true;
- //button.previousElementSibling.disabled = false;
- console.log('Stopped recording.');
-
- // create WAV download link using audio data blob
- createDownloadLink();
-
- recorder.clear();
- }
-
- function createDownloadLink() {
- recorder && recorder.exportWAV(function(blob) {
- var url = URL.createObjectURL(blob);
- var li = document.createElement('li');
- var au = document.createElement('audio');
- var hf = document.createElement('a');
-
- au.controls = true;
- au.src = url;
- hf.href = url;
- hf.download = new Date().toISOString() + '.wav';
- hf.innerHTML = hf.download;
- li.appendChild(au);
- li.appendChild(hf);
- document.getElementById('recordingslist').appendChild(li);
- });
- }
|