Files
FileRelay/web/assets/TokenManagement-Cwst5YRl.js

2 lines
15 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 se,v as k,Z as le,o as te,h as I,z as t,T as M,j as a,I as l,C as o,u as s,f as u,F as ae,J as oe,P as ne,i as V,D as f,G as P,g as d}from"./index-BhaIiTEj.js";import{t as m,d as _,b as S,_ as h,a as re}from"./Sonner.vue_vue_type_script_setup_true_lang-BwfWndxy.js";import{_ as ie}from"./Input.vue_vue_type_script_setup_true_lang-CD5fb2oW.js";import{_ as j}from"./Label.vue_vue_type_script_setup_true_lang-D-_Evs0_.js";import{_ as D}from"./index-Catk2Spn.js";import{_ as de,a as ue,b as fe}from"./CardTitle.vue_vue_type_script_setup_true_lang-DBp3brf1.js";import{_ as E,b as U,c as N,d as F,e as v}from"./SelectValue.vue_vue_type_script_setup_true_lang-Dkj-rl5_.js";import{_ as H,a as me,b as pe,c as q,d as c,e as ve,f as x}from"./TableHeader.vue_vue_type_script_setup_true_lang-NIN1xtGv.js";import{a as G,b as J,c as O,d as Z,e as K,_ as Q}from"./DialogTitle.vue_vue_type_script_setup_true_lang-CF3XyDt2.js";import{_ as ke}from"./AdminLayout.vue_vue_type_script_setup_true_lang-B_6YVjYZ.js";import{_ as _e}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./useForwardExpose-CRFbVhil.js";import"./Teleport-DV_BGdH0.js";import"./PopperContent-MQwziWLW.js";import"./utils-BNRHOSl8.js";const ce={class:"mb-8"},xe={class:"md:flex md:items-center md:justify-between"},ye={class:"mt-4 flex md:mt-0 md:ml-4"},we={class:"flex items-center justify-between"},Te={key:0,class:"space-y-4"},ge={key:1,class:"text-center py-12"},be={key:2,class:"overflow-x-auto"},$e={key:0},Ce={key:1,class:"text-gray-500"},Ae={key:0},Me={key:1,class:"text-gray-500"},Ve={class:"flex items-center space-x-2"},ze={key:0,class:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24"},Be={key:1,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Ie={key:0,class:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24"},je={key:1,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},De={key:0,class:"animate-spin -ml-1 mr-3 h-4 w-4",fill:"none",viewBox:"0 0 24 24"},He={key:0,class:"py-4"},Le={class:"bg-gray-50 p-4 rounded-lg border border-gray-200"},Pe={class:"flex items-center justify-between mb-3"},Se={class:"font-medium"},he={class:"space-y-2"},Ee={class:"flex items-center space-x-2"},Ue={class:"flex-1 p-2 bg-white border rounded text-sm font-mono break-all"},Ne={key:0,class:"mt-3 text-sm text-gray-600"},Fe=se({__name:"TokenManagement",setup(qe){const z=k(!0),B=k([]),y=k(!1),b=k(!1),w=k(!1),$=k(new Set),C=k(new Set),i=le({name:"",scope:"all",expireType:"never"}),p=k(null),T=async()=>{z.value=!0;try{const r=await M.getTokens();if(r.data.code===200)B.value=r.data.data;else throw new Error(r.data.msg||"获取 Token 列表失败")}catch(r){console.error("获取 Token 列表失败:",r),m.error(r.response?.data?.msg||"获取 Token 列表失败")}finally{z.value=!1}},L=async()=>{if(!i.name.trim()){m.warning("请输入 Token 名称");return}w.value=!0;try{const r={name:i.name.trim()};if(i.scope&&i.scope!=="all"&&(r.scope=i.scope),i.expireType&&i.expireType!=="never"){const n=parseInt(i.expireType),g=new Date;g.setDate(g.getDate()+n),r.expire_at=g.toISOString()}const e=await M.createToken(r);if(e.data.code===201)p.value=e.data.data,y.value=!1,b.value=!0,i.name="",i.scope="all",i.expireType="never",T(),m.success("Token 创建成功");else throw new Error(e.data.msg||"Token 创建失败")}catch(r){console.error("创建 Token 失败:",r),m.error(r.response?.data?.msg||"创建 Token 失败")}finally{w.value=!1}},R=async r=>{if(confirm(`确定要撤销 Token "${r.name}" 吗?撤销后将立即失效。`)){$.value.add(r.id);try{const e=await M.revokeToken(r.id);if(e.data.code===200)m.success("Token 已撤销"),T();else throw new Error(e.data.msg||"撤销失败")}catch(e){console.error("撤销 Token 失败:",e),m.error(e.response?.data?.msg||"撤销 Token 失败")}finally{$.value.delete(r.id)}}},W=async r=>{if(confirm(`确定要删除 Token "${r.name}" 吗?此操作不可撤销。`)){C.value.add(r.id);try{const e=await M.deleteToken(r.id);if(e.data.code===200)m.success("Token 删除成功"),T();else throw new Error(e.data.msg||"删除失败")}catch(e){console.error("删除 Token 失败:",e),m.error(e.response?.data?.msg||"删除 Token 失败")}finally{C.value.delete(r.id)}}},X=async()=>{p.value?.token&&(await P.copyToClipboard(p.value.token)?m.success("Token 已复制到剪贴板"):m.error("复制失败,请手动复制"))},Y=()=>{b.value=!1,p.value=null},ee=()=>{T(),m.success("数据已刷新")},A=r=>P.formatDate(r);return te(()=>{T()}),(r,e)=>(d(),I(ke,null,{default:t(()=>[a("div",ce,[a("div",xe,[e[9]||(e[9]=a("div",{class:"flex-1 min-w-0"},[a("h2",{class:"text-3xl font-bold text-gray-900"},"API Token 管理"),a("p",{class:"mt-2 text-gray-600"},"创建和管理 API 访问凭证")],-1)),a("div",ye,[l(s(_),{onClick:ee,variant:"outline",size:"sm",class:"mr-2"},{default:t(()=>[...e[7]||(e[7]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1),o(" 刷新 ",-1)])]),_:1}),l(s(_),{onClick:e[0]||(e[0]=n=>y.value=!0)},{default:t(()=>[...e[8]||(e[8]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),o(" 创建 Token ",-1)])]),_:1})])])]),l(s(h),{class:"mb-6 border-blue-200 bg-blue-50"},{default:t(()=>[l(s(S),{class:"pt-6"},{default:t(()=>[...e[10]||(e[10]=[a("div",{class:"flex"},[a("div",{class:"flex-shrink-0"},[a("svg",{class:"h-5 w-5 text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})])]),a("div",{class:"ml-3"},[a("h3",{class:"text-sm font-medium text-blue-800"},"API Token 使用说明"),a("div",{class:"mt-2 text-sm text-blue-700"},[a("ul",{class:"list-disc list-inside space-y-1"},[a("li",null,"API Token 用于程序化访问文件中转站的接口"),a("li",null,"Token 创建后只显示一次,请妥善保存"),a("li",null,"可以设置 Token 的权限范围和过期时间"),a("li",null,"被撤销的 Token 会立即失效,但记录会保留")])])])],-1)])]),_:1})]),_:1}),l(s(h),null,{default:t(()=>[l(s(de),null,{default:t(()=>[a("div",we,[a("div",null,[l(s(ue),null,{default:t(()=>[...e[11]||(e[11]=[o("API Token 列表",-1)])]),_:1}),l(s(fe),null,{default:t(()=>[...e[12]||(e[12]=[o(" 管理系统中的 API 访问凭证 ",-1)])]),_:1})])])]),_:1}),l(s(S),null,{default:t(()=>[z.value?(d(),u("div",Te,[l(s(H),{class:"h-4 w-full"}),l(s(H),{class:"h-4 w-3/4"}),l(s(H),{class:"h-4 w-1/2"})])):B.value.length===0?(d(),u("div",ge,[...e[13]||(e[13]=[a("svg",{class:"w-16 h-16 mx-auto text-gray-400 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})],-1),a("p",{class:"text-gray-500 text-lg"},"暂无 API Token",-1),a("p",{class:"text-gray-400 text-sm"},"点击上方按钮创建第一个 Token",-1)])])):(d(),u("div",be,[l(s(me),null,{default:t(()=>[l(s(pe),null,{default:t(()=>[l(s(q),null,{default:t(()=>[l(s(c),null,{default:t(()=>[...e[14]||(e[14]=[o("名称",-1)])]),_:1}),l(s(c),null,{default:t(()=>[...e[15]||(e[15]=[o("权限范围",-1)])]),_:1}),l(s(c),null,{default:t(()=>[...e[16]||(e[16]=[o("状态",-1)])]),_:1}),l(s(c),null,{default:t(()=>[...e[17]||(e[17]=[o("创建时间",-1)])]),_:1}),l(s(c),null,{default:t(()=>[...e[18]||(e[18]=[o("最后使用",-1)])]),_:1}),l(s(c),null,{default:t(()=>[...e[19]||(e[19]=[o("过期时间",-1)])]),_:1}),l(s(c),{class:"text-center"},{default:t(()=>[...e[20]||(e[20]=[o("操作",-1)])]),_:1})]),_:1})]),_:1}),l(s(ve),null,{default:t(()=>[(d(!0),u(ae,null,oe(B.value,n=>(d(),I(s(q),{key:n.id,class:"hover:bg-gray-50"},{default:t(()=>[l(s(x),{class:"font-medium"},{default:t(()=>[o(f(n.name),1)]),_:2},1024),l(s(x),null,{default:t(()=>[l(s(D),{variant:"outline"},{default:t(()=>[o(f(n.scope||"ALL"),1)]),_:2},1024)]),_:2},1024),l(s(x),null,{default:t(()=>[l(s(D),{variant:n.revoked?"destructive":"default"},{default:t(()=>[o(f(n.revoked?"已撤销":"活跃"),1)]),_:2},1032,["variant"])]),_:2},1024),l(s(x),null,{default:t(()=>[o(f(A(n.created_at)),1)]),_:2},1024),l(s(x),null,{default:t(()=>[n.last_used_at?(d(),u("span",$e,f(A(n.last_used_at)),1)):(d(),u("span",Ce,"从未使用"))]),_:2},1024),l(s(x),null,{default:t(()=>[n.expire_at?(d(),u("span",Ae,f(A(n.expire_at)),1)):(d(),u("span",Me,"永不过期"))]),_:2},1024),l(s(x),null,{default:t(()=>[a("div",Ve,[n.revoked?V("",!0):(d(),I(s(_),{key:0,variant:"outline",size:"sm",onClick:g=>R(n),disabled:$.value.has(n.id)},{default:t(()=>[$.value.has(n.id)?(d(),u("svg",ze,[...e[21]||(e[21]=[a("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),a("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"},null,-1)])])):(d(),u("svg",Be,[...e[22]||(e[22]=[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636m12.728 12.728L18.364 5.636M5.636 18.364l12.728-12.728"},null,-1)])])),e[23]||(e[23]=o(" 撤销 ",-1))]),_:2},1032,["onClick","disabled"])),l(s(_),{variant:"destructive",size:"sm",onClick:g=>W(n),disabled:C.value.has(n.id)},{default:t(()=>[C.value.has(n.id)?(d(),u("svg",Ie,[...e[24]||(e[24]=[a("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),a("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"},null,-1)])])):(d(),u("svg",je,[...e[25]||(e[25]=[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"},null,-1)])])),e[26]||(e[26]=o(" 删除 ",-1))]),_:2},1032,["onClick","disabled"])])]),_:2},1024)]),_:2},1024))),128))]),_:1})]),_:1})]))]),_:1})]),_:1}),l(s(Q),{open:y.value,"onUpdate:open":e[5]||(e[5]=n=>y.value=n)},{default:t(()=>[l(s(G),{class:"sm:max-w-[500px]"},{default:t(()=>[l(s(J),null,{default:t(()=>[l(s(O),null,{default:t(()=>[...e[27]||(e[27]=[o("创建 API Token",-1)])]),_:1}),l(s(Z),null,{default:t(()=>[...e[28]||(e[28]=[o(" 创建新的 API 访问凭证 ",-1)])]),_:1})]),_:1}),a("form",{onSubmit:ne(L,["prevent"]),class:"py-4 space-y-4"},[a("div",null,[l(s(j),{for:"token-name"},{default:t(()=>[...e[29]||(e[29]=[o("Token 名称 *",-1)])]),_:1}),l(s(ie),{id:"token-name",modelValue:i.name,"onUpdate:modelValue":e[1]||(e[1]=n=>i.name=n),placeholder:"为这个 Token 起一个名字...",required:""},null,8,["modelValue"])]),a("div",null,[l(s(j),{for:"token-scope"},{default:t(()=>[...e[30]||(e[30]=[o("权限范围",-1)])]),_:1}),l(s(E),{modelValue:i.scope,"onUpdate:modelValue":e[2]||(e[2]=n=>i.scope=n)},{default:t(()=>[l(s(U),{class:"mt-1.5"},{default:t(()=>[l(s(N),{placeholder:"选择权限范围"})]),_:1}),l(s(F),null,{default:t(()=>[l(s(v),{value:"all"},{default:t(()=>[...e[31]||(e[31]=[o("全部权限",-1)])]),_:1}),l(s(v),{value:"upload"},{default:t(()=>[...e[32]||(e[32]=[o("仅上传",-1)])]),_:1}),l(s(v),{value:"pickup"},{default:t(()=>[...e[33]||(e[33]=[o("仅下载",-1)])]),_:1}),l(s(v),{value:"upload,pickup"},{default:t(()=>[...e[34]||(e[34]=[o("上传和下载",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"]),e[35]||(e[35]=a("p",{class:"text-xs text-gray-500 mt-1"}," 限制此 Token 可以访问的功能范围 ",-1))]),a("div",null,[l(s(j),{for:"token-expire"},{default:t(()=>[...e[36]||(e[36]=[o("过期时间",-1)])]),_:1}),l(s(E),{modelValue:i.expireType,"onUpdate:modelValue":e[3]||(e[3]=n=>i.expireType=n)},{default:t(()=>[l(s(U),{class:"mt-1.5"},{default:t(()=>[l(s(N),{placeholder:"选择过期策略"})]),_:1}),l(s(F),null,{default:t(()=>[l(s(v),{value:"never"},{default:t(()=>[...e[37]||(e[37]=[o("永不过期",-1)])]),_:1}),l(s(v),{value:"7"},{default:t(()=>[...e[38]||(e[38]=[o("7 天后过期",-1)])]),_:1}),l(s(v),{value:"30"},{default:t(()=>[...e[39]||(e[39]=[o("30 天后过期",-1)])]),_:1}),l(s(v),{value:"90"},{default:t(()=>[...e[40]||(e[40]=[o("90 天后过期",-1)])]),_:1}),l(s(v),{value:"365"},{default:t(()=>[...e[41]||(e[41]=[o("1 年后过期",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"])])],32),l(s(K),null,{default:t(()=>[l(s(_),{variant:"outline",onClick:e[4]||(e[4]=n=>y.value=!1)},{default:t(()=>[...e[42]||(e[42]=[o(" 取消 ",-1)])]),_:1}),l(s(_),{onClick:L,disabled:w.value||!i.name.trim()},{default:t(()=>[w.value?(d(),u("svg",De,[...e[43]||(e[43]=[a("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),a("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"},null,-1)])])):V("",!0),o(" "+f(w.value?"创建中...":"创建 Token"),1)]),_:1},8,["disabled"])]),_:1})]),_:1})]),_:1},8,["open"]),l(s(Q),{open:b.value,"onUpdate:open":e[6]||(e[6]=n=>b.value=n)},{default:t(()=>[l(s(G),{class:"sm:max-w-[600px]"},{default:t(()=>[l(s(J),null,{default:t(()=>[l(s(O),{class:"text-green-600"},{default:t(()=>[...e[44]||(e[44]=[o("Token 创建成功",-1)])]),_:1}),l(s(Z),null,{default:t(()=>[...e[45]||(e[45]=[o(" 请妥善保存以下 Token它只会显示一次 ",-1)])]),_:1})]),_:1}),p.value?(d(),u("div",He,[a("div",Le,[a("div",Pe,[a("div",null,[e[46]||(e[46]=a("p",{class:"text-sm text-gray-600"},"Token 名称",-1)),a("p",Se,f(p.value.data.name),1)]),l(s(D),{variant:"outline"},{default:t(()=>[o(f(p.value.data.scope||"ALL"),1)]),_:1})]),a("div",he,[e[48]||(e[48]=a("p",{class:"text-sm text-gray-600"},"API Token",-1)),a("div",Ee,[a("code",Ue,f(p.value.token),1),l(s(_),{onClick:X,variant:"outline",size:"sm"},{default:t(()=>[...e[47]||(e[47]=[a("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})],-1)])]),_:1})])]),p.value.data.expire_at?(d(),u("div",Ne," 过期时间: "+f(A(p.value.data.expire_at)),1)):V("",!0)]),e[49]||(e[49]=a("div",{class:"mt-4 p-4 bg-yellow-50 border border-yellow-200 rounded-lg"},[a("div",{class:"flex"},[a("div",{class:"flex-shrink-0"},[a("svg",{class:"h-5 w-5 text-yellow-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})])]),a("div",{class:"ml-3"},[a("p",{class:"text-sm font-medium text-yellow-800"},"重要提醒"),a("p",{class:"text-sm text-yellow-700 mt-1"}," 此 Token 只显示一次,关闭对话框后将无法再次查看。请确保已妥善保存。 ")])])],-1))])):V("",!0),l(s(K),null,{default:t(()=>[l(s(_),{onClick:Y},{default:t(()=>[...e[50]||(e[50]=[o(" 我已保存,关闭 ",-1)])]),_:1})]),_:1})]),_:1})]),_:1},8,["open"]),l(s(re))]),_:1}))}}),os=_e(Fe,[["__scopeId","data-v-c7a1641d"]]);export{os as default};