java-mall-app/unpackage/dist/build/mp-weixin/im/chat/chat.js
2024-11-01 16:35:40 +08:00

1 line
19 KiB
JavaScript

require('../common/vendor.js');(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["im/chat/chat"],{3278:function(t,e,i){"use strict";i.r(e);var s=i("80f4"),o=i("bcaa");for(var n in o)["default"].indexOf(n)<0&&function(t){i.d(e,t,(function(){return o[t]}))}(n);i("ee77");var r=i("828b"),a=Object(r["a"])(o["default"],s["b"],s["c"],!1,null,null,null,!1,s["a"],void 0);e["default"]=a.exports},"80f4":function(t,e,i){"use strict";i.d(e,"b",(function(){return o})),i.d(e,"c",(function(){return n})),i.d(e,"a",(function(){return s}));var s={uParse:function(){return Promise.all([i.e("common/vendor"),i.e("components/u-parse/u-parse")]).then(i.bind(null,"986d"))}},o=function(){var t=this,e=t.$createElement,i=(t._self._c,t.__map(t.msgList,(function(e,i){var s=t.__get_orig(e),o="user"!=e.type||e.msg.userinfo.uid!=t.myuid||"voice"!=e.msg.type||e.message_length?null:e.msg.content.length,n="user"==e.type&&e.msg.userinfo.uid==t.myuid&&"item"==e.msg.type?t.__("¥"):null,r="user"==e.type&&e.msg.userinfo.uid==t.myuid&&"item"==e.msg.type?t.number_format(e.msg.content.item_unit_price,2):null,a=("user"==e.type&&(e.msg.userinfo.uid,t.myuid),null),c="user"!=e.type||e.msg.userinfo.uid==t.myuid||"voice"!=e.msg.type||e.message_length?null:e.msg.content.length;return{$orig:s,g0:o,m0:n,m1:r,m2:a,g1:c}}))),s=t.__("发送"),o=t.isPlay?t.__("退出"):null;t._isMounted||(t.e0=function(e){t.isPlay=!1},t.e1=function(e){t.isPlay=!1},t.e2=function(e){t.isPlay=!1}),t.$mp.data=Object.assign({},{$root:{l0:i,m3:s,m4:o}})},n=[]},8954:function(t,e,i){"use strict";(function(t,e){var s=i("47a9");i("90c2");s(i("3240"));var o=s(i("3278"));t.__webpack_require_UNI_MP_PLUGIN__=i,e(o.default)}).call(this,i("3223")["default"],i("df3c")["createPage"])},bcaa:function(t,e,i){"use strict";i.r(e);var s=i("f2b8"),o=i.n(s);for(var n in s)["default"].indexOf(n)<0&&function(t){i.d(e,t,(function(){return s[t]}))}(n);e["default"]=o.a},e792:function(t,e,i){},ee77:function(t,e,i){"use strict";var s=i("e792"),o=i.n(s);o.a},f2b8:function(t,e,i){"use strict";(function(t){var s=i("47a9");Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=s(i("7eb4")),n=s(i("ee10")),r=s(i("7ca3")),a=s(i("5f53")),c=i("8f59"),u=(s(i("be2d")),s(i("3779")),s(i("bdc9")));function h(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,s)}return i}function d(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?h(Object(i),!0).forEach((function(e){(0,r.default)(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):h(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}var l={components:{emotion:function(){i.e("im/chat/emotion/index").then(function(){return resolve(i("a64f"))}.bind(null,i)).catch(i.oe)},uParse:function(){Promise.all([i.e("common/vendor"),i.e("components/u-parse/u-parse")]).then(function(){return resolve(i("986d"))}.bind(null,i)).catch(i.oe)}},data:function(){return{options:{},textMsg:"",isHistoryLoading:!1,scrollAnimation:!1,scrollTop:0,scrollToView:"",screenMsgId:[],msgList:[],msgImgList:[],myuid:0,RECORDER:t.getRecorderManager(),isVoice:!1,voiceTis:"按住 说话",recordTis:"手指上滑 取消发送",recording:!1,willStop:!1,initPoint:{identifier:0,Y:0},recordTimer:null,recordLength:0,AUDIO:t.createInnerAudioContext(),playMsgid:null,VoiceTimer:null,popupLayerClass:"",hideMore:!0,hideEmoji:!0,emojiList:[{}],emojiPath:"",windowsState:"",redenvelopeData:{rid:null,from:null,face:null,blessing:null,money:null},chattype:"user",chat_to_puid:0,user_other_row:{},chattitle:"",chatlog:[],page:1,ispage:!1,flag:!1,video:"",isPlay:!1}},computed:d({},(0,c.mapState)(["Config","hasLogin","userInfo","plantformInfo","getMsg"])),watch:{getMsg:function(t){var e=0;console.log("获取到数据"),console.log(t);new Date;var i=t.message_id,s=this.userInfo.im,o=t.msg_type,n={type:"user",sendmethod:this.chattype,needload:!1,fromid:this.chat_to_puid,toid:s.puid,msg:{id:i,type:o,userinfo:{uid:this.chat_to_puid,username:this.user_other_row.user_nickname,face:this.user_other_row.user_avatar},content:{text:t.content}}};switch(o){case"text":n.msg.content.text=t.content;break;case"voice":n.msg.content.url=t.content;break;case"img":n.msg.content.url=t.content;break;case"video":n.msg.content.url=t.content;break;case"redEnvelope":n.msg.content.blessing=t.content;break;case"rtc":n.msg.content.text=t.content;break}"user"==this.chattype&&"friend"==t.type?(this.chat_to_puid==t.id&&(console.log("screenMsg"),console.log(n),this.screenMsg(n),"rtc"==o&&this.$.gotopage("/rtc/room/1v1wx?to_user_id="+this.options.uid)),e=n.fromid):"group"==this.chattype&&"group"==t.type&&(this.chat_to_puid==t.toid&&this.screenMsg(n),e=n.toid),this.chat_to_puid==t.id&&u.default.setMsgRead(i,(function(){})),this.$apiconfig.cacheMessage(t,t.sendmethod,e,s),this.$store.commit("resetWeidu",{type:this.chattype,val:this.chat_to_puid})}},onUnload:function(){this.$store.commit("resetWeidu",{type:this.chattype,val:this.chat_to_puid}),this.$store.commit("setCurrentPuid",""),this.plantformInfo.config.chat_global||this.$Socket.nclose()},onHide:function(){console.log("onHide")},onLoad:function(e){var i=this;return(0,n.default)(o.default.mark((function s(){var n,r;return o.default.wrap((function(s){while(1)switch(s.prev=s.next){case 0:return n=i,s.next=3,i.$onLaunched;case 3:n.voiceTis=i.__("按住 说话"),n.recordTis=i.__("手指上滑 取消发送"),"undefined"==typeof e.uid&&n.$.navigateBack(1),i.forceUserInfo((function(t){n.userInfo.im&&n.getPlantformInfo((function(t){n.plantformInfo.config.chat_global||n.$Socket.connectserver(n.userInfo.im)}))})),i.setData({options:e}),e.name&&(i.chattitle=e.name,t.setNavigationBarTitle({title:e.name})),r={user_other_id:e.uid,is_group:1==e.type?1:0},i.$.request({url:i.Config.URL.user.msg_config,data:r,success:function(s,o,n,r){if(console.info(s),200==o){e.name||(i.chattitle=s.user_other_info.user_nickname,t.setNavigationBarTitle({title:s.user_other_info.user_nickname})),i.chat_to_puid=s.user_other_info.puid,i.user_other_row=s.user_other_info,i.chattype=1==e.type?"group":"user",i.chattitle=e.title,i.getMsgList(),i.$store.commit("updateChaterAttr",{type:i.chattype,val:i.chat_to_puid,attr:"weidu",data:0,addinfo:{weidu:0,lastmsg:"",id:i.chat_to_puid,avatar:i.user_other_row.user_avatar,user_id:i.user_other_row.user_id,username:i.user_other_row.user_nickname,logtype:i.chattype}}),i.$store.commit("resetWeidu",{type:i.chattype,val:i.chat_to_puid}),i.$store.commit("setCurrentPuid",i.chat_to_puid);var c={user_other_id:i.user_other_row.user_id};i.$.request({url:i.Config.URL.user.msg_set_read,data:c,loading:!1,success:function(t,e,i,s){}}),i.AUDIO.onEnded((function(t){i.playMsgid=null})),i.RECORDER.onStart((function(t){i.recordBegin(t)})),i.RECORDER.onStop((function(t){i.recordEnd(t)}));var u=i;if(i.emojiList=a.default.imgArr[1].emojiList,e.item_id){var h={item_id:e.item_id};u.$.request({url:i.Config.URL.product.item,data:h,loading:!1,ajaxCache:{timeout:i.Config.CACHE_EXPIRE},success:function(t,e,i,s){if(200==e){t.item_row.item_unit_price,t.item_row.product_item_name,t.item_row.product_image,t.item_row.item_id;var o='<img class="chatimg" src="'+t.item_row.product_image+'">',n='<div class="chat-bubble-box">'+o+' <a href="/pages/product/detail?pid='+t.item_row.item_id+'">'+t.item_row.product_item_name+u.__("¥")+t.item_row.item_unit_price+"</a></div>",r={text:n,item_id:t.item_row.item_id};u.sendMsg(r,"text")}},complete:function(t,e){}})}if(e.text){var d={text:e.text};u.sendMsg(d,"text")}}else t.navigateBack({})}});case 11:case"end":return s.stop()}}),s)})))()},onShow:function(){this.scrollTop=9999999;this.myuid=this.userInfo.im.puid},methods:d(d({},(0,c.mapMutations)(["login","logout","getPlantformInfo","forceUserInfo","getUserInfo"])),{},{translate:function(t,e){var i=this;i.$.request({url:this.Config.URL.translate,data:{txt:t},success:function(t,s,o,n){200==s?(console.log(e),i.msgList[e].translate_txt=t.text,console.log(i.msgList)):i.Msg(o)}})},screenMsg:function(e){if(console.info("screenMsg"),console.info(e),!this.$.inArray(this.screenMsgId,e.msg.id)){if(this.screenMsgId.push(e.msg.id),"system"==e.type)switch(e.msg.type){case"text":this.addSystemTextMsg(e);break;case"redEnvelope":this.addSystemRedEnvelopeMsg(e);break}else if("user"==e.type||"friend"==e.type){switch(e.msg.type){case"text":this.addTextMsg(e);break;case"voice":this.addVoiceMsg(e);break;case"img":this.addImgMsg(e);break;case"video":this.addTextMsg(e);break;case"redEnvelope":this.addRedEnvelopeMsg(e);break}e.msg.userinfo.uid!=this.myuid&&t.vibrateLong()}this.$nextTick((function(){this.scrollToView="msg"+e.msg.id}))}},loadHistory:function(t){var e=this;if(!this.isHistoryLoading){this.isHistoryLoading=!0,this.scrollAnimation=!1;var i=this.msgList[0].msg.id,s=this;if(this.flag&&this.ispage){s.setData({flag:!1}),clearTimeout(o);var o=setTimeout((function(){s.setData({page:parseInt(s.page)+1}),s.getMsgList((function(){e.$nextTick((function(){this.scrollToView="msg"+i,console.info("this.scrollToView "),console.info(this.scrollToView),this.$nextTick((function(){this.scrollAnimation=!0}))})),e.isHistoryLoading=!1}))}),500)}else this.isHistoryLoading=!1}},getLeavemsg:function(){var t=this.userInfo.im;this.$apiconfig.getrecentmsg_f({data:{mid:t.user_id,tid:this.chat_to_puid,type:this.chattype}}).then((function(t){console.log(t.data)}))},getMsgList:function(t){var e=this,i=this,s=[],o=this.userInfo.im;console.info("tempmy"),console.info(o);var n={user_other_id:this.user_other_row.user_id,data:{mid:o.puid,tid:this.chat_to_puid,type:this.chattype},page:this.page};this.$apiconfig.getrecentmsg_f(n,(function(o,n,r,a){if(console.info("getrecentmsg_f"),console.info(JSON.stringify(o)),console.info(n),console.info(r),o.items.length>0){var c=[];if(s=o.items.forEach((function(t){c.push(t)})),s=c,s.length>0)for(var u=0;u<s.length;u++)"user"==s[u].type&&"img"==s[u].msg.type&&(s[u].msg.content=e.setPicSize(s[u].msg.content),e.msgImgList.push(s[u].msg.content.url)),s[u].msg=e.$apiconfig.im_decode_msg(s[u].msg),s[u].translate_txt=e.__("翻译"),s[u].msg.translate_txt=e.__("翻译");e.msgList=s.concat(e.msgList),o.page>=o.total?i.setData({flag:!1,ispage:!1}):i.setData({flag:!0,ispage:!0})}else i.setData({flag:!1,ispage:!1});console.info(o),console.info(e.msgList),t?t():e.$nextTick((function(){this.scrollTop=9999,this.$nextTick((function(){this.scrollAnimation=!0}))}))}))},setPicSize:function(e){var i=t.upx2px(350),s=t.upx2px(350);if(e.w>i||e.h>s){var o=e.w/e.h;e.w=o>1?i:s*o,e.h=o>1?i/o:s}return e},showMore:function(){this.isVoice=!1,this.hideEmoji=!0,this.hideMore?(this.hideMore=!1,this.openDrawer()):this.hideDrawer()},openDrawer:function(){this.popupLayerClass="showLayer"},hideDrawer:function(){var t=this;this.popupLayerClass="",setTimeout((function(){t.hideMore=!0,t.hideEmoji=!0}),150)},chooseImage:function(){this.getImage("album")},chooseVideo:function(){this.upLoadVideo("album")},upLoadVideo:function(){var e=this;t.chooseVideo({count:1,sourceType:["camera","album"],success:function(i){t.showLoading({title:"视频上传中..",mask:!0}),t.uploadFile({url:e.Config.URL.upload_file,filePath:i.tempFilePath,name:"upfile",success:function(s){var o={url:i.tempFilePath,w:s.width,h:s.height};t.hideLoading();var n=JSON.parse(s.data);200==n.status?(o.url=n.data.url,e.sendMsg(o,"video")):e.$.confirm(n.msg||e.__("发生错误"))}})}})},camera:function(){this.getImage("camera")},handRedEnvelopes:function(){t.navigateTo({url:"HM-hand/HM-hand"}),this.hideDrawer()},yuyintonghua:function(){var t={text:this.__("发起语音通话")};this.sendMsg(t,"rtc"),this.$.gotopage("/rtc/room/1v1wx?to_user_id="+this.options.uid)},getImage:function(e){var i=this,s=this;this.hideDrawer(),s.$.chooseImage({sourceType:[e],sizeType:["original","compressed"],success:function(e){for(var o=function(o){t.getImageInfo({src:e.tempFilePaths[o],success:function(t){var n={url:e.tempFilePaths[o],w:t.width,h:t.height};s.$.uploadFile({url:s.Config.URL.upload,filePath:e.tempFilePaths[o],name:"upfile",formData:{user:"test"},success:function(t){var e=JSON.parse(t.data);200==e.status?(n.url=e.data.url,i.sendMsg(n,"img")):s.$.confirm(e.msg||s.__("发生错误"))}})}})},n=0;n<e.tempFilePaths.length;n++)o(n)}})},chooseEmoji:function(){this.hideMore=!0,this.hideEmoji?(this.hideEmoji=!1,this.openDrawer()):this.hideDrawer()},addEmoji:function(t){if("[删除]"===t.emojiItem.alt){var e,i=this.textMsg.length-1,s=this.textMsg.lastIndexOf("["),o=this.textMsg.lastIndexOf("]"),n=o-s;return e=-1!=o&&o===i&&n>=2&&n<=4?this.textMsg.slice(0,s):this.textMsg.slice(0,i),void(this.textMsg=e)}this.emojiList=a.default.imgArr[t.groupIndex].emojiList,this.emojiPath=a.default.imgArr[t.groupIndex].emojiPath,!1===t.minEmoji?this.sendBigEmoji(t.emojiItem.url):this.textMsg+=t.emojiItem.alt},sendBigEmoji:function(t){if(this.hideDrawer(),t){var e='<img style="width:48px;height:48px;" src="'+this.emojiPath+t+'">',i='<div style="align-items: center;word-wrap:break-word;">'+e+"</div>",s={text:i};this.sendMsg(s,"text"),this.textMsg=""}},textareaFocus:function(){"showLayer"==this.popupLayerClass&&0==this.hideMore&&this.hideDrawer()},sendText:function(){if(this.hideDrawer(),this.textMsg){var t=this.replaceEmoji(this.textMsg),e={text:t};this.sendMsg(e,"text"),this.textMsg=""}},replaceEmoji:function(t){var e=this,i=t.replace(/\[([^(\]|\[)]*)\]/g,(function(t,i){for(var s=0;s<e.emojiList.length;s++)for(var o=e.emojiList[s],n=0;n<o.length;n++){var r=o[n];if(r.alt==t){var a=e.emojiPath,c='<img style="width:24px;height:24px;" src="'+a+r.url+'">';return c}}}));return i},sendMsg:function(t,e){var i=this,s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];console.info("--------------"),console.info(t),console.info(t.text),console.info(e),console.info(s);var o={username:this.userInfo.user_nickname,avatar:this.userInfo.user_avatar,id:this.userInfo.im.puid,user_id:this.userInfo.user_id,content:t.text||t.url,length:"voice"==e?t.length:0,w:"img"==e?t.w:0,h:"img"==e?t.h:0,item_id:"undefined"!=typeof t.item_id?t.item_id:0,type:e,mine:!0},n={id:this.chat_to_puid,friend_id:this.user_other_row.user_id,user_id:this.user_other_row.user_id,name:this.user_other_row.user_nickname,avatar:this.user_other_row.user_avatar,type:this.chattype};""!==o.content.replace(/\s/g,"")&&o.content.length;var r={mine:o,to:n},a={user_other_id:this.user_other_row.user_id,message_content:o.content,item_id:"undefined"!=typeof t.item_id?t.item_id:0,length:o.length,w:o.w,h:o.h,type:e};this.$apiconfig.sendMessage_f(a,(function(o,n,a,c){r.mine.message_id=o.message_other_id,i.$Socket.nsend(r);new Date;var u=o.message_other_id,h=i.userInfo.im,d={type:"user",sendmethod:i.chattype,needload:s,fromid:h.puid,toid:i.chat_to_puid,msg:{id:u,type:e,userinfo:{uid:h.puid,username:i.userInfo.user_nickname,face:i.userInfo.user_avatar},content:t}};"group"==i.chattype||(i.screenMsg(d),d.display=!0,i.$store.commit("updateChaterAttr",{type:i.chattype,val:i.chat_to_puid,attr:"lastmsg",data:t,addinfo:{weidu:0,lastmsg:t,id:i.chat_to_puid,avatar:i.user_other_row.user_avatar,user_id:i.user_other_row.user_id,username:i.user_other_row.user_nickname,logtype:i.chattype}}),i.$store.commit("resetWeidu",{type:i.chattype,val:i.chat_to_puid}),i.$apiconfig.cacheMessage(d,i.chattype,i.chat_to_puid,h))}))},addTextMsg:function(t){console.info("addTextMsg"),console.info(t),this.msgList.push(t)},addVoiceMsg:function(t){this.msgList.push(t)},addImgMsg:function(t){t.msg.content=this.setPicSize(t.msg.content),this.msgImgList.push(t.msg.content.url),this.msgList.push(t)},addRedEnvelopeMsg:function(t){this.msgList.push(t)},addSystemTextMsg:function(t){this.msgList.push(t)},addSystemRedEnvelopeMsg:function(t){this.msgList.push(t)},openRedEnvelope:function(e,i){var s=this,o=e.content.rid;t.showLoading({title:"加载中..."}),setTimeout((function(){0==o?s.redenvelopeData={rid:0,from:"大黑哥",face:"https://static.lancerdt.com/xcxfile/appicon/im/img/im/face/face.jpg",blessing:"恭喜发财,大吉大利",money:"已领完"}:(s.redenvelopeData={rid:1,from:"售后客服008",face:"https://static.lancerdt.com/xcxfile/appicon/im/img/im/face/face_2.jpg",blessing:"恭喜发财",money:"0.01"},e.content.isReceived||(s.sendSystemMsg({text:"你领取了"+(e.userinfo.uid==s.myuid?"自己":e.userinfo.username)+"的红包"},"redEnvelope"),s.msgList[i].msg.content.isReceived=!0)),t.hideLoading(),s.windowsState="show"}),200)},closeRedEnvelope:function(){var t=this;this.windowsState="hide",setTimeout((function(){t.windowsState=""}),200)},sendSystemMsg:function(t,e){var i=this.msgList[this.msgList.length-1].msg.id;i++;var s={type:"system",msg:{id:i,type:e,content:t}};this.screenMsg(s)},toDetails:function(e){t.navigateTo({url:"HM-details/HM-details?rid="+e})},showPic:function(e){t.previewImage({indicator:"none",current:e.content.url,urls:this.msgImgList})},getSplit:function(t,e){return 1==e?t.split(",")[e]+"?200*200.png":t.split(",")[e]},playVideo:function(t){var e=this;console.log(t);var i="";i=t.message_cat?t.message_content:t.msg.content.url,console.log(i),this.video=i,this.isPlay=!0,setTimeout((function(){e.$refs.video.play()}),100)},playVoice:function(t){this.playMsgid=t.msg.id,t.message_length?this.AUDIO.src=t.message_content:this.AUDIO.src=t.msg.content.url,this.$nextTick((function(){this.AUDIO.play()}))},voiceBegin:function(t){t.touches.length>1||(this.initPoint.Y=t.touches[0].clientY,this.initPoint.identifier=t.touches[0].identifier,this.RECORDER.start({format:"mp3"}))},recordBegin:function(t){var e=this;this.recording=!0,this.voiceTis=this.__("松开 结束"),this.recordLength=0,this.recordTimer=setInterval((function(){e.recordLength++}),1e3)},voiceCancel:function(){this.recording=!1,this.voiceTis=this.__("按住 说话"),this.recordTis=this.__("手指上滑 取消发送"),this.willStop=!0,this.RECORDER.stop()},voiceIng:function(e){if(this.recording){var i=e.touches[0];this.initPoint.Y-i.clientY>=t.upx2px(100)?(this.willStop=!0,this.recordTis=this.__("松开手指 取消发送")):(this.willStop=!1,this.recordTis=this.__("手指上滑 取消发送"))}},voiceEnd:function(t){this.recording&&(this.recording=!1,this.voiceTis=this.__("按住 说话"),this.recordTis=this.__("手指上滑 取消发送"),this.RECORDER.stop())},recordEnd:function(t){var e=this;if(clearInterval(this.recordTimer),!this.willStop){var i=t.tempFilePath,s=this.Config.URL.upload_file;this.$.uploadFile({url:s,filePath:i,header:{merchcode:this.$apiconfig.merchcode},name:"upfile",formData:{user:"test"},success:function(t){var i=JSON.parse(t.data),s={length:0,url:i.data.url},o=parseInt(e.recordLength/60),n=e.recordLength%60;o=o<10?"0"+o:o,n=n<10?"0"+n:n,s.length=o+":"+n,e.sendMsg(s,"voice")}})}this.willStop=!1},switchVoice:function(){this.hideDrawer(),this.isVoice=!this.isVoice},discard:function(){},preview:function(t,e){},navigate:function(t,e){console.info(t),console.info(e),this.$.gopage(t)}})};e.default=l}).call(this,i("df3c")["default"])}},[["8954","common/runtime","common/vendor","im/common/vendor"]]]);