Files
usernode/internal/webui/dist/assets/KeysView-Cvkkr-hT.js
T

2 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{d as P,o as j,c as $,a as l,w as t,r as u,V as G,b as n,e as c,B as I,l as C,k as o,t as S,s as W,G as X,D as Y,h as K,m as J,E as _,W as L,X as Q,O as Z,Y as ee,C as le}from"./index-OD70Gdif.js";import{f as te}from"./format-BLhrtLRJ.js";import{_ as ae}from"./_plugin-vue_export-helper-DlAUqK2U.js";const ne={class:"card-header"},oe=P({__name:"KeysView",setup(se){const v=u([]),y=u(!1),m=u(!1),k=u(!1),s=J({name:"",public_key:""});async function g(){y.value=!0;try{const i=await G();v.value=i.items}catch{}finally{y.value=!1}}async function U(){if(!s.name.trim()){_.warning("请填写密钥名称");return}if(!s.public_key.trim()){_.warning("请粘贴公钥内容");return}k.value=!0;try{await L({name:s.name.trim(),public_key:s.public_key.trim()}),_.success("上传成功,已同步到 authorized_keys"),m.value=!1,Object.assign(s,{name:"",public_key:""}),g()}catch{}finally{k.value=!1}}const p=u(!1),b=u(null),f=u(""),V=u(!1);function z(i){b.value=i,f.value=i.name,p.value=!0}async function N(){if(!(!b.value||!f.value.trim())){V.value=!0;try{await Q(b.value.id,f.value.trim()),_.success("已重命名"),p.value=!1,g()}catch{}finally{V.value=!1}}}async function T(i){try{await Z.confirm(`吊销密钥「${i.name}」(${i.fingerprint})后将立即从 authorized_keys 移除,SSH 登录立即失效。确认?`,"吊销密钥",{type:"warning",confirmButtonText:"确认吊销",cancelButtonText:"取消"})}catch{return}try{await ee(i.id),_.success("已吊销"),g()}catch{}}return j(g),(i,e)=>{const D=n("Plus"),E=n("el-icon"),r=n("el-button"),d=n("el-table-column"),H=n("el-tag"),M=n("el-text"),h=n("el-table"),R=n("el-empty"),q=n("el-card"),w=n("el-input"),x=n("el-form-item"),A=n("el-form"),B=n("el-dialog"),F=le("loading");return c(),$("div",null,[l(q,{shadow:"never"},{header:t(()=>[K("div",ne,[K("b",null,"我的 SSH 公钥("+S(v.value.length)+"",1),l(r,{type:"primary",size:"small",onClick:e[0]||(e[0]=a=>m.value=!0)},{default:t(()=>[l(E,null,{default:t(()=>[l(D)]),_:1}),e[8]||(e[8]=o(" 上传公钥 ",-1))]),_:1})])]),default:t(()=>[I((c(),C(h,{data:v.value,stripe:""},{default:t(()=>[l(d,{prop:"name",label:"名称","min-width":"140"}),l(d,{prop:"key_type",label:"类型",width:"120"}),l(d,{prop:"fingerprint",label:"指纹","min-width":"200","show-overflow-tooltip":""}),l(d,{label:"状态",width:"90"},{default:t(({row:a})=>[l(H,{type:a.status==="active"?"success":"danger",size:"small"},{default:t(()=>[o(S(a.status==="active"?"生效":"已吊销"),1)]),_:2},1032,["type"])]),_:1}),l(d,{label:"上传时间",width:"170"},{default:t(({row:a})=>[o(S(W(te)(a.created_at)),1)]),_:1}),l(d,{label:"操作",width:"140",fixed:"right"},{default:t(({row:a})=>[a.status==="active"?(c(),$(X,{key:0},[l(r,{link:"",type:"primary",onClick:O=>z(a)},{default:t(()=>[...e[9]||(e[9]=[o("重命名",-1)])]),_:1},8,["onClick"]),l(r,{link:"",type:"danger",onClick:O=>T(a)},{default:t(()=>[...e[10]||(e[10]=[o("吊销",-1)])]),_:1},8,["onClick"])],64)):(c(),C(M,{key:1,type:"info",size:"small"},{default:t(()=>[...e[11]||(e[11]=[o("已吊销",-1)])]),_:1}))]),_:1})]),_:1},8,["data"])),[[F,y.value]]),!y.value&&v.value.length===0?(c(),C(R,{key:0,description:"暂无密钥,上传公钥后即可 SSH 登录"})):Y("",!0)]),_:1}),l(B,{modelValue:m.value,"onUpdate:modelValue":e[4]||(e[4]=a=>m.value=a),title:"上传 SSH 公钥",width:"520px"},{footer:t(()=>[l(r,{onClick:e[3]||(e[3]=a=>m.value=!1)},{default:t(()=>[...e[12]||(e[12]=[o("取消",-1)])]),_:1}),l(r,{type:"primary",loading:k.value,onClick:U},{default:t(()=>[...e[13]||(e[13]=[o("上传",-1)])]),_:1},8,["loading"])]),default:t(()=>[l(A,{"label-width":"80px"},{default:t(()=>[l(x,{label:"名称",required:""},{default:t(()=>[l(w,{modelValue:s.name,"onUpdate:modelValue":e[1]||(e[1]=a=>s.name=a),placeholder:"如 我的笔记本",maxlength:"64"},null,8,["modelValue"])]),_:1}),l(x,{label:"公钥",required:""},{default:t(()=>[l(w,{modelValue:s.public_key,"onUpdate:modelValue":e[2]||(e[2]=a=>s.public_key=a),type:"textarea",rows:5,placeholder:"ssh-ed25519 AAAA... 或 ssh-rsa AAAA..."},null,8,["modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue"]),l(B,{modelValue:p.value,"onUpdate:modelValue":e[7]||(e[7]=a=>p.value=a),title:"重命名密钥",width:"400px"},{footer:t(()=>[l(r,{onClick:e[6]||(e[6]=a=>p.value=!1)},{default:t(()=>[...e[14]||(e[14]=[o("取消",-1)])]),_:1}),l(r,{type:"primary",loading:V.value,onClick:N},{default:t(()=>[...e[15]||(e[15]=[o("保存",-1)])]),_:1},8,["loading"])]),default:t(()=>[l(A,{"label-width":"80px"},{default:t(()=>[l(x,{label:"名称"},{default:t(()=>[l(w,{modelValue:f.value,"onUpdate:modelValue":e[5]||(e[5]=a=>f.value=a),maxlength:"64"},null,8,["modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue"])])}}}),de=ae(oe,[["__scopeId","data-v-9032698c"]]);export{de as default};