
/* eslint-disable */
// sd-skip-auto-import
import axios from"@/common/services/axios-instance";import errorUtil from"@/common/services/error-util";import PageService from"@/common/services/page-service";import{sdSessionStorage}from"@/common/services/storage-service";class FormService{getTepmlateTootNode(e){return axios.get(`api/framework/v1/onlinetemplet/getRootNode/${e}`)}getTemplateCateTree(e,t="false"){return axios({url:`api/framework/v1/onlinetemplet/categoryTree/${e}/${t}`,method:"get"})}deleteTemplateCate(e){return axios({url:`api/framework/v1/onlinetemplet/delete`,method:"delete",params:{ids:e.join(",")}})}getFormTemplateData(e={}){return PageService.get(e,"online/templet/onlFormTemplet").then((e=>{const t=e.data.pageFormData?.pageFieldInfos||[];const r={};t.forEach((e=>{switch(e.name){case"id":r.id=e.value;break;case"templetName":r.templetName=e.value;break;case"templetCategory":r.templetCategory=e.value;break;case"templetType":r.templetType=e.value;break;case"attrFd":r.attrFd=JSON.parse(e.value);break;case"fieldsArray":r.fields=JSON.parse(e.value);break;default:break}}));return r}))}getLock(e,t=false){const r=JSON.parse(sdSessionStorage.getItem(`Lock${e}`)||"{}").lockId;if(!t)return Promise.resolve(r);else return axios.post("api/framework/v1/onlineform/lock-refresh",{formId:e,lockId:r}).then((t=>{sdSessionStorage.setItem(`Lock${e}`,JSON.stringify(t.data));return t.data.lockId}),(e=>{errorUtil.handleError(e.response.data);return false}))}unLockWhenBrowerClose(e){var t=sdSessionStorage.getItem(`Lock${e}`);if(t?.startsWith("{")&&e){const r=new Blob([JSON.stringify({formId:e,lockId:JSON.parse(t).lockId})],{type:"application/json"});const o="api/framework/v1/onlineform/unlock";if(navigator.sendBeacon)navigator.sendBeacon(o,r);else{const e=new XMLHttpRequest;e.open("POST",o,false);e.setRequestHeader("Content-Type","application/json");e.send(r)}sdSessionStorage.removeItem(`Lock${e}`)}}}export default new FormService;