Files
YelayMaths/yelaymaths_admin/.next/static/chunks/app/login/page-25e80207b9a6b8e3.js
T
2026-09-29 15:25:40 +08:00

1 line
7.9 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.
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[520],{1513:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>d});var r=n(1333),s=n(4705),a=n(8166),o=n(8312),l=n(1910),i=n(2787);function d(){let e=(0,a.useRouter)(),[t,n]=(0,s.useState)(""),[d,c]=(0,s.useState)(""),[u,m]=(0,s.useState)("login"),[h,g]=(0,s.useState)(""),[x,b]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1);return(0,r.jsx)("main",{className:"flex min-h-screen items-center justify-center p-4",children:(0,r.jsxs)("div",{className:"w-full max-w-sm",children:[(0,r.jsxs)("div",{className:"mb-6 text-center",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold text-gray-900",children:"叶雷讲数学"}),(0,r.jsx)("p",{className:"mt-1 text-sm text-gray-500",children:"管理后台"})]}),(0,r.jsxs)(i.Zp,{children:[(0,r.jsx)(i.$T,{message:h}),x&&(0,r.jsx)(i.$T,{message:x,kind:"success"}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"mb-1 block text-sm text-gray-600",children:"账号"}),(0,r.jsx)(i.pd,{value:t,onChange:n,placeholder:"管理员账号"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"mb-1 block text-sm text-gray-600",children:"密码"}),(0,r.jsx)(i.pd,{value:d,onChange:c,placeholder:"密码",type:"password"})]}),(0,r.jsx)(i.$n,{onClick:()=>{if(g(""),b(""),!t||!d)return void g("请输入账号与密码");p(!0),("login"===u?o.F.login(t,d):o.F.bootstrap(t,d)).then(t=>{if("bootstrap"===u){b(t.created?"管理员已创建,请切换到登录。":"系统已存在管理员,无法重复创建。"),m("login");return}(0,l.WG)(t.accessToken),e.replace("/")}).catch(e=>g(e.message)).finally(()=>p(!1))},disabled:f,children:f?"处理中…":"login"===u?"登录":"创建管理员"})]}),(0,r.jsx)("button",{onClick:()=>{m("login"===u?"bootstrap":"login"),g(""),b("")},className:"mt-4 text-xs text-blue-600 hover:underline",children:"login"===u?"首次部署?创建管理员账号":"返回登录"})]})]})})}},1910:(e,t,n)=>{"use strict";n.d(t,{L:()=>o,M3:()=>l,WG:()=>a,gf:()=>s});let r="yelay_admin_token";function s(){var e;return null!=(e=window.localStorage.getItem(r))?e:""}function a(e){window.localStorage.setItem(r,e)}function o(){window.localStorage.removeItem(r)}function l(){return""!==s()}},2787:(e,t,n)=>{"use strict";n.d(t,{$T:()=>c,$n:()=>s,Sv:()=>u,TM:()=>o,Zp:()=>i,aF:()=>d,l6:()=>l,pd:()=>a});var r=n(1333);function s(e){let{children:t,onClick:n,variant:s="primary",disabled:a,type:o="button"}=e;return(0,r.jsx)("button",{type:o,onClick:n,disabled:a,className:"rounded-md px-3 py-1.5 text-sm font-medium transition disabled:cursor-not-allowed disabled:opacity-50 ".concat({primary:"bg-blue-600 text-white hover:bg-blue-700",ghost:"bg-white text-gray-700 border border-gray-300 hover:bg-gray-50",danger:"bg-red-600 text-white hover:bg-red-700"}[s]),children:t})}function a(e){let{value:t,onChange:n,placeholder:s,type:a="text"}=e;return(0,r.jsx)("input",{type:a,value:t,placeholder:s,onChange:e=>n(e.target.value),className:"w-full rounded-md border border-gray-300 px-3 py-1.5 text-sm outline-none focus:border-blue-500"})}function o(e){let{value:t,onChange:n}=e;return(0,r.jsx)("textarea",{value:t,rows:6,onChange:e=>n(e.target.value),className:"w-full rounded-md border border-gray-300 px-3 py-1.5 font-mono text-xs outline-none focus:border-blue-500"})}function l(e){let{value:t,onChange:n,options:s}=e;return(0,r.jsx)("select",{value:t,onChange:e=>n(e.target.value),className:"w-full rounded-md border border-gray-300 px-3 py-1.5 text-sm outline-none focus:border-blue-500",children:s.map(e=>(0,r.jsx)("option",{value:String(e.value),children:e.label},e.value))})}function i(e){let{title:t,children:n,action:s}=e;return(0,r.jsxs)("section",{className:"rounded-lg border border-gray-200 bg-white p-5 shadow-sm",children:[(t||s)&&(0,r.jsxs)("header",{className:"mb-4 flex items-center justify-between",children:[t&&(0,r.jsx)("h2",{className:"text-base font-semibold text-gray-900",children:t}),s]}),n]})}function d(e){let{open:t,title:n,onClose:s,children:a,footer:o}=e;return t?(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:(0,r.jsxs)("div",{className:"max-h-[85vh] w-full max-w-2xl overflow-auto rounded-lg bg-white shadow-xl",children:[(0,r.jsxs)("header",{className:"flex items-center justify-between border-b border-gray-200 px-5 py-3",children:[(0,r.jsx)("h3",{className:"text-base font-semibold",children:n}),(0,r.jsx)("button",{onClick:s,className:"text-gray-400 hover:text-gray-600","aria-label":"关闭",children:"✕"})]}),(0,r.jsx)("div",{className:"px-5 py-4",children:a}),o&&(0,r.jsx)("footer",{className:"flex justify-end gap-2 border-t border-gray-200 px-5 py-3",children:o})]})}):null}function c(e){let{message:t,kind:n="error"}=e;return t?(0,r.jsx)("div",{className:"mb-3 rounded-md border px-3 py-2 text-sm ".concat("error"===n?"bg-red-50 text-red-700 border-red-200":"bg-green-50 text-green-700 border-green-200"),children:t}):null}function u(e){let{text:t="暂无数据"}=e;return(0,r.jsx)("div",{className:"py-10 text-center text-sm text-gray-400",children:t})}},5106:(e,t,n)=>{Promise.resolve().then(n.bind(n,1513))},8166:(e,t,n)=>{"use strict";var r=n(8874);n.o(r,"useParams")&&n.d(t,{useParams:function(){return r.useParams}}),n.o(r,"usePathname")&&n.d(t,{usePathname:function(){return r.usePathname}}),n.o(r,"useRouter")&&n.d(t,{useRouter:function(){return r.useRouter}})},8312:(e,t,n)=>{"use strict";n.d(t,{F:()=>l});var r=n(1910);let s="http://127.0.0.1:3000".replace(/\/+$/,"");async function a(e){var t,n,a,o,l;let i,d=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=(0,r.gf)(),u={"content-type":"application/json",...null!=(t=d.headers)?t:{}};c&&(u.Authorization="Bearer ".concat(c));try{i=await fetch("".concat(s).concat(e),{...d,headers:u})}catch(e){throw{code:-1,message:"无法连接服务端,请检查网络或接口地址"}}let m=null;try{m=await i.json()}catch(e){throw{code:-1,message:"服务端返回异常(HTTP ".concat(i.status,")")}}if(401===i.status)throw(0,r.L)(),window.location.pathname.startsWith("/login")||(window.location.href="/login"),{code:null!=(n=null==m?void 0:m.code)?n:2e3,message:null!=(a=null==m?void 0:m.message)?a:"登录已失效,请重新登录"};if(!m||0!==m.code)throw{code:null!=(o=null==m?void 0:m.code)?o:-1,message:null!=(l=null==m?void 0:m.message)?l:"请求失败"};return m.data}let o=e=>{let t=Object.entries(e).filter(e=>{let[,t]=e;return void 0!==t&&""!==t}).map(e=>{let[t,n]=e;return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(String(n)))});return t.length?"?".concat(t.join("&")):""},l={base:s,request:a,login:(e,t)=>a("/admin/v1/auth/login",{method:"POST",body:JSON.stringify({username:e,password:t})}),bootstrap:(e,t)=>a("/admin/v1/auth/bootstrap",{method:"POST",body:JSON.stringify({username:e,password:t})}),stats:()=>a("/admin/v1/stats"),listUsers:(e,t,n)=>a("/admin/v1/users".concat(o({page:e,pageSize:t,keyword:n}))),updateUser:(e,t)=>a("/admin/v1/users/".concat(e),{method:"PATCH",body:JSON.stringify(t)}),listResource:(e,t)=>a("/admin/v1/data/".concat(e).concat(o(t))),createResource:(e,t)=>a("/admin/v1/data/".concat(e),{method:"POST",body:JSON.stringify(t)}),updateResource:(e,t,n)=>a("/admin/v1/data/".concat(e,"/").concat(t),{method:"PATCH",body:JSON.stringify(n)}),deleteResource:(e,t)=>a("/admin/v1/data/".concat(e,"/").concat(t),{method:"DELETE"}),listSettings:()=>a("/admin/v1/settings"),upsertSetting:(e,t,n)=>a("/admin/v1/settings",{method:"PUT",body:JSON.stringify({key:e,value:t,remark:n})}),listOrders:(e,t,n)=>a("/admin/v1/orders".concat(o({page:e,pageSize:t,status:n}))),refundOrder:(e,t)=>a("/admin/v1/orders/".concat(e,"/refund"),{method:"POST",body:JSON.stringify({reason:t})}),listEntitlements:e=>a("/admin/v1/entitlements".concat(o({userId:e}))),grantEntitlement:(e,t,n)=>a("/admin/v1/entitlements",{method:"POST",body:JSON.stringify({userId:e,courseId:t,note:n})}),revokeEntitlement:(e,t)=>a("/admin/v1/entitlements".concat(o({userId:e,courseId:t})),{method:"DELETE"})}}},e=>{e.O(0,[964,857,358],()=>e(e.s=5106)),_N_E=e.O()}]);