Files

2 lines
8.5 KiB
JavaScript

import{c,I as P,k as I,r as m,o as T,a as U,b as f,d as a,w as s,j as g,g as i,f as y,u as v,h as d,e as M,t as z,R as G,q as J}from"./index.js";import{D as C}from"./DesktopOutlined.js";var Q={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"defs",attrs:{},children:[{tag:"style",attrs:{}}]},{tag:"path",attrs:{d:"M326 664H104c-8.8 0-16 7.2-16 16v48c0 8.8 7.2 16 16 16h174v176c0 8.8 7.2 16 16 16h48c8.8 0 16-7.2 16-16V696c0-17.7-14.3-32-32-32zm16-576h-48c-8.8 0-16 7.2-16 16v176H104c-8.8 0-16 7.2-16 16v48c0 8.8 7.2 16 16 16h222c17.7 0 32-14.3 32-32V104c0-8.8-7.2-16-16-16zm578 576H698c-17.7 0-32 14.3-32 32v224c0 8.8 7.2 16 16 16h48c8.8 0 16-7.2 16-16V744h174c8.8 0 16-7.2 16-16v-48c0-8.8-7.2-16-16-16zm0-384H746V104c0-8.8-7.2-16-16-16h-48c-8.8 0-16 7.2-16 16v224c0 17.7 14.3 32 32 32h222c8.8 0 16-7.2 16-16v-48c0-8.8-7.2-16-16-16z"}}]},name:"compress",theme:"outlined"};function $(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?Object(arguments[e]):{},l=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(l=l.concat(Object.getOwnPropertySymbols(t).filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable}))),l.forEach(function(o){W(n,o,t[o])})}return n}function W(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}var E=function(e,t){var l=$({},e,t.attrs);return c(P,$({},l,{icon:Q}),null)};E.displayName="CompressOutlined";E.inheritAttrs=!1;var X={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M832.6 191.4c-84.6-84.6-221.5-84.6-306 0l-96.9 96.9 51 51 96.9-96.9c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204l-96.9 96.9 51.1 51.1 96.9-96.9c84.4-84.6 84.4-221.5-.1-306.1zM446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l96.9-96.9-51.1-51.1-96.9 96.9c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l96.9-96.9-51-51-96.8 97zM260.3 209.4a8.03 8.03 0 00-11.3 0L209.4 249a8.03 8.03 0 000 11.3l554.4 554.4c3.1 3.1 8.2 3.1 11.3 0l39.6-39.6c3.1-3.1 3.1-8.2 0-11.3L260.3 209.4z"}}]},name:"disconnect",theme:"outlined"};function H(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?Object(arguments[e]):{},l=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(l=l.concat(Object.getOwnPropertySymbols(t).filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable}))),l.forEach(function(o){Y(n,o,t[o])})}return n}function Y(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}var k=function(e,t){var l=H({},e,t.attrs);return c(P,H({},l,{icon:X}),null)};k.displayName="DisconnectOutlined";k.inheritAttrs=!1;var Z={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"defs",attrs:{},children:[{tag:"style",attrs:{}}]},{tag:"path",attrs:{d:"M342 88H120c-17.7 0-32 14.3-32 32v224c0 8.8 7.2 16 16 16h48c8.8 0 16-7.2 16-16V168h174c8.8 0 16-7.2 16-16v-48c0-8.8-7.2-16-16-16zm578 576h-48c-8.8 0-16 7.2-16 16v176H682c-8.8 0-16 7.2-16 16v48c0 8.8 7.2 16 16 16h222c17.7 0 32-14.3 32-32V680c0-8.8-7.2-16-16-16zM342 856H168V680c0-8.8-7.2-16-16-16h-48c-8.8 0-16 7.2-16 16v224c0 17.7 14.3 32 32 32h222c8.8 0 16-7.2 16-16v-48c0-8.8-7.2-16-16-16zM904 88H682c-8.8 0-16 7.2-16 16v48c0 8.8 7.2 16 16 16h174v176c0 8.8 7.2 16 16 16h48c8.8 0 16-7.2 16-16V120c0-17.7-14.3-32-32-32z"}}]},name:"expand",theme:"outlined"};function L(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?Object(arguments[e]):{},l=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(l=l.concat(Object.getOwnPropertySymbols(t).filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable}))),l.forEach(function(o){K(n,o,t[o])})}return n}function K(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}var S=function(e,t){var l=L({},e,t.attrs);return c(P,L({},l,{icon:Z}),null)};S.displayName="ExpandOutlined";S.inheritAttrs=!1;const ee={key:0,style:{"text-align":"center",padding:"48px"}},te={key:1,style:{"text-align":"center",padding:"48px"}},ne={key:2,style:{"text-align":"center",padding:"48px"}},oe={key:3},re={style:{"margin-bottom":"16px",display:"flex","justify-content":"space-between","align-items":"center"}},le={key:4,style:{"margin-left":"8px",color:"#ff4d4f","font-size":"12px"}},ae={key:0,style:{height:"100%",display:"flex","align-items":"center","justify-content":"center",color:"#595959"}},ce={style:{"text-align":"center"}},se={style:{"margin-top":"12px","font-size":"12px",color:"#8c8c8c"}},de={__name:"display",setup(n){const e=I(),t=m(!0),l=m(null),o=m("disconnected"),b=m(""),h=m(!1),x=m(null);let u=null,V=null;async function j(){try{const p=await fetch("/admin/vnc/status",{headers:e.getHeaders()});p.ok&&(l.value=await p.json())}catch(p){console.error("获取 VNC 状态失败",p)}finally{t.value=!1}}async function B(){if(l.value?.enabled){o.value="connecting",b.value="";try{V||(V=(await J(()=>import("./rfb.js"),[])).default);const r=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/admin/vnc?token=${e.token}`;u=new V(x.value,r,{wsProtocols:["binary"]}),u.scaleViewport=!0,u.clipViewport=!1,u.resizeSession=!1,u.addEventListener("connect",()=>{o.value="connected"}),u.addEventListener("disconnect",_=>{o.value="disconnected",_.detail.clean===!1&&(b.value="连接意外断开"),u=null}),u.addEventListener("credentialsrequired",()=>{u.sendCredentials({password:""})})}catch(p){o.value="error",b.value=p.message||"连接失败"}}}function N(){u&&(u.disconnect(),u=null),o.value="disconnected"}function F(){x.value&&(document.fullscreenElement?(document.exitFullscreen(),h.value=!1):(x.value.requestFullscreen(),h.value=!0))}function D(){h.value=!!document.fullscreenElement}return T(async()=>{await j(),document.addEventListener("fullscreenchange",D)}),U(()=>{N(),document.removeEventListener("fullscreenchange",D)}),(p,r)=>{const _=y("a-spin"),O=y("a-tag"),w=y("a-button"),A=y("a-space"),R=y("a-card"),q=y("a-layout");return a(),f(q,{style:{background:"transparent"}},{default:s(()=>[c(R,{title:"虚拟显示器",bordered:!1,style:{height:"100%"}},{default:s(()=>[t.value?(a(),g("div",ee,[c(_,{size:"large"}),r[0]||(r[0]=i("div",{style:{"margin-top":"16px",color:"#8c8c8c"}},"正在检查 VNC 状态...",-1))])):l.value?.xvfbMode?l.value?.enabled?(a(),g("div",oe,[i("div",re,[i("div",null,[o.value==="connected"?(a(),f(O,{key:0,color:"success"},{default:s(()=>[...r[5]||(r[5]=[d("已连接",-1)])]),_:1})):o.value==="connecting"?(a(),f(O,{key:1,color:"processing"},{default:s(()=>[...r[6]||(r[6]=[d("连接中...",-1)])]),_:1})):o.value==="error"?(a(),f(O,{key:2,color:"error"},{default:s(()=>[...r[7]||(r[7]=[d("连接错误",-1)])]),_:1})):(a(),f(O,{key:3,color:"default"},{default:s(()=>[...r[8]||(r[8]=[d("未连接",-1)])]),_:1})),b.value?(a(),g("span",le,z(b.value),1)):M("",!0)]),c(A,null,{default:s(()=>[o.value!=="connected"?(a(),f(w,{key:0,type:"primary",onClick:B,loading:o.value==="connecting"},{icon:s(()=>[c(v(C))]),default:s(()=>[r[9]||(r[9]=d(" 连接 ",-1))]),_:1},8,["loading"])):(a(),f(w,{key:1,danger:"",onClick:N},{icon:s(()=>[c(v(k))]),default:s(()=>[r[10]||(r[10]=d(" 断开 ",-1))]),_:1})),c(w,{onClick:F,disabled:o.value!=="connected"},{icon:s(()=>[h.value?(a(),f(v(E),{key:0})):(a(),f(v(S),{key:1}))]),_:1},8,["disabled"]),c(w,{onClick:j},{icon:s(()=>[c(v(G))]),_:1})]),_:1})]),i("div",{ref_key:"vncContainer",ref:x,style:{width:"100%","aspect-ratio":"16/9","min-height":"400px","max-height":"70vh",background:"#000","border-radius":"8px",overflow:"hidden"}},[o.value==="disconnected"?(a(),g("div",ae,[i("div",ce,[c(v(C),{style:{"font-size":"48px",color:"#434343"}}),r[11]||(r[11]=i("div",{style:{"margin-top":"16px"}},'点击"连接"按钮查看远程显示器',-1))])])):M("",!0)],512),i("div",se," 显示器: "+z(l.value.display)+" | VNC 端口: "+z(l.value.port),1)])):(a(),g("div",ne,[c(v(C),{style:{"font-size":"64px",color:"#bfbfbf"}}),r[3]||(r[3]=i("div",{style:{"margin-top":"16px","font-size":"16px",color:"#595959"}},"VNC 服务未启动",-1)),r[4]||(r[4]=i("div",{style:{"margin-top":"8px",color:"#8c8c8c"}},[d(" 请确保启动时包含 "),i("code",null,"-vnc"),d(" 参数,并已安装 x11vnc ")],-1))])):(a(),g("div",te,[c(v(k),{style:{"font-size":"64px",color:"#bfbfbf"}}),r[1]||(r[1]=i("div",{style:{"margin-top":"16px","font-size":"16px",color:"#595959"}},"程序未使用虚拟显示器运行",-1)),r[2]||(r[2]=i("div",{style:{"margin-top":"8px",color:"#8c8c8c"}},[d(" VNC 远程显示功能仅在 Linux 环境下使用 "),i("code",null,"-xvfb -vnc"),d(" 参数启动时可用 ")],-1))]))]),_:1})]),_:1})}}};export{de as default};