import{n as m,ab as u}from"./index-b54f5418.js";import{J as v}from"./index-cf27e902.js";import"./three-dc46505d.js";var y=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",{staticClass:"headerOperation-container"},[t("div",{staticClass:"operate-history"},[t("vis-icon",{attrs:{code:"#iconbianjiantouzuo"},nativeOn:{click:function(i){return(function(){e.$store.commit("shaderLibrary/backOffHistory")}).apply(null,arguments)}}}),t("vis-icon",{attrs:{code:"#iconbianjiantouyou"},nativeOn:{click:function(i){return(function(){e.$store.commit("shaderLibrary/forwardHistory")}).apply(null,arguments)}}})],1),t("div",{staticClass:"operate-address"},e._l(e.addressList,function(i,l){return t("span",{key:l,staticClass:"address-sign-box",on:{click:function(r){return e.chouseFile(i)}}},[l>0?t("vis-icon",{style:{transform:"scale(0.6)"},attrs:{code:"#iconsanjiaojiantouyou"}}):e._e(),t("span",{staticClass:"address-title",domProps:{textContent:e._s(i.name)}})],1)}),0),t("div",{staticClass:"operate-operation"},[t("el-popover",{attrs:{placement:"bottom",width:"200",trigger:"click"},model:{value:e.classifyVisible,callback:function(i){e.classifyVisible=i},expression:"classifyVisible"}},[t("el-input",{staticClass:"popover-input",attrs:{size:"mini",placeholder:"输入分类名称"},model:{value:e.classifyName,callback:function(i){e.classifyName=i},expression:"classifyName"}}),t("div",{staticClass:"popover-operation"},[t("el-button",{attrs:{size:"mini",type:"text"},on:{click:e.addClassify}},[e._v(" 确定 ")])],1),t("vis-icon",{directives:[{name:"show",rawName:"v-show",value:e.canAddClassify,expression:"canAddClassify"},{name:"tooltip",rawName:"v-tooltip.top",value:"新增分类",expression:"'新增分类'",modifiers:{top:!0}}],attrs:{slot:"reference",code:"#iconjia1"},slot:"reference"})],1),e.canUpload?t("vis-icon",{directives:[{name:"tooltip",rawName:"v-tooltip.top",value:"上传着色器npm压缩包，包含js文件、package.json、preview.png预览图",expression:`
        '上传着色器npm压缩包，包含js文件、package.json、preview.png预览图'
      `,modifiers:{top:!0}}],attrs:{code:"#iconshangchuan-fill"},nativeOn:{click:function(i){return e.upload.apply(null,arguments)}}}):e._e(),t("input",{ref:"uploadInput",staticStyle:{display:"none"},attrs:{type:"file",accept:".zip, .tgz",multiple:"multiple"},on:{change:e.fileHandler}})],1)])},g=[];const _={data(){return{classifyName:"",classifyVisible:!1}},computed:{currentFloder(){return this.$store.getters["shaderLibrary/currentFloder"]},canUpload(){const e=this.currentFloder.children;return this.currentFloder.parent?e.length&&!e[0].dir?!0:!e.length&&this.currentFloder.url!=="/":!1},canAddClassify(){const e=this.currentFloder.children;return e.length&&e[0].dir?!0:!e.length},addressList(){const e=[this.currentFloder],s=t=>{t.parent&&(e.unshift(t.parent),s(t.parent))};return s(this.currentFloder),e}},methods:{chouseFile(e){e.dir&&this.$store.commit("shaderLibrary/currentFloder",e)},upload(){this.$tool.safeTips().then(()=>{this.$refs.uploadInput.click()})},async fileHandler(e){const s=e.target.files[0],t=this.currentFloder.id,r=(await new v().loadAsync(s)).files;if(!r["package.json"]){this.$message.warning("上传失败！找不到配置文件：package.json"),this.$refs.uploadInput.value="";return}const c=JSON.parse(await r["package.json"].async("string"));let a=c.module||c.main;if(!a){this.$message.warning("上传失败！无法从package.json中获取有效的入口路径。"),this.$refs.uploadInput.value="";return}if(a.startsWith("/")?a=a.slice(1):a.startsWith("./")&&(a=a.slice(2)),!r[a]){this.$message.warning("上传失败！无法根据package.json的相关字段获取入口文件。"),this.$refs.uploadInput.value="";return}let o=r[a];o=await o.async("string"),o=new Blob([o],{type:"application/javascript"});const h=["jpg","png","jpeg"];let p;for(const n of h)r[`preview.${n}`]&&(p=`data:image/${n};base64,`+await r[`preview.${n}`].async("base64"));u.uploadShader({classifyId:t,name:s.name.split(".").shift(),shader:o,pkg:c,preview:p,size:Object.values(r).reduce((n,d)=>d.dir?n:n+d._data.uncompressedSize,0)}).then(n=>{this.$store.commit("shaderLibrary/addChildren",n)}).finally(()=>{this.$refs.uploadInput.value=""})},addClassify(){this.classifyName.trim()?u.addClassify({name:this.classifyName.trim(),parentId:this.currentFloder.id}).then(e=>{this.$store.commit("shaderLibrary/addChildren",e),this.classifyName="",this.classifyVisible=!1,this.$message.success("添加分类成功！")}):(this.classifyName="",this.classifyVisible=!1)}}},f={};var b=m(_,y,g,!1,$,"218ac3cf",null,null);function $(e){for(let s in f)this[s]=f[s]}const k=function(){return b.exports}();export{k as default};
