1 line
16 KiB
JavaScript
1 line
16 KiB
JavaScript
(this["webpackJsonpbeancount-web"]=this["webpackJsonpbeancount-web"]||[]).push([[12],{125:function(t,e,n){"use strict";var a=n(61),c=n(12),i=n(13),o=n(15),r=n(14),s=n(135),u=n(73),l=n.n(u),h=n(0),d=n(59),j=n(1),f=function(t){Object(o.a)(n,t);var e=Object(r.a)(n);function n(){var t;Object(c.a)(this,n);for(var a=arguments.length,i=new Array(a),o=0;o<a;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).currentYear=l()().format("YYYY"),t.currentMonth=l()().format("YYYY-M"),t.state={loading:!1,years:[t.currentYear],months:[t.currentMonth]},t.queryMonthList=function(){t.setState({loading:!0}),Object(d.b)("/api/auth/stats/months").then((function(e){var n=Array.from(new Set(e.map((function(t){return t.split("-")[0]}))));t.setState({months:e,years:n})})).catch(console.error).finally((function(){t.setState({loading:!1})}))},t}return Object(i.a)(n,[{key:"componentDidMount",value:function(){this.queryMonthList()}},{key:"render",value:function(){return Object(j.jsxs)(s.a,Object(a.a)(Object(a.a)({size:"small",showSearch:!0,placeholder:"\u9009\u62e9\u6708\u4efd",style:{width:"120px"}},this.props),{},{children:[Object(j.jsx)(s.a.Option,{value:"",children:"\u4e0d\u9650"}),this.state.years.map((function(t){return Object(j.jsx)(s.a.Option,{value:t,children:l()(t).format("YYYY\u5e74")},t)})),this.state.months.map((function(t){return Object(j.jsx)(s.a.Option,{value:t,children:l()(t).format("YYYY\u5e74MM\u6708")},t)}))]}))}}]),n}(h.Component);e.a=f},174:function(t,e,n){"use strict";var a=n(61),c=n(455),i=(n(0),n(1));e.a=function(t){return t.hide?Object(i.jsx)(c.a,Object(a.a)(Object(a.a)({},t),{},{value:"***",prefix:t.hide?"":t.prefix})):Object(i.jsx)(c.a,Object(a.a)({},t))}},356:function(t,e,n){},478:function(t,e,n){"use strict";n.r(e);var a=n(12),c=n(13),i=n(15),o=n(14),r=n(469),s=n(273),u=n(352),l=n(353),h=n(270),d=n(0),j=n(124),f=n(476),p=n(135),b=n(150),y=n(59),O=n(125),v=n(1),x=function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).state={loading:!1,dayAmountData:[],type:"avg",accountPrefix:"Expenses",selectedMonth:Object(y.f)()},t.queryAccountDayTrend=function(){var e,n;t.setState({loading:!0});var a=t.state,c=a.accountPrefix,i=a.selectedMonth,o=a.type;if(i){var r=i.split("-").filter((function(t){return t}));1===r.length?e=r[0]:2===r.length&&(e=r[0],n=r[1])}Object(y.b)("/api/auth/stats/account/trend?prefix=".concat(c,"&year=").concat(e||"","&month=").concat(n||"","&type=").concat(o)).then((function(e){t.setState({dayAmountData:e})})).finally((function(){t.setState({loading:!1})}))},t.handleEnter=function(e){if("Enter"===e.key){var n=t.accountInput.input.value.trim();t.setState({accountPrefix:n},(function(){t.queryAccountDayTrend()}))}},t.handleChangeStatsType=function(e){t.setState({type:e},(function(){t.queryAccountDayTrend()}))},t.handleChangeMonth=function(e){t.setState({selectedMonth:e},(function(){t.queryAccountDayTrend()}))},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.queryAccountDayTrend()}},{key:"render",value:function(){var t=this;return this.props.chartLoading?Object(v.jsx)("div",{style:{height:480,display:"flex",alignItems:"center",justifyContent:"center"},children:Object(v.jsx)(j.a,{})}):Object(v.jsxs)("div",{style:{marginTop:"1rem"},children:[Object(v.jsx)(O.a,{size:"middle",value:this.state.selectedMonth,onChange:this.handleChangeMonth}),"\xa0",Object(v.jsx)(f.a,{ref:function(e){return t.accountInput=e},defaultValue:this.state.accountPrefix,placeholder:"\u8f93\u5165\u8d26\u6237",style:{width:"240px"},onKeyPress:this.handleEnter,addonAfter:Object(v.jsxs)(p.a,{value:this.state.type,onChange:this.handleChangeStatsType,children:[Object(v.jsx)(p.a.Option,{value:"avg",children:"\u6bcf\u5929"}),Object(v.jsx)(p.a.Option,{value:"sum",children:"\u7d2f\u8ba1"})]})}),Object(v.jsx)(j.a,{spinning:this.state.loading,children:Object(v.jsxs)(b.Chart,{height:480,autoFit:!0,data:this.state.dayAmountData,interactions:["active-region"],padding:[30,30,30,50],children:[Object(v.jsx)(b.Interval,{position:"date*amount"}),Object(v.jsx)(b.Tooltip,{children:function(t,e){return Object(v.jsxs)("div",{style:{padding:".8rem 1rem"},children:[t,": ",e[0].data.amount,"\u5143"]})}})]})})]})}}]),n}(d.Component),m=function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).state={loading:!1,incomeExpenses:[]},t.queryMonthIncomeExpenses=function(){t.setState({loading:!0}),Object(y.b)("/api/auth/stats/month/total").then((function(e){t.setState({incomeExpenses:e})})).finally((function(){t.setState({loading:!1})}))},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.queryMonthIncomeExpenses()}},{key:"render",value:function(){return this.props.chartLoading?Object(v.jsx)("div",{style:{height:400,display:"flex",alignItems:"center",justifyContent:"center"},children:Object(v.jsx)(j.a,{})}):Object(v.jsx)("div",{children:Object(v.jsx)(j.a,{spinning:this.state.loading,children:Object(v.jsx)(b.Chart,{animate:!1,padding:[10,20,80,40],autoFit:!0,height:400,data:this.state.incomeExpenses,children:Object(v.jsx)(b.LineAdvance,{shape:"smooth",point:!0,area:!0,position:"month*amount",color:"type"})})})})}}]),n}(d.Component),g=function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).state={loading:!1,payee:[],type:"cot",accountPrefix:"Expenses",selectedMonth:Object(y.f)()},t.queryPayeeStatsValue=function(){var e,n;t.setState({loading:!0});var a=t.state,c=a.accountPrefix,i=a.selectedMonth,o=a.type;if(i){var r=i.split("-").filter((function(t){return t}));1===r.length?e=r[0]:2===r.length&&(e=r[0],n=r[1])}Object(y.b)("/api/auth/stats/payee?prefix=".concat(c,"&year=").concat(e||"","&month=").concat(n||"","&type=").concat(o)).then((function(e){var n=e.slice(-25);t.setState({payee:n})})).finally((function(){t.setState({loading:!1})}))},t.handleEnter=function(e){if("Enter"===e.key){var n=t.accountInput.input.value.trim();t.setState({accountPrefix:n},(function(){t.queryPayeeStatsValue()}))}},t.handleChangeStatsType=function(e){t.setState({type:e},(function(){t.queryPayeeStatsValue()}))},t.handleChangeMonth=function(e){t.setState({selectedMonth:e},(function(){t.queryPayeeStatsValue()}))},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.queryPayeeStatsValue()}},{key:"render",value:function(){var t=this;return this.props.chartLoading?Object(v.jsx)("div",{style:{height:560,display:"flex",alignItems:"center",justifyContent:"center"},children:Object(v.jsx)(j.a,{})}):Object(v.jsxs)("div",{style:{marginTop:"1rem"},children:[Object(v.jsx)(O.a,{size:"middle",value:this.state.selectedMonth,onChange:this.handleChangeMonth}),"\xa0",Object(v.jsx)(f.a,{ref:function(e){return t.accountInput=e},defaultValue:this.state.accountPrefix,placeholder:"\u8f93\u5165\u8d26\u6237",style:{width:"240px"},onKeyPress:this.handleEnter,addonAfter:Object(v.jsxs)(p.a,{value:this.state.type,onChange:this.handleChangeStatsType,children:[Object(v.jsx)(p.a.Option,{value:"cot",children:"\u9891\u6b21"}),Object(v.jsx)(p.a.Option,{value:"avg",children:"\u5355\u7b14"}),Object(v.jsx)(p.a.Option,{value:"sum",children:"\u7d2f\u8ba1"})]})}),Object(v.jsx)(j.a,{spinning:this.state.loading,children:Object(v.jsxs)(b.Chart,{height:560,data:this.state.payee,autoFit:!0,scale:{value:{formatter:function(e){return"".concat(e).concat("cot"===t.state.type?"\u6b21":"\u5143")}}},children:[Object(v.jsx)(b.Coordinate,{transpose:!0}),Object(v.jsx)(b.Interval,{position:"payee*value",label:["value",function(t){return{position:"middle",style:{fill:"#fff"}}}]}),Object(v.jsx)(b.Interaction,{type:"active-region"})]})})]})}}]),n}(d.Component),S=n(91),C=n.n(S),M=function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).state={loading:!1,subAccountPercentData:[],level:"1",accountPrefix:"Expenses",selectedMonth:Object(y.f)()},t.queryStatsSubAccountPercent=function(){var e,n;t.setState({loading:!0});var a=t.state,c=a.accountPrefix,i=a.level,o=a.selectedMonth;if(o){var r=o.split("-").filter((function(t){return t}));1===r.length?e=r[0]:2===r.length&&(e=r[0],n=r[1])}Object(y.b)("/api/auth/stats/account/percent?prefix=".concat(c,"&year=").concat(e||"","&month=").concat(n||"","&level=").concat(i)).then((function(e){var n=C()(0);e.forEach((function(t){n=n.plus(t.amount)})),n=n.toFixed(2),t.setState({subAccountPercentData:e.map((function(e){var a=C()(e.amount).toFixed(2);return{item:e.account.replace(t.state.accountPrefix,"").replace(":",""),count:Number(a),percent:Number(C()(a/n).toFixed(5))}}))})})).finally((function(){t.setState({loading:!1})}))},t.handleEnter=function(e){if("Enter"===e.key){var n=t.accountInput.input.value.trim();t.setState({accountPrefix:n},(function(){t.queryStatsSubAccountPercent()}))}},t.handleChangeAccountLevel=function(e){t.setState({level:e},(function(){t.queryStatsSubAccountPercent()}))},t.handleChangeMonth=function(e){t.setState({selectedMonth:e},(function(){t.queryStatsSubAccountPercent()}))},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.queryStatsSubAccountPercent()}},{key:"render",value:function(){var t=this;return this.props.chartLoading?Object(v.jsx)("div",{style:{height:500,display:"flex",alignItems:"center",justifyContent:"center"},children:Object(v.jsx)(j.a,{})}):Object(v.jsxs)("div",{style:{marginTop:"1rem"},children:[Object(v.jsx)(O.a,{size:"middle",value:this.state.selectedMonth,onChange:this.handleChangeMonth}),"\xa0",Object(v.jsx)(f.a,{ref:function(e){return t.accountInput=e},defaultValue:this.state.accountPrefix,placeholder:"\u8f93\u5165\u8d26\u6237",style:{width:"240px"},onKeyPress:this.handleEnter,addonAfter:Object(v.jsxs)(p.a,{defaultValue:"1",value:this.state.level,onChange:this.handleChangeAccountLevel,children:[Object(v.jsx)(p.a.Option,{value:"1",children:"\u4e00\u5c42"}),Object(v.jsx)(p.a.Option,{value:"2",children:"\u4e8c\u5c42"}),Object(v.jsx)(p.a.Option,{value:"",children:"\u4e0d\u9650\u5236"})]})}),Object(v.jsx)(j.a,{spinning:this.state.loading,children:Object(v.jsxs)(b.Chart,{height:560,data:this.state.subAccountPercentData,scale:{percent:{formatter:function(t){return t=100*t+"%"}}},autoFit:!0,onGetG2Instance:function(t){t.geometries[0].elements.forEach((function(t,e){t.setState("selected",0===e)}))},children:[Object(v.jsx)(b.Coordinate,{type:"theta",radius:.75}),Object(v.jsx)(b.Tooltip,{children:function(t,e){return Object(v.jsxs)("div",{style:{padding:".8rem 1rem"},children:[t,": ",e[0].data.count,"\u5143"]})}}),Object(v.jsx)(b.Axis,{visible:!1}),Object(v.jsx)(b.Interval,{position:"percent",adjust:"stack",color:"item",style:{lineWidth:1,stroke:"#fff"},label:["count",{content:function(t){var e=t.item;if(e.indexOf(":")>=0){var n=e.split(":");e=n[n.length-1]}return"".concat(e,": ").concat(Number(100*t.percent).toFixed(2),"%")}}]}),Object(v.jsx)(b.Interaction,{type:"element-single-selected"})]})})]})}}]),n}(d.Component),A=n(174),P=n(16),E=n(70),I=(n(356),function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];return(t=e.call.apply(e,[this].concat(i))).theme=t.context.theme,t.timeoutEvent=null,t.state={loading:!1,chartLoading:!1,Assets:0,Income:0,Expenses:0,Liabilities:0,hideMoney:window.localStorage.getItem("hideMoney")||!1},t.queryStatsTotalAmount=function(){t.setState({loading:!0}),Object(y.b)("/api/auth/stats/total").then((function(e){var n=e.Income,a=e.Expenses,c=e.Liabilities,i=e.Assets;t.setState({Assets:i,Income:n,Expenses:a,Liabilities:c})})).catch(console.error).finally((function(){t.setState({loading:!1})}))},t.handleChnageTab=function(){t.timeoutEvent&&clearTimeout(t.timeoutEvent),t.setState({chartLoading:!0}),t.timeoutEvent=setTimeout((function(){t.setState({chartLoading:!1})}),300)},t.handleHideMoney=function(){var e=!t.state.hideMoney;t.setState({hideMoney:e}),window.localStorage.setItem("hideMoney",e)},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.queryStatsTotalAmount()}},{key:"componentWillUnmount",value:function(){this.timeoutEvent&&clearTimeout(this.timeoutEvent)}},{key:"render",value:function(){this.context.theme!==this.theme&&(this.theme=this.context.theme);var t=this.state,e=t.loading,n=t.hideMoney;return Object(v.jsxs)("div",{className:"stats-page",children:[Object(v.jsxs)("h1",{children:["\u8d44\u4ea7\u7edf\u8ba1",n?Object(v.jsx)(r.a,{onClick:this.handleHideMoney}):Object(v.jsx)(s.a,{onClick:this.handleHideMoney})]}),Object(v.jsxs)("div",{children:[Object(v.jsx)(u.a,{gutter:16,children:Object(v.jsx)(l.a,{span:12,offset:6,children:Object(v.jsx)(A.a,{hide:n,style:{cursor:"pointer"},title:"".concat(y.a.Assets,"\u603b\u989d"),value:this.state.Assets||0,loading:e})})}),Object(v.jsx)("div",{style:{height:"1rem"}}),Object(v.jsxs)(u.a,{gutter:16,children:[Object(v.jsx)(l.a,{span:8,children:Object(v.jsx)(A.a,{hide:n,title:"\u7d2f\u8ba1".concat(y.a.Income),value:-this.state.Income||0,loading:e,prefix:"+",valueStyle:{color:"#cf1322"}})}),Object(v.jsx)(l.a,{span:8,children:Object(v.jsx)(A.a,{hide:n,title:"\u7d2f\u8ba1".concat(y.a.Expenses),value:this.state.Expenses||0,loading:e,prefix:"-",valueStyle:{color:"#3f8600"}})}),Object(v.jsx)(l.a,{span:8,children:Object(v.jsx)(A.a,{hide:n,title:"\u7d2f\u8ba1".concat(y.a.Liabilities),value:-this.state.Liabilities||0,loading:e,prefix:"-",valueStyle:{color:"#3f8600"}})})]})]}),Object(v.jsxs)(h.a,{defaultActiveKey:"1",centered:!0,style:{marginTop:"2rem"},onChange:this.handleChnageTab,children:[Object(v.jsx)(h.a.TabPane,{tab:"\u6708\u5ea6\u6536\u652f\u7edf\u8ba1\u56fe",children:Object(v.jsx)(m,{chartLoading:this.state.chartLoading})},"1"),Object(v.jsx)(h.a.TabPane,{tab:"\u8d26\u6237\u5206\u5e03\u5360\u6bd4",children:Object(v.jsx)(M,{chartLoading:this.state.chartLoading})},"2"),Object(v.jsx)(h.a.TabPane,{tab:"\u8d26\u6237\u65e5\u8d8b\u52bf",children:Object(v.jsx)(x,{chartLoading:this.state.chartLoading})},"3"),Object(v.jsx)(h.a.TabPane,{tab:"\u5546\u6237\u6d88\u8d39\u6392\u884c",children:Object(v.jsx)(g,{chartLoading:this.state.chartLoading})},"4")]})]})}}]),n}(d.Component));I.contextType=P.a;e.default=Object(E.a)(I)},59:function(t,e,n){"use strict";n.d(e,"c",(function(){return s})),n.d(e,"d",(function(){return u})),n.d(e,"e",(function(){return l})),n.d(e,"a",(function(){return h})),n.d(e,"b",(function(){return j})),n.d(e,"f",(function(){return f}));var a=n(463),c=n(73),i=n.n(c),o=n(112),r=n.n(o),s=function(t){var e=t.split(":");return e&&e.length>=1?t.split(":")[0]:""},u=function(t){return t.split(":").join("_")},l=function(t){var e=t.split(":");return e&&e.length>=2?t.split(":")[e.length-1]:""},h={Income:"\u6536\u5165",Expenses:"\u652f\u51fa",Liabilities:"\u8d1f\u503a",Assets:"\u8d44\u4ea7"},d=function(t){return t},j=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.method,c=e.headers,i=e.body,o={"Content-Type":"application/json",ledgerId:window.localStorage.getItem("ledgerId")};return new Promise((function(e,s){r()(t,{method:n,headers:Object.assign({},o,c),body:JSON.stringify(i)}).then(d).then((function(t){return t.json()})).then((function(t){var n=t.code;200===n?e(t.data):200!==n&&(400===n?a.b.error("\u8bf7\u6c42\u53c2\u6570\u9519\u8bef"):1001===n?a.b.error("\u8d26\u76ee\u4e0d\u5e73\u8861"):1003===n?a.b.error("\u65e0\u6548\u8d26\u6237"):1005===n?a.b.error("\u65e0\u6548\u547d\u4ee4"):1006===n?a.b.error("\u5bc6\u7801\u9519\u8bef"):1007===n?a.b.error("\u8d26\u6237\u5df2\u5b58\u5728"):1010===n||401===n?window.location.href="/web/#/ledger":a.b.error("\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5"),s(t))})).catch((function(t){a.b.error("\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5"),s(t)}))}))},f=function(){return i()().format("YYYY-M")}},70:function(t,e,n){"use strict";var a=n(61),c=n(12),i=n(13),o=n(15),r=n(14),s=n(0),u=n(1);e.a=function(t){return function(e){Object(o.a)(s,e);var n=Object(r.a)(s);function s(){var t;Object(c.a)(this,s);for(var e=arguments.length,a=new Array(e),i=0;i<e;i++)a[i]=arguments[i];return(t=n.call.apply(n,[this].concat(a))).defaultCommodity={currency:"CNY",symbol:"\uffe5"},t.currentCommodity=window.localStorage.getItem("ledgerCurrency"),t}return Object(i.a)(s,[{key:"render",value:function(){return Object(u.jsx)(t,Object(a.a)(Object(a.a)({},this.props),{},{commodity:this.currentCommodity?JSON.parse(this.currentCommodity):this.defaultCommodity}))}}]),s}(s.Component)}}}]); |