chunk-2dd1ef1a.4e6fd43c.js 3.0 KB

1
  1. (window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2dd1ef1a"],{2046:function(t,e,s){"use strict";s("7974")},7974:function(t,e,s){},"87a0":function(t,e,s){"use strict";s.r(e);var i=function(){var t=this,e=t._self._c;return e("div",{staticClass:"cl-upload"},[e("el-input",{attrs:{type:"hidden"},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}}),t._l(t.list,(function(s,i){return e("el-upload",t._b({key:i,attrs:{accept:"image/*",headers:{token:t.token},name:"content","on-change":t.getFile,"auto-upload":!1,action:t.action,"show-file-list":!1,"on-error":t.onError,"before-upload":e=>{t.beforeUpload(e,s,i)}}},"el-upload",t.props,!1),[t._t("content",(function(){return[e("div",{directives:[{name:"loading",rawName:"v-loading",value:s.loading,expression:"item.loading"}],staticClass:"upload-wrap"},[s.url?e("img",{attrs:{src:t._f("check_prefix")(s.url),alt:""}}):e("i",{staticClass:"el-icon-plus avatar-uploader-icon"}),s.url?e("i",{staticClass:"el-icon-close",on:{click:function(e){return e.stopPropagation(),t.removeFile(i)}}}):t._e()])]}))],2)}))],2)},o=[],l=(s("f16c"),s("45d2"),s("4e1c"),s("9052"),s("5880")),r=s("51be"),n={props:{props:{type:Object,default:()=>({})},value:[Array,String],hostUrl:{default:""}},data(){const t=this.$service.common.upload();return{imgHostUrl:r["imgHostUrl"],action:t.url,list:[],index:0}},filters:{check_prefix(t){return t.includes("http")?t:r["imgHostUrl"]+t}},computed:{...Object(l["mapGetters"])(["token"])},watch:{value(){this.render()}},mounted(){this.render()},methods:{render(){const{multiple:t}=this.props;let e=this.value;if(t){let t=[];t=e instanceof Array?e:(e||"").split(","),this.list=t.filter(Boolean).map(t=>({url:t,loading:!1})),this.ajSize()}else this.list=[{url:e,loading:!1}]},callback(){this.ajSize(),this.$emit("input",this.list.filter(t=>t.url).map(t=>t.url).join(","))},ajSize(){const{"multiple-limit":t=1}=this.props;this.list.length<t&&this.list.unshift({})},beforeUpload(t,e,s){this.index=s,this.props&&this.props["before-upload"]&&this.props["before-upload"](t),e.loading=!0},onSuccess(t,e){let s=this.list[this.index];const{url:i,smallUrl:o,shortUrl:l}=t,{multiple:r}=this.props;s.loading=!1,r?s.url?s.url=l:this.list.push({url:l}):this.list=[{url:l}],this.callback(),console.log("this.props",this.props),this.props&&this.props["on-success"]&&this.props["on-success"](t,e)},onError(t,e,s){console.error("upload error",t),this.$message.error("图片上传失败"),this.loading=!1,this.props&&this.props["on-error"]&&this.props["on-error"](t,e,s)},removeFile(t){this.list.splice(t,1),this.callback()},getFile(t,e){this.getBase64(t.raw).then(t=>{let e=null;e=this.hostUrl?()=>this.$service.common[this.hostUrl]({content:t}):()=>this.$service.common.uploadImg({content:t}),e().then(t=>{console.log("subRes",t),this.onSuccess(t)})})},getBase64(t){return new Promise((function(e,s){let i=new FileReader,o="";i.readAsDataURL(t),i.onload=function(){o=i.result},i.onerror=function(t){s(t)},i.onloadend=function(){e(o)}}))}}},a=n,c=(s("2046"),s("1805")),u=Object(c["a"])(a,i,o,!1,null,"851feb34",null);e["default"]=u.exports}}]);