26 lines
12 KiB
JavaScript
Raw Normal View History

2025-06-30 09:38:03 +08:00
import{_ as z,aF as U,aG as I,aH as P,a4 as oe,r as s,o as l,d as u,w as d,f as a,b as r,c as p,t as O,u as _,m as E,D as C,v as ae,ab as se,ac as ie,j as le,C as re,a as T,F as j,k as ce,l as y,E as he,G as de}from"./index-f87df9cc.js";import{M as B}from"./monaco-editor-f9caa2e2.js";const ue={inject:["contain"],components:{AvueEchartCommon:U,AvueEchartVue:I,AvueEchartHtml:P,MonacoEditor:B},watch:{"form.content"(t){this.handleOption()},modelValue:{handler(t){this.form=t},deep:!0},form:{handler(t){this.$emit("update:modelValue",t)},deep:!0}},props:{modelValue:{}},data(){return{common:oe,error:"",vueOption:"",box:!1,reload:!1,options:{height:600,language:"javascript"},form:{}}},methods:{errorChange(t){this.error=t},handleOpen(){this.form=this.modelValue,this.box=!0,this.$nextTick(()=>{this.handleOption()})},handleClose(){this.$emit("update:modelValue",this.form),this.box=!1},handleOption(){this.reload=!1,this.vueOption=this.deepClone(this.form),this.$nextTick(()=>{this.reload=!0})}}},pe={class:"code-edit"},_e={class:"left"},me={key:0,class:"right"},ge={key:0,class:"tip"};function ve(t,n,c,h,e,i){const w=s("monaco-editor"),m=s("avue-echart-vue"),x=s("avue-echart-common"),D=s("avue-echart-html"),S=s("el-dialog");return l(),u(S,{title:"代码编辑",fullscreen:"","modal-append-to-body":"",modelValue:e.box,"onUpdate:modelValue":n[1]||(n[1]=f=>e.box=f),"append-to-body":"","close-on-click-modal":!1,width:"100%"},{default:d(()=>[a("div",pe,[a("div",_e,[r(w,{modelValue:e.form.content,"onUpdate:modelValue":n[0]||(n[0]=f=>e.form.content=f),language:e.options.language,height:e.options.height,options:e.options},null,8,["modelValue","language","height","options"])]),e.reload?(l(),p("div",me,[e.error?(l(),p("div",ge,O(e.error),1)):_("",!0),e.form.type==0?(l(),u(m,E({key:1},i.contain&&i.contain.activeObj,{option:e.vueOption,onErrorChange:i.errorChange,width:"100%",height:"100%"}),null,16,["option","onErrorChange"])):e.form.type==1?(l(),u(x,E({key:2},i.contain&&i.contain.activeObj,{"echart-formatter-str":e.vueOption.content,onErrorChange:i.errorChange,width:"100%"}),null,16,["echart-formatter-str","onErrorChange"])):e.form.type==2?(l(),u(D,E({key:3},i.contain&&i.contain.activeObj,{option:e.vueOption,onErrorChange:i.errorChange,width:"100%"}),null,16,["option","onErrorChange"])):_("",!0)])):_("",!0)])]),_:1},8,["modelValue"])}const fe=z(ue,[["render",ve],["__scopeId","data-v-b4a49101"]]),k=ae+"/component",be=t=>C({url:k+"/list",method:"get",params:t}),L=t=>C({url:k+"/detail",method:"get",params:{id:t}}),ye=t=>C({url:k+"/save",method:"post",data:t}),Ce=t=>C({url:k+"/update",method:"post",data:t}),ke=t=>C({url:k+"/remove",method:"post",params:{ids:t}});const V=[{label:"vue组件",value:0,content:`<template>
<div>
</div>
</template>
<script>
export default{
data(){
return {}
},
created(){
},
methods:{
}
}
<\/script>
<style>
</style>`},{label:"echart",value:1,content:`function (data,params){
const myChart = this.myChart;
return option;
}`},{label:"html组件",value:2,content:"<div style=''>html</div>"}],we={components:{codeEdit:fe,AvueEchartCommon:U,AvueEchartVue:I,AvueEchartHtml:P,MonacoEditor:B},props:{menu:{type:Boolean,default:!0},activeName:""},data(){return{search:{},error:"",loading:!1,reload:!1,active:0,dicData:V,options:{height:300,language:"javascript"},content:"",index:-1,isEdit:!1,form:{},vueOption:{},data:[],type:"",page:{size:50,page:1,total:0},dialog:!1,option:{labelWidth:120,column:[{label:"组件名称",prop:"name",row:!0,rules:[{required:!0,message:"请输入组件名称",trigger:"blur"}]},{label:"组件类型",prop:"type",type:"select",dicData:V,rules:[{required:!0,message:"请选择组件类型",trigger:"blur"}]},{label:"组件数据",prop:"content",span:24},{label:"组件预览",prop:"view",span:24}]},publicPath:"/DataV/"}},created(){this.menu||(this.active=this.activeName),this.getList()},watch:{"form.content"(t){this.handleOption()},"form.type"(t){if(this.isEdit){this.isEdit=!1;return}let n=V.find(c=>c.value==t)||{};this.form.content=n.content}},methods:{errorChange(t){this.error=t},handleTabClick(t){this.active=t.props.name,this.page.page=1,this.$nextTick(()=>{this.getList()})},getTypeLabel(t){return V.find(n=>n.value==t).label},handleRow(t,n){this.$emit("change",t)},validData(t){return[0,1,2,3,4].includes(t)},rowDel(t,n){if(this.validData(n)&&this.$website.isDemo)return this.$message.error(this.$website.isDemoTip),!1;this.$confirm("此操作将永久删除, 是否继续?","提示",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then(()=>{ke(t.id).then(()=>{this.$message.success("删除成功"),this.getList()})})},handleOption(){this.reload=!1,this.vueOption=this.deepClone(this.form),this.$nextTick(()=>{this.reload=!0})},getImg(){return new Promise(t=>{html2canvas(document.querySelector(".view"),{useCORS:!0,backgroundColor:null,logging:!1,allowTaint:!0}).then(n=>{let c=n.toDataURL("image/jpeg",.1);c.length<10&&t("");var h=se(c,new Date().getTime()+".jpg"),e=new FormData;e.append("file",h),ie(e,"screenShot").then(i=>{const m=i.data.data.link;t(m)})})})},handleAdd(){this.form={name:"",type:"",content:""},this.type="add",this.isEdit=!0,this.handleOption(),this.dialog=!0},handleEdit(t,n){this.index=n,this.type="edit",this.isEdit=!0,L(t.id).then(c=>{const h=c.data.data;this.form=h,this.handleOption(),this.dialog=!0})},handleSubmit(t,n){this.type=="add"?this.rowSave(this.from,n):this.type=="edit"&&this.rowUpdate(this.from,this.index,n)},rowUpdate(t,n,c,h){if(this.validData(n)&&this.$website.isDemo)return c(),this.$message.error(this.$website.isDemoTip),!1;this.getImg().then(e=>(this.form.img=e,Ce(this.form))).then(()=>{c(),this.dialog=!1,this.$message.success("修改成功"),this.getList()}).catch(e=>{h()})},rowSave(t,n,c){this.getImg().then(h=>(this.form.img=h,ye(this.form))).then(()=>{n(),this.dialog=!1,this.$message.success("新增成功"),this.getList()}).catch(h=>{c()})},handleView(t,n){this.type="edit",this.isEdit=!0,L(t.id).then(c=>{const h=c.data.data;this.form=h,this.vueOption=this.deepClone({content:h.content}),this.$refs.code.handleOpen()})},handleCurrentChange(t){this.page.page=t,this.getList()},handleSizeChange(t){this.page.size=t,this.getList()},getList(){this.loading=!0,this.data=[],be({name:this.search.name,current:this.page.page,size:this.page.size,type:this.active}).then(t=>{this.loading=!1;const n=t.data.data;this.page.total=n.total,this.data=n.records,this.data.forEach((c,h)=>{this.data[h].type=this.data[h].type||0,this.data[h]._menu=!1})})}}},v=t=>(he("data-v-03b9aae9"),t=t(),de(),t),Ve={class:"content__box content__nav"},Oe=["src"],Ee=v(()=>a("div",null,[a("p",null,"创建组件"),a("span",null,"丰富组件,按需引入项目")],-1)),xe={class:"content__page"},De={class:"list-search"},Se={class:"content__box"},je=["onMouseenter","onMouseleave"],Te={class:"content__info"},Le=["src"],ze={key:0,class:"content__menu"},Ue={class:"content__right"},Ie={class:"content__start"},Pe=["onClick"],Be=["onClick"],Me=["onClick"],Ae={class:"content__main"},Ne={class:"content__name"},Fe={class:"content__