kefu/h5/static/js/pages-index-index.bf125a86.js

1 line
17 KiB
JavaScript
Raw Normal View History

2024-12-10 02:50:12 +00:00
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["pages-index-index"],{"28e8":function(e,t,i){"use strict";i("7a82");var n=i("4ea4").default;Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=n(i("1f61")),o=n(i("81b7")),r=n(i("3242")),s=getApp(),c={data:function(){return{title:"Hello",baseUrl:getApp().globalData.baseUrl,wsBaseUrl:getApp().globalData.wsBaseUrl,visitorList:[],token:"",timer:null,wsOpen:!1,noticeContent:"通知: 无",innerAudioContext:null}},onShow:function(){var e=uni.getStorageSync("app");console.log(e),e&&(this.token=e.token);var t=uni.getStorageSync("domain");t&&(this.baseUrl=t.domain,this.wsBaseUrl=o.default.getWsUrl(t.domain)),this.checkAuth(),this.initPush()},onLoad:function(){},methods:{initSocket:function(){s.globalData.socketObj?s.globalData.socketObj.isConnect||s.globalData.socketObj.initSocket():(s.globalData.socketObj=new r.default(this.wsBaseUrl+"?token="+this.token,60),s.globalData.socketObj.initSocket())},onlineIntime:function(){var e=this;uni.onSocketMessage((function(t){var i=JSON.parse(t.data);switch(i.type){case"allUsers":break;case"userOnline":e.addOnlineUser(i.data),o.default.playVoice();break;case"userOffline":console.log("下线"),e.removeOfflineUser(i.data);break;case"notice":break;case"message":e.recvMessage(i.data);break}}))},getOnlineUser:function(){var e=this,t=this.baseUrl;uni.request({url:t+"/kefu/onlineVisitors?token="+e.token,method:"GET",success:function(t){if(console.log(t),t.data.result){for(var i=t.data.result,n=0;n<i.length;n++)i[n].avator=o.default.getImageUrl(i[n].avator,e.baseUrl);e.visitorList=i}},fail:function(e){}})},addOnlineUser:function(e){var t=this.visitorList;e.avator=o.default.getImageUrl(e.avator,this.baseUrl),this.visitorList=a.default.addVisitor(t,e)},removeOfflineUser:function(e){var t=this.visitorList;t=a.default.removeVisitor(t,e.visitor_id),this.visitorList=t},chatVisitor:function(e,t){uni.navigateTo({url:"/pages/index/detail?visitor_id="+t})},recvMessage:function(e){this.visitorList=a.default.receiveMessage(this.visitorList,e),this.showNoticeBar(e.name+":"+e.content),"yes"!=e.is_kefu&&o.default.playVoice()},initPush:function(){},showNotice:function(e){},showNoticeBar:function(e){this.noticeContent=e},checkAuth:function(){var e=this;uni.request({url:e.baseUrl+"/uc/v1/refreshToken?token="+e.token,method:"POST",header:{"Content-Type":"application/x-www-form-urlencoded"},success:function(t){var i=t.data.code;2e4!=i?uni.navigateTo({url:"/pages/index/login"}):(uni.setStorageSync("app",{token:t.data.result.token}),e.token=t.data.result.token,e.initSocket(),e.onlineIntime(),e.getOnlineUser())}})},registerClient:function(e){var t=this.baseUrl;uni.request({url:t+"/kefu/appClient?token="+this.token,data:{client_id:e},method:"POST",header:{"Content-Type":"application/x-www-form-urlencoded"},success:function(e){console.log(e)}})},showLastMessage:function(e){return""==e?"无消息":(e=o.default.replaceHtml(e),e)},showUnreadNum:function(e){return 0==e||"0"==e?"dot":e},formatTime:function(e){e=Math.round(new Date(e).getTime()/1e3);return o.default.beautifyTime(e)}}};t.default=c},3242:function(e,t,i){"use strict";i("7a82");var n=i("4ea4").default;Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,i("e9c4"),i("d3b7");var a=n(i("d4ec")),o=n(i("bee2")),r=function(){function e(t,i){(0,a.default)(this,e),this.url=t,this.data=null,this.isCreate=!1,this.isConnect=!1,this.isInitiative=!1,this.timeoutNumber=i,this.heartbeatTimer=null,this.reconnectTimer=null,this.socketExamples=null,this.againTime=3,this.reconnectNum=0}return(0,o.default)(e,[{key:"initSocket",value:function(){var e=this;this.socketExamples=uni.connectSocket({url:e.url,header:{"content-type":"application/json"},success:function(t){e.isCreate=!0,console.log(t)},fail:function(t){console.error(t),e.isCreate=!1}}),this.createSocket()}},{key:"createSocket",value:function(){var e=this;if(this.isCreate){console.log("WebSocket 开始初始化");try{this.socketExamples.onOpen((function(){console.log("WebSocket 连接成功"),e.isConnect=!0,clearInterval(e.heartbeatTimer),