var $url="/cms/templates/templatesAssetsEditor",validateRelatedFileName=function(t,e,i){""===e||"T_"===e?i(new Error("请输入文件文件")):i()},data=utils.init({siteId:utils.getQueryInt("siteId"),directoryPath:utils.getQueryString("directoryPath"),fileName:utils.getQueryString("fileName"),fileType:utils.getQueryString("fileType"),tabName:utils.getQueryString("tabName"),templatesAssetsIncludeDir:null,templatesAssetsCssDir:null,templatesAssetsJsDir:null,form:{path:null},contentEditor:null}),methods={apiGet:function(){var t=this;utils.loading(this,!0),$api.get($url,{params:{siteId:this.siteId,directoryPath:this.directoryPath,fileName:this.fileName,fileType:this.fileType}}).then(function(e){var i=e.data;t.templatesAssetsIncludeDir=i.templatesAssetsIncludeDir,t.templatesAssetsCssDir=i.templatesAssetsCssDir,t.templatesAssetsJsDir=i.templatesAssetsJsDir,t.form.path=i.path,t.setEditorContent(i.content)}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiSubmit:function(t){var e={siteId:this.siteId,path:this.form.path,fileType:this.fileType,content:this.getEditorContent(),directoryPath:this.directoryPath,fileName:this.fileName},i=this;utils.loading(this,!0),this.fileName?$api.put($url,e).then(function(e){var s=e.data;i.directoryPath=s.directoryPath,i.fileName=s.fileName,utils.success("文件保存成功!"),t&&i.closeAndReload()}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)}):$api.post($url,e).then(function(e){var s=e.data;i.directoryPath=s.directoryPath,i.fileName=s.fileName,utils.success("文件保存成功!"),t&&i.closeAndReload()}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},closeAndReload:function(){var t=utils.getTabVue(this.tabName);t&&t.apiList(),utils.removeTab(),utils.openTab(this.tabName)},getFileType:function(){return"html"===this.fileType?"包含文件":"css"===this.fileType?"样式文件":"js"===this.fileType?"脚本文件":""},getFileTypeDir:function(){return"html"===this.fileType?this.templatesAssetsIncludeDir+"/":"css"===this.fileType?this.templatesAssetsCssDir+"/":"js"===this.fileType?this.templatesAssetsJsDir+"/":""},getEditorContent:function(){return this.contentEditor.getModel().getValue()},setEditorContent:function(t){if(this.contentEditor)this.contentEditor.getModel().setValue(t),this.contentEditor.focus();else{var e=this,i="html";"css"===this.fileType?i="css":"js"===this.fileType&&(i="javascript"),setTimeout(function(){require.config({paths:{vs:utils.getAssetsUrl("lib/monaco-editor/min/vs")}}),require(["vs/editor/editor.main"],function(){e.contentEditor=monaco.editor.create(document.getElementById("content"),{value:t,language:i}),e.contentEditor.focus()})},100)}},btnFormatClick:function(){this.contentEditor.getAction("editor.action.formatDocument").run().then(function(){utils.success("文件代码格式化成功!")})},btnSubmitClick:function(t){var e=this;this.$refs.form.validate(function(i){i&&e.apiSubmit(t)})}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});