2 lines
2.3 KiB
JavaScript
2 lines
2.3 KiB
JavaScript
"use strict";const e=require("../../../common/vendor.js"),t=require("../../index.js"),i={name:"uploadImage",emits:["uploadFiles","choose","delFile"],props:{filesList:{type:[Array,String],default:()=>[]},disabled:{type:Boolean,default:!1},disablePreview:{type:Boolean,default:!1},limit:{type:[Number,String],default:9},imageStyles:{type:Object,default:()=>({width:"auto",height:"auto",border:{}})},delIcon:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1}},computed:{list(){return"string"==typeof this.filesList?this.filesList?[this.filesList]:[]:this.filesList},styles(){return Object.assign({width:"auto",height:"auto",border:{}},this.imageStyles)},boxStyle(){const{width:e="auto",height:t="auto"}=this.styles,i={};"auto"===t?"auto"!==e?(i.height=this.value2px(e),i["padding-top"]=0):i.height=0:(i.height=this.value2px(t),i["padding-top"]=0),i.width="auto"===e?"auto"!==t?this.value2px(t):"33.3%":this.value2px(e);let o="";for(const s in i)o+=`${s}:${i[s]};`;return o},borderStyle(){const{border:e}=this.styles;let t={};if("boolean"==typeof e)t.border=e?"1px #eee solid":"none";else{let i=e&&e.width||1;i=this.value2px(i);let o=e&&e.radius||3;o=this.value2px(o),t={"border-width":i,"border-style":e&&e.style||"solid","border-color":e&&e.color||"#eee","border-radius":o}}let i="";for(const o in t)i+=`${o}:${t[o]};`;return i}},methods:{getImageUrl:e=>"blob:http:"===e.substr(0,10)?e:t.sheep.$url.cdn(e),uploadFiles(e,t){this.$emit("uploadFiles",e)},choose(){this.$emit("choose")},delFile(e){this.$emit("delFile",e)},previewImage(t,i){const o=[];1===Number(this.limit)&&this.disablePreview&&!this.disabled&&this.$emit("choose"),this.disablePreview||(this.list.forEach((e=>{o.push(this.getImageUrl(e))})),e.index.previewImage({urls:o,current:i}))},value2px:e=>("number"==typeof e?e+="px":-1===e.indexOf("%")&&(e=-1!==e.indexOf("px")?e:e+"px"),e)}};const o=e._export_sfc(i,[["render",function(t,i,o,s,l,r){return e.e({a:e.f(r.list,((t,i,s)=>e.e({a:r.getImageUrl(t),b:e.o((e=>r.previewImage(t,i)),i)},o.delIcon&&!o.readonly?{c:e.o((e=>r.delFile(i)),i)}:{},{d:i}))),b:o.delIcon&&!o.readonly,c:e.s(r.borderStyle),d:e.s(r.boxStyle),e:r.list.length<o.limit&&!o.readonly},r.list.length<o.limit&&!o.readonly?{f:e.s(r.borderStyle),g:e.o(((...e)=>r.choose&&r.choose(...e))),h:e.s(r.boxStyle)}:{})}]]);wx.createComponent(o);
|