全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

2 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{d as u,t as n}from"./index-5f4ce139.js";import{c as i}from"./cloneDeep-f98af5ea.js";import{E as o}from"./index-548a7823.js";import{a}from"./index-be5dc120.js";import{ab as s}from"./runtime-core.esm-bundler-7c3fd514.js";const h=u("diy",{state:()=>({id:0,load:!1,currentIndex:-99,currentComponent:"edit-page",name:"",type:"",typeName:"",components:[],global:{title:"页面",pageBgColor:"",tabbarSwitch:!0},value:[]}),getters:{editComponent:e=>e.value[e.currentIndex]},actions:{addComponent(e){if(!this.load)return;let t=i(e);t.id=this.generateRandom(),t.componentName=t.name,t.componentTitle=t.title,t.maxCount=t.max_count,Object.assign(t,t.value),delete t.name,delete t.title,delete t.value,delete t.type,delete t.icon,delete t.max_count,this.checkComponentIsAdd(t)&&(this.currentIndex===-99?(this.value.push(t),this.currentIndex=this.value.length-1):this.value.splice(++this.currentIndex,0,t),this.currentComponent=t.path)},generateRandom(e=5){return Number(Math.random().toString().substr(3,e)+Date.now()).toString(36)},postMessage(){var e=JSON.stringify({currentIndex:this.currentIndex,global:s(this.global),value:s(this.value)});window.previewIframe.contentWindow.postMessage(e,"*")},changeCurrentIndex(e,t=null){this.currentIndex=e,this.currentIndex==-99?this.currentComponent="edit-page":t&&(this.currentComponent=t.path)},delComponent(){this.currentIndex!=-99&&o.confirm(n("delComponentTips"),n("warning"),{confirmButtonText:n("confirm"),cancelButtonText:n("cancel"),type:"warning",autofocus:!1}).then(()=>{this.value.splice(this.currentIndex,1),this.value.length===0&&(this.currentIndex=-99),this.currentIndex===this.value.length&&this.currentIndex--;let e=i(this.value[this.currentIndex]);this.changeCurrentIndex(this.currentIndex,e)}).catch(()=>{})},moveUpComponent(){if(this.currentIndex-1<0)return;var e=i(this.value[this.currentIndex]);e.id=this.generateRandom();let t=this.currentIndex-1;var r=i(this.value[t]);r.id=this.generateRandom(),this.value[this.currentIndex]=r,this.value[t]=e,this.changeCurrentIndex(t,e)},moveDownComponent(){if(!(this.currentIndex+1>=this.value.length)){var e=this.currentIndex+1,t=i(this.value[this.currentIndex]);t.id=this.generateRandom();var r=i(this.value[e]);r.id=this.generateRandom(),this.value[this.currentIndex]=r,this.value[e]=t,this.changeCurrentIndex(e,t)}},copyComponent(){if(this.currentIndex<0)return;let e=i(this.value[this.currentIndex]);if(e.id=this.generateRandom(),!this.checkComponentIsAdd(e)){a({type:"warning",message:`${n("notCopy")}${e.componentTitle}${n("componentCanOnlyAdd")}${e.maxCount}${n("piece")}`});return}var t=this.currentIndex+1;this.value.splice(t,0,e),this.changeCurrentIndex(t,e)},checkComponentIsAdd(e){if(e.maxCount===0)return!0;var t=0;for(var r in this.value)this.value[r].componentName===e.componentName&&t++;return!(t>=e.maxCount)},resetComponent(){this.currentIndex<0||o.confirm(n("resetComponentTips"),n("warning"),{confirmButtonText:n("confirm"),cancelButtonText:n("cancel"),type:"warning",autofocus:!1}).then(()=>{for(let e=0;e<this.components.length;e++)if(this.components[e].componentName==this.editComponent.componentName){Object.assign(this.editComponent,this.components[e]);break}}).catch(()=>{})},verify(){if(this.global.title==="")return a({message:n("pageNamePlaceholder"),type:"warning"}),this.changeCurrentIndex(-99),!1;for(var e=0;e<this.value.length;e++)try{if(this.value[e].verify){var t=this.value[e].verify(e);if(!t.code)return this.changeCurrentIndex(e,this.value[e]),a({message:t.message,type:"warning"}),!1}}catch(r){console.log("verify Error:",r,e,this.value[e])}return!0}}}),g=h;export{g as u};