2 lines
7.6 KiB
JavaScript
2 lines
7.6 KiB
JavaScript
|
"use strict";var e=Object.defineProperty,t=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s,a=(e,t)=>{for(var i in t||(t={}))l.call(t,i)&&o(e,i,t[i]);if(s)for(var i of s(t))r.call(t,i)&&o(e,i,t[i]);return e},h=(e,t,i)=>new Promise(((s,l)=>{var r=e=>{try{a(i.next(e))}catch(t){l(t)}},o=e=>{try{a(i.throw(e))}catch(t){l(t)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(r,o);a((i=i.apply(e,t)).next())}));const n=require("../../../../../common/vendor.js"),u=require("./choose-and-upload-file.js"),d=require("./utils.js"),p=require("../../index.js"),c={name:"sUploader",components:{uploadImage:()=>"./upload-image.js",uploadFile:()=>"./upload-file.js"},options:{virtualHost:!0},emits:["select","success","fail","progress","delete","update:modelValue","update:url"],props:{modelValue:{type:[Array,Object],default:()=>[]},url:{type:[Array,String],default:()=>[]},disabled:{type:Boolean,default:!1},disablePreview:{type:Boolean,default:!1},delIcon:{type:Boolean,default:!0},autoUpload:{type:Boolean,default:!0},limit:{type:[Number,String],default:9},mode:{type:String,default:"grid"},fileMediatype:{type:String,default:"image"},fileExtname:{type:[Array,String],default:()=>[]},title:{type:String,default:""},listStyles:{type:Object,default:()=>({border:!0,dividline:!0,borderStyle:{}})},imageStyles:{type:Object,default:()=>({width:"auto",height:"auto"})},readonly:{type:Boolean,default:!1},sizeType:{type:Array,default:()=>["original","compressed"]},driver:{type:String,default:"local"},subtitle:{type:String,default:""}},data:()=>({files:[],localValue:[],imgsrc:p.sheep.$url.static("/static/img/shop/upload-camera.png")}),watch:{modelValue:{handler(e,t){this.setValue(e,t)},immediate:!0}},computed:{returnType(){return this.limit>1?"array":"object"},filesList(){let e=[];return this.files.forEach((t=>{e.push(t)})),e},showType(){return"image"===this.fileMediatype?this.mode:"list"},limitLength(){return"object"===this.returnType?1:this.limit?this.limit>=9?9:this.limit:1}},created(){"local"===this.driver&&(n.Ws.chooseAndUploadFile=u.chooseAndUploadFile),this.form=this.getForm("uniForms"),this.formItem=this.getForm("uniFormsItem"),this.form&&this.formItem&&this.formItem.name&&(this.rename=this.formItem.name,this.form.inputChildrens.push(this))},methods:{clearFiles(e){0===e||e?this.files.splice(e,1):(this.files=[],this.$nextTick((()=>{this.setEmit()}))),this.$nextTick((()=>{this.setEmit()}))},upload(){let e=[];return this.files.forEach(((t,i)=>{"ready"!==t.status&&"error"!==t.status||e.push(Object.assign({},t))})),this.uploadFiles(e)},setValue(e,t){return h(this,null,(function*(){const t=e=>h(this,null,(function*(){let t="";return t=e.fileID?e.fileID:e.url,/cloud:\/\/([\w.]+\/?)\S*/.test(t)&&(e.fileID=t,e.url=yield this.getTempFileURL(t)),e.url&&(e.path=e.url),e}));if("object"===this.returnType)e?yield t(e):e={};else{e||(e=[]);for(let i=0;i<e.length;i++){let s=e[i];yield t(s)}}this.localValue=e,this.form&&this.formItem&&!this.is_reset&&(this.is_reset=!1,this.formItem.setValue(this.localValue));let i=Object.keys(e).length>0?e:[];this.files=[].concat(i)}))},choose(){this.disabled||(this.files.length>=Number(this.limitLength)&&"grid"!==this.showType&&"array"===this.returnType?n.index.showToast({title:`您最多选择 ${this.limitLength} 个文件`,icon:"none"}):this.chooseFiles())},chooseFiles(){const e=d.get_extname(this.fileExtname);n.Ws.chooseAndUploadFile({type:this.fileMediatype,compressed:!1,sizeType:this.sizeType,extension:e.length>0?e:void 0,count:this.limitLength-this.files.length,onChooseFile:this.chooseFileCallback,onUploadProgress:e=>{this.setProgress(e,e.index)}}).then((e=>{this.setSuccessAndError(e.tempFiles)})).catch((e=>{}))},chooseFileCallback(e){return h(this,null,(function*(){const s=d.get_extname(this.fileExtname);(1===Number(this.limitLength)&&this.disablePreview&&!this.disabled||"object"===this.returnType)&&(this.files=[]);let{filePaths:l
|