Files
aiot-platform-ui/apps/web-antd/dist/js/index-BIsei1VN.js
lzh afa6949ff1
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 8s
chore: build and deploy web-antd
2026-01-26 16:16:37 +08:00

2 lines
5.8 KiB
JavaScript

var z=(C,B,c)=>new Promise((v,r)=>{var S=o=>{try{p(c.next(o))}catch(g){r(g)}},I=o=>{try{p(c.throw(o))}catch(g){r(g)}},p=o=>o.done?v(o.value):Promise.resolve(o.value).then(S,I);p((c=c.apply(C,B)).next())});import{a5 as K,au as O,aL as $,bD as D,ay as U,ca as Q,bT as T,an as E,cF as L,bE as X,a9 as k}from"./bootstrap-CjlLFctT.js";import{m as Y,b9 as y,aa as w,dE as Z,bF as ee,v as se,ab as h,b2 as i,bJ as l,ae as a,j as n,u as t,ai as f,bp as d,ad as b,I as J,bb as M,ac as R,cB as te}from"../jse/index-index-muiiV4cL.js";import{g as ae}from"./index-tReKF1Mp.js";import{A as j}from"./index-EsemDJmm.js";import{_ as le}from"./doc-alert.vue_vue_type_script_setup_true_lang-CibcfA4T.js";import{_ as ne}from"./page.vue_vue_type_script_setup_true_lang-Co1UjCR-.js";const oe={class:"mt-4 flex flex-col gap-4 md:flex-row"},re={class:"flex items-center"},ue={class:"mb-4 flex items-center rounded-lg p-3"},ie={class:"mb-6 flex space-x-2"},de={class:"flex items-center"},ce={class:"flex items-center"},me={class:"flex items-center"},fe={class:"h-96 overflow-auto rounded-lg p-2"},ve={key:1,class:"space-y-3"},pe={class:"mb-1 flex items-center justify-between"},ge={class:"flex items-center"},xe={class:"ml-1 font-medium text-gray-600"},ye={key:0,class:"ml-2 text-gray-500"},be={class:"text-xs text-gray-400"},_e={class:"mt-2 break-words text-gray-800"},Be=Y({__name:"index",setup(C){const c=K().refreshToken,v=y(`${"/admin-api/infra/ws".replace("http","ws")}?token=${c}`),r=w(()=>p.value==="OPEN"),S=w(()=>r.value?"success":"red"),I=w(()=>r.value?"已连接":"未连接"),{status:p,data:o,send:g,close:A,open:V}=Z(v.value,{autoReconnect:!0,heartbeat:!0}),m=y([]),F=w(()=>[...m.value].toReversed());ee(()=>{if(o.value)try{if(o.value==="pong")return;const u=JSON.parse(o.value),e=u.type,s=JSON.parse(u.content);if(!e){k.error(`未知的消息类型:${o.value}`);return}if(e==="demo-message-receive"){const H=s.single;m.value.push({text:s.text,time:Date.now(),type:H?"single":"group",userId:s.fromUserId});return}if(e==="notice-push"){m.value.push({text:s.title,time:Date.now(),type:"system"});return}k.error(`未处理消息:${o.value}`)}catch(u){k.error(`处理消息发生异常:${o.value}`),console.error(u)}});const x=y(""),_=y("all");function W(){if(!x.value.trim()){k.warning("消息内容不能为空");return}const u=JSON.stringify({text:x.value,toUserId:_.value==="all"?void 0:_.value}),e=JSON.stringify({type:"demo-message-send",content:u});g(e),x.value=""}function P(){r.value?A():V()}function q(u){switch(u){case"group":return"green";case"single":return"blue";case"system":return"red";default:return"default"}}function G(u){switch(u){case"group":return"群发";case"single":return"单发";case"system":return"系统";default:return"未知"}}const N=y([]);return se(()=>z(null,null,function*(){N.value=yield ae()})),(u,e)=>(i(),h(t(ne),null,{doc:l(()=>[n(t(le),{title:"WebSocket 实时通信",url:"https://doc.iocoder.cn/websocket/"})]),default:l(()=>[a("div",oe,[n(t(O),{bordered:!1,class:"w-full md:w-1/2"},{title:l(()=>[a("div",re,[n(t(L),{status:r.value?"success":"error"},null,8,["status"]),e[3]||(e[3]=a("span",{class:"ml-2 text-lg font-medium"},"连接管理",-1))])]),default:l(()=>[a("div",ue,[e[4]||(e[4]=a("span",{class:"mr-4 font-medium"},"连接状态:",-1)),n(t($),{color:S.value,class:"px-3 py-1"},{default:l(()=>[f(d(I.value),1)]),_:1},8,["color"])]),a("div",ie,[n(t(D),{value:v.value,"onUpdate:value":e[0]||(e[0]=s=>v.value=s),disabled:"",class:"rounded-md",size:"large"},{addonBefore:l(()=>[...e[5]||(e[5]=[a("span",{class:"text-gray-600"},"服务地址",-1)])]),_:1},8,["value"]),n(t(U),{type:r.value?"default":"primary",danger:r.value,size:"large",class:"flex-shrink-0",onClick:P},{default:l(()=>[f(d(r.value?"关闭连接":"开启连接"),1)]),_:1},8,["type","danger"])]),n(t(Q),null,{default:l(()=>[...e[6]||(e[6]=[a("span",{class:"text-gray-500"},"消息发送",-1)])]),_:1}),n(t(T),{value:_.value,"onUpdate:value":e[1]||(e[1]=s=>_.value=s),class:"mb-3 w-full",size:"large",placeholder:"请选择接收人",disabled:!r.value},{default:l(()=>[n(t(T).Option,{key:"",value:"",label:"所有人"},{default:l(()=>[a("div",de,[n(t(j),{size:"small",class:"mr-2"},{default:l(()=>[...e[7]||(e[7]=[f("全",-1)])]),_:1}),e[8]||(e[8]=a("span",null,"所有人",-1))])]),_:1}),(i(!0),b(J,null,M(N.value,s=>(i(),h(t(T).Option,{key:s.id,value:s.id,label:s.nickname},{default:l(()=>[a("div",ce,[n(t(j),{size:"small",class:"mr-2"},{default:l(()=>[f(d(s.nickname.slice(0,1)),1)]),_:2},1024),a("span",null,d(s.nickname),1)])]),_:2},1032,["value","label"]))),128))]),_:1},8,["value","disabled"]),n(t(D).TextArea,{value:x.value,"onUpdate:value":e[2]||(e[2]=s=>x.value=s),"auto-size":{minRows:3,maxRows:6},disabled:!r.value,class:"border-1 rounded-lg","allow-clear":"",placeholder:"请输入你要发送的消息..."},null,8,["value","disabled"]),n(t(U),{disabled:!r.value,block:"",class:"mt-4",type:"primary",size:"large",onClick:W},{icon:l(()=>[n(t(E),{icon:"lucide:send-horizontal"})]),default:l(()=>[e[9]||(e[9]=f(" 发送消息 ",-1))]),_:1},8,["disabled"])]),_:1}),n(t(O),{bordered:!1,class:"w-full md:w-1/2"},{title:l(()=>[a("div",me,[n(t(E),{icon:"lucide:message-circle-more",class:"mr-2 text-lg"}),e[10]||(e[10]=a("span",{class:"text-lg font-medium"},"消息记录",-1)),m.value.length>0?(i(),h(t($),{key:0,class:"ml-2"},{default:l(()=>[f(d(m.value.length)+" 条 ",1)]),_:1})):R("",!0)])]),default:l(()=>[a("div",fe,[m.value.length===0?(i(),h(t(X),{key:0,description:"暂无消息记录"})):(i(),b("div",ve,[(i(!0),b(J,null,M(F.value,s=>(i(),b("div",{key:s.time,class:"rounded-lg p-3 shadow-sm"},[a("div",pe,[a("div",ge,[n(t(L),{color:q(s.type)},null,8,["color"]),a("span",xe,d(G(s.type)),1),s.userId?(i(),b("span",ye," 用户 ID: "+d(s.userId),1)):R("",!0)]),a("span",be,d(t(te)(s.time)),1)]),a("div",_e,d(s.text),1)]))),128))]))])]),_:1})])]),_:1}))}});export{Be as default};