1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2026-03-21 09:13:10 +00:00
Classworks/assets/ChatWidget-C65TaUP3.js

4 lines
25 KiB
JavaScript

import{s as Q,g as F,j as D,a as x}from"./socketClient-BhDBx1xd.js";import{_ as V,n as N,e as S,d as w,h as _,f as p,k as K,c as W,g as E,G as j,i as b,o as H,l as q}from"./index-C305lth9.js";import{X as u,_ as m,j as i,Z as a,k as c,S as f,a1 as g,$ as y,F as k,N as M,R as L,V as G,m as J,a2 as U,n as X,Y as $,ad as R,a9 as B}from"./vendor-vue-PFj_oO9L.js";import{p as O,s as Y}from"./soundList-D9U-Grcp.js";import{V as C}from"./VChip-BAz4LI6s.js";import{f as Z,s as ee,c as te}from"./deviceEvents-BdDlJtiW.js";import{V as se,a as ie}from"./VTooltip-i51F1dF1.js";import{V as ne,a as T}from"./VRow-BQOh1CLA.js";import{V as oe}from"./VPagination-DtF5C3cQ.js";import{V as re}from"./VTextarea-6rLGvsne.js";const ae={name:"EventSender",emits:["sent","error"],methods:{async sendEvent(e,t={}){try{return Q(e,t),this.$emit("sent",{eventName:e,content:t,timestamp:new Date().toISOString(),success:!0}),{success:!0,eventId:(t==null?void 0:t.eventId)||null,notificationId:(t==null?void 0:t.notificationId)||null}}catch(o){return console.error("发送事件失败:",o),this.$emit("error",{eventName:e,content:t,error:o.message,timestamp:new Date().toISOString(),success:!1}),{success:!1,error:o.message}}},async sendNotification(e,t=!1,o=[],d={},l=null){const r=`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return this.sendEvent("notification",{eventId:r,notificationId:l,message:e,isUrgent:t,targetDevices:o,senderInfo:d})},async sendReceipt(e,t,o={},d=null){const l=`rcpt-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return this.sendEvent("notification-receipt",{eventId:l,originalEventId:e,notificationId:d,status:t,deviceInfo:o})},async sendDisplayedReceipt(e={},t=null){const o=`disp-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return this.sendEvent("notification-displayed",{eventId:o,notificationId:t,deviceInfo:e})},async sendReadReceipt(e={},t=null){const o=`read-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return this.sendEvent("notification-read",{eventId:o,notificationId:t,deviceInfo:e})}}},le={style:{display:"none"}};function de(e,t,o,d,l,r){return u(),m("div",le)}const P=V(ae,[["render",de]]),ce={name:"UrgentNotification",components:{EventSender:P},data(){return{visible:!1,notificationQueue:[],currentIndex:0,autoCloseTimer:null,urgentSoundTimer:null,currentAudio:null}},computed:{currentNotification(){return this.notificationQueue[this.currentIndex]||null},hasNotifications(){return this.notificationQueue.length>0},hasMultipleNotifications(){return this.notificationQueue.length>1},notificationCountText(){return this.hasMultipleNotifications?`${this.currentIndex+1} / ${this.notificationQueue.length}`:""},isUrgent(){var e,t;return((t=(e=this.currentNotification)==null?void 0:e.content)==null?void 0:t.isUrgent)||!1},urgencyColor(){return this.isUrgent?"red darken-2":"blue darken-2"},iconColor(){return"white"},urgencyIcon(){return this.isUrgent?"mdi-alert-circle-outline":"mdi-information-outline"},urgencyTitle(){return this.isUrgent?"🚨 紧急通知":"📢 通知消息"},senderName(){var t,o,d;const e=((t=this.currentNotification)==null?void 0:t.senderInfo)||((d=(o=this.currentNotification)==null?void 0:o.content)==null?void 0:d.senderInfo);return e?e.deviceName||e.deviceType||"未知设备":"未知发送者"},deviceType(){var t,o,d;const e=((t=this.currentNotification)==null?void 0:t.senderInfo)||((d=(o=this.currentNotification)==null?void 0:o.content)==null?void 0:d.senderInfo);return(e==null?void 0:e.deviceType)=="teacher"?"教师":(e==null?void 0:e.deviceType)=="student"?"学生":(e==null?void 0:e.deviceType)=="classroom"?"教室":(e==null?void 0:e.deviceType)||"未知类型"},targetDevices(){var e,t;return((t=(e=this.currentNotification)==null?void 0:e.content)==null?void 0:t.targetDevices)||[]}},beforeUnmount(){this.autoCloseTimer&&clearTimeout(this.autoCloseTimer),this.urgentSoundTimer&&clearInterval(this.urgentSoundTimer),this.stopNotificationSound()},methods:{show(e){var o;if(this.notificationQueue.findIndex(d=>{var l,r;return((l=d.content)==null?void 0:l.notificationId)===((r=e.content)==null?void 0:r.notificationId)})!==-1){console.log("通知已存在,跳过添加");return}this.notificationQueue.push(e),this.visible?(o=e.content)!=null&&o.isUrgent&&!this.isUrgent?(this.currentIndex=this.notificationQueue.length-1,this.sendDisplayedReceipt(),this.playNotificationSound(),this.sendBrowserNotification(e),this.startUrgentSound()):this.sendBrowserNotification(e):(this.currentIndex=this.notificationQueue.length-1,this.visible=!0,this.sendDisplayedReceipt(),this.playNotificationSound(),this.sendBrowserNotification(e),this.isUrgent&&this.startUrgentSound())},close(){var e,t,o,d;try{this.sendReadReceipt(),console.log("已发送已读回执")}catch(l){console.warn("发送已读回执失败:",l)}if((t=(e=this.currentNotification)==null?void 0:e.content)!=null&&t.message){const l=this.isUrgent?"紧急通知":"通知";this.isUrgent?(o=this.$message)==null||o.error(l,`${this.currentNotification.content.message}`):(d=this.$message)==null||d.info(l,`${this.currentNotification.content.message}`)}this.notificationQueue.length>0&&(this.notificationQueue.splice(this.currentIndex,1),this.currentIndex>=this.notificationQueue.length&&(this.currentIndex=Math.max(0,this.notificationQueue.length-1)),this.notificationQueue.length>0?(this.sendDisplayedReceipt(),this.isUrgent?this.startUrgentSound():this.stopUrgentSound()):this.closeWithoutRead())},closeWithoutRead(){this.visible=!1,this.notificationQueue=[],this.currentIndex=0,this.autoCloseTimer&&(clearTimeout(this.autoCloseTimer),this.autoCloseTimer=null),this.stopUrgentSound()},formatTime(e){if(!e)return"";try{const t=new Date(e);if(new Date-t<24*60*60*1e3){const l=String(t.getHours()).padStart(2,"0"),r=String(t.getMinutes()).padStart(2,"0");return`${l}:${r}`}else{const l=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${l}/${r}`}}catch{return"无效时间"}},getDeviceTypeLabel(e){return{classroom:"教室设备",student:"学生设备",teacher:"教师设备",admin:"管理员设备",system:"系统设备"}[e]||e},playNotificationSound(){try{this.stopNotificationSound();const e=this.isUrgent?N("notification.urgentSound"):N("notification.singleSound");this.currentAudio=O(e,!1),this.currentAudio||this.playFallbackSound()}catch(e){console.warn("无法播放通知音效:",e),this.playFallbackSound()}},playFallbackSound(){try{const e=new(window.AudioContext||window.webkitAudioContext),t=e.createOscillator(),o=e.createGain();t.connect(o),o.connect(e.destination),t.frequency.value=1e3,t.type="sine",o.gain.value=.3,t.start(),t.stop(e.currentTime+.3)}catch(e){console.warn("无法播放备用音效:",e)}},stopNotificationSound(){this.currentAudio&&(Y(this.currentAudio),this.currentAudio=null)},sendDisplayedReceipt(){var e;try{this.$refs.eventSender&&((e=this.currentNotification)!=null&&e.eventId)&&(this.$refs.eventSender.sendDisplayedReceipt({},this.currentNotification.content.notificationId),console.log("已发送显示回执:",this.currentNotification.eventId))}catch(t){console.warn("发送显示回执失败:",t)}},sendReadReceipt(){var e;try{this.$refs.eventSender&&((e=this.currentNotification)!=null&&e.eventId)&&(this.$refs.eventSender.sendReadReceipt({},this.currentNotification.content.notificationId),console.log("已发送已读回执:",this.currentNotification.eventId))}catch(t){console.warn("发送已读回执失败:",t)}},previousNotification(){this.currentIndex>0&&(this.currentIndex--,this.sendDisplayedReceipt(),this.isUrgent?this.startUrgentSound():this.stopUrgentSound())},nextNotification(){this.currentIndex<this.notificationQueue.length-1&&(this.currentIndex++,this.sendDisplayedReceipt(),this.isUrgent?this.startUrgentSound():this.stopUrgentSound())},startUrgentSound(){this.stopUrgentSound(),this.stopNotificationSound();const e=N("notification.urgentSound");this.currentAudio=O(e,!0),this.currentAudio||(this.urgentSoundTimer=setInterval(()=>{this.visible&&this.isUrgent?this.playFallbackSound():this.stopUrgentSound()},1e3))},stopUrgentSound(){this.urgentSoundTimer&&(clearInterval(this.urgentSoundTimer),this.urgentSoundTimer=null),this.stopNotificationSound()},async sendBrowserNotification(e){var t,o,d,l;if(!("Notification"in window)){console.warn("浏览器不支持通知API");return}try{let r=Notification.permission;if(r==="default"&&(r=await Notification.requestPermission()),r!=="granted"){console.warn("用户未授予通知权限");return}const I=((t=e.content)==null?void 0:t.message)||"新通知",n=e.senderInfo||((o=e.content)==null?void 0:o.senderInfo),v=(n==null?void 0:n.deviceName)||(n==null?void 0:n.deviceType)||"未知发送者",s=((d=e.content)==null?void 0:d.isUrgent)||!1,h=new Notification(s?"🚨 紧急通知":"📢 通知消息",{body:`${I}
来自: ${v}`,icon:"/pwa/image/icon-192.png",badge:"/pwa/image/icon-192.png",tag:((l=e.content)==null?void 0:l.notificationId)||`notification-${Date.now()}`,requireInteraction:s,silent:!1,vibrate:s?[200,100,200,100,200]:[200],timestamp:e.timestamp||Date.now()});h.onclick=()=>{window.focus(),h.close()},s||setTimeout(()=>{h.close()},1e4)}catch(r){console.error("发送浏览器通知失败:",r)}}}},ue={class:"urgent-title mb-6"},he={class:"urgent-subtitle mb-6"},fe={key:0,class:"navigation-controls mt-6"},me={class:"notification-counter mb-3"},ge={class:"navigation-buttons"},pe={class:"mt-8"};function ve(e,t,o,d,l,r){const I=P;return u(),m(k,null,[i(K,{modelValue:l.visible,"onUpdate:modelValue":t[0]||(t[0]=n=>l.visible=n),"max-width":"800",persistent:"",transition:"dialog-transition",class:"urgent-notification-dialog"},{default:a(()=>[i(S,{class:"urgent-notification-card",color:r.urgencyColor,elevation:"24"},{default:a(()=>[i(w,null,{default:a(()=>{var n,v,s;return[c("div",ue,f(((v=(n=r.currentNotification)==null?void 0:n.content)==null?void 0:v.message)||"无内容"),1),c("div",he,f(r.senderName)+" "+f(r.deviceType)+" "+f(r.formatTime((s=r.currentNotification)==null?void 0:s.timestamp)),1),r.hasMultipleNotifications?(u(),m("div",fe,[i(S,{variant:"flat",color:"rgba(255,255,255,0.1)"},{default:a(()=>[i(w,{class:"text-center"},{default:a(()=>[c("div",me,[i(C,{color:"white",variant:"flat",size:"small"},{default:a(()=>[g(f(r.notificationCountText),1)]),_:1})]),c("div",ge,[i(_,{disabled:l.currentIndex===0,color:"white",variant:"outlined",size:"small",onClick:r.previousNotification},{default:a(()=>[i(p,null,{default:a(()=>[...t[1]||(t[1]=[g(" mdi-chevron-left ",-1)])]),_:1}),t[2]||(t[2]=g(" 上一个 ",-1))]),_:1},8,["disabled","onClick"]),i(_,{disabled:l.currentIndex===l.notificationQueue.length-1,color:"white",variant:"outlined",size:"small",class:"ml-2",onClick:r.nextNotification},{default:a(()=>[t[4]||(t[4]=g(" 下一个 ",-1)),i(p,null,{default:a(()=>[...t[3]||(t[3]=[g(" mdi-chevron-right ",-1)])]),_:1})]),_:1},8,["disabled","onClick"])])]),_:1})]),_:1})])):y("",!0),c("div",pe,[i(_,{color:"white",size:"large",variant:"flat",onClick:r.close},{default:a(()=>[i(p,{left:""},{default:a(()=>[...t[5]||(t[5]=[g(" mdi-check ",-1)])]),_:1}),t[6]||(t[6]=g(" 我知道了 ",-1))]),_:1},8,["onClick"])])]}),_:1})]),_:1},8,["color"])]),_:1},8,["modelValue"]),i(I,{ref:"eventSender"},null,512)],64)}const z=V(ce,[["render",ve],["__scopeId","data-v-6190a823"]]),ye={name:"ChatWidget",components:{UrgentNotification:z},props:{modelValue:{type:Boolean,default:!1},showButton:{type:Boolean,default:!0},offset:{type:Number,default:16},width:{type:Number,default:380},height:{type:Number,default:520}},emits:["update:modelValue"],data(){return{visible:this.modelValue,text:"",messages:[],allEvents:[],lastVisit:null,unreadCount:0,connected:!1,socketId:"",currentMode:"chat",currentPage:1,itemsPerPage:20,loading:!1,isDestroying:!1,eventStats:{chat:0,kvChanged:0,other:0},cleanupFunctions:[]}},computed:{panelStyle(){return{right:this.offset+"px",bottom:this.offset+"px",width:this.width+"px",height:this.height+"px"}},toggleStyle(){return{right:this.offset+"px",bottom:this.offset+"px"}},canSend(){return!!(N("server.kvToken")&&this.text.trim())},showToggleButton(){return this.$props.showButton&&!this.visible},decoratedMessages(){if(!this.lastVisit)return this.messages;const e=this.messages.findIndex(d=>d.at&&new Date(d.at).getTime()>=new Date(this.lastVisit).getTime());if(e<=0)return this.messages;const t=this.messages.slice(0,e),o=this.messages.slice(e);return[...t,{_id:"divider",_type:"divider"},...o]},currentDisplayItems(){return this.currentMode==="chat"?this.decoratedMessages:this.paginatedEvents},paginatedEvents(){if(this.isDestroying||!this.allEvents)return[];const e=(this.currentPage-1)*this.itemsPerPage,t=e+this.itemsPerPage;return this.allEvents.slice(e,t)},totalPages(){return this.isDestroying||!this.allEvents?1:Math.ceil(this.allEvents.length/this.itemsPerPage)},modeTitle(){return this.currentMode==="chat"?"设备聊天室":"所有事件"}},watch:{modelValue(e){this.visible=e,e&&this.onOpen()}},mounted(){try{const s=localStorage.getItem("chat.lastVisit");s&&(this.lastVisit=s)}catch{}const e=F();this.connected=!!e.connected,this.socketId=e.id||"",e.on("connect",()=>{this.connected=!0,this.socketId=e.id||""}),e.on("disconnect",()=>{this.connected=!1});const t=N("server.kvToken");t&&D(t);const o=s=>(...h)=>{if(!this.isDestroying)try{s(...h)}catch(A){console.error("ChatWidget 事件处理错误:",A)}},d=x("chat:message",o(s=>{this.pushMessage(s),this.addEvent({_id:`legacy-chat-${Date.now()}-${Math.random()}`,type:"chat:message",content:s,timestamp:s.at||new Date().toISOString(),senderId:s.senderId,uuid:s.uuid,senderInfo:s.senderInfo})})),l=x("chat",o(s=>{if(s&&s.content&&s.content.text){const h={text:s.content.text,senderId:s.senderId,at:s.timestamp,uuid:s.senderId,senderInfo:s.senderInfo};this.pushMessage(h),this.addEvent({_id:s.eventId||`chat-${Date.now()}-${Math.random()}`,type:"chat",content:s.content,timestamp:s.timestamp,eventId:s.eventId,senderId:s.senderId,senderInfo:s.senderInfo})}}));this.deviceEventHandler=te({onChat:o((s,h)=>{this.pushMessage(s),this.addEvent(h)}),onKvChanged:o((s,h)=>{this.addEvent(h)}),onUrgentNotice:o((s,h)=>{this.addEvent(h),this.showUrgentNotification(h)}),onNotification:o((s,h)=>{console.log("收到通知事件:",s,h),this.addEvent(h),this.showUrgentNotification(h)}),onOtherEvent:o(s=>{(s.type==="urgent-notice"||s.type==="notification")&&this.showUrgentNotification(s),this.addEvent(s)}),enableLegacySupport:!0});const r=x("device-event",this.deviceEventHandler),I=x("kv-key-changed",o(s=>{s.content&&s.timestamp?this.addEvent({_id:`kv-${Date.now()}-${Math.random()}`,type:"kv-key-changed",content:s.content,timestamp:s.timestamp,eventId:s.eventId,senderId:s.senderId,senderInfo:s.senderInfo}):this.addEvent({_id:`legacy-kv-${Date.now()}-${Math.random()}`,type:"kv-key-changed",content:s,timestamp:s.updatedAt||new Date().toISOString(),uuid:s.uuid})})),n=x("urgent-notice",o(s=>{console.log("收到紧急通知:",s),this.addEvent({_id:`urgent-${Date.now()}-${Math.random()}`,type:"urgent-notice",content:s.content||s,timestamp:s.timestamp||new Date().toISOString(),eventId:s.eventId,senderId:s.senderId,senderInfo:s.senderInfo}),this.showUrgentNotification(s)})),v=x("notification",o(s=>{var h;console.log("收到通知事件:",s),this.addEvent({_id:`notification-${Date.now()}-${Math.random()}`,type:"notification",content:s.content||s,timestamp:s.timestamp||new Date().toISOString(),eventId:s.eventId,senderId:s.senderId,senderInfo:s.senderInfo||((h=s.content)==null?void 0:h.senderInfo)}),this.showUrgentNotification(s)}));this.cleanupFunctions=[d,l,n,v,r,I],this.visible&&this.onOpen()},beforeUnmount(){this.isDestroying=!0,this.cleanupFunctions&&Array.isArray(this.cleanupFunctions)&&this.cleanupFunctions.forEach(e=>{try{typeof e=="function"&&e()}catch(t){console.warn("ChatWidget 清理函数执行失败:",t)}});try{this.offMessage&&this.offMessage(),this.offDeviceEvent&&this.offDeviceEvent(),this.offKvChanged&&this.offKvChanged()}catch(e){console.warn("ChatWidget 旧清理函数执行失败:",e)}this.cleanupFunctions=[],this.messages=[],this.allEvents=[]},methods:{open(){this.visible=!0,this.$emit("update:modelValue",!0),this.onOpen()},close(){this.visible=!1,this.$emit("update:modelValue",!1);try{localStorage.setItem("chat.lastVisit",new Date().toISOString())}catch{}this.unreadCount=0},onOpen(){this.$nextTick(()=>this.scrollToBottom())},insertEmoji(e){this.text+=e,this.$nextTick(()=>{var t,o;if((o=(t=this.$refs.inputRef)==null?void 0:t.$el)!=null&&o.querySelector){const d=this.$refs.inputRef.$el.querySelector("textarea");d==null||d.focus()}})},handleEnter(e){e.shiftKey||this.send()},send(){const e=this.text.trim();if(!e)return;const t={_id:`self-${Date.now()}-${Math.random()}`,text:e,at:new Date().toISOString(),senderId:this.socketId,self:!0,senderInfo:{deviceName:"我",deviceType:"client",isReadOnly:!1}};this.pushMessage(t),this.addEvent({_id:`self-event-${Date.now()}-${Math.random()}`,type:"chat",content:{text:e},timestamp:new Date().toISOString(),senderId:this.socketId,senderInfo:{deviceName:"本设备",deviceType:"client",isReadOnly:!1}}),ee(e),this.text=""},pushMessage(e){if(!(this.isDestroying||!e))try{const t={_id:`${e.at||Date.now()}-${Math.random()}`,text:typeof(e==null?void 0:e.text)=="string"?e.text:(e==null?void 0:e.text)||"",at:e.at||new Date().toISOString(),senderId:e.senderId,self:!!(e.senderId&&e.senderId===this.socketId),senderInfo:e.senderInfo||null,deviceName:this.getDeviceName(e.senderInfo,e.senderId===this.socketId)};if(!t.text)return;this.messages.push(t),this.visible||this.unreadCount++,this.$nextTick(()=>{this.isDestroying||this.scrollToBottom()}),this.messages.length>500&&this.messages.shift()}catch(t){console.error("ChatWidget pushMessage 错误:",t)}},formatTime(e){try{const t=new Date(e),o=String(t.getHours()).padStart(2,"0"),d=String(t.getMinutes()).padStart(2,"0");return`${o}:${d}`}catch{return""}},scrollToBottom(){if(!this.isDestroying)try{const e=this.$refs.listRef;if(!e)return;requestAnimationFrame(()=>{!this.isDestroying&&e&&(e.scrollTop=e.scrollHeight)})}catch(e){console.warn("ChatWidget scrollToBottom 错误:",e)}},addEvent(e){if(!(this.isDestroying||!e))try{this.allEvents.unshift(e),e.type==="chat"||e.type==="chat:message"?this.eventStats.chat++:e.type==="kv-key-changed"?this.eventStats.kvChanged++:this.eventStats.other++,this.allEvents.length>200&&(this.allEvents=this.allEvents.slice(0,200))}catch(t){console.error("ChatWidget addEvent 错误:",t)}},getEventColor(e){switch(e){case"chat":case"chat:message":return"success";case"kv-key-changed":return"info";default:return"warning"}},getEventTypeLabel(e){switch(e){case"chat":case"chat:message":return"聊天";case"kv-key-changed":return"KV变化";default:return e}},formatDeviceInfo(e){return Z(e)},getDeviceName(e,t=!1){return t?"我":e?e.deviceName==="realtime"?"系统":e.deviceName||e.deviceType||"未知设备":"未知设备"},showUrgentNotification(e){try{this.$refs.urgentNotification?this.$refs.urgentNotification.show(e):console.warn("紧急通知组件未找到")}catch(t){console.error("显示紧急通知失败:",t)}}}},_e={class:"text-subtitle-1"},Ie={key:0,ref:"listRef",class:"messages"},Se={key:0,class:"divider-row"},we={class:"avatar"},xe={class:"bubble"},ke={key:0,class:"sender-name"},Ne={class:"text"},be={class:"meta"},Te={key:0,class:"device-name"},Ce={key:1,class:"events-container"},Ve={class:"event-stats mb-3"},Ee={class:"text-h6"},Me={class:"text-h6"},Ue={class:"text-h6"},$e={class:"events-list"},Re={class:"d-flex align-center mb-1"},Be={class:"text-caption"},Oe={key:0,class:"mb-1 text-caption"},Pe={class:"event-content"},ze={key:0,class:"chat-content"},Ae={key:1,class:"text-caption event-data"},Qe={key:0,class:"text-center text-grey pa-4"},Fe={key:0,class:"pagination mt-2"};function De(e,t,o,d,l,r){const I=z;return u(),m(k,null,[r.showToggleButton?(u(),m("div",{key:0,style:M(r.toggleStyle),class:"chat-toggle"},[i(_,{color:"primary",icon:"",variant:"flat",onClick:t[0]||(t[0]=n=>r.open())},{default:a(()=>[i(se,{content:l.unreadCount||void 0,"model-value":l.unreadCount>0,color:"error",overlap:""},{default:a(()=>[i(p,null,{default:a(()=>[...t[7]||(t[7]=[g(" mdi-chat ",-1)])]),_:1})]),_:1},8,["content","model-value"])]),_:1})],4)):y("",!0),L(c("div",{style:M(r.panelStyle),class:"chat-panel"},[i(S,{border:"",class:"chat-card",elevation:"8"},{default:a(()=>[i(W,{class:"d-flex align-center"},{default:a(()=>[i(p,{class:"mr-2"},{default:a(()=>[...t[8]||(t[8]=[g(" mdi-chat-processing ",-1)])]),_:1}),c("span",_e,f(r.modeTitle),1),i(E),i(j,{modelValue:l.currentMode,"onUpdate:modelValue":t[1]||(t[1]=n=>l.currentMode=n),class:"mr-2",mandatory:"",size:"small",variant:"outlined"},{default:a(()=>[i(_,{value:"chat",size:"small"},{default:a(()=>[i(p,null,{default:a(()=>[...t[9]||(t[9]=[g("mdi-chat",-1)])]),_:1})]),_:1}),i(_,{value:"events",size:"small"},{default:a(()=>[i(p,null,{default:a(()=>[...t[10]||(t[10]=[g("mdi-format-list-bulleted",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"]),i(ie,{location:"top"},{activator:a(({props:n})=>[i(C,J({color:l.connected?"success":"grey",size:"x-small"},n,{variant:"tonal"}),{default:a(()=>[g(f(l.connected?"已连接":"未连接"),1)]),_:1},16,["color"])]),default:a(()=>[c("span",null,"Socket "+f(l.socketId||"-"),1)]),_:1}),i(_,{icon:"",variant:"text",onClick:t[2]||(t[2]=n=>r.close())},{default:a(()=>[i(p,null,{default:a(()=>[...t[11]||(t[11]=[g("mdi-close",-1)])]),_:1})]),_:1})]),_:1}),i(b),i(w,{class:"chat-body"},{default:a(()=>[l.currentMode==="chat"?(u(),m("div",Ie,[(u(!0),m(k,null,U(r.decoratedMessages,n=>(u(),m(k,{key:n._id},[n._type==="divider"?(u(),m("div",Se,[i(b,{class:"my-2"}),t[12]||(t[12]=c("div",{class:"divider-text"}," 今天 - 上次访问 ",-1)),i(b,{class:"my-2"})])):(u(),m("div",{key:1,class:X([{self:n.self},"message-row"])},[c("div",we,[i(H,{color:n.self?"primary":"grey",size:"24"},{default:a(()=>[i(p,{size:"small"},{default:a(()=>[g(f(n.self?"mdi-account":"mdi-account-outline"),1)]),_:2},1024)]),_:2},1032,["color"])]),c("div",xe,[!n.self&&n.deviceName?(u(),m("div",ke,f(n.deviceName),1)):y("",!0),c("div",Ne,f(n.text),1),c("div",be,[n.self&&n.deviceName?(u(),m("span",Te,f(n.deviceName)+" • ",1)):y("",!0),g(" "+f(r.formatTime(n.at)),1)])])],2))],64))),128))],512)):(u(),m("div",Ce,[c("div",Ve,[i(ne,{dense:""},{default:a(()=>[i(T,{cols:"4"},{default:a(()=>[i(S,{color:"success",dark:"",size:"small"},{default:a(()=>[i(w,{class:"text-center pa-2"},{default:a(()=>[c("div",Ee,f(l.eventStats.chat),1),t[13]||(t[13]=c("div",{class:"text-caption"}," 聊天 ",-1))]),_:1})]),_:1})]),_:1}),i(T,{cols:"4"},{default:a(()=>[i(S,{color:"info",dark:"",size:"small"},{default:a(()=>[i(w,{class:"text-center pa-2"},{default:a(()=>[c("div",Me,f(l.eventStats.kvChanged),1),t[14]||(t[14]=c("div",{class:"text-caption"}," KV变化 ",-1))]),_:1})]),_:1})]),_:1}),i(T,{cols:"4"},{default:a(()=>[i(S,{color:"warning",dark:"",size:"small"},{default:a(()=>[i(w,{class:"text-center pa-2"},{default:a(()=>[c("div",Ue,f(l.eventStats.other),1),t[15]||(t[15]=c("div",{class:"text-caption"}," 其他 ",-1))]),_:1})]),_:1})]),_:1})]),_:1})]),c("div",$e,[(u(!0),m(k,null,U(r.paginatedEvents,n=>(u(),m("div",{key:n._id,class:"event-item mb-2"},[i(S,{color:r.getEventColor(n.type),size:"small",variant:"outlined"},{default:a(()=>[i(w,{class:"pa-2"},{default:a(()=>{var v;return[c("div",Re,[i(C,{color:r.getEventColor(n.type),size:"x-small"},{default:a(()=>[g(f(r.getEventTypeLabel(n.type)),1)]),_:2},1032,["color"]),i(E),c("span",Be,f(r.formatTime(n.timestamp||n.at)),1)]),n.senderInfo?(u(),m("div",Oe,[t[16]||(t[16]=c("strong",null,"发送者:",-1)),g(" "+f(r.formatDeviceInfo(n.senderInfo)),1)])):y("",!0),c("div",Pe,[n.type==="chat"||n.type==="chat:message"?(u(),m("div",ze,f(((v=n.content)==null?void 0:v.text)||n.text),1)):(u(),m("pre",Ae,f(JSON.stringify(n.content||n,null,1)),1))])]}),_:2},1024)]),_:2},1032,["color"])]))),128)),l.allEvents.length===0?(u(),m("div",Qe," 暂无事件 ")):y("",!0)]),r.totalPages>1?(u(),m("div",Fe,[i(oe,{modelValue:l.currentPage,"onUpdate:modelValue":t[3]||(t[3]=n=>l.currentPage=n),length:r.totalPages,"total-visible":3,size:"small"},null,8,["modelValue","length"])])):y("",!0)]))]),_:1}),l.currentMode==="chat"?(u(),$(b,{key:0})):y("",!0),l.currentMode==="chat"?(u(),$(q,{key:1,class:"chat-input"},{default:a(()=>[i(_,{class:"mr-1",icon:"",variant:"text",onClick:t[4]||(t[4]=n=>r.insertEmoji("😄"))},{default:a(()=>[i(p,null,{default:a(()=>[...t[17]||(t[17]=[g("mdi-emoticon-outline",-1)])]),_:1})]),_:1}),i(re,{ref:"inputRef",modelValue:l.text,"onUpdate:modelValue":t[5]||(t[5]=n=>l.text=n),"auto-grow":"",class:"flex-grow-1","hide-details":"",placeholder:"输入消息",rows:"1",variant:"solo",onKeydown:[R(B(r.handleEnter,["prevent"]),["enter"]),t[6]||(t[6]=R(B(()=>{},["shift","stop"]),["enter"]))]},null,8,["modelValue","onKeydown"]),i(_,{disabled:!r.canSend,class:"ml-2",color:"primary",onClick:r.send},{default:a(()=>[i(p,{start:""},{default:a(()=>[...t[18]||(t[18]=[g(" mdi-send ",-1)])]),_:1}),t[19]||(t[19]=g(" 发送 ",-1))]),_:1},8,["disabled","onClick"])]),_:1})):y("",!0)]),_:1})],4),[[G,l.visible]]),i(I,{ref:"urgentNotification"},null,512)],64)}const Ke=V(ye,[["render",De],["__scopeId","data-v-1a62ac2a"]]),et=Object.freeze(Object.defineProperty({__proto__:null,default:Ke},Symbol.toStringTag,{value:"Module"}));export{et as C,P as _,Ke as a};