(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[459],{6429:function(n,e,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/login",function(){return t(1632)}])},6248:function(n,e,t){"use strict";t.d(e,{Z:function(){return o}});var a=t(5893),r=t(7294),c=t(1163),i=t(9415);let s=[{href:"/",label:"首页",icon:"home"},{href:"/stats",label:"统计",icon:"chart"},{href:"/recurring",label:"周期",icon:"repeat"},{href:"/categories",label:"分类",icon:"tags"}];function o(n){let{title:e,subtitle:t,actions:o,headerContent:u,children:l,contentClassName:d="",hideNav:h=!1,compactHeader:p=!1}=n,f=(0,c.useRouter)(),m=(0,r.useMemo)(()=>{let n=s.find(n=>n.href===f.pathname);return(null==n?void 0:n.href)||null},[f.pathname]),y=u||(e?(0,a.jsxs)("div",{className:"app-header__text",children:[(0,a.jsx)("h1",{children:e}),t?(0,a.jsx)("p",{children:t}):null]}):null),g=["app-header",p?"app-header--compact":"",y?"app-header--with-content":"app-header--actions-only",o?"app-header--with-actions":""].filter(Boolean).join(" ");return(0,a.jsxs)("div",{className:"app-shell".concat(h?" app-shell--standalone":""),children:[(0,a.jsx)("header",{className:g,children:(0,a.jsxs)("div",{className:"app-shell__container app-header__inner",children:[y?(0,a.jsx)("div",{className:"app-header__main",children:y}):(0,a.jsx)("div",{className:"app-header__spacer","aria-hidden":"true"}),o?(0,a.jsx)("div",{className:"app-header__actions",children:o}):null]})}),(0,a.jsx)("main",{className:"app-content ".concat(d).trim(),children:(0,a.jsx)("div",{className:"app-shell__container app-content__inner",children:l})}),h?null:(0,a.jsx)("nav",{className:"bottom-nav","aria-label":"主导航",children:(0,a.jsx)("div",{className:"app-shell__container bottom-nav__inner",children:s.map(n=>{let e=m===n.href;return(0,a.jsxs)("button",{type:"button",className:"bottom-nav__item".concat(e?" is-active":""),onClick:()=>f.push(n.href),"aria-current":e?"page":void 0,children:[(0,a.jsx)(i.J,{name:n.icon,size:20}),(0,a.jsx)("span",{children:n.label})]},n.href)})})})]})}},610:function(n,e,t){"use strict";async function a(n){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=await fetch("".concat("").concat(n),{...e,headers:{"Content-Type":"application/json",...function(){let n=localStorage.getItem("token");return n?{Authorization:"Bearer ".concat(n)}:{}}(),...e.headers}}),a=await t.json();if(!t.ok)throw Error(a.error||"请求失败");return a}async function r(n,e){let t=await a("/api/auth/login",{method:"POST",body:JSON.stringify({username:n,password:e})});return localStorage.setItem("token",t.token),t}async function c(n,e){let t=await a("/api/auth/register",{method:"POST",body:JSON.stringify({username:n,password:e})});return localStorage.setItem("token",t.token),t}function i(){localStorage.removeItem("token")}function s(){return!!localStorage.getItem("token")}async function o(n){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",t="/api/records?month=".concat(n);return"all"!==e&&(t+="&type=".concat(e)),a(t)}async function u(n){return a("/api/stats?month=".concat(n))}async function l(n){return a("/api/records",{method:"POST",body:JSON.stringify(n)})}async function d(n,e){return a("/api/records/".concat(n),{method:"PUT",body:JSON.stringify(e)})}async function h(n){return a("/api/records/".concat(n),{method:"DELETE"})}async function p(n){return a("/api/records/search?q=".concat(encodeURIComponent(n)))}async function f(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"month",e=arguments.length>1?arguments[1]:void 0,t="/api/stats/trend?period=".concat(n);return e&&(t+="&month=".concat(e)),a(t)}async function m(n){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",t="/api/stats/category?type=".concat(e);return n&&(t+="&month=".concat(n)),a(t)}async function y(){return a("/api/recurring")}async function g(n){return a("/api/recurring",{method:"POST",body:JSON.stringify(n)})}async function x(n,e){return a("/api/recurring/".concat(n),{method:"PUT",body:JSON.stringify(e)})}async function j(n){return a("/api/recurring/".concat(n),{method:"DELETE"})}async function N(n){return a("/api/recurring/".concat(n,"/apply"),{method:"POST"})}async function b(){return a("/api/categories")}async function v(n){return a("/api/categories",{method:"POST",body:JSON.stringify(n)})}async function _(n){return a("/api/categories/".concat(n),{method:"DELETE"})}async function S(){return a("/api/export")}async function k(n){return a("/api/import",{method:"POST",body:JSON.stringify(n)})}t.d(e,{Ap:function(){return m},CP:function(){return b},JS:function(){return h},Kp:function(){return p},Q6:function(){return o},TZ:function(){return j},Vn:function(){return y},Vs:function(){return d},Xu:function(){return N},ae:function(){return l},dk:function(){return k},fy:function(){return u},gR:function(){return f},jl:function(){return s},k4:function(){return v},kS:function(){return i},u1:function(){return S},uO:function(){return x},uu:function(){return _},x4:function(){return r},z0:function(){return g},z2:function(){return c}})},1632:function(n,e,t){"use strict";t.r(e),t.d(e,{default:function(){return l}});var a=t(5893),r=t(7294),c=t(1163),i=t(610),s=t(6248),o=t(9415),u=t(5546);function l(){let n=(0,c.useRouter)(),{showToast:e}=(0,u.p)(),[t,l]=(0,r.useState)(!0),[d,h]=(0,r.useState)(""),[p,f]=(0,r.useState)(""),[m,y]=(0,r.useState)(""),[g,x]=(0,r.useState)(!1);(0,r.useEffect)(()=>{(0,i.jl)()&&n.push("/")},[n]);let j=async a=>{a.preventDefault(),y(""),x(!0);try{t?(await (0,i.x4)(d,p),e("登录成功",{tone:"success"})):(await (0,i.z2)(d,p),e("注册成功",{tone:"success"})),n.push("/")}catch(n){y(n.message),e(n.message,{tone:"error"})}finally{x(!1)}};return(0,a.jsx)(s.Z,{title:"记账本",subtitle:"随时记录每一笔收支",hideNav:!0,contentClassName:"auth-layout",compactHeader:!0,children:(0,a.jsx)("div",{className:"auth-page",children:(0,a.jsxs)("div",{className:"auth-card auth-card--refresh",children:[(0,a.jsxs)("div",{className:"auth-logo auth-logo--refresh",children:[(0,a.jsx)("div",{className:"auth-logo__mark","aria-hidden":"true",children:(0,a.jsx)(o.J,{name:"chart",size:24})}),(0,a.jsx)("h1",{children:t?"欢迎回来":"创建账户"}),(0,a.jsx)("p",{children:t?"登录后继续记录每一笔收支":"注册后即可开始管理你的账本"})]}),(0,a.jsxs)("div",{className:"auth-switch",role:"tablist","aria-label":"登录或注册",children:[(0,a.jsx)("button",{type:"button",className:t?"is-active":"",onClick:()=>{l(!0),y("")},children:"登录"}),(0,a.jsx)("button",{type:"button",className:t?"":"is-active",onClick:()=>{l(!1),y("")},children:"注册"})]}),m&&(0,a.jsx)("div",{className:"error-msg",children:m}),(0,a.jsxs)("form",{onSubmit:j,className:"auth-form",children:[(0,a.jsxs)("div",{className:"form-group",children:[(0,a.jsx)("label",{htmlFor:"username",children:"用户名"}),(0,a.jsx)("input",{id:"username",type:"text",value:d,onChange:n=>h(n.target.value),placeholder:"3-20个字符",required:!0,disabled:g})]}),(0,a.jsxs)("div",{className:"form-group",children:[(0,a.jsx)("label",{htmlFor:"password",children:"密码"}),(0,a.jsx)("input",{id:"password",type:"password",value:p,onChange:n=>f(n.target.value),placeholder:"6-20个字符",required:!0,disabled:g})]}),(0,a.jsx)("button",{type:"submit",className:"btn btn-primary",disabled:g,children:g?(0,a.jsxs)("span",{className:"button-content",children:[(0,a.jsx)(o.J,{name:"spinner",size:16,className:"is-spinning"}),"处理中..."]}):t?"登录":"注册"})]})]})})})}},1163:function(n,e,t){n.exports=t(3079)}},function(n){n.O(0,[888,774,179],function(){return n(n.s=6429)}),_N_E=n.O()}]);