Files
tk-mini-program/unpackage/dist/build/mp-weixin/pages/index/chat/chat.js
pengxiaolong 7116e57fc3 优化
2025-07-21 22:10:59 +08:00

2 lines
8.7 KiB
JavaScript

"use strict";const t=require("../../../common/vendor.js"),e=require("../../../components/ChatId.js"),i=require("../../../components/TimeFormatting.js"),s=require("../../../components/request.js"),o=require("../../../components/goEasyTool/tool.js"),n={data:()=>({userId:"",nickname:"",avatar:"",chatList:[],userinfo:{},ButtonStatus:!1,MoreStatus:!1,KeyboardHeight:0,content:"",MoreItemStatus:null,ioshide:0,ElementPositioning:null,scrollviewheight:0,Elementheight:0,Scrolling:!1,scrollTop:0,judgescrollTop:!1,onPage:!1,timer:null,lastTimestamp:null,LastTime:null,MoreMessageList:[],Record:null,myitem:null,youritem:null,type:null,popUpList:[{name:"邀请",icon:"https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/chat_invite.png",type:"Invitation"}]}),onShow(){this.onPage=!0,t.index.onKeyboardHeightChange((t=>{this.KeyboardHeight=2*t.height-this.ioshide}))},onHide(){this.onPage=!1},onLoad(i){t.index.getStorage({key:"userinfo",success:t=>{this.userinfo=t.data}}),this.userId=i.userId,this.nickname=i.nickname,this.avatar=i.avatar,this.type=i.type;try{this.myitem=JSON.parse(i.myitem),this.youritem=JSON.parse(i.youritem)}catch(n){}"pk"==this.type&&setTimeout((()=>{this.sendCustomMessage()}),500),o.getConversationMessages(this.$goeasy,this.userId,null).then((i=>{this.chatList=i.map((t=>(t.id=e.generateId(),t.timestampStatus=this.checkInterval(t.timestamp),t))),setTimeout((()=>{this.chatList.length>0?(this.ElementPositioning=this.chatList[this.chatList.length-1].id,this.LastTime=this.chatList[0].timestamp):t.index.showToast({title:"您和对方暂无聊天记录,快去聊天吧",icon:"none",duration:2e3})}),300);t.index.createSelectorQuery().in(this).select(".inputComponent").boundingClientRect((t=>{this.Elementheight=2*t.height})).exec()})),o.messageRead(this.$goeasy,this.userId).then((t=>{console.log("已读对方的消息")})),this.getIOSDeviceType();var s=this.$goeasy.im;s.on(t.jo.IM_EVENT.PRIVATE_MESSAGE_RECEIVED,this.onPrivateMessageReceived),s.on(t.jo.IM_EVENT.MESSAGE_READ,this.onMessageRead),this.getscrollviewheight()},methods:{sendCustomMessage(){s.request({url:"pk/createPkRecord",method:"POST",data:{pkIdA:this.youritem.id,pkIdB:this.myitem.id,userIdA:this.userId,userIdB:this.userinfo.id,pkTime:this.youritem.pkTime,pkNumber:this.youritem.pkNumber,anchorIdA:this.youritem.anchorId,anchorIdB:this.myitem.anchorId,anchorIconA:this.youritem.anchorIcon,anchorIconB:this.myitem.anchorIcon,piIdA:this.youritem.id,piIdB:this.myitem.id},userInfo:!0}).then((i=>{if(200==i.code){let s={customData:{id:i.data.id,pkIdA:this.youritem.id,pkIdB:this.myitem.id},link:"https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/pk.png",text:"PK邀请消息"};o.sendCustomMessage(this.$goeasy,this.type,this.userId,s,this.avatar,this.nickname).then((i=>{this.ElementPositioning=i.id=e.generateId(),i.timestampStatus=this.checkInterval(i.timestamp),this.chatList.push(i),t.index.showToast({title:"发送成功",icon:"none"})}))}else t.index.showToast({title:i.msg,icon:"none"})}))},checkInterval(t){if(!this.lastTimestamp)return this.lastTimestamp=t,!0;return t-this.lastTimestamp>=3e5&&(this.lastTimestamp=t,!0)},TimeFormatting:i.TimeFormatting,getscrollviewheight(){t.index.createSelectorQuery().in(this).select(".scroll").boundingClientRect((t=>{this.scrollviewheight=t.height})).exec()},onScroll(t){this.judgescrollTop?this.scrollTop-t.detail.scrollTop>this.scrollviewheight?this.Scrolling=!0:this.scrollTop-t.detail.scrollTop<this.scrollviewheight&&(this.Scrolling=!1):(this.scrollTop=t.detail.scrollTop,this.judgescrollTop=!0)},onScrollToUpper(){this.lastTimestamp=null,o.getConversationMessages(this.$goeasy,this.userId,this.LastTime).then((t=>{this.Record=this.chatList[0].id,this.MoreMessageList=t.map((t=>(t.id=e.generateId(),t.timestampStatus=this.checkInterval(t.timestamp),t)))})),setTimeout((()=>{this.chatList=[...this.MoreMessageList,...this.chatList],console.log("获取更多聊天记录",this.chatList),this.LastTime=this.chatList[0].timestamp,this.ElementPositioning=this.Record}),300)},onMessageRead(t){console.log("1已读消息",t)},onPrivateMessageReceived(t){this.Scrolling?(t.id=e.generateId(),t.timestampStatus=this.checkInterval(t.timestamp)):(this.ElementPositioning=t.id=e.generateId(),t.timestampStatus=this.checkInterval(t.timestamp),this.judgescrollTop=!1),this.chatList.push(t),this.onPage&&o.messageRead(this.$goeasy,this.userId).then((t=>{console.log("已读对方的消息")}))},onSend(){""!=this.content&&(o.sendMessage(this.$goeasy,this.userId,this.content,this.avatar,this.nickname).then((t=>{console.log("发送成功",t),this.ElementPositioning=t.id=e.generateId(),t.timestampStatus=this.checkInterval(t.timestamp),this.chatList.push(t),this.judgescrollTop=!1})),this.content="",this.ButtonStatus=!1)},refreshMessage(t){this.MoreItemStatus=null,this.ElementPositioning=t.message.id=e.generateId(),t.timestampStatus=this.checkInterval(t.message.timestamp),this.chatList.push(t.message),this.judgescrollTop=!1,this.MoreStatus=!1},getIOSDeviceType(){const e=t.index.getSystemInfoSync().model;/iPhone X|iPhone11|iPhone12|iPhone13|iPhone14/i.test(e)&&(/iPhone X|iPhone XS|iPhone 11 Pro/i.test(e)?this.ioshide=88:/iPhone 12|iPhone 13|iPhone 14/i.test(e)&&(this.ioshide=94))},onMore(e){this.Scrolling||(this.ElementPositioning=null,setTimeout((()=>{this.ElementPositioning=this.chatList[this.chatList.length-1].id}),100),this.judgescrollTop=!1),this.getscrollviewheight(),this.MoreStatus=e;t.index.createSelectorQuery().in(this).select(".inputComponent").boundingClientRect((t=>{this.Elementheight=2*t.height})).exec()},onMoreItem(t){this.MoreItemStatus=t},onFocus(e){this.Scrolling||(this.ElementPositioning=null,setTimeout((()=>{this.ElementPositioning=this.chatList[this.chatList.length-1].id}),100),this.judgescrollTop=!1),this.getscrollviewheight();t.index.createSelectorQuery().in(this).select(".inputComponent").boundingClientRect((t=>{this.Elementheight=2*t.height})).exec()},onBlur(e){t.index.createSelectorQuery().in(this).select(".inputComponent").boundingClientRect((t=>{this.Elementheight=2*t.height})).exec(),this.getscrollviewheight()},SendInput(e){t.index.createSelectorQuery().in(this).select(".inputComponent").boundingClientRect((t=>{this.Elementheight=2*t.height})).exec(),""!=e.target.value?this.ButtonStatus=!0:this.ButtonStatus=!1},onBack(){this.onPage=!1,t.wx$1.navigateBack({delta:1})}},components:{textmessage:()=>"./messageComponent/textmessage.js",InvitationComponents:()=>"./moreMessageComponents/InvitationComponents.js",customPKMessage:()=>"./messageComponent/customPKMessage.js"}};if(!Array){(t.resolveComponent("textmessage")+t.resolveComponent("customPKMessage")+t.resolveComponent("InvitationComponents"))()}const h=t._export_sfc(n,[["render",function(e,i,s,o,n,h){return t.e({a:t.o((t=>h.onMore(!1))),b:t.o(((...t)=>h.onBack&&h.onBack(...t))),c:t.t(n.nickname),d:t.o((t=>h.onMore(!1))),e:t.f(n.chatList,((e,i,s)=>t.e({a:e.timestampStatus},e.timestampStatus?{b:t.t(h.TimeFormatting(e.timestamp))}:{},{c:e.senderId==n.userId},e.senderId==n.userId?t.e({d:n.avatar,e:"text"==e.type},"text"==e.type?{f:"9e93d865-0-"+s,g:t.p({messagetext:e.payload.text})}:{},{h:"pk"==e.type},"pk"==e.type?{i:"9e93d865-1-"+s,j:t.p({message:e.payload})}:{}):{},{k:e.senderId==n.userinfo.id},e.senderId==n.userinfo.id?t.e({l:n.userinfo.headerIcon,m:"text"==e.type},"text"==e.type?{n:"9e93d865-2-"+s,o:t.p({messagetext:e.payload.text})}:{},{p:"pk"==e.type},"pk"==e.type?{q:"9e93d865-3-"+s,r:t.p({message:e.payload})}:{}):{},{s:e.id,t:e.id}))),f:t.o(((...t)=>h.onScrollToUpper&&h.onScrollToUpper(...t))),g:n.ElementPositioning,h:t.o(((...t)=>h.onScroll&&h.onScroll(...t))),i:t.o((t=>h.onMore(!1))),j:n.MoreStatus||0!=n.KeyboardHeight||0!=n.Elementheight?n.MoreStatus?650+n.Elementheight+"rpx":0!=n.KeyboardHeight?n.KeyboardHeight+n.Elementheight+"rpx":n.Elementheight+"rpx":n.Elementheight+"rpx",k:t.o([t=>n.content=t.detail.value,(...t)=>h.SendInput&&h.SendInput(...t)]),l:t.o(((...t)=>h.onFocus&&h.onFocus(...t))),m:t.o(((...t)=>h.onBlur&&h.onBlur(...t))),n:n.content,o:!n.ButtonStatus},n.ButtonStatus?{}:{p:t.o((t=>h.onMore(!n.MoreStatus)))},{q:n.ButtonStatus},n.ButtonStatus?{r:t.o(((...t)=>h.onSend&&h.onSend(...t)))}:{},{s:n.MoreStatus||n.KeyboardHeight>300?n.MoreStatus?"650rpx":n.KeyboardHeight>300?n.KeyboardHeight+"rpx":"0":"0",t:t.f(n.popUpList,((e,i,s)=>({a:e.icon,b:t.t(e.name),c:t.o((t=>h.onMoreItem(e.type)),i),d:i}))),v:n.MoreStatus||n.KeyboardHeight>300?n.MoreStatus||n.KeyboardHeight>300?"0":n.KeyboardHeight+"rpx":"-650rpx",w:"Invitation"==n.MoreItemStatus},"Invitation"==n.MoreItemStatus?{x:t.o(h.refreshMessage),y:t.p({oppositeId:n.userId,myId:n.userinfo.id,avatar:n.avatar,nickname:n.nickname})}:{},{z:t.o((()=>{})),A:null==n.MoreItemStatus?"-1000rpx":"0",B:t.o((t=>h.onMoreItem(null))),C:null==n.MoreItemStatus?"100vh":"0"})}],["__scopeId","data-v-9e93d865"]]);wx.createPage(h);