2 lines
2.2 KiB
Vue
Raw Permalink Normal View History

2025-04-29 09:38:12 +08:00
import{s as d,g as u}from"./chat.62bb1667.js";import{o,c as a,b as r,aa as g,a9 as m,h as _,ag as x,n as h,g as n,ab as v}from"./vendor.3937d42d.js";import{_ as p}from"./index.e47da145.js";const f={data(){return{chatList:[],message:"",schoolId:"",lastId:"",needScroll:!0,timer:null}},watch:{message(){let e=document.querySelector(".input_area");parseInt(e.style.height)>window.innerHeight*.2||(e.style.height=e.scrollHeight+"px",this.calcChatBox())}},created(){document.title=this.$route.query.schoolName,this.schoolId=this.$route.query.schoolId?this.$route.query.schoolId:"1"},mounted(){this.getChatListFn(),this.timer=setInterval(()=>{this.getChatListFn(!0)},2e3),document.querySelector(".chatBox").addEventListener("scroll",this.scrollLoadMore)},methods:{calcChatBox(){let t=document.querySelector(".sendMessage").offsetHeight,c=document.querySelector(".chatBox");c.style.height=window.innerHeight-t+"px",this.needScroll&&(c.scrollTop=99999)},formatChatList(){},sendMessage(){d({content:this.message,schoolId:this.schoolId,noCover:!0,type:1}).then(e=>{this.message="",this.getChatListFn(!0)})},scrollLoadMore(){document.querySelector(".chatBox").scrollTop<10&&this.getChatListFn()},getChatListFn(e){u({schoolId:this.schoolId,noCover:e,lastId:this.lastId,type:1}).then(t=>{t[0]&&(this.lastId=t[0].chatId),this.chatList=this.chatList.concat(t.reverse()),this.$nextTick(()=>{this.calcChatBox()})})}},unmounted(){console.log(1234),clearInterval(this.timer)}},y={class:"chat"},I={class:"chatBox"},B={key:0,class:"flexFill"},C={key:1,class:"flexFill"},L={class:"sendMessage"};function M(e,t,c,q,i,l){return o(),a("div",y,[r("div",I,[(o(!0),a(g,null,m(i.chatList,s=>(o(),a("div",{class:h(["chatItem",[s.source==1?"chat_right":"chat_left"]])},[s.source==1?(o(),a("div",B)):n("v-if",!0),r("div",{class:h([s.source==1?"left":"right"])},v(s.content),3),s.source!=1?(o(),a("div",C)):n("v-if",!0)],2))),256))]),r("div",L,[_(r("textarea",{"onUpdate:modelValue":t[0]||(t[0]=s=>i.message=s),class:"input_area"},null,512),[[x,i.message]]),r("div",{class:"sendBtn",onClick:t[1]||(t[1]=(...s)=>l.sendMessage&&l.sendMessage(...s))},"\u53D1\u9001")])])}var w=p(f,[["render",M],["__scopeId","data-v-71064116"]]);export{w as default};