chat.js 6.6 KB

12
  1. (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pages/chat/chat"],{40:function(e,t,n){"use strict";(function(e,t){var o=n(4);n(26);o(n(25));var s=o(n(41));e.__webpack_require_UNI_MP_PLUGIN__=n,t(s.default)}).call(this,n(1)["default"],n(2)["createPage"])},41:function(e,t,n){"use strict";n.r(t);var o=n(42),s=n(44);for(var a in s)["default"].indexOf(a)<0&&function(e){n.d(t,e,(function(){return s[e]}))}(a);n(49);var i,c=n(32),r=Object(c["default"])(s["default"],o["render"],o["staticRenderFns"],!1,null,null,null,!1,o["components"],i);r.options.__file="pages/chat/chat.vue",t["default"]=r.exports},42:function(e,t,n){"use strict";n.r(t);var o=n(43);n.d(t,"render",(function(){return o["render"]})),n.d(t,"staticRenderFns",(function(){return o["staticRenderFns"]})),n.d(t,"recyclableRender",(function(){return o["recyclableRender"]})),n.d(t,"components",(function(){return o["components"]}))},43:function(e,t,n){"use strict";var o;n.r(t),n.d(t,"render",(function(){return s})),n.d(t,"staticRenderFns",(function(){return i})),n.d(t,"recyclableRender",(function(){return a})),n.d(t,"components",(function(){return o}));try{o={uniIcons:function(){return Promise.all([n.e("common/vendor"),n.e("uni_modules/uni-icons/components/uni-icons/uni-icons")]).then(n.bind(null,154))}}}catch(c){if(-1===c.message.indexOf("Cannot find module")||-1===c.message.indexOf(".vue"))throw c;console.error(c.message),console.error("1. 排查组件名称拼写是否正确"),console.error("2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom"),console.error("3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件")}var s=function(){var e=this,t=e.$createElement,n=(e._self._c,e.__map(e.chatList,(function(t,n){var o=e.__get_orig(t),s="text"!==t.type?e.returnImageClass(t.body):null;return{$orig:o,m0:s}})));e.$mp.data=Object.assign({},{$root:{l0:n}})},a=!1,i=[];s._withStripped=!0},44:function(e,t,n){"use strict";n.r(t);var o=n(45),s=n.n(o);for(var a in o)["default"].indexOf(a)<0&&function(e){n.d(t,e,(function(){return o[e]}))}(a);t["default"]=s.a},45:function(e,t,n){"use strict";(function(e){var o=n(4);Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=o(n(46)),a=o(n(18)),i=o(n(48)),c=n(297),r=n(298),u=o(n(299)),l={data:function(){return{message:"",chatList:[],postData:{rows:10,page:1,flag:!0,loading:!0,loadText:"正在获取消息..."},nextMessageId:""}},onShow:function(){c.YeIMUniSDK.getInstance().addEventListener(c.YeIMUniSDKDefines.EVENT.MESSAGE_RECEIVED,this.onMessage)},onHide:function(){c.YeIMUniSDK.getInstance().removeEventListener(c.YeIMUniSDKDefines.EVENT.MESSAGE_RECEIVED,this.onMessage)},onLoad:function(){var e=this,t="whx",n=(new Date).getTime()+864e8,o=(0,u.default)(t+n+"50abd47112ebe8c5a73f4694c96a49ce");(0,r.login)({userId:t,timestamp:n,sign:o}).then((function(n){if(200===n.code){var o=n.data.token;c.YeIMUniSDK.getInstance().connect({userId:t,token:o,success:function(t){200===t.code&&e.getHistoryMsg()},fail:function(e){console.log(e)}})}}))},onPageScroll:function(e){e.scrollTop<5&&this.getHistoryMsg()},methods:{returnImageClass:function(e){var t=e.thumbnailWidth,n=e.thumbnailHeight,o="";return t>n&&(o="image-width"),t==n&&(o="image-width-height"),t<n&&(o="image-height"),o+" image-box"},onMessage:function(e){var t=e;this.insertMessage(t)},insertMessage:function(t){try{this.chatList.push(t),this.message="",setTimeout((function(){e.pageScrollTo({scrollTop:99999999,duration:0})}),200)}catch(n){console.log(n)}},getHistoryMsg:function(){var e=this;if(this.postData.flag){var t=function(){var t=(0,i.default)(s.default.mark((function t(){var n,o;return s.default.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return e.toggleTips(),e.postData.flag=!1,t.next=4,e.joinHistoryMsg();case 4:n=t.sent,o="",o=e.postData.page>1?"#msg-".concat(e.chatList[0].time):"#msg-".concat(n[n.length-1].time),e.chatList=[].concat((0,a.default)(n),(0,a.default)(e.chatList)),e.$nextTick((function(){e.setPageScrollTo(o),e.toggleTips(!0),n.length<e.postData.rows||(e.postData.page++,setTimeout((function(){e.postData.flag=!0}),200))}));case 9:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();t()}},setPageScrollTo:function(t){var n=e.createSelectorQuery().in(this).select(t);n.boundingClientRect((function(t){e.pageScrollTo({scrollTop:t.top-30,duration:0})})).exec()},toggleTips:function(e){var t=this;e?(this.postData.loadText="消息获取成功",setTimeout((function(){t.postData.loading=!1}),300)):(this.postData.loading=!0,this.postData.loadText="正在获取消息...")},joinHistoryMsg:function(){var e=this;return new Promise((function(t,n){c.YeIMUniSDK.getInstance().getHistoryMessageList({nextMessageId:e.nextMessageId,conversationId:"dcs",success:function(n){e.nextMessageId=n.data.nextMessageId,t(n.data.list),console.log(n.data)},fail:function(e){console.log(e)}})}))},previewImage:function(t){e.previewImage({urls:[t]})},sendImage:function(){var t=this;e.chooseImage({count:1,sizeType:["original","compressed"],sourceType:["album"],success:function(n){e.getImageInfo({src:n.tempFilePaths[0],success:function(o){var s=c.YeIMUniSDK.getInstance().createImageMessage({toId:"dcs",conversationType:c.YeIMUniSDKDefines.CONVERSATION_TYPE.PRIVATE,body:{file:{tempFilePath:n.tempFilePaths[0],width:o.width,height:o.height}},extra:"这是拓展的自定义的内容",onProgress:function(e){console.log("上传进度"+e.progress),console.log("已经上传的数据长度"+e.totalBytesSent),console.log("预期需要上传的数据总长度"+e.totalBytesExpectedToSend)}});c.YeIMUniSDK.getInstance().sendMessage({message:s,success:function(n){t.chatList.push(n.data),t.message="",setTimeout((function(){e.pageScrollTo({scrollTop:99999999,duration:0}),console.log(9999)}),200)},fail:function(e){console.log(e)}})}})}})},send:function(){var t=this;if(!this.message)return this.$toast("内容不能为空");var n=c.YeIMUniSDK.getInstance().createTextMessage({toId:"dcs",conversationType:c.YeIMUniSDKDefines.CONVERSATION_TYPE.PRIVATE,body:{text:this.message},extra:""});c.YeIMUniSDK.getInstance().sendMessage({message:n,success:function(n){t.chatList.push(n.data),t.message="",setTimeout((function(){e.pageScrollTo({scrollTop:99999999,duration:0}),console.log(9999)}),200)},fail:function(e){console.log(e)}})}}};t.default=l}).call(this,n(2)["default"])},49:function(e,t,n){"use strict";n.r(t);var o=n(50),s=n.n(o);for(var a in o)["default"].indexOf(a)<0&&function(e){n.d(t,e,(function(){return o[e]}))}(a);t["default"]=s.a},50:function(e,t,n){}},[[40,"common/runtime","common/vendor"]]]);
  2. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/chat/chat.js.map