var C=Object.defineProperty,I=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var y=(t,e,a)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,F=(t,e)=>{for(var a in e||(e={}))V.call(e,a)&&y(t,a,e[a]);if(k)for(var a of k(e))L.call(e,a)&&y(t,a,e[a]);return t},w=(t,e)=>I(t,E(e));import{d as O,r as S,h,e as g,I as x,U as r,a2 as v,ad as N,af as u,a4 as s,k as l,G as d,a5 as p,a3 as A,ae as P,F as W}from"./vue-vendor-CxLCUzY4.js";import{Y as _,j as T}from"./antd-vue-vendor-CahNzUUa.js";import{P as $}from"./index-D55rh6hR.js";import{b4 as U,aQ as M,_ as R}from"./index-CLZzJyTP.js";import"./useContentHeight-DLfJuPsF.js";import"./useWindowSizeFn-D9PllI8g.js";import"./vxe-table-vendor-Cdi8WfTx.js";import"./useContentViewHeight-BIb_dTbE.js";import"./usePageContext-FyDvfV_K.js";import"./injectionKey-DPVn4AgL.js";const j=O({components:{PageWrapper:$,[T.name]:T,InputTextArea:T.TextArea,Tag:_},setup(){const t=S({server:"ws://localhost:3300/test",sendValue:"",recordList:[]}),{status:e,data:a,send:b,close:D,open:B}=U(t.server,{autoReconnect:!1,heartbeat:!0});h(()=>{if(a.value)try{const o=JSON.parse(a.value);t.recordList.push(o)}catch(o){t.recordList.push({res:a.value,id:Math.ceil(Math.random()*1e3),time:new Date().getTime()})}});const n=g(()=>e.value==="OPEN"),m=g(()=>n.value?"success":"red"),i=g(()=>[...t.recordList].reverse());function f(){b(t.sendValue),t.sendValue=""}function c(){n.value?D():B()}return w(F({status:e,formatToDateTime:M},x(t)),{handlerSend:f,getList:i,toggle:c,getIsOpen:n,getTagColor:m})}}),G={class:"flex"},J={class:"w-1/3 bg-white p-4"},Q={class:"flex items-center"},Y={class:"flex"},q={class:"w-2/3 bg-white ml-4 p-4"},z={class:"max-h-80 overflow-auto"},H={class:"flex items-center"};function K(t,e,a,b,D,B){const n=r("Tag"),m=r("a-input"),i=r("a-button"),f=r("InputTextArea"),c=r("PageWrapper");return v(),N(c,{title:"WebSocket 示例"},{default:u(()=>[s("div",G,[s("div",J,[s("div",Q,[e[2]||(e[2]=s("span",{class:"text-lg font-medium mr-4"}," 连接状态: ",-1)),l(n,{color:t.getTagColor},{default:u(()=>[d(p(t.status),1)]),_:1},8,["color"])]),e[5]||(e[5]=s("hr",{class:"my-4"},null,-1)),s("div",Y,[l(m,{value:t.server,"onUpdate:value":e[0]||(e[0]=o=>t.server=o),disabled:""},{addonBefore:u(()=>e[3]||(e[3]=[d(" 服务地址 ")])),_:1},8,["value"]),l(i,{type:t.getIsOpen?"danger":"primary",onClick:t.toggle},{default:u(()=>[d(p(t.getIsOpen?"关闭连接":"开启连接"),1)]),_:1},8,["type","onClick"])]),e[6]||(e[6]=s("p",{class:"text-lg font-medium mt-4"},"设置",-1)),e[7]||(e[7]=s("hr",{class:"my-4"},null,-1)),l(f,{placeholder:"需要发送到服务器的内容",disabled:!t.getIsOpen,value:t.sendValue,"onUpdate:value":e[1]||(e[1]=o=>t.sendValue=o),allowClear:""},null,8,["disabled","value"]),l(i,{type:"primary",block:"",class:"mt-4",disabled:!t.getIsOpen,onClick:t.handlerSend},{default:u(()=>e[4]||(e[4]=[d(" 发送 ")])),_:1},8,["disabled","onClick"])]),s("div",q,[e[9]||(e[9]=s("span",{class:"text-lg font-medium mr-4"}," 消息记录: ",-1)),e[10]||(e[10]=s("hr",{class:"my-4"},null,-1)),s("div",z,[s("ul",null,[(v(!0),A(W,null,P(t.getList,o=>(v(),A("li",{class:"mt-2",key:o.time},[s("div",H,[e[8]||(e[8]=s("span",{class:"mr-2 text-primary font-medium"},"收到消息:",-1)),s("span",null,p(t.formatToDateTime(o.time)),1)]),s("div",null,p(o.res),1)]))),128))])])])])]),_:1})}const ie=R(j,[["render",K]]);export{ie as default};
