1 line
4.7 KiB
JavaScript
1 line
4.7 KiB
JavaScript
|
|
(this["webpackJsonpbeancount-web"]=this["webpackJsonpbeancount-web"]||[]).push([[13],{468:function(t,e,n){"use strict";n.r(e);var i=n(11),o=n(12),a=n(14),r=n(13),c=n(474),s=n(458),l=n(208),u=n(327),h=n(355),d=(n(450),n(0)),f=n(60),b=n(15),p=n(80),m=n(1),j=function(t){Object(a.a)(n,t);var e=Object(r.a)(n);function n(){var t;Object(i.a)(this,n);for(var o=arguments.length,a=new Array(o),r=0;r<o;r++)a[r]=arguments[r];return(t=e.call.apply(e,[this].concat(a))).theme=t.context.theme,t.state={loading:!1,path:null,files:[],rawContent:"",content:"",editorState:h.EditorState.createEmpty()},t.fetchFileDir=function(){t.setState({loading:!0}),Object(f.b)("/api/auth/file/dir").then((function(e){t.setState({files:e})})).finally((function(){t.setState({loading:!1})}))},t.handldEditContent=function(e){t.setState({editorState:e,content:e.getCurrentContent().getPlainText()})},t.handleChangeFile=function(e){t.setState({path:e},(function(){t.fetchFileContent(e)}))},t.fetchFileContent=function(){t.setState({loading:!0}),Object(f.b)("/api/auth/file/content?path=".concat(t.state.path)).then((function(e){t.setState({rawContent:e,content:e,editorState:h.EditorState.createWithContent(h.ContentState.createFromText(e))})})).finally((function(){t.setState({loading:!1})}))},t.saveFileContent=function(){var e=t.state,n=e.path,i=e.content;t.setState({loading:!0}),Object(f.b)("/api/auth/file",{method:"POST",body:{path:n,content:i}}).then((function(){t.setState({rawContent:i}),s.b.success("\u4fdd\u5b58\u6210\u529f")})).finally((function(){t.setState({loading:!1})}))},t}return Object(o.a)(n,[{key:"componentDidMount",value:function(){this.fetchFileDir()}},{key:"render",value:function(){return this.context.theme!==this.theme&&(this.theme=this.context.theme),Object(m.jsxs)("div",{className:"edit-page",children:[Object(m.jsxs)("div",{children:[Object(m.jsx)(l.a,{showSearch:!0,placeholder:"\u8bf7\u9009\u62e9\u6e90\u6587\u4ef6",style:{width:"200px"},onChange:this.handleChangeFile,children:this.state.files.map((function(t){return Object(m.jsx)(l.a.Option,{value:t,children:t},t)}))}),"\xa0\xa0",Object(m.jsx)(u.a,{type:"primary",icon:Object(m.jsx)(c.a,{}),disabled:this.state.rawContent===this.state.content,loading:this.state.loading,onClick:this.saveFileContent,children:"\u4fdd\u5b58"})]}),Object(m.jsx)("div",{style:{marginTop:"1rem"},children:Object(m.jsx)(h.Editor,{placeholder:"\u672a\u9009\u62e9\u6587\u4ef6",editorState:this.state.editorState,onChange:this.handldEditContent})})]})}}]),n}(d.Component);j.contextType=b.a,e.default=Object(p.a)(j)},60:function(t,e,n){"use strict";n.d(e,"c",(function(){return s})),n.d(e,"d",(function(){return l})),n.d(e,"e",(function(){return u})),n.d(e,"a",(function(){return h})),n.d(e,"b",(function(){return f})),n.d(e,"f",(function(){return b}));var i=n(458),o=n(88),a=n.n(o),r=n(214),c=n.n(r),s=function(t){var e=t.split(":");return e&&e.length>=1?t.split(":")[0]:""},l=function(t){for(var e=t.split(":").reverse(),n=0;n<e.length;n++){var i=e[n];if(new RegExp("^[a-zA-Z]").test(i))return i}return""},u=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},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.method,o=e.headers,a=e.body,r={"Content-Type":"application/json",ledgerId:window.localStorage.getItem("ledgerId")};return new Promise((function(e,s){c()(t,{method:n,headers:Object.assign({},r,o),body:JSON.stringify(a)}).then(d).then((function(t){return t.json()})).then((function(t){var n=t.code;200===n?e(t.data):200!==n&&(400===n?i.b.error("\u8bf7\u6c42\u53c2\u6570\u9519\u8bef"):1001===n?i.b.error("\u8d26\u76ee\u4e0d\u5e73\u8861"):1003===n?i.b.error("\u65e0\u6548\u8d26\u6237"):1005===n?i.b.error("\u65e0\u6548\u547d\u4ee4"):1006===n?i.b.error("\u5bc6\u7801\u9519\u8bef"):1010===n?window.location.href="/#/ledger":i.b.error("\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5"),s(t))})).catch((function(t){i.b.error("\u8bf7\u6c42\u5931\u8d25
|