mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2026-03-21 09:13:10 +00:00
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import{_ as O,a as L}from"./ChatWidget-DYJheQfy.js";import{a as S}from"./socketClient-BSmNJE3a.js";import{d as N}from"./dataProvider-CpnSKNsN.js";import{_ as W,e as h,f as I,g as V,h as v,d as y,l as w,c as T,p as j,q,k as b}from"./index-C2sjQt3C.js";import{b as E,c as A}from"./VAppBarTitle-BsRcxoV-.js";import{V as K}from"./VContainer-BmJzhuEQ.js";import{V as F,a as x}from"./VRow-CqS1TlWE.js";import{V as M}from"./VForm-DRusiccZ.js";import{V as P}from"./VSwitch-DQAKeiDM.js";import{V as R}from"./VCheckbox-F53ln6pg.js";import{V as z}from"./VTextarea-CMU_B0UR.js";import{X as f,Y as D,Z as s,j as t,a1 as a,S as u,_,F as U,a2 as k,k as m}from"./vendor-vue-PFj_oO9L.js";import"./soundList-D9U-Grcp.js";import"./VChip-C5r6iPJT.js";import"./vendor-vuetify-DYDJMXkZ.js";import"./deviceEvents-cuIYx-Nf.js";import"./VTooltip-BO-8gBVl.js";import"./VPagination-DnXH8YU9.js";import"./vendor-socket-CyTcV1HU.js";import"./serverRotation-DZGX69ae.js";import"./vendor-utils-DDRLRfsI.js";import"./VTextField-DVKvT3Uf.js";import"./VCheckboxBtn-DU7_gUCF.js";const X={name:"UrgentTestDialog",components:{ChatWidget:L,EventSender:O},props:{modelValue:{type:Boolean,default:!1}},emits:["update:modelValue"],data(){return{sending:!1,notificationForm:{isUrgent:!1,message:"",isPersistent:!1},sentMessages:[],receiptCleanup:[],persistentNotifications:[],editDialog:!1,editForm:{id:null,message:"",isUrgent:!1,resend:!1},savingEdit:!1,deleteConfirmDialog:!1,itemToDelete:null}},computed:{dialog:{get(){return this.modelValue},set(i){this.$emit("update:modelValue",i)}}},mounted(){this.setupEventListeners(),this.loadPersistentNotifications()},beforeUnmount(){this.cleanup()},methods:{generateNotificationId(){const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let e="";for(let l=0;l<32;l++)e+=i.charAt(Math.floor(Math.random()*i.length));return e},async sendNotification(){if(this.notificationForm.message.trim()){this.sending=!0;try{const i=this.generateNotificationId(),e=this.notificationForm.message,l=this.notificationForm.isUrgent,c=this.notificationForm.isPersistent,o=await this.$refs.eventSender.sendNotification(e,l,[],{deviceName:"测试设备",deviceType:"system",isReadOnly:!1},i),r=(o==null?void 0:o.eventId)||`msg-${Date.now()}`;if(this.sentMessages.push({id:r,notificationId:i,message:e,isUrgent:l,timestamp:new Date().toISOString(),receipts:{displayed:[],read:[]}}),c)try{const p="notification-list",g=await N.loadData(p);let n=[];g&&Array.isArray(g)?n=g:g&&g.success!==!1&&Array.isArray(g.data)&&(n=g.data);const d={id:i,message:e,isUrgent:l,timestamp:new Date().toISOString()};n.unshift(d),await N.saveData(p,n),this.persistentNotifications=n,console.log("常驻通知已保存")}catch(p){console.error("保存常驻通知失败",p)}console.log("通知已发送,事件ID:",r,"通知ID:",i),this.resetForm()}catch(i){console.error("发送通知失败:",i)}finally{this.sending=!1}}},resetForm(){this.notificationForm={isUrgent:!1,message:"",isPersistent:!1}},close(){this.dialog=!1},setupEventListeners(){const i=S("notification-displayed",l=>{console.log("收到显示回执:",l),this.updateReceipt(l,"displayed")}),e=S("notification-read",l=>{console.log("收到已读回执:",l),this.updateReceipt(l,"read")});this.receiptCleanup.push(i,e)},updateReceipt(i,e){var r,p,g,n,d;const l=i.originalEventId,c=i.notificationId||((r=i.content)==null?void 0:r.notificationId);if(!l&&!c)return;const o=this.sentMessages.find(C=>C.id===l||C.notificationId===c);if(o){const C={senderId:i.senderId||"unknown-sender",deviceName:((p=i.senderInfo)==null?void 0:p.deviceName)||((g=i.deviceInfo)==null?void 0:g.deviceName)||"未知设备",deviceType:((n=i.senderInfo)==null?void 0:n.deviceType)||((d=i.deviceInfo)==null?void 0:d.deviceType)||"unknown",timestamp:new Date().toISOString()};o.receipts[e].find(B=>B.senderId===C.senderId)||(o.receipts[e].push(C),console.log(`更新${e}回执:`,o.id,C))}},cleanup(){this.receiptCleanup.forEach(i=>i()),this.receiptCleanup=[]},formatTime(i){return new Date(i).toLocaleString("zh-CN")},getReceiptStatus(i){return i.read.length>0?"已读":i.displayed.length>0?"已显示":"已发送"},getReceiptColor(i){return i.read.length>0?"success":i.displayed.length>0?"info":"grey"},formatDeviceTime(i){return new Date(i).toLocaleTimeString("zh-CN")},getMainCardColor(i){return i.read.length>0?"success":i.displayed.length>0?"info":"grey"},hasAnyReceipts(i){return i.read.length>0||i.displayed.length>0},getDisplayedOnlyDevices(i){const e=i.read.map(l=>l.senderId);return i.displayed.filter(l=>!e.includes(l.senderId))},openEditDialog(i){this.editForm={id:i.id,message:i.message,isUrgent:i.isUrgent||!1,resend:!1,timestamp:i.timestamp},this.editDialog=!0},async saveEdit(){var i,e;if(this.editForm.message.trim()){this.savingEdit=!0;try{const l=this.persistentNotifications.findIndex(c=>c.id===this.editForm.id);if(l!==-1){if(this.persistentNotifications[l]={...this.persistentNotifications[l],message:this.editForm.message,isUrgent:this.editForm.isUrgent,timestamp:new Date().toISOString()},await N.saveData("notification-list",this.persistentNotifications),this.editForm.resend){const c=this.editForm.id,o=this.editForm.message,r=this.editForm.isUrgent,p=await this.$refs.eventSender.sendNotification(o,r,[],{deviceName:"测试设备",deviceType:"system",isReadOnly:!1},c),g=(p==null?void 0:p.eventId)||`msg-${Date.now()}`;this.sentMessages.push({id:g,notificationId:c,message:o,isUrgent:r,timestamp:new Date().toISOString(),receipts:{displayed:[],read:[]}})}this.editDialog=!1,(i=this.$message)==null||i.success("已更新")}}catch(l){console.error("保存失败",l),(e=this.$message)==null||e.error("保存失败")}finally{this.savingEdit=!1}}},async loadPersistentNotifications(){try{const i=await N.loadData("notification-list");i&&Array.isArray(i)?this.persistentNotifications=i:i&&i.success!==!1&&Array.isArray(i.data)?this.persistentNotifications=i.data:this.persistentNotifications=[]}catch(i){console.error("加载常驻通知失败",i)}},async deleteNotification(i){if(confirm("确定要删除这个通知吗?"))try{this.sentMessages=this.sentMessages.filter(l=>l.id!==i),this.persistentNotifications=this.persistentNotifications.filter(l=>l.id!==i),console.log("通知已删除,通知ID:",i)}catch(l){console.error("删除通知失败:",l)}},deletePersistentNotification(i){this.itemToDelete=i,this.deleteConfirmDialog=!0},async executeDelete(){var e,l;if(!this.itemToDelete)return;const i=this.itemToDelete;this.deleteConfirmDialog=!1,this.itemToDelete=null;try{this.persistentNotifications=this.persistentNotifications.filter(o=>o.id!==i);const c=this.persistentNotifications.length>0?this.persistentNotifications:{};await N.saveData("notification-list",c),(e=this.$message)==null||e.success("已删除")}catch(c){console.error("删除失败",c),(l=this.$message)==null||l.error("删除失败")}}}},Y={key:0,class:"text-center text-grey py-4"},Z={key:0,class:"text-center text-grey py-8"},G={class:"d-flex align-center mb-2"},H={class:"font-weight-medium"},J={class:"text-caption font-weight-medium"},Q={class:"text-body-2 mb-3",style:{"max-height":"60px",overflow:"hidden"}},$={class:"text-caption"},ee={key:0},te={class:"align-center"},ie={class:"text-body-2 font-weight-medium"},se={class:"text-caption mt-1"},ne={class:"align-center"},oe={class:"text-body-2 font-weight-medium"},le={class:"text-caption text-grey"},re={class:"text-caption text-grey mt-1"},ae={key:1};function de(i,e,l,c,o,r){const p=L,g=O;return f(),D(b,{modelValue:r.dialog,"onUpdate:modelValue":e[11]||(e[11]=n=>r.dialog=n),fullscreen:"",transition:"dialog-bottom-transition",scrollable:""},{default:s(()=>[t(h,null,{default:s(()=>[t(E,{dark:"",flat:""},{default:s(()=>[t(A,null,{default:s(()=>[t(I,{class:"mr-2"},{default:s(()=>[...e[12]||(e[12]=[a(" mdi-chat ",-1)])]),_:1}),e[13]||(e[13]=a(" 发送通知 ",-1))]),_:1}),t(V),t(v,{icon:"mdi-close",onClick:r.close},null,8,["onClick"])]),_:1}),t(y,{class:"pa-0"},{default:s(()=>[t(K,null,{default:s(()=>[t(F,null,{default:s(()=>[t(x,{cols:"12"},{default:s(()=>[t(h,null,{default:s(()=>[t(y,null,{default:s(()=>[t(M,null,{default:s(()=>[t(F,null,{default:s(()=>[t(x,{cols:"12",md:"6"},{default:s(()=>[t(P,{modelValue:o.notificationForm.isUrgent,"onUpdate:modelValue":e[0]||(e[0]=n=>o.notificationForm.isUrgent=n),label:"强调通知",color:"red",inset:""},null,8,["modelValue"]),t(R,{modelValue:o.notificationForm.isPersistent,"onUpdate:modelValue":e[1]||(e[1]=n=>o.notificationForm.isPersistent=n),label:"常驻展示",color:"primary","hide-details":"",class:"mt-0"},null,8,["modelValue"])]),_:1}),t(x,{cols:"12"},{default:s(()=>[t(z,{modelValue:o.notificationForm.message,"onUpdate:modelValue":e[2]||(e[2]=n=>o.notificationForm.message=n),label:"通知内容",outlined:"",rows:"3",placeholder:"请输入强调通知的内容..."},null,8,["modelValue"])]),_:1})]),_:1})]),_:1})]),_:1}),t(w,{class:"px-6 pb-6"},{default:s(()=>[t(v,{color:o.notificationForm.isUrgent?"red":"blue",disabled:!o.notificationForm.message.trim(),loading:o.sending,size:"large",variant:"elevated",onClick:r.sendNotification},{default:s(()=>[t(I,{left:""},{default:s(()=>[a(u(o.notificationForm.isUrgent?"mdi-alert-circle":"mdi-information"),1)]),_:1}),a(" "+u(o.notificationForm.isUrgent?"发送强调通知":"发送通知"),1)]),_:1},8,["color","disabled","loading","onClick"]),t(V)]),_:1})]),_:1})]),_:1})]),_:1}),t(F,{class:"mt-4"},{default:s(()=>[t(x,{cols:"12"},{default:s(()=>[t(h,null,{default:s(()=>[t(T,null,{default:s(()=>[t(I,{class:"mr-2"},{default:s(()=>[...e[14]||(e[14]=[a("mdi-pin",-1)])]),_:1}),e[15]||(e[15]=a(" 常驻通知管理 ",-1))]),_:1}),t(y,null,{default:s(()=>[o.persistentNotifications.length===0?(f(),_("div",Y," 暂无常驻通知 ")):(f(),D(j,{key:1},{default:s(()=>[(f(!0),_(U,null,k(o.persistentNotifications,n=>(f(),D(q,{key:n.id,title:n.message,subtitle:r.formatTime(n.timestamp),lines:"two"},{prepend:s(()=>[t(I,{color:n.isUrgent?"error":"primary"},{default:s(()=>[a(u(n.isUrgent?"mdi-alert-circle":"mdi-information"),1)]),_:2},1032,["color"])]),append:s(()=>[t(v,{icon:"mdi-pencil",variant:"text",size:"small",onClick:d=>r.openEditDialog(n)},null,8,["onClick"]),t(v,{icon:"mdi-delete",variant:"text",color:"error",size:"small",onClick:d=>r.deletePersistentNotification(n.id)},null,8,["onClick"])]),_:2},1032,["title","subtitle"]))),128))]),_:1}))]),_:1})]),_:1})]),_:1})]),_:1}),t(F,{class:"mt-4"},{default:s(()=>[t(x,{cols:"12"},{default:s(()=>[t(h,null,{default:s(()=>[t(T,null,{default:s(()=>[t(I,{class:"mr-2"},{default:s(()=>[...e[16]||(e[16]=[a(" mdi-history ",-1)])]),_:1}),e[17]||(e[17]=a(" 消息记录 ",-1)),t(V)]),_:1}),t(y,null,{default:s(()=>[o.sentMessages.length===0?(f(),_("div",Z,[t(I,{size:"64",color:"grey-lighten-2"},{default:s(()=>[...e[18]||(e[18]=[a(" mdi-message-outline ",-1)])]),_:1}),e[19]||(e[19]=m("div",{class:"mt-2"}," 暂无发送记录 ",-1))])):(f(),D(F,{key:1},{default:s(()=>[(f(!0),_(U,null,k(o.sentMessages.slice().reverse(),n=>(f(),D(x,{key:n.id,cols:"12",md:"6",lg:"4"},{default:s(()=>[t(h,{color:r.getMainCardColor(n.receipts),class:"mb-2"},{default:s(()=>[t(y,null,{default:s(()=>[m("div",G,[m("span",H,u(n.isUrgent?"强调通知":"通知"),1),t(V),m("span",J,u(r.getReceiptStatus(n.receipts)),1)]),m("div",Q,u(n.message),1),m("div",$,[m("div",null,"发送时间:"+u(r.formatTime(n.timestamp)),1),m("div",null,"事件ID:"+u(n.id),1),m("div",null,"通知ID:"+u(n.notificationId),1)])]),_:2},1024)]),_:2},1032,["color"]),r.hasAnyReceipts(n.receipts)?(f(),_("div",ee,[(f(!0),_(U,null,k(n.receipts.read,d=>(f(),D(h,{key:`${d.senderId}-read`,color:"success",class:"mb-1",size:"small"},{default:s(()=>[t(y,{class:"pa-2"},{default:s(()=>[m("div",te,[m("span",ie,u(d.deviceName),1),e[20]||(e[20]=m("br",null,null,-1)),a(" "+u(d.deviceType),1)]),m("div",se," 已读于 "+u(r.formatDeviceTime(d.timestamp)),1)]),_:2},1024)]),_:2},1024))),128)),(f(!0),_(U,null,k(r.getDisplayedOnlyDevices(n.receipts),d=>(f(),D(h,{key:`${d.senderId}-displayed`,color:"info-lighten-4",variant:"outlined",class:"mb-1",size:"small"},{default:s(()=>[t(y,{class:"pa-2"},{default:s(()=>[m("div",ne,[m("span",oe,u(d.deviceName),1),t(V),m("span",le,u(d.deviceType=="classroom"?"教室设备上的应用":d.deviceType),1)]),m("div",re," 已显示于 "+u(r.formatDeviceTime(d.timestamp)),1)]),_:2},1024)]),_:2},1024))),128))])):(f(),_("div",ae,[t(h,{color:"info-lighten-4",variant:"outlined",class:"mb-1",size:"small",title:"无设备在线"},{default:s(()=>[t(y,null,{default:s(()=>[...e[21]||(e[21]=[a(" 如果数秒后任然显示这个提示,则可能没有任何设备在线接收通知。 ",-1)])]),_:1})]),_:1})]))]),_:2},1024))),128))]),_:1}))]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})]),_:1}),t(p),t(g,{ref:"eventSender"},null,512),t(b,{modelValue:o.editDialog,"onUpdate:modelValue":e[8]||(e[8]=n=>o.editDialog=n),"max-width":"500",fullscreen:i.$vuetify.display.xs},{default:s(()=>[t(h,null,{default:s(()=>[t(E,{flat:"",density:"compact"},{default:s(()=>[t(A,null,{default:s(()=>[...e[22]||(e[22]=[a("编辑常驻通知",-1)])]),_:1}),t(V),t(v,{icon:"mdi-close",onClick:e[3]||(e[3]=n=>o.editDialog=!1)})]),_:1}),t(y,null,{default:s(()=>[t(M,null,{default:s(()=>[t(z,{modelValue:o.editForm.message,"onUpdate:modelValue":e[4]||(e[4]=n=>o.editForm.message=n),label:"通知内容",rows:"3","auto-grow":""},null,8,["modelValue"]),t(P,{modelValue:o.editForm.isUrgent,"onUpdate:modelValue":e[5]||(e[5]=n=>o.editForm.isUrgent=n),label:"强调通知",color:"error","hide-details":""},null,8,["modelValue"]),t(R,{modelValue:o.editForm.resend,"onUpdate:modelValue":e[6]||(e[6]=n=>o.editForm.resend=n),label:"保存并重新发送通知",hint:"勾选后将作为新通知发送给所有在线设备","persistent-hint":""},null,8,["modelValue"])]),_:1})]),_:1}),t(w,null,{default:s(()=>[t(V),t(v,{variant:"text",onClick:e[7]||(e[7]=n=>o.editDialog=!1)},{default:s(()=>[...e[23]||(e[23]=[a("取消",-1)])]),_:1}),t(v,{color:"primary",loading:o.savingEdit,onClick:r.saveEdit},{default:s(()=>[...e[24]||(e[24]=[a("保存",-1)])]),_:1},8,["loading","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue","fullscreen"]),t(b,{modelValue:o.deleteConfirmDialog,"onUpdate:modelValue":e[10]||(e[10]=n=>o.deleteConfirmDialog=n),"max-width":"400"},{default:s(()=>[t(h,null,{default:s(()=>[t(T,{class:"text-h5"},{default:s(()=>[...e[25]||(e[25]=[a("确认删除",-1)])]),_:1}),t(y,null,{default:s(()=>[...e[26]||(e[26]=[a("确定要删除这条常驻通知吗?此操作无法撤销。",-1)])]),_:1}),t(w,null,{default:s(()=>[t(V),t(v,{color:"grey-darken-1",variant:"text",onClick:e[9]||(e[9]=n=>o.deleteConfirmDialog=!1)},{default:s(()=>[...e[27]||(e[27]=[a("取消",-1)])]),_:1}),t(v,{color:"error",variant:"text",onClick:r.executeDelete},{default:s(()=>[...e[28]||(e[28]=[a("删除",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1},8,["modelValue"])}const Ae=W(X,[["render",de],["__scopeId","data-v-c6850940"]]);export{Ae as default};
|