UNPKG

vxe-pc-ui

Version:
1 lines • 30 kB
Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _vue=require("vue"),_comp=require("../../ui/src/comp"),_xeUtils=_interopRequireDefault(require("xe-utils")),_ui=require("../../ui"),_vn=require("../../ui/src/vn"),_log=require("../../ui/src/log"),_dom=require("../../ui/src/dom"),_util=require("./util"),_button=_interopRequireDefault(require("../../button/src/button"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function createReactData(){return{isDragUploadStatus:!1,showMorePopup:!1,isActivated:!1,fileList:[],fileCacheMaps:{},isDragMove:!1,dragIndex:-1,dragTipText:""}}function createInternalData(){return{moreId:_xeUtils.default.uniqueId("upload"),imagePreviewTypes:["jpg","jpeg","png","gif"],prevDragIndex:-1}}var _default=exports.default=(0,_comp.defineVxeComponent)({name:"VxeUpload",props:{modelValue:[Array,String,Object],showList:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showList},moreConfig:Object,readonly:{type:Boolean,default:null},disabled:{type:Boolean,default:null},autoSubmit:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.autoSubmit},mode:{type:String,default:()=>(0,_ui.getConfig)().upload.mode},imageTypes:{type:Array,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.imageTypes,!0)},imageConfig:{type:Object,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.imageConfig,!0)},imageStyle:{type:Object,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.imageStyle,!0)},fileTypes:{type:Array,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.fileTypes,!0)},dragSort:Boolean,dragToUpload:{type:Boolean,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.dragToUpload,!0)},dragPlaceholder:{type:String,default:()=>(0,_ui.getConfig)().upload.dragPlaceholder},pasteToUpload:{type:Boolean,default:()=>_xeUtils.default.clone((0,_ui.getConfig)().upload.pasteToUpload,!0)},keyField:String,singleMode:Boolean,urlMode:Boolean,urlArgs:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.urlArgs},multiple:Boolean,limitSize:{type:[String,Number],default:()=>(0,_ui.getConfig)().upload.limitSize},showLimitSize:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showLimitSize},limitSizeText:{type:[String,Number,Function],default:()=>(0,_ui.getConfig)().upload.limitSizeText},limitCount:{type:[String,Number],default:()=>(0,_ui.getConfig)().upload.limitCount},showLimitCount:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showLimitCount},limitCountText:{type:[String,Number,Function],default:()=>(0,_ui.getConfig)().upload.limitCountText},nameField:{type:String,default:()=>(0,_ui.getConfig)().upload.nameField},typeField:{type:String,default:()=>(0,_ui.getConfig)().upload.typeField},urlField:{type:String,default:()=>(0,_ui.getConfig)().upload.urlField},sizeField:{type:String,default:()=>(0,_ui.getConfig)().upload.sizeField},showErrorStatus:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showErrorStatus},showProgress:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showProgress},progressText:{type:[String,Number,Function],default:()=>(0,_ui.getConfig)().upload.progressText},previewImageConfig:Object,showSubmitButton:Boolean,autoHiddenButton:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.autoHiddenButton},showUploadButton:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showUploadButton},buttonText:{type:[String,Number,Function],default:()=>(0,_ui.getConfig)().upload.buttonText},buttonIcon:{type:String,default:()=>(0,_ui.getConfig)().upload.buttonIcon},showButtonText:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showButtonText},showButtonIcon:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showButtonIcon},showRemoveButton:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showRemoveButton},showDownloadButton:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showDownloadButton},showPreview:{type:Boolean,default:()=>(0,_ui.getConfig)().upload.showPreview},showTip:{type:Boolean,default:()=>null},maxSimultaneousUploads:{type:Number,default:()=>(0,_ui.getConfig)().upload.maxSimultaneousUploads},tipText:[String,Number,Function],hintText:String,previewMethod:Function,beforeSelectMethod:Function,uploadMethod:Function,beforeRemoveMethod:Function,removeMethod:Function,beforeDownloadMethod:Function,downloadMethod:Function,getUrlMethod:Function,getThumbnailUrlMethod:Function,size:{type:String,default:()=>(0,_ui.getConfig)().upload.size||(0,_ui.getConfig)().size}},emits:["update:modelValue","add","remove","remove-fail","download","download-fail","upload-success","upload-error","sort-dragend","more-visible"],setup(S,e){let{emit:i,slots:D}=e,C=(0,_vue.inject)("$xeForm",null),U=(0,_vue.inject)("xeFormItemInfo",null),l=(0,_vue.inject)("$xeTable",null);var t=_xeUtils.default.uniqueId();let G=(0,_ui.useSize)(S).computeSize,m=(0,_vue.ref)(),_=(0,_vue.ref)(),c=(0,_vue.ref)(),f=(0,_vue.ref)(),B=(0,_vue.reactive)(createReactData()),r=createInternalData(),a={refElem:m},L=(0,_vue.computed)(()=>{var e=S.readonly;return null===e?!!C&&C.props.readonly:e}),P=(0,_vue.computed)(()=>{var e=S.disabled;return null===e?!!C&&C.props.disabled:e}),E=(0,_vue.computed)(()=>S.keyField||"_X_KEY"),h=(0,_vue.computed)(()=>"image"===S.mode),V=(0,_vue.computed)(()=>S.nameField||"name"),F=(0,_vue.computed)(()=>S.typeField||"type"),M=(0,_vue.computed)(()=>S.urlField||"url"),T=(0,_vue.computed)(()=>S.sizeField||"size"),H=(0,_vue.computed)(()=>1024*_xeUtils.default.toNumber(S.limitSize)*1024),O=(0,_vue.computed)(()=>S.multiple?_xeUtils.default.toNumber(S.limitCount):1),Y=(0,_vue.computed)(()=>{var e=S.showDownloadButton;return Object.assign({showDownloadButton:e},(0,_ui.getConfig)().upload.previewImageConfig,S.previewImageConfig)}),Q=(0,_vue.computed)(()=>{var e=S.multiple,t=B.fileList,o=O.value;return e?!o||t.length>=o:1<=t.length}),X=(0,_vue.computed)(()=>{var e=_xeUtils.default.toNumber(S.limitSize);return e?1048576<e?e/1048576+"T":1024<e?e/1024+"G":e+"M":""}),W=(0,_vue.computed)(()=>{var{showTip:e,tipText:t}=S;return _xeUtils.default.isBoolean(e)||(e=(0,_ui.getConfig)().upload.showTip,_xeUtils.default.isBoolean(e))?e:!!t}),K=(0,_vue.computed)(()=>{var{limitSize:e,fileTypes:t,multiple:o,limitCount:i}=S,l=S.tipText||S.hintText,a=h.value,u=X.value;return _xeUtils.default.isString(l)?l:_xeUtils.default.isFunction(l)?""+l({}):(l=[],a?(o&&i&&l.push((0,_ui.getI18n)("vxe.upload.imgCountHint",[i])),e&&u&&l.push((0,_ui.getI18n)("vxe.upload.imgSizeHint",[u]))):(t&&t.length&&l.push((0,_ui.getI18n)("vxe.upload.fileTypeHint",[t.join("/")])),e&&u&&l.push((0,_ui.getI18n)("vxe.upload.fileSizeHint",[u])),o&&i&&l.push((0,_ui.getI18n)("vxe.upload.fileCountHint",[i]))),l.join((0,_ui.getI18n)("vxe.base.comma")))}),u=(0,_vue.computed)(()=>Object.assign({},S.imageConfig||S.imageStyle)),J=(0,_vue.computed)(()=>{var{width:e,height:t}=u.value,o={};return e&&(o.width=(0,_dom.toCssUnit)(e)),t&&(o.height=(0,_dom.toCssUnit)(t)),o}),Z=(0,_vue.computed)(()=>Object.assign({showMoreButton:!0},S.moreConfig)),n={},A={xID:t,props:S,context:e,reactData:B,internalData:r,getRefMaps:()=>a,getComputeMaps:()=>n},N=()=>_xeUtils.default.uniqueId(),z=e=>e[E.value],d=()=>{var{modelValue:e,multiple:t}=S,o=L.value;let l=E.value,a=V.value,u=F.value,n=M.value,r=T.value;e=e?(e?_xeUtils.default.isArray(e)?e:[e]:[]).map(t=>{if(!t||_xeUtils.default.isString(t)){var o=""+(t||""),i=_xeUtils.default.parseUrl(t);let e=(i?i.searchQuery[a]:"")||decodeURIComponent(""+(o||"")).split("/").pop()||"";return{[a]:e,[u]:(i?i.searchQuery[u]:"")||j(e),[n]:o,[r]:_xeUtils.default.toNumber(i?i.searchQuery[r]:0)||0,[l]:N()}}let e=t[a]||"";return t[a]=e,t[u]=t[u]||j(e),t[n]=t[n]||"",t[r]=t[r]||0,t[l]=t[l]||N(),t}):[];B.fileList=o||t?e:e.slice(0,1)},j=e=>{var t=e.lastIndexOf(".");return 0<t?e.substring(t+1).toLowerCase():""},k=(e,t,o)=>{i(e,(0,_ui.createEvent)(o,{$upload:A},t))},s=e=>{i("update:modelValue",e)},R=e=>{let{singleMode:t,urlMode:o,urlArgs:i}=S,l=M.value,a=V.value,u=e?e.slice(0):[];o&&(u=u.map(e=>{var t=e[l];if(t&&i){var o=_xeUtils.default.parseUrl(t);if(!o.searchQuery[a]&&-1===t.indexOf("blob:"))return""+t+(-1===t.indexOf("?")?"?":"&")+a+"="+encodeURIComponent(e[a]||"")}return t})),s(t?u[0]||null:u)},$=e=>{var t=S.getUrlMethod||(0,_ui.getConfig)().upload.getUrlMethod,o=M.value;return t?t({$upload:A,option:e}):e[o]},ee=t=>{var{imageTypes:e,showDownloadButton:o}=S;let i=F.value;var l=Y.value;let a=S.beforeDownloadMethod||(0,_ui.getConfig)().upload.beforeDownloadMethod;var u=r.imagePreviewTypes;u.concat(e||[]).some(e=>(""+e).toLowerCase()===(""+t[i]).toLowerCase())&&_ui.VxeUI.previewImage&&_ui.VxeUI.previewImage(Object.assign(Object.assign({},l),{urlList:[$(t)],showDownloadButton:o,beforeDownloadMethod:a?()=>a({$upload:A,option:t}):void 0}))},q=(o,e)=>{let i=S.showErrorStatus,l=z(o);var t=S.uploadMethod||(0,_ui.getConfig)().upload.uploadMethod;return t?Promise.resolve(t({$upload:A,file:e,option:o,updateProgress(e){var t=B.fileCacheMaps,t=t[z(o)];t&&(t.percent=Math.max(0,Math.min(99,_xeUtils.default.toNumber(e))))}})).then(e=>{var t=B.fileCacheMaps,t=t[l];t&&(t.percent=100,t.status="success"),Object.assign(o,e),k("upload-success",{option:o,data:e},null)}).catch(e=>{var t=B.fileCacheMaps,t=t[l];t&&(t.status="error"),i?Object.assign(o,e):B.fileList=B.fileList.filter(e=>z(e)!==l),k("upload-error",{option:o,data:e},null)}).finally(()=>{var e=B.fileCacheMaps,e=e[l];e&&(e.loading=!1)}):(t=B.fileCacheMaps,(e=t[l])&&(e.loading=!1),Promise.resolve())},te=e=>{let{uploadMethod:t,urlMode:o}=S;var i,l=B.fileCacheMaps,l=l[z(e)];(t||(0,_ui.getConfig)().upload.uploadMethod)&&l&&(i=l.file,l.loading=!0,l.status="pending",l.percent=0,q(e,i).then(()=>{o&&R(B.fileList)}))},p=(t,o)=>{let{multiple:e,urlMode:i,showLimitSize:l,limitSizeText:a,showLimitCount:u,limitCountText:n,autoSubmit:r}=S;var d=B.fileList;let s=S.beforeSelectMethod||(0,_ui.getConfig)().upload.beforeSelectMethod,p=S.uploadMethod||(0,_ui.getConfig)().upload.uploadMethod,v=E.value,g=V.value,m=F.value,_=M.value,c=T.value;var f=H.value;let h=O.value;var x=X.value;let w=t;if(e&&h){if(u&&d.length>=h)return void(_ui.VxeUI.modal&&_ui.VxeUI.modal.notification({title:(0,_ui.getI18n)("vxe.modal.errTitle"),status:"error",content:n?""+(_xeUtils.default.isFunction(n)?n({maxCount:h}):n):(0,_ui.getI18n)("vxe.upload.overCountErr",[h])}));let t=w.length-(h-d.length);if(u&&0<t){let e=w.slice(h-d.length);n?_ui.VxeUI.modal.notification({title:(0,_ui.getI18n)("vxe.modal.errTitle"),status:"error",content:""+(_xeUtils.default.isFunction(n)?n({maxCount:h}):n)}):_ui.VxeUI.modal&&_ui.VxeUI.modal.notification({title:(0,_ui.getI18n)("vxe.modal.errTitle"),status:"error",width:null,slots:{default(){return(0,_vue.h)("div",{class:"vxe-upload--file-message-over-error"},[(0,_vue.h)("div",{},(0,_ui.getI18n)("vxe.upload.overCountExtraErr",[h,t])),(0,_vue.h)("div",{class:"vxe-upload--file-message-over-extra"},e.map((e,t)=>(0,_vue.h)("div",{key:t,class:"vxe-upload--file-message-over-extra-item"},e.name)))])}}})}w=w.slice(0,h-d.length)}if(l&&f)for(let e=0;e<t.length;e++)if(t[0].size>f)return void(_ui.VxeUI.modal&&_ui.VxeUI.modal.notification({title:(0,_ui.getI18n)("vxe.modal.errTitle"),status:"error",content:a?""+(_xeUtils.default.isFunction(a)?a({maxSize:f}):a):(0,_ui.getI18n)("vxe.upload.overSizeErr",[x])}));let y=Object.assign({},B.fileCacheMaps),b=e?d:[],I=[];w.forEach(e=>{var t=e.name,o=N(),t={[g]:t,[m]:j(t),[c]:e.size,[_]:URL.createObjectURL(e),[v]:o},o=(p&&(y[o]={file:e,loading:!!r,status:"pending",percent:0}),(0,_vue.reactive)(t));s&&!s({$upload:A,file:e})||(p&&r&&I.push(q(o,e)),b.push(o))}),B.fileList=b,B.fileCacheMaps=y,b.forEach(e=>{k("add",{option:e},o)}),Promise.all(i?I:[]).then(()=>{R(b),C&&U&&C.triggerItemEvent(o,U.itemConfig.field,b)})},v=t=>{var{multiple:e,imageTypes:o,fileTypes:i}=S,l=P.value,a=h.value;return l?Promise.resolve({status:!1,files:[],file:null}):(0,_util.readLocalFile)({multiple:e,types:a?o:i}).then(e=>(p(e.files,t),e))},oe=e=>{v(e).catch(()=>{})},g=(e,t,o)=>{var i=B.fileList;i.splice(o,1),R(i),C&&U&&C.triggerItemEvent(e,U.itemConfig.field,i),k("remove",{option:t},e)},ie=(t,o,i)=>{var e=S.beforeRemoveMethod||(0,_ui.getConfig)().upload.beforeRemoveMethod;let l=S.removeMethod||(0,_ui.getConfig)().upload.removeMethod;Promise.resolve(!e||e({$upload:A,option:o})).then(e=>{e?l?Promise.resolve(l({$upload:A,option:o})).then(()=>{g(t,o,i)}).catch(e=>e):g(t,o,i):k("remove-fail",{option:o},t)})},le=(e,t)=>{k("download",{option:t},e)},ae=e=>{var t,o,i,l=e.currentTarget,{clientX:e,clientY:a}=e;l&&({x:l,y:t,height:o,width:i}=l.getBoundingClientRect(),e<l||l+i<e||a<t||t+o<a)&&(B.isDragUploadStatus=!1)},ue=e=>{var t=e.dataTransfer;t&&(t=t.items,t)&&t.length&&(e.preventDefault(),B.isDragUploadStatus=!0)},ne=(e,t)=>{let{imageTypes:i,fileTypes:l}=S;var a=r.imagePreviewTypes;if(h.value){let o=a.concat(i&&i.length?i:[]);t=t.filter(e=>{let t=(""+(e.type.split("/")[1]||"")).toLowerCase();return!!o.some(e=>(""+e).toLowerCase()===t)})}else if(l&&l.length){let o=[];if(t.forEach(e=>{let t=j(e.name);l.some(e=>(""+e).toLowerCase()===t)||o.push(t)}),o.length)return void(_ui.VxeUI.modal&&_ui.VxeUI.modal.message({content:(0,_ui.getI18n)("vxe.error.notType",[o.join(", ")]),status:"error"}))}t.length?p(t,e):_ui.VxeUI.modal&&_ui.VxeUI.modal.notification({title:(0,_ui.getI18n)("vxe.modal.errTitle"),status:"error",content:(0,_ui.getI18n)("vxe.upload.uploadTypeErr")})},re=e=>{var t=e.dataTransfer;t&&(t=t.items,t)&&t.length&&(e.preventDefault(),(t=de(t)).length)&&ne(e,t),B.isDragUploadStatus=!1},de=e=>{let t=[];return _xeUtils.default.arrayEach(e,e=>{e=e.getAsFile();e&&t.push(e)}),t},x=e=>{let v=L.value,g=h.value;e=e.$event;_ui.VxeUI.modal&&(_ui.VxeUI.modal.open({id:r.moreId,title:v?(0,_ui.getI18n)("vxe.upload.morePopup.readTitle"):(0,_ui.getI18n)("vxe.upload.morePopup."+(g?"imageTitle":"fileTitle")),width:660,height:500,escClosable:!0,showMaximize:!0,resize:!0,maskClosable:!0,slots:{default(){var{showErrorStatus:e,dragToUpload:t,dragSort:o,dragPlaceholder:i}=S,{isActivated:l,isDragMove:a,isDragUploadStatus:u,dragIndex:n}=B;let r=B.fileList;var d=P.value,s=D.moreContent||D["more-content"],p={};return t&&-1===n&&(p.onDragover=ue,p.onDragleave=ae,p.onDrop=re),(0,_vue.h)("div",Object.assign({ref:_,class:["vxe-upload--more-popup",{"is--readonly":v,"is--disabled":d,"is--active":l,"show--error":e,"is--drag":u}]},p),s?(0,_vn.getSlotVNs)(s({options:r})):[g?o?(0,_vue.h)(_vue.TransitionGroup,{name:"vxe-upload--drag-list"+(a?"":"-disabled"),tag:"div",class:"vxe-upload--image-more-list"},{default:()=>b(r,!0).concat(I(!0))}):(0,_vue.h)("div",{class:"vxe-upload--image-more-list"},b(r,!0).concat(I(!0))):(0,_vue.h)("div",{class:"vxe-upload--file-more-list"},[y(!0),o?(0,_vue.h)(_vue.TransitionGroup,{name:"vxe-upload--drag-list"+(a?"":"-disabled"),tag:"div",class:"vxe-upload--file-list"},{default:()=>w(r,!1)}):(0,_vue.h)("div",{class:"vxe-upload--file-list"},w(r,!0))]),o?(0,_vue.h)("div",{ref:f,class:"vxe-upload--drag-line"}):(0,_ui.renderEmptyElement)(A),u?(0,_vue.h)("div",{class:"vxe-upload--drag-placeholder"},i||(0,_ui.getI18n)("vxe.upload.dragPlaceholder")):(0,_ui.renderEmptyElement)(A)])}},onShow(){B.showMorePopup=!0},onHide({$event:e}){B.showMorePopup=!1,e&&k("more-visible",{visible:!1},e)}}),e)&&k("more-visible",{visible:!0},e)},se=(e,t,o)=>{var i,l=B.showMorePopup,a=m.value,u=_.value,u=l?u:a;u&&(a=u.getBoundingClientRect(),u=c.value,i=f.value,l=l?i:u)&&(i=t.getBoundingClientRect(),l.style.display="block",l.style.top=Math.max(1,i.y-a.y)+"px",l.style.left=Math.max(1,i.x-a.x)+"px",l.style.height=i.height+"px",l.style.width=i.width-1+"px",l.setAttribute("drag-pos",o))},pe=()=>{var e=c.value,t=f.value;e&&(e.style.display=""),t&&(t.style.display="")},ve=e=>{e.stopPropagation(),e.dataTransfer&&e.dataTransfer.setDragImage((0,_dom.getTpImg)(),0,0);let t=e.currentTarget;e=t.parentElement,e=_xeUtils.default.findIndexOf(Array.from(e.children),e=>t===e);B.isDragMove=!0,B.dragIndex=e,setTimeout(()=>{B.isDragMove=!1},500)},ge=o=>{o.stopPropagation(),o.preventDefault();var i=B.dragIndex;if(-1!==i){var l=h.value;let t=o.currentTarget;var a=t.parentElement,a=_xeUtils.default.findIndexOf(Array.from(a.children),e=>t===e);let e="";e=l?o.clientX-t.getBoundingClientRect().x<t.clientWidth/2?"left":"right":o.clientY-t.getBoundingClientRect().y<t.clientHeight/2?"top":"bottom",i===a?se(o,t,e):(se(o,t,e),r.prevDragIndex=a,r.prevDragPos=e)}},me=e=>{var{fileList:t,dragIndex:o}=B,{prevDragIndex:i,prevDragPos:l}=r,a="bottom"===l||"right"===l?1:0,u=t[o];let n=t[i];u&&n&&(t.splice(o,1),i=_xeUtils.default.findIndexOf(t,e=>n===e)+a,t.splice(i,0,u),k("sort-dragend",{oldItem:u,newItem:n,dragPos:l,offsetIndex:a,_index:{newIndex:i,oldIndex:o}},e)),pe(),B.dragIndex=-1},_e=e=>{l&&e.stopPropagation(),B.isActivated=!0},ce=e=>{var t=S.pasteToUpload,o=B.isActivated;o&&t&&(o=e.clipboardData||e.originalEvent.clipboardData)&&(t=o.items,t)&&(o=de(t)).length&&(e.preventDefault(),ne(e,o))},fe=e=>{var t=m.value,o=_.value;let i=(0,_dom.getEventTargetNode)(e,t).flag;!i&&o&&(o=(t=o.parentElement||o)&&t.parentElement,i=(0,_dom.getEventTargetNode)(e,o).flag),B.isActivated=i},he=()=>{B.isActivated=!1};t={dispatchEvent:k,choose(){return v(null)},getPendingFiles(){let{fileList:e,fileCacheMaps:t}=B,o=[];return e.forEach(e=>{e=z(e),e=t[e];e&&"pending"===e.status&&o.push(e.file)}),o},submit(i){var e=S.maxSimultaneousUploads,e=_xeUtils.default.toNumber(e||1)||1;let{fileList:t,fileCacheMaps:l}=B,o=t.filter(e=>{e=z(e),e=l[e];return e&&("pending"===e.status||i&&"error"===e.status)}),a=e=>{var t=z(e),t=l[t];if(t){var o=t.file;if(o&&("pending"===t.status||i&&"error"===t.status))return t.loading=!0,t.percent=0,q(e,o).then(u)}return u()},u=()=>{var e;return o.length?(e=o[0],o.splice(0,1),a(e).then(u)):Promise.resolve()};return Promise.all(o.splice(0,e).map(a)).then(()=>{})},getMoreVisible(){return B.showMorePopup},openMore(){return x({$event:new Event("click")}),(0,_vue.nextTick)()},openMoreByEvent(e){return x({$event:e}),(0,_vue.nextTick)()},closeMore(){return _ui.VxeUI.modal&&_ui.VxeUI.modal.close(r.moreId),(0,_vue.nextTick)()}};Object.assign(A,t,{});let w=(e,r)=>{let{showRemoveButton:d,showDownloadButton:s,showProgress:p,progressText:v,showPreview:g,showErrorStatus:m,dragSort:_,autoSubmit:c,showSubmitButton:f}=S,{fileList:h,fileCacheMaps:x}=B,w=P.value,y=L.value,b=V.value,I=F.value,C=D.option,U=D.action,E=D.corner,M=D.name,T={};return _&&1<e.length&&(T.onDragstart=ve,T.onDragover=ge,T.onDragend=me),e.map((i,t)=>{var e=z(i),o=x[e];let l=!1,a=!1,u=!1;var n=""+(i[b]||"");return o&&(l=o.loading,a="error"===o.status,u="pending"===o.status),(0,_vue.h)("div",Object.assign({key:_?e:t,class:["vxe-upload--file-item",{"is--preview":g,"is--loading":l,"is--pending":u,"is--error":a}],fileid:e,draggable:!!_||null},T),C?(0,_vn.getSlotVNs)(C({option:i,isMoreView:r,options:h})):[(0,_vue.h)("div",{class:"vxe-upload--file-item-icon"},[(0,_vue.h)("i",{class:(0,_ui.getIcon)()["UPLOAD_FILE_TYPE_"+(""+i[I]).toLocaleUpperCase()]||(0,_ui.getIcon)().UPLOAD_FILE_TYPE_DEFAULT})]),(0,_vue.h)("div",{class:"vxe-upload--file-item-name",title:n,onClick(e){var t,o;l||a||(t=i,o=S.previewMethod||(0,_ui.getConfig)().upload.previewMethod,S.showPreview&&(o?o({$upload:A,option:t}):ee(t)))}},M?(0,_vn.getSlotVNs)(M({option:i,isMoreView:r,options:h})):n),l?(0,_vue.h)("div",{class:"vxe-upload--file-item-loading-icon"},[(0,_vue.h)("i",{class:(0,_ui.getIcon)().UPLOAD_LOADING})]):(0,_ui.renderEmptyElement)(A),p&&l&&o?(0,_vue.h)("div",{class:"vxe-upload--file-item-loading-text"},v?_xeUtils.default.toFormatString(""+(_xeUtils.default.isFunction(v)?v({}):v),{percent:o.percent}):(0,_ui.getI18n)("vxe.upload.uploadProgress",[o.percent])):(0,_ui.renderEmptyElement)(A),!l&&(a&&m||u&&f&&!c)?(0,_vue.h)("div",{class:"vxe-upload--file-item-rebtn"},[(0,_vue.h)(_button.default,{icon:a?(0,_ui.getIcon)().UPLOAD_IMAGE_RE_UPLOAD:(0,_ui.getIcon)().UPLOAD_IMAGE_UPLOAD,mode:"text",status:"primary",content:a?(0,_ui.getI18n)("vxe.upload.reUpload"):(0,_ui.getI18n)("vxe.upload.manualUpload"),onClick(){te(i)}})]):(0,_ui.renderEmptyElement)(A),(0,_vue.h)("div",{class:"vxe-upload--file-item-btn-wrapper"},U?(0,_vn.getSlotVNs)(U({option:i,isMoreView:r,options:h,readonly:y})):[E?(0,_vue.h)("div",{class:"vxe-upload--file-item-action"},(0,_vn.getSlotVNs)(E({option:i,isMoreView:r,options:h,readonly:y}))):(0,_ui.renderEmptyElement)(A),!s||l||u?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{class:"vxe-upload--file-item-download-btn",onClick(e){((t,o)=>{var e=S.beforeDownloadMethod||(0,_ui.getConfig)().upload.beforeDownloadMethod;let i=S.downloadMethod||(0,_ui.getConfig)().upload.downloadMethod;Promise.resolve(!e||e({$upload:A,option:o})).then(e=>{e?i?Promise.resolve(i({$upload:A,option:o})).then(()=>{le(t,o)}).catch(e=>e):le(t,o):k("download-fail",{option:o},t)})})(e,i)}},[(0,_vue.h)("i",{class:(0,_ui.getIcon)().UPLOAD_FILE_DOWNLOAD})]),!d||y||w||l?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{class:"vxe-upload--file-item-remove-btn",onClick(e){ie(e,i,t)}},[(0,_vue.h)("i",{class:(0,_ui.getIcon)().UPLOAD_FILE_REMOVE})])])])})},y=e=>{var{showUploadButton:t,buttonText:o,buttonIcon:i,showButtonText:l,showButtonIcon:a,autoHiddenButton:u}=S,n=B.fileList,r=P.value,d=L.value,s=W.value,p=K.value,v=Q.value,g=D.default,m=D.tip||D.hint;return d||!t?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{class:"vxe-upload--file-action"},[u&&v?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{class:"vxe-upload--file-action-btn",onClick:oe},g?(0,_vn.getSlotVNs)(g({isMoreView:e,options:n,$upload:A})):[(0,_vue.h)(_button.default,{class:"vxe-upload--file-action-button",content:e||l?o?""+(_xeUtils.default.isFunction(o)?o({}):o):(0,_ui.getI18n)("vxe.upload.fileBtnText"):"",icon:a?i||(0,_ui.getIcon)().UPLOAD_FILE_ADD:"",disabled:r})]),s&&(p||m)?(0,_vue.h)("div",{class:"vxe-upload--file-action-tip"},m?(0,_vn.getSlotVNs)(m({isMoreView:e,options:n,$upload:A})):""+p):(0,_ui.renderEmptyElement)(A)])},b=(e,n)=>{let{showRemoveButton:r,showProgress:d,progressText:s,showPreview:p,showErrorStatus:v,dragSort:g,autoSubmit:m,showSubmitButton:_}=S,{fileList:c,fileCacheMaps:f}=B,h=P.value,x=L.value,w=u.value,y=J.value,b=D.option,I=D.action,C=D.corner,U={onMousedown:_e};return g&&1<e.length&&(U.onDragstart=ve,U.onDragover=ge,U.onDragend=me),e.map((t,o)=>{var e=z(t),i=f[e];let l=!1,a=!1,u=!1;return i&&(l=i.loading,a="error"===i.status,u="pending"===i.status),(0,_vue.h)("div",Object.assign({key:g?e:o,class:["vxe-upload--image-item",{"is--preview":p,"is--circle":w.circle,"is--loading":l,"is--pending":u,"is--error":a}],fileid:e,draggable:!!g||null},U),b?(0,_vn.getSlotVNs)(b({option:t,isMoreView:n,options:c})):[(0,_vue.h)("div",{class:"vxe-upload--image-item-box",style:n?null:y,onClick(e){l||a||((e,t)=>{var o=S.showDownloadButton;let i=B.fileList;var l=Y.value,a=S.previewMethod||(0,_ui.getConfig)().upload.previewMethod;let u=S.beforeDownloadMethod||(0,_ui.getConfig)().upload.beforeDownloadMethod;S.showPreview&&(a?a({$upload:A,option:e}):_ui.VxeUI.previewImage&&_ui.VxeUI.previewImage(Object.assign(Object.assign({},l),{urlList:i.map(e=>$(e)),activeIndex:t,showDownloadButton:o,beforeDownloadMethod:u?({index:e})=>u({$upload:A,option:i[e]}):void 0})))})(t,o)}},[l&&i?(0,_vue.h)("div",{class:"vxe-upload--image-item-loading"},[(0,_vue.h)("div",{class:"vxe-upload--image-item-loading-icon"},[(0,_vue.h)("i",{class:(0,_ui.getIcon)().UPLOAD_LOADING})]),d?(0,_vue.h)("div",{class:"vxe-upload--image-item-loading-text"},s?_xeUtils.default.toFormatString(""+(_xeUtils.default.isFunction(s)?s({}):s),{percent:i.percent}):(0,_ui.getI18n)("vxe.upload.uploadProgress",[i.percent])):(0,_ui.renderEmptyElement)(A)]):(0,_ui.renderEmptyElement)(A),(0,_vue.h)("div",{class:"vxe-upload--image-item-img-wrapper",title:(0,_ui.getI18n)("vxe.upload.viewItemTitle")},[(0,_vue.h)("img",{class:"vxe-upload--image-item-img",src:(e=t,(i=S.getThumbnailUrlMethod||(0,_ui.getConfig)().upload.getThumbnailUrlMethod)?i({$upload:A,option:e}):$(e))})]),!l&&(a&&v||u&&_&&!m)?(0,_vue.h)("div",{class:"vxe-upload--image-item-rebtn"},[(0,_vue.h)(_button.default,{icon:a?(0,_ui.getIcon)().UPLOAD_IMAGE_RE_UPLOAD:(0,_ui.getIcon)().UPLOAD_IMAGE_UPLOAD,mode:"text",status:"primary",content:a?(0,_ui.getI18n)("vxe.upload.reUpload"):(0,_ui.getI18n)("vxe.upload.manualUpload"),onClick(){te(t)}})]):(0,_ui.renderEmptyElement)(A),(0,_vue.h)("div",{class:"vxe-upload--image-item-btn-wrapper",onClick(e){e.stopPropagation()}},I?(0,_vn.getSlotVNs)(I({option:t,isMoreView:n,options:c,readonly:x})):[C?(0,_vue.h)("div",{class:"vxe-upload--file-item-action"},(0,_vn.getSlotVNs)(C({option:t,isMoreView:n,options:c,readonly:x}))):(0,_ui.renderEmptyElement)(A),!r||x||h||l?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{class:"vxe-upload--image-item-remove-btn",onClick(e){e.stopPropagation(),ie(e,t,o)}},[(0,_vue.h)("i",{class:(0,_ui.getIcon)().UPLOAD_IMAGE_REMOVE})])])])])})},I=e=>{var{showUploadButton:t,buttonText:o,buttonIcon:i,showButtonText:l,showButtonIcon:a,autoHiddenButton:u}=S,n=B.fileList,r=L.value,d=W.value,s=K.value,p=Q.value,v=J.value,g=D.default,m=D.tip||D.hint;return r||!t||u&&p?(0,_ui.renderEmptyElement)(A):(0,_vue.h)("div",{key:"action",class:"vxe-upload--image-action"},[(0,_vue.h)("div",{class:"vxe-upload--image-action-btn",onClick:oe},g?g({isMoreView:e,options:n,$upload:A}):[(0,_vue.h)("div",{class:"vxe-upload--image-action-box",style:e?null:v},[a?(0,_vue.h)("div",{class:"vxe-upload--image-action-icon"},[(0,_vue.h)("i",{class:i||(0,_ui.getIcon)().UPLOAD_IMAGE_ADD})]):(0,_ui.renderEmptyElement)(A),e||l?(0,_vue.h)("div",{class:"vxe-upload--image-action-content"},o?""+(_xeUtils.default.isFunction(o)?o({}):o):(0,_ui.getI18n)("vxe.upload.imgBtnText")):(0,_ui.renderEmptyElement)(A),d&&(s||m)?(0,_vue.h)("div",{class:"vxe-upload--image-action-hint"},m?(0,_vn.getSlotVNs)(m({isMoreView:e,options:n,$upload:A})):""+s):(0,_ui.renderEmptyElement)(A)])])])};let o=(0,_vue.ref)(0);return(0,_vue.watch)(()=>S.modelValue?S.modelValue.length:0,()=>{o.value++}),(0,_vue.watch)(()=>S.modelValue,()=>{o.value++}),(0,_vue.watch)(o,()=>{d()}),(0,_vue.onMounted)(()=>{S.multiple&&S.singleMode&&(0,_log.errLog)("vxe.error.errConflicts",["[upload] multiple","single-mode"]),S.imageStyle&&(0,_log.warnLog)("vxe.error.delProp",["[upload] image-style","image-config"]),S.dragSort&&(0,_dom.initTpImg)(),_ui.globalEvents.on(A,"paste",ce),_ui.globalEvents.on(A,"mousedown",fe),_ui.globalEvents.on(A,"blur",he)}),(0,_vue.onBeforeUnmount)(()=>{B.isDragUploadStatus=!1,_ui.globalEvents.off(A,"paste"),_ui.globalEvents.off(A,"mousedown"),_ui.globalEvents.off(A,"blur"),_xeUtils.default.assign(B,createReactData()),_xeUtils.default.assign(r,createInternalData())}),d(),A.renderVN=()=>{var{showErrorStatus:e,dragToUpload:t,pasteToUpload:o,dragSort:i,dragPlaceholder:l}=S,{isDragUploadStatus:a,showMorePopup:u,isActivated:n,dragIndex:r}=B,d=G.value,s=P.value,p=L.value,v=h.value,g={onMousedown:_e};return t&&-1===r&&(g.onDragover=ue,g.onDragleave=ae,g.onDrop=re),(0,_vue.h)("div",Object.assign({ref:m,class:["vxe-upload",{["size--"+d]:d,"is--active":n,"is--readonly":p,"is--disabled":s,"is--paste":o,"show--error":e,"is--drag":a}]},g),[(v?()=>{var{showList:e,dragSort:t}=S;let{fileList:o,isDragMove:i}=B;var l=Z.value;let a=D.moreButton||D["more-button"],{maxCount:u,showMoreButton:n,moreButtonText:r}=l,d=o,s=0,p=!1,v=!1;return _xeUtils.default.isNumber(u)&&o.length>u&&(p=!0,v=0===u,s=o.length-u,d=o.slice(0,u)),(0,_vue.h)("div",{key:"image",class:"vxe-upload--image-wrapper"},e?[t?(0,_vue.h)(_vue.TransitionGroup,{name:"vxe-upload--drag-list"+(i?"":"-disabled"),tag:"div",class:"vxe-upload--image-list"},{default:()=>b(d,!1).concat([n&&s?(0,_vue.h)("div",{key:"om",class:"vxe-upload--image-over-more"},a?(0,_vn.getSlotVNs)(a({options:o})):[(0,_vue.h)(_button.default,{mode:"text",content:r?_xeUtils.default.isFunction(r)?r({$upload:A,options:o}):_xeUtils.default.toFormatString(r,[o.length]):(0,_ui.getI18n)(p&&v?"vxe.upload.moreImgBtnText":"vxe.upload.moreBtnText",[o.length]),status:"primary",onClick:x})]):(0,_ui.renderEmptyElement)(A),I(!1)])}):(0,_vue.h)("div",{class:"vxe-upload--image-list"},b(d,!1).concat([n&&s?(0,_vue.h)("div",{class:"vxe-upload--image-over-more"},a?(0,_vn.getSlotVNs)(a({options:o})):[(0,_vue.h)(_button.default,{mode:"text",content:r?_xeUtils.default.isFunction(r)?r({$upload:A,options:o}):_xeUtils.default.toFormatString(r,[o.length]):(0,_ui.getI18n)(p&&v?"vxe.upload.moreImgBtnText":"vxe.upload.moreBtnText",[o.length]),status:"primary",onClick:x})]):(0,_ui.renderEmptyElement)(A),I(!1)]))]:[(0,_vue.h)("div",{class:"vxe-upload--image-list"},[I(!1)])])}:()=>{var{showList:e,moreConfig:t,dragSort:o}=S,{fileList:i,isDragMove:l}=B,{maxCount:a,showMoreButton:u,layout:n,moreButtonText:r}=Z.value,n="horizontal"===n,d=D.moreButton||D["more-button"];let s=i,p=0,v=!1,g=!1;return _xeUtils.default.isNumber(a)&&i.length>a&&(v=!0,g=0===a,p=i.length-a,s=i.slice(0,a)),(0,_vue.h)("div",{key:"all",class:"vxe-upload--file-wrapper"},e?[u&&t&&n?(0,_ui.renderEmptyElement)(A):y(!0),(0,_vue.h)("div",{class:["vxe-upload--file-list-wrapper",{"is--horizontal":n}]},[s.length?o?(0,_vue.h)(_vue.TransitionGroup,{name:"vxe-upload--drag-list"+(l?"":"-disabled"),tag:"div",class:"vxe-upload--file-list"},{default:()=>w(s,!1)}):(0,_vue.h)("div",{class:"vxe-upload--file-list"},w(s,!1)):(0,_ui.renderEmptyElement)(A),u&&p?(0,_vue.h)("div",{class:"vxe-upload--file-over-more"},d?(0,_vn.getSlotVNs)(d({options:i})):[(0,_vue.h)(_button.default,{mode:"text",content:r?_xeUtils.default.isFunction(r)?r({$upload:A,options:i}):_xeUtils.default.toFormatString(r,[i.length]):(0,_ui.getI18n)(v&&g?"vxe.upload.moreFileBtnText":"vxe.upload.moreBtnText",[i.length]),status:"primary",onClick:x})]):(0,_ui.renderEmptyElement)(A),u&&t&&n?y(!1):(0,_ui.renderEmptyElement)(A)])]:[y(!1)])})(),i?(0,_vue.h)("div",{ref:c,class:"vxe-upload--drag-line"}):(0,_ui.renderEmptyElement)(A),a&&!u?(0,_vue.h)("div",{class:"vxe-upload--drag-placeholder"},l||(0,_ui.getI18n)("vxe.upload.dragPlaceholder")):(0,_ui.renderEmptyElement)(A)])},A},render(){return this.renderVN()}});