1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[240],{1273:function(e,t,r){Promise.resolve().then(r.bind(r,2688))},2688:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return i}});var a=r(7437),s=r(2265),n=r(8145),o=r(1837);function i(){let{user:e}=(0,n.a)(),[t,r]=(0,s.useState)([]),[i,c]=(0,s.useState)(!0),[l,d]=(0,s.useState)(""),[m,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,b]=(0,s.useState)("user"),[p,y]=(0,s.useState)(!1),[g,j]=(0,s.useState)(""),[w,N]=(0,s.useState)(null),[v,k]=(0,s.useState)(null),[S,C]=(0,s.useState)(!1);function _(e,t){let r="用户名:".concat(e,"\n密码:").concat(t);navigator.clipboard.writeText(r).then(()=>{C(!0),setTimeout(()=>C(!1),2e3)})}let E=(0,s.useCallback)(async()=>{try{let e=await (0,o.jK)();r(e)}catch(e){d("加载用户列表失败")}finally{c(!1)}},[]);if((0,s.useEffect)(()=>{(null==e?void 0:e.role)==="admin"&&E()},[e,E]),(null==e?void 0:e.role)!=="admin")return(0,a.jsx)("div",{className:"max-w-4xl mx-auto px-4 md:px-8 pt-6",children:(0,a.jsx)("p",{className:"text-text-muted text-sm",children:"需要管理员权限"})});async function I(e){if(e.preventDefault(),j(""),!x.trim()){j("请输入用户名");return}y(!0);try{let e=await (0,o.Pj)(x.trim(),f);N({username:e.username,password:e.password}),h(""),b("user"),E()}catch(e){j(e instanceof Error?e.message:"创建失败")}finally{y(!1)}}async function O(e){try{await (0,o.fK)(e),E()}catch(e){alert(e instanceof Error?e.message:"操作失败")}}async function P(e){try{let t=await (0,o.oQ)(e);k({username:t.username,password:t.password}),E()}catch(e){alert(e instanceof Error?e.message:"操作失败")}}return(0,a.jsxs)("div",{className:"max-w-4xl mx-auto px-4 md:px-8 pt-6 pb-20 md:pb-10 space-y-6",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between animate-fade-in-up",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-xl font-semibold tracking-tight",children:"用户管理"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-1",children:"创建和管理系统用户"})]}),(0,a.jsx)("button",{onClick:()=>{u(!0),j(""),N(null)},className:"px-4 py-2 rounded-xl text-sm font-medium bg-gradient-to-r from-amber-500/20 to-amber-600/15 text-amber-400 border border-amber-500/10 hover:from-amber-500/30 hover:to-amber-600/25 transition-all",children:"+ 创建用户"})]}),l&&(0,a.jsx)("p",{className:"text-sm text-amber-400/80 animate-fade-in-up",children:l}),i?(0,a.jsx)("div",{className:"space-y-3",children:[1,2,3].map(e=>(0,a.jsx)("div",{className:"glass-card-static p-4 animate-shimmer rounded-xl h-16"},e))}):(0,a.jsxs)("div",{className:"space-y-2 animate-fade-in-up delay-75",children:[t.map(t=>(0,a.jsxs)("div",{className:"glass-card p-4 rounded-xl flex items-center justify-between gap-4 ".concat(t.is_active?"":"opacity-50"),children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,a.jsx)("div",{className:"w-9 h-9 rounded-full bg-white/[0.04] border border-white/[0.06] flex items-center justify-center text-sm font-medium text-text-secondary shrink-0",children:t.username.charAt(0).toUpperCase()}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-text-primary truncate",children:t.username}),(0,a.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded ".concat("admin"===t.role?"bg-amber-500/10 text-amber-400/80":"bg-white/[0.04] text-text-muted"),children:t.role}),!t.is_active&&(0,a.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-red-500/10 text-red-400/80",children:"已禁用"})]}),t.created_at&&(0,a.jsxs)("p",{className:"text-xs text-text-muted mt-0.5",children:["创建于 ",new Date(t.created_at).toLocaleDateString("zh-CN")]})]})]}),t.id!==e.id&&(0,a.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,a.jsx)("button",{onClick:()=>P(t.id),className:"px-3 py-1.5 rounded-lg text-xs text-text-secondary hover:text-text-primary bg-white/[0.03] hover:bg-white/[0.06] border border-white/[0.04] transition-all",children:"重置密码"}),t.is_active?(0,a.jsx)("button",{onClick:()=>O(t.id),className:"px-3 py-1.5 rounded-lg text-xs text-red-400/60 hover:text-red-400 bg-red-500/[0.03] hover:bg-red-500/[0.08] border border-red-500/[0.06] transition-all",children:"禁用"}):(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"已禁用"})]})]},t.id)),0===t.length&&(0,a.jsx)("div",{className:"glass-card-static p-8 rounded-xl text-center",children:(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"暂无用户"})})]}),m&&(0,a.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>u(!1)}),(0,a.jsx)("div",{className:"relative w-full max-w-sm mx-4 p-6 rounded-2xl bg-bg-card border border-white/[0.06] shadow-card",children:w?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("h3",{className:"text-base font-semibold text-text-primary",children:"用户创建成功"}),(0,a.jsxs)("div",{className:"p-4 rounded-xl bg-white/[0.02] border border-white/[0.04] space-y-2",children:[(0,a.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,a.jsx)("span",{className:"text-text-muted",children:"用户名"}),(0,a.jsx)("span",{className:"text-text-primary font-medium",children:w.username})]}),(0,a.jsxs)("div",{className:"flex justify-between text-sm items-center",children:[(0,a.jsx)("span",{className:"text-text-muted",children:"密码"}),(0,a.jsx)("span",{className:"text-amber-400 font-mono text-xs",children:w.password})]})]}),(0,a.jsx)("p",{className:"text-xs text-amber-400/60",children:"请妥善保管密码,此密码仅显示一次"}),(0,a.jsxs)("div",{className:"flex gap-3",children:[(0,a.jsx)("button",{onClick:()=>_(w.username,w.password),className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-gradient-to-r from-amber-500/20 to-amber-600/15 text-amber-400 border border-amber-500/10 hover:from-amber-500/30 hover:to-amber-600/25 transition-all",children:S?"已复制":"一键复制"}),(0,a.jsx)("button",{onClick:()=>u(!1),className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-white/[0.04] border border-white/[0.06] text-text-secondary hover:text-text-primary hover:bg-white/[0.06] transition-all",children:"关闭"})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h3",{className:"text-base font-semibold text-text-primary mb-5",children:"创建新用户"}),(0,a.jsxs)("form",{onSubmit:I,className:"space-y-3",children:[(0,a.jsx)("input",{type:"text",placeholder:"用户名",value:x,onChange:e=>h(e.target.value),className:"w-full bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-2.5 text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-amber-500/30 placeholder-text-muted/40"}),(0,a.jsxs)("select",{value:f,onChange:e=>b(e.target.value),className:"w-full bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-2.5 text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-amber-500/30 appearance-none",children:[(0,a.jsx)("option",{value:"user",className:"bg-bg-card text-text-primary",children:"普通用户"}),(0,a.jsx)("option",{value:"admin",className:"bg-bg-card text-text-primary",children:"管理员"})]}),g&&(0,a.jsx)("p",{className:"text-xs text-amber-400/80",children:g}),(0,a.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>u(!1),className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-white/[0.04] border border-white/[0.06] text-text-secondary hover:text-text-primary hover:bg-white/[0.06] transition-all",children:"取消"}),(0,a.jsx)("button",{type:"submit",disabled:p,className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-gradient-to-r from-amber-500/20 to-amber-600/15 text-amber-400 border border-amber-500/10 hover:from-amber-500/30 hover:to-amber-600/25 transition-all disabled:opacity-50",children:p?"创建中...":"创建"})]})]})]})})]}),v&&(0,a.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>k(null)}),(0,a.jsxs)("div",{className:"relative w-full max-w-sm mx-4 p-6 rounded-2xl bg-bg-card border border-white/[0.06] shadow-card space-y-4",children:[(0,a.jsx)("h3",{className:"text-base font-semibold text-text-primary",children:"密码已重置"}),(0,a.jsxs)("div",{className:"p-4 rounded-xl bg-white/[0.02] border border-white/[0.04] space-y-2",children:[(0,a.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,a.jsx)("span",{className:"text-text-muted",children:"用户名"}),(0,a.jsx)("span",{className:"text-text-primary font-medium",children:v.username})]}),(0,a.jsxs)("div",{className:"flex justify-between text-sm items-center",children:[(0,a.jsx)("span",{className:"text-text-muted",children:"新密码"}),(0,a.jsx)("span",{className:"text-amber-400 font-mono text-xs",children:v.password})]})]}),(0,a.jsx)("p",{className:"text-xs text-amber-400/60",children:"请妥善保管新密码,此密码仅显示一次"}),(0,a.jsxs)("div",{className:"flex gap-3",children:[(0,a.jsx)("button",{onClick:()=>_(v.username,v.password),className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-gradient-to-r from-amber-500/20 to-amber-600/15 text-amber-400 border border-amber-500/10 hover:from-amber-500/30 hover:to-amber-600/25 transition-all",children:S?"已复制":"一键复制"}),(0,a.jsx)("button",{onClick:()=>k(null),className:"flex-1 py-2.5 rounded-xl text-sm font-medium bg-white/[0.04] border border-white/[0.06] text-text-secondary hover:text-text-primary hover:bg-white/[0.06] transition-all",children:"关闭"})]})]})]})]})}},8145:function(e,t,r){"use strict";r.d(t,{AuthProvider:function(){return i},a:function(){return c}});var a=r(7437),s=r(2265),n=r(1837);let o=(0,s.createContext)({user:null,loading:!0,login:async()=>{},logout:()=>{}});function i(e){let{children:t}=e,[r,i]=(0,s.useState)(null),[c,l]=(0,s.useState)(!0);(0,s.useEffect)(()=>{let e=localStorage.getItem("auth_token"),t=localStorage.getItem("auth_user");if(e&&t)try{i(JSON.parse(t))}catch(e){localStorage.removeItem("auth_token"),localStorage.removeItem("auth_user")}l(!1)},[]);let d=(0,s.useCallback)(async(e,t)=>{let r=await (0,n.UO)(e,t);localStorage.setItem("auth_token",r.token),localStorage.setItem("auth_user",JSON.stringify(r.user)),i(r.user)},[]),m=(0,s.useCallback)(()=>{localStorage.removeItem("auth_token"),localStorage.removeItem("auth_user"),i(null),window.location.href="/login"},[]);return(0,a.jsx)(o.Provider,{value:{user:r,loading:c,login:d,logout:m},children:t})}function c(){return(0,s.useContext)(o)}},1837:function(e,t,r){"use strict";function a(){return localStorage.getItem("auth_token")}function s(){localStorage.removeItem("auth_token"),localStorage.removeItem("auth_user"),window.location.href="/login"}async function n(e){let t=a(),r={};t&&(r.Authorization="Bearer ".concat(t));let n=await fetch("".concat("").concat(e),{headers:r});if(401===n.status)throw s(),Error("Unauthorized");if(!n.ok)throw Error("API error: ".concat(n.status));return n.json()}async function o(e,t){let r=a(),n={"Content-Type":"application/json"};r&&(n.Authorization="Bearer ".concat(r));let o=await fetch("".concat("").concat(e),{method:"POST",headers:n,body:t?JSON.stringify(t):void 0});if(401===o.status)throw s(),Error("Unauthorized");if(!o.ok)throw Error("API error: ".concat(o.status));return o.json()}async function i(e){let t=a(),r={};t&&(r.Authorization="Bearer ".concat(t));let n=await fetch("".concat("").concat(e),{method:"DELETE",headers:r});if(401===n.status)throw s(),Error("Unauthorized");if(!n.ok)throw Error((await n.json().catch(()=>({}))).detail||"API error: ".concat(n.status));return n.json()}async function*c(e){let t=a(),r={"Content-Type":"application/json"};t&&(r.Authorization="Bearer ".concat(t));let n=await fetch("".concat("","/api/chat/stream"),{method:"POST",headers:r,body:JSON.stringify({messages:e})});if(401===n.status)throw s(),Error("Unauthorized");if(!n.ok)throw Error("Chat API error: ".concat(n.status));if(!n.body)throw Error("No response body");let o=n.body.getReader(),i=new TextDecoder,c="";for(;;){let{done:e,value:t}=await o.read();if(e)break;let r=(c+=i.decode(t,{stream:!0})).split("\n");for(let e of(c=r.pop()||"",r))if(e.startsWith("data: ")){let t=e.slice(6).trim();if("[DONE]"===t)return;try{let e=JSON.parse(t);yield e}catch(e){}}}}async function l(e,t){let r=await fetch("".concat("","/api/auth/login"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!r.ok)throw Error((await r.json().catch(()=>({}))).detail||"Login failed: ".concat(r.status));return r.json()}async function d(){return n("/api/auth/users")}async function m(e,t){return o("/api/auth/users",{username:e,role:t})}async function u(e){return i("/api/auth/users/".concat(e))}async function x(e){return o("/api/auth/users/".concat(e,"/reset-password"))}async function h(e,t){return o("/api/auth/change-password",{old_password:e,new_password:t})}r.d(t,{Io:function(){return n},Pj:function(){return m},UO:function(){return l},Ul:function(){return h},fK:function(){return u},jK:function(){return d},l8:function(){return o},oQ:function(){return x},ov:function(){return c}})}},function(e){e.O(0,[971,117,744],function(){return e(e.s=1273)}),_N_E=e.O()}]); |