

<script>
/* eslint-disable */
// sd-skip-auto-import
import cloneDeep from"lodash.clonedeep";import{message}from"ant-design-vue";import axios from"@/common/services/axios-instance";import crossWindowWatcher from"@/common/services/cross-window-watcher";import sdLoading from"@/common/pages/sd-loading.vue";import{sdSessionStorage}from"@/common/services/storage-service";import sdFormTemplateSaveModal from"./form-template/sd-form-template-save-modal.vue";import components from"./_import-components/sd-designer-page-import";import formService from"./form-service";var _render=function e(){var t=this,a=t._self._c;return a("div",{class:t.$style.wrapper},[t.designerData?a("sd-designer",{ref:"designer",attrs:{value:t.designerData},on:{change:t.onChange},scopedSlots:t._u([{key:"toolbar",fn:function(){return[a("sd-full-page-editor-util",{ref:"editorUtil"}),a("sd-switch-mode-btn"),a("a-button",{attrs:{icon:"save",type:"link"},on:{click:t.saveAsTemplate}},[t._v("存为模板")]),0!==t.designerData.head.attrFD.type?a("span",[a("sd-preview-mobile-btn"),a("sd-preview-btn")],1):a("sd-preview-non-flow-btn"),a("a-button",{attrs:{icon:"save",type:"link",loading:t.saving,disabled:!t.isValid,title:t.isValid?void 0:"只读模式，无法保存"},on:{click:t.save}},[t._v(" 保存 ")])]},proxy:true}],null,false,1794076790)}):a("sd-loading"),a("sd-form-template-save-modal",{attrs:{visible:t.showSaveTempl,"form-data":t.formDesignerData},on:{hide:()=>t.showSaveTempl=false}})],1)};var staticRenderFns=[];_render._withStripped=true;export default{name:"SdDesignerPage",components:{...components,sdLoading:sdLoading,sdFormTemplateSaveModal:sdFormTemplateSaveModal},metaInfo(){return{title:this.designerData?.head.tableTxt}},props:{id:{type:String,default:void 0}},data(){return{designerData:void 0,saving:false,showSaveTempl:false,formDesignerData:{},isValid:true}},created(){let e;if(this.id)e=this.loadForm().then((e=>formService.getLock(this.id,true).then((t=>{if(false===t)this.isValid=false;const a=e.data;if(a.head.attrFD?.columns)return a;else return this.loadDefaultForm().then((e=>{a.fields=e.fields;a.head.attrFD=e.head.attrFD;return a}))}))));else e=this.loadDefaultForm();e.then((e=>this.designerData=e));window.addEventListener("unload",(()=>{crossWindowWatcher.notifyChange(true);formService.unLockWhenBrowerClose(this.designerData?.head.id)}))},methods:{loadForm(){return axios.get(`api/framework/v1/onlineform/getById/${this.id}/true`)},loadDefaultForm(){const e="1"===this.$route.query.layoutable;if("0"===this.$route.query.type)return Promise.resolve({head:{tableTxt:"新表单",tableName:"form_"+Date.now(),tableType:1,formType:0,attrFD:{columns:1,fixedColumns:true,type:0,layoutable:e,modalProps:{}}},fields:[]});else{const t=e?1:2;const a=[{caption:"标题",name:"title",dataType:"title",required:true,attrFD:{cid:"sd-text",columns:t},sdNewItem:true}];return Promise.resolve({head:{tableTxt:"新表单",tableName:"form_"+Date.now(),tableType:1,formType:1,attrFD:{columns:t,fixedColumns:e,theme:"sd-default",type:1,layoutable:e}},fields:a})}},save(){this.$refs.designer.setComponentName(this.$refs.designer.selectedID);const e=this.getFormData();this.saving=true;let t;if(this.designerData.head.id)t=formService.getLock(this.id).then((t=>axios.put("api/framework/v1/onlineform/editAll",{...e,lockId:t})));else t=axios.post("api/framework/v1/onlineform/addAll",e).then((e=>{this.$router.replace({params:{id:e.data.head.id}});return e}));t.finally((()=>this.saving=false)).then((e=>{this.designerData=e.data;crossWindowWatcher.notifyChange(true);message.success("保存成功");this.$refs.editorUtil.updateDataSaved();sdSessionStorage.removeItem(`Lock${this.designerData.head.id}`);formService.getLock(this.designerData.head.id,true)}))},getFormData(){return this.$refs.designer.getSaveData()},saveAsTemplate(){this.formDesignerData=this.getFormData();this.showSaveTempl=true},onChange(){if(this.isValid)return;message.error("只读模式，无法修改数据");this.designerData=cloneDeep(this.designerData);this.$refs.designer.initSnapshot()}},render:_render,staticRenderFns:staticRenderFns};</script>

<style module lang="scss">
@use '@/common/design' as *;
.wrapper {
  height: 100%;
}
</style>
