51948469c2
- Stop ignoring web/app/index.html and web/app/assets/ - Bundle index-DBKIQT7H.js from current vite build (~101MB assets) Co-authored-by: Cursor <cursoragent@cursor.com>
2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{Dr as e,F as t,Gn as n,Jn as r,Kn as ee,L as i,Lr as a,Lt as o,M as s,N as c,Nr as l,O as te,P as u,Qn as d,Sr as ne,Tt as re,Vt as ie,Xn as f,Y as ae,Yn as p,Zn as m,br as h,er as g,fr as _,j as oe,mr as se,rr as ce,t as v,tr as y,ur as le,w as ue}from"./index-D6kmN0iw.js";import{a as de}from"./VSelectionControl-CB3RXt-d.js";import{n as b,t as fe}from"./VRow-BDVYLJeC.js";import{t as x}from"./VSpacer-D_GqDOug.js";import{t as pe}from"./useSnackbar-D7YOfKok.js";import{t as S}from"./VChip-BtzC63Ui.js";import{t as C}from"./VDialog-LUpcFvdq.js";import{t as me}from"./VSelect-6PVoJJ_P.js";import{i as he,n as ge,r as _e,t as ve}from"./VTabs-C9wskg7t.js";import{t as ye}from"./VDataTableServer-ZeDQGEA6.js";import{i as w}from"./validation-DMwOxx4a.js";import{a as be,i as T,n as xe,r as E,t as Se}from"./StatCardsRow-CP8tQxSi.js";import{t as Ce}from"./VAlert-iRqYZk6X.js";import{n as we,t as D}from"./apiError-CWntzMul.js";function O(e){if(typeof e==`number`&&Number.isFinite(e)&&e>0)return Math.trunc(e);if(typeof e==`string`&&/^\d+$/.test(e.trim())){let t=Number(e.trim());return Number.isFinite(t)&&t>0?t:null}return null}function k(e){let t=[];for(let n of e){let e=O(typeof n==`object`&&n&&`id`in n?n.id:n);e!==null&&t.push(e)}return[...new Set(t)]}function A(e){return(e||[]).filter(e=>e.success).length}var Te={class:`text-body-2 mr-4`},Ee={class:`font-weight-medium`},De={class:`text-medium-emphasis`},Oe={key:1,class:`text-medium-emphasis`},ke={class:`text-medium-emphasis`},Ae={class:`text-caption text-medium-emphasis`},je={class:`d-flex ga-1`},Me={class:`text-h6`},Ne={class:`text-h6`},Pe={class:`text-h6`},Fe={class:`text-h6`},Ie={key:0,class:`text-medium-emphasis text-center py-4`},j=ce({__name:`ServersPage`,setup(ce){let O=pe(),j=ie(),{servers:Le,loading:Re,page:ze,itemsPerPage:Be,total:Ve,search:M,loadServers:He,onSearch:Ue,onPageChange:We,onItemsPerPageChange:Ge}=be();async function N(){try{await He()}catch{O(`加载服务器列表失败`,`error`)}}let Ke=e([]),P=e(!1),F=e(!1),I=e(!1),L=e(!1),R=e(!1),z=e(null),B=e(null),qe=[{title:`自动(权限失败时 sudo)`,value:`auto_sudo`},{title:`关闭 sudo`,value:`off`},{title:`始终 sudo(排障)`,value:`always_sudo`}],V=e({name:``,address:``,category:``,platform_id:null,ssh_user:``,ssh_port:22,password:``,files_elevation:`auto_sudo`}),H=e([]),U=r(()=>new Set(k(H.value))),W=e(null),G=e(`info`),K=e([]),Je=[{title:`状态`,key:`status`,width:100},{title:`名称`,key:`name`},{title:`地址`,key:`address`},{title:`分类`,key:`category`,width:100},{title:`Agent`,key:`agent`,width:100},{title:`心跳`,key:`heartbeat`,width:120},{title:`操作`,key:`actions`,width:200,align:`end`}],q=e([{subtitle:`服务器总数`,title:`0`,icon:`mdi-server-network`,color:`blue`},{subtitle:`在线`,title:`0`,icon:`mdi-check-circle-outline`,color:`green`},{subtitle:`离线`,title:`0`,icon:`mdi-alert-circle-outline`,color:`orange`},{subtitle:`告警中`,title:`0`,icon:`mdi-bell-alert-outline`,color:`red`}]);async function J(){try{let e=await o.get(`/servers/stats`);q.value[0].title=String(e.total),q.value[1].title=String(e.online),q.value[2].title=String(e.offline),q.value[3].title=String(e.alerts??0)}catch{}}async function Ye(){try{Ke.value=(await o.get(`/assets/platforms`)).items||[]}catch{}}function Xe(e){j.push({path:`/terminal`,query:{server_id:String(e.id)}})}function Ze(e){j.push({path:`/files`,query:{server_id:String(e.id)}})}let Y=e(!1);async function Qe(){let e=k(H.value);if(e.length){O(`正在检查 ${e.length} 台服务器...`);try{await o.post(`/servers/check`,{server_ids:e}),O(`健康检查完成`),N()}catch(e){O(D(e,`检查失败`),`error`)}}}async function $e(){if(confirm(`确定删除选中的 ${U.value.size} 台服务器?`)){for(let e of U.value)try{await o.delete(`/servers/${e}`)}catch{}H.value=[],O(`批量删除完成`),N(),J()}}async function et(){let e=k(H.value);if(e.length){Y.value=!0;try{O(`安装完成: ${A((await o.post(`/servers/batch/install-agent`,{server_ids:e})).results)}/${e.length} 成功`),N()}catch(e){O(D(e,`安装失败`),`error`)}finally{Y.value=!1}}}async function tt(){let e=k(H.value);if(e.length){Y.value=!0;try{O(`升级完成: ${A((await o.post(`/servers/batch/upgrade-agent`,{server_ids:e})).results)}/${e.length} 成功`),N()}catch(e){O(D(e,`升级失败`),`error`)}finally{Y.value=!1}}}async function nt(){let e=k(H.value);if(e.length&&confirm(`确定卸载选中的 ${e.length} 台服务器的 Agent?`)){Y.value=!0;try{O(`卸载完成: ${A((await o.post(`/servers/batch/uninstall-agent`,{server_ids:e})).results)}/${e.length} 成功`),N()}catch(e){O(D(e,`卸载失败`),`error`)}finally{Y.value=!1}}}async function rt(){try{let e=await o.getList(`/servers/`,{per_page:5e3}),t=[`ID`,`名称`,`地址`,`端口`,`用户名`,`分类`,`状态`,`Agent版本`,`最后心跳`],n=(e.items||[]).map(e=>[e.id,e.name,e.domain,e.port,e.username,e.category||``,e.status,e.agent_version||``,e.last_heartbeat||``]),r=``+[t.join(`,`),...n.map(e=>e.map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`))].join(`
|
||
`),ee=new Blob([r],{type:`text/csv;charset=utf-8;`}),i=URL.createObjectURL(ee),a=document.createElement(`a`);a.href=i,a.download=`servers_${new Date().toISOString().slice(0,10)}.csv`,a.click(),URL.revokeObjectURL(i),O(`导出完成`)}catch(e){O(e.message||`导出失败`,`error`)}}let X=e(!1),Z=e([]),Q=e(!1),$=e(null);async function it(){if(Z.value?.length){Q.value=!0,$.value=null;try{let e=new FormData;e.append(`file`,Z.value[0]),$.value=await o.upload(`/servers/import`,e),O(`导入完成`),N()}catch(e){O(e instanceof Error?e.message:`导入失败`,`error`)}finally{Q.value=!1}}}async function at(e){W.value=e,G.value=`info`;try{K.value=(await o.get(`/servers/${e.id}/logs`,{limit:20})).items||[]}catch{K.value=[]}}function ot(e){I.value=!0,B.value=e.id,V.value={name:e.name,address:e.domain||``,category:e.category||``,platform_id:e.platform_id,ssh_user:e.username||``,ssh_port:e.port||22,password:``,files_elevation:e.files_elevation||`auto_sudo`},P.value=!0}function st(e){z.value=e,F.value=!0}async function ct(){L.value=!0;try{let e={name:V.value.name,domain:V.value.address,username:V.value.ssh_user,port:V.value.ssh_port,category:V.value.category||void 0,platform_id:V.value.platform_id||void 0,password:V.value.password||void 0,files_elevation:V.value.files_elevation};I.value&&B.value?await o.put(`/servers/${B.value}`,e):await o.post(`/servers/`,e),P.value=!1,ut(),N(),J(),O(`保存成功`)}catch(e){O(e.message||`保存失败`,`error`)}finally{L.value=!1}}async function lt(){if(z.value){R.value=!0;try{await o.delete(`/servers/${z.value.id}`),F.value=!1,N(),J(),O(`已删除`)}catch(e){O(e.message||`删除失败`,`error`)}finally{R.value=!1}}}function ut(){I.value=!1,B.value=null,V.value={name:``,address:``,category:``,platform_id:null,ssh_user:``,ssh_port:22,password:``,files_elevation:`auto_sudo`}}return le(()=>{J(),N(),Ye()}),(e,r)=>(_(),f(de,{fluid:``,class:`pa-4 pa-md-6`},{default:h(()=>[y(Se,{items:q.value},null,8,[`items`]),y(s,{elevation:`0`,rounded:`lg`,class:`my-5`,border:``},{default:h(()=>[y(u,{class:`d-flex align-center`},{default:h(()=>[r[27]||=g(` 服务器列表 `,-1),y(x),y(v,{modelValue:l(M),"onUpdate:modelValue":[r[0]||=e=>ne(M)?M.value=e:null,l(Ue)],"prepend-inner-icon":`mdi-magnify`,label:`搜索...`,density:`compact`,"hide-details":``,rounded:``,style:{"max-width":`240px`},variant:`outlined`},null,8,[`modelValue`,`onUpdate:modelValue`]),y(i,{color:`primary`,variant:`flat`,class:`ml-3`,"prepend-icon":`mdi-plus`,size:`small`,onClick:r[1]||=e=>P.value=!0},{default:h(()=>[...r[24]||=[g(` 添加 `,-1)]]),_:1}),y(i,{variant:`tonal`,class:`ml-2`,"prepend-icon":`mdi-download`,size:`small`,onClick:rt},{default:h(()=>[...r[25]||=[g(` 导出CSV `,-1)]]),_:1}),y(i,{variant:`tonal`,class:`ml-2`,"prepend-icon":`mdi-file-import`,size:`small`,onClick:r[2]||=e=>X.value=!0},{default:h(()=>[...r[26]||=[g(` 导入 `,-1)]]),_:1})]),_:1}),U.value.size>0?(_(),f(s,{key:0,class:`mx-4 mb-2`,color:`primary`,variant:`tonal`,rounded:`lg`},{default:h(()=>[y(c,{class:`d-flex align-center py-2`},{default:h(()=>[p(`span`,Te,`已选择 `+a(U.value.size)+` 台服务器`,1),y(x),y(i,{size:`small`,variant:`text`,onClick:Qe},{default:h(()=>[...r[28]||=[g(`健康检查`,-1)]]),_:1}),y(i,{size:`small`,variant:`text`,onClick:et,loading:Y.value},{default:h(()=>[...r[29]||=[g(`安装Agent`,-1)]]),_:1},8,[`loading`]),y(i,{size:`small`,variant:`text`,onClick:tt,loading:Y.value},{default:h(()=>[...r[30]||=[g(`升级Agent`,-1)]]),_:1},8,[`loading`]),y(i,{size:`small`,variant:`text`,color:`error`,onClick:nt,loading:Y.value},{default:h(()=>[...r[31]||=[g(`卸载Agent`,-1)]]),_:1},8,[`loading`]),y(i,{size:`small`,variant:`text`,color:`error`,onClick:$e},{default:h(()=>[...r[32]||=[g(`批量删除`,-1)]]),_:1}),y(i,{size:`small`,variant:`text`,onClick:r[3]||=e=>H.value=[]},{default:h(()=>[...r[33]||=[g(`取消选择`,-1)]]),_:1})]),_:1})]),_:1})):m(``,!0),y(ye,{items:l(Le),headers:Je,"items-length":l(Ve),loading:l(Re),page:l(ze),"items-per-page":l(Be),hover:``,density:`comfortable`,"item-value":`id`,"show-select":``,modelValue:H.value,"onUpdate:modelValue":r[4]||=e=>H.value=e,"onUpdate:page":l(We),"onUpdate:itemsPerPage":l(Ge),"onClick:row":r[5]||=(e,{item:t})=>at(t)},{"item.status":h(({item:e})=>[y(S,{color:l(E)(e.status),size:`x-small`,variant:`tonal`,label:``,border:`sm`},{default:h(()=>[g(a(l(T)(e.status)),1)]),_:2},1032,[`color`])]),"item.name":h(({item:e})=>[p(`span`,Ee,a(e.name),1)]),"item.address":h(({item:e})=>[p(`span`,De,a(e.domain)+`:`+a(e.port),1)]),"item.category":h(({item:e})=>[e.category?(_(),f(S,{key:0,color:`primary`,variant:`tonal`,size:`small`,label:``},{default:h(()=>[g(a(e.category),1)]),_:2},1024)):(_(),d(`span`,Oe,`—`))]),"item.agent":h(({item:e})=>[p(`span`,ke,a(e.agent_version||`—`),1)]),"item.heartbeat":h(({item:e})=>[p(`span`,Ae,a(l(xe)(e.last_heartbeat)),1)]),"item.actions":h(({item:e})=>[p(`div`,je,[y(i,{variant:`text`,size:`x-small`,color:`primary`,density:`compact`,onClick:n(t=>Xe(e),[`stop`])},{default:h(()=>[...r[34]||=[g(`终端`,-1)]]),_:1},8,[`onClick`]),y(i,{variant:`text`,size:`x-small`,density:`compact`,onClick:n(t=>Ze(e),[`stop`])},{default:h(()=>[...r[35]||=[g(`文件`,-1)]]),_:1},8,[`onClick`]),y(i,{variant:`text`,size:`x-small`,density:`compact`,onClick:n(t=>ot(e),[`stop`])},{default:h(()=>[...r[36]||=[g(`编辑`,-1)]]),_:1},8,[`onClick`]),y(i,{variant:`text`,size:`x-small`,color:`error`,density:`compact`,onClick:n(t=>st(e),[`stop`])},{default:h(()=>[...r[37]||=[g(`删除`,-1)]]),_:1},8,[`onClick`])])]),"no-data":h(()=>[...r[38]||=[p(`div`,{class:`text-center text-medium-emphasis py-6`},`暂无服务器数据`,-1)]]),_:1},8,[`items`,`items-length`,`loading`,`page`,`items-per-page`,`modelValue`,`onUpdate:page`,`onUpdate:itemsPerPage`])]),_:1}),y(re,null,{default:h(()=>[W.value?(_(),f(s,{key:0,class:`mt-4`,elevation:`0`,border:``,rounded:`lg`},{default:h(()=>[y(u,{class:`d-flex align-center`},{default:h(()=>[y(ae,{class:`mr-2`},{default:h(()=>[...r[39]||=[g(`mdi-information-outline`,-1)]]),_:1}),g(` `+a(W.value.name)+` `,1),y(S,{color:l(E)(W.value.status),size:`small`,variant:`tonal`,label:``,class:`ml-2`},{default:h(()=>[g(a(l(T)(W.value.status)),1)]),_:1},8,[`color`]),y(x),y(i,{icon:`mdi-close`,size:`small`,variant:`text`,onClick:r[6]||=e=>W.value=null})]),_:1}),y(oe),y(ve,{modelValue:G.value,"onUpdate:modelValue":r[7]||=e=>G.value=e,density:`compact`},{default:h(()=>[y(he,{value:`info`},{default:h(()=>[...r[40]||=[g(`系统信息`,-1)]]),_:1}),y(he,{value:`logs`},{default:h(()=>[...r[41]||=[g(`同步日志`,-1)]]),_:1})]),_:1},8,[`modelValue`]),y(_e,{modelValue:G.value,"onUpdate:modelValue":r[8]||=e=>G.value=e},{default:h(()=>[y(ge,{value:`info`},{default:h(()=>[y(c,null,{default:h(()=>[y(fe,{dense:``},{default:h(()=>[y(b,{cols:`6`,md:`3`},{default:h(()=>[r[42]||=p(`div`,{class:`text-caption text-medium-emphasis`},`CPU`,-1),p(`div`,Me,a(W.value.system_info?.cpu_usage??`—`)+`%`,1)]),_:1}),y(b,{cols:`6`,md:`3`},{default:h(()=>[r[43]||=p(`div`,{class:`text-caption text-medium-emphasis`},`内存`,-1),p(`div`,Ne,a(W.value.system_info?.mem_usage??`—`)+`%`,1)]),_:1}),y(b,{cols:`6`,md:`3`},{default:h(()=>[r[44]||=p(`div`,{class:`text-caption text-medium-emphasis`},`磁盘`,-1),p(`div`,Pe,a(W.value.system_info?.disk_usage??`—`)+`%`,1)]),_:1}),y(b,{cols:`6`,md:`3`},{default:h(()=>[r[45]||=p(`div`,{class:`text-caption text-medium-emphasis`},`Agent`,-1),p(`div`,Fe,a(W.value.agent_version||`未安装`),1)]),_:1})]),_:1})]),_:1})]),_:1}),y(ge,{value:`logs`},{default:h(()=>[y(c,null,{default:h(()=>[K.value.length===0?(_(),d(`div`,Ie,`暂无同步日志`)):(_(),f(ue,{key:1,density:`compact`},{default:h(()=>[(_(!0),d(ee,null,se(K.value,e=>(_(),f(te,{key:e.id,subtitle:e.created_at,title:`${e.source_path} → ${e.target_path}`},{append:h(()=>[y(S,{size:`x-small`,color:e.status===`success`?`green`:`red`,variant:`tonal`,label:``},{default:h(()=>[g(a(e.status),1)]),_:2},1032,[`color`])]),_:2},1032,[`subtitle`,`title`]))),128))]),_:1}))]),_:1})]),_:1})]),_:1},8,[`modelValue`])]),_:1})):m(``,!0)]),_:1}),y(C,{modelValue:P.value,"onUpdate:modelValue":r[18]||=e=>P.value=e,"max-width":`600`},{default:h(()=>[y(s,{border:``},{default:h(()=>[y(u,null,{default:h(()=>[g(a(I.value?`编辑服务器`:`添加服务器`),1)]),_:1}),y(c,null,{default:h(()=>[y(v,{modelValue:V.value.name,"onUpdate:modelValue":r[9]||=e=>V.value.name=e,label:`名称`,variant:`outlined`,density:`compact`,class:`mb-2`,rules:[l(w)(`服务器名称`)]},null,8,[`modelValue`,`rules`]),y(v,{modelValue:V.value.address,"onUpdate:modelValue":r[10]||=e=>V.value.address=e,label:`地址 (IP:端口)`,variant:`outlined`,density:`compact`,class:`mb-2`,rules:[l(w)(`地址`)]},null,8,[`modelValue`,`rules`]),y(v,{modelValue:V.value.category,"onUpdate:modelValue":r[11]||=e=>V.value.category=e,label:`分类`,variant:`outlined`,density:`compact`,class:`mb-2`},null,8,[`modelValue`]),y(me,{modelValue:V.value.platform_id,"onUpdate:modelValue":r[12]||=e=>V.value.platform_id=e,items:Ke.value,"item-title":`name`,"item-value":`id`,label:`平台`,variant:`outlined`,density:`compact`,class:`mb-2`,clearable:``},null,8,[`modelValue`,`items`]),y(v,{modelValue:V.value.ssh_user,"onUpdate:modelValue":r[13]||=e=>V.value.ssh_user=e,label:`SSH 用户`,variant:`outlined`,density:`compact`,class:`mb-2`,rules:[l(w)(`用户名`)]},null,8,[`modelValue`,`rules`]),y(v,{modelValue:V.value.ssh_port,"onUpdate:modelValue":r[14]||=e=>V.value.ssh_port=e,label:`SSH 端口`,variant:`outlined`,density:`compact`,type:`number`,class:`mb-2`},null,8,[`modelValue`]),y(v,{modelValue:V.value.password,"onUpdate:modelValue":r[15]||=e=>V.value.password=e,label:`密码`,variant:`outlined`,density:`compact`,type:`password`,class:`mb-2`},null,8,[`modelValue`]),y(me,{modelValue:V.value.files_elevation,"onUpdate:modelValue":r[16]||=e=>V.value.files_elevation=e,items:qe,"item-title":`title`,"item-value":`value`,label:`文件管理提权`,variant:`outlined`,density:`compact`,hint:`非 root SSH 用户需目标机配置免密 sudo;示例见 docs/deploy/nexus-files-sudoers.example`,"persistent-hint":``},null,8,[`modelValue`])]),_:1}),y(t,null,{default:h(()=>[y(x),y(i,{variant:`text`,onClick:r[17]||=e=>P.value=!1},{default:h(()=>[...r[46]||=[g(`取消`,-1)]]),_:1}),y(i,{color:`primary`,variant:`flat`,onClick:ct,loading:L.value},{default:h(()=>[...r[47]||=[g(`保存`,-1)]]),_:1},8,[`loading`])]),_:1})]),_:1})]),_:1},8,[`modelValue`]),y(C,{modelValue:F.value,"onUpdate:modelValue":r[20]||=e=>F.value=e,"max-width":`400`},{default:h(()=>[y(s,{border:``},{default:h(()=>[y(u,null,{default:h(()=>[...r[48]||=[g(`确认删除`,-1)]]),_:1}),y(c,null,{default:h(()=>[r[49]||=g(`确定要删除服务器 `,-1),p(`strong`,null,a(z.value?.name),1),r[50]||=g(` 吗?`,-1)]),_:1}),y(t,null,{default:h(()=>[y(x),y(i,{variant:`text`,onClick:r[19]||=e=>F.value=!1},{default:h(()=>[...r[51]||=[g(`取消`,-1)]]),_:1}),y(i,{color:`error`,variant:`flat`,onClick:lt,loading:R.value},{default:h(()=>[...r[52]||=[g(`删除`,-1)]]),_:1},8,[`loading`])]),_:1})]),_:1})]),_:1},8,[`modelValue`]),y(C,{modelValue:X.value,"onUpdate:modelValue":r[23]||=e=>X.value=e,"max-width":`500`},{default:h(()=>[y(s,{border:``},{default:h(()=>[y(u,null,{default:h(()=>[...r[53]||=[g(`导入服务器`,-1)]]),_:1}),y(c,null,{default:h(()=>[r[54]||=p(`div`,{class:`text-body-2 text-medium-emphasis mb-3`},[g(` 上传 CSV 文件批量导入服务器。 `),p(`a`,{href:`/app/servers_import_template.csv`,download:``,class:`text-primary`},`下载模板`)],-1),y(we,{modelValue:Z.value,"onUpdate:modelValue":r[21]||=e=>Z.value=e,label:`选择 CSV 文件`,variant:`outlined`,density:`compact`,accept:`.csv`,"show-size":``},null,8,[`modelValue`]),$.value?(_(),f(Ce,{key:0,type:$.value.failed>0?`warning`:`success`,density:`compact`,variant:`tonal`,class:`mt-3`},{default:h(()=>[g(` 成功 `+a($.value.created)+`,跳过 `+a($.value.skipped)+`,失败 `+a($.value.failed),1)]),_:1},8,[`type`])):m(``,!0)]),_:1}),y(t,null,{default:h(()=>[y(x),y(i,{variant:`text`,onClick:r[22]||=e=>X.value=!1},{default:h(()=>[...r[55]||=[g(`关闭`,-1)]]),_:1}),y(i,{color:`primary`,variant:`flat`,onClick:it,loading:Q.value,disabled:!Z.value?.length},{default:h(()=>[...r[56]||=[g(`开始导入`,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1})]),_:1})]),_:1},8,[`modelValue`])]),_:1}))}});export{j as default}; |