mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 09:03:19 +08:00
2 lines
23 KiB
JavaScript
2 lines
23 KiB
JavaScript
"use strict";(self["webpackChunksanyue_imghub"]=self["webpackChunksanyue_imghub"]||[]).push([[733],{6733:function(t,e,i){i.r(e),i.d(e,{default:function(){return q}});var s=i(6768),r=i(5130),o=i(4232);const n=["src"],a=["src"];function l(t,e,i,l,h,c){return(0,s.uX)(),(0,s.CE)("div",{class:"tm-viewport",ref:"viewport",onPointerdown:e[1]||(e[1]=(...t)=>c.onPointerDown&&c.onPointerDown(...t)),onPointermove:e[2]||(e[2]=(...t)=>c.onPointerMove&&c.onPointerMove(...t)),onPointerup:e[3]||(e[3]=(...t)=>c.onPointerUp&&c.onPointerUp(...t)),onPointercancel:e[4]||(e[4]=(...t)=>c.onPointerUp&&c.onPointerUp(...t)),onDblclick:e[5]||(e[5]=(0,r.D$)((...t)=>c.onDblClick&&c.onDblClick(...t),["prevent"]))},[i.isImage?((0,s.uX)(),(0,s.CE)("img",{key:0,class:"tm-media",src:i.src,draggable:"false",style:(0,o.Tr)(c.mediaStyle),onLoad:e[0]||(e[0]=(...t)=>c.onLoad&&c.onLoad(...t))},null,44,n)):i.isVideo?((0,s.uX)(),(0,s.CE)("video",{key:1,class:"tm-media",src:i.src,controls:"",autoplay:"",playsinline:"",style:(0,o.Tr)(c.mediaStyle)},null,12,a)):(0,s.Q3)("",!0)],544)}var h={name:"TransformMedia",props:{file:{type:Object,required:!0},src:{type:String,required:!0},isImage:{type:Boolean,default:!0},isVideo:{type:Boolean,default:!1}},data(){return{pointers:new Map,scale:1,rotation:0,rotatePreview:0,tx:0,ty:0,naturalWidth:0,naturalHeight:0,startScale:1,startRotation:0,startTx:0,startTy:0,startCenter:null,startDist:0,startAngle:0,dragging:!1,dragStart:null,viewportRect:null,minScale:1,maxScale:4,gestureMode:null}},computed:{isActiveTransform(){return this.scale>1.001||this.pointers.size>=2||this.dragging},displayRotation(){return this.rotation+this.rotatePreview},rotateShrink(){const t=Math.min(1,Math.abs(this.rotatePreview)/90),e=Math.sin(Math.PI*t);return 1-.12*e},mediaStyle(){const t=this.scale*this.rotateShrink,e=this.pointers.size>0;return{transform:`translate3d(${this.tx}px, ${this.ty}px, 0) scale(${t}) rotate(${this.displayRotation}deg)`,transition:e?"none":"transform 0.25s ease",transformOrigin:"center center"}}},watch:{isActiveTransform(t){this.$emit(t?"lock":"unlock")}},methods:{onLoad(t){const e=t.target;this.naturalWidth=e.naturalWidth,this.naturalHeight=e.naturalHeight},reset(){this.scale=1,this.rotation=0,this.rotatePreview=0,this.tx=0,this.ty=0,this.pointers.clear(),this.dragging=!1,this.$emit("unlock")},clamp(t,e,i){return Math.max(e,Math.min(i,t))},rubberBand(t,e,i=.55){return t*e*i/(e+i*t)},getViewportRect(){return this.$refs.viewport?.getBoundingClientRect()},getPanBounds(){const t=this.$refs.viewport?.getBoundingClientRect();if(!t)return{maxX:0,maxY:0,vw:0,vh:0};const e=t.width,i=t.height,s=this.$el.querySelector("img, video"),r=s?.clientWidth||e,o=s?.clientHeight||i,n=r*this.scale,a=o*this.scale,l=Math.max(0,(n-e)/2),h=Math.max(0,(a-i)/2);return{maxX:l,maxY:h,vw:e,vh:i}},applyBoundWithRubber(t,e,i){return t>e?e+this.rubberBand(t-e,i,.55):t<-e?-e-this.rubberBand(-e-t,i,.55):t},calcTwoPointer(){const t=Array.from(this.pointers.values()),e=t[0],i=t[1],s=i.x-e.x,r=i.y-e.y,o=Math.hypot(s,r),n=Math.atan2(r,s)*(180/Math.PI),a={x:(e.x+i.x)/2,y:(e.y+i.y)/2};return{dist:o,angle:n,center:a}},normalizeAngle(t){return t=(t%360+360)%360,t>180?t-360:t},onPointerDown(t){if(t.currentTarget.setPointerCapture?.(t.pointerId),this.viewportRect=this.getViewportRect(),this.pointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),2===this.pointers.size){const{dist:t,angle:e,center:i}=this.calcTwoPointer();return this.startDist=t,this.startAngle=e,this.startCenter=i,this.startScale=this.scale,this.startRotation=this.rotation,this.startTx=this.tx,this.startTy=this.ty,this.dragging=!1,this.gestureMode=null,void(this.rotatePreview=0)}this.scale>1.001&&(this.dragging=!0,this.dragStart={x:t.clientX,y:t.clientY},this.startTx=this.tx,this.startTy=this.ty)},onPointerMove(t){if(this.pointers.has(t.pointerId)){if(this.pointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),2===this.pointers.size){t.preventDefault();const{dist:e,angle:i,center:s}=this.calcTwoPointer(),r=e/(this.startDist||e),o=Math.abs(r-1),n=this.normalizeAngle(i-this.startAngle),a=Math.abs(n),l=8,h=.08;if(!this.gestureMode)if(a>=l)this.gestureMode="rotate";else{if(!(o>=h))return;this.gestureMode="pinch"}if("rotate"===this.gestureMode)return this.scale=this.startScale,void(this.rotatePreview=this.clamp(n,-90,90));if("pinch"===this.gestureMode&&(this.scale=this.clamp(this.startScale*r,this.minScale,this.maxScale),this.rotatePreview=0),this.startCenter&&this.viewportRect){const t=this.startCenter.x-this.viewportRect.left-this.viewportRect.width/2,e=this.startCenter.y-this.viewportRect.top-this.viewportRect.height/2,i=s.x-this.viewportRect.left-this.viewportRect.width/2,r=s.y-this.viewportRect.top-this.viewportRect.height/2;this.tx=this.startTx+(i-t),this.ty=this.startTy+(r-e)}return}if(this.dragging&&this.scale>1.001){t.preventDefault();const e=t.clientX-this.dragStart.x,i=t.clientY-this.dragStart.y,s=this.startTx+e,r=this.startTy+i,{maxX:o,maxY:n,vw:a,vh:l}=this.getPanBounds();this.tx=this.applyBoundWithRubber(s,o,a),this.ty=this.applyBoundWithRubber(r,n,l)}}},onPointerUp(t){if(this.pointers.has(t.pointerId)&&this.pointers.delete(t.pointerId),this.pointers.size<2&&"rotate"===this.gestureMode&&(this.finishRotate(),this.gestureMode=null),this.pointers.size<2&&(this.startCenter=null,this.startDist=0,this.startAngle=0,this.gestureMode=null),0===this.pointers.size)if(this.dragging=!1,this.scale<=1.001)this.scale=1,this.tx=0,this.ty=0;else{const{maxX:t,maxY:e}=this.getPanBounds();this.tx=Math.max(-t,Math.min(t,this.tx)),this.ty=Math.max(-e,Math.min(e,this.ty))}},finishRotate(){const t=this.rotatePreview,e=30;let i=0;Math.abs(t)>=e&&(i=t>0?90:-90);const s=((this.rotation+i)%360+360)%360;this.rotation=s,this.rotatePreview=0,this.updateFillScale()},updateFillScale(){const t=this.$refs.viewport?.getBoundingClientRect();if(!t||!this.naturalWidth||!this.naturalHeight)return;const e=t.width,i=t.height,s=this.naturalWidth,r=this.naturalHeight,o=this.rotation%360,n=90===o||270===o,a=n?r:s,l=n?s:r,h=Math.min(e/a,i/l),c=Math.max(e/a,i/l);if(n){const t=c/h;this.scale=Math.min(t,this.maxScale),this.tx=0,this.ty=0}else this.scale=1,this.tx=0,this.ty=0},onDblClick(){this.scale>1.001?(this.scale=1,this.tx=0,this.ty=0):this.scale=2}}},c=i(1241);const d=(0,c.A)(h,[["render",l],["__scopeId","data-v-5c291694"]]);var u=d;const p={class:"public-browse"},m={class:"header"},g={class:"header-left"},v={class:"logo"},w={class:"header-center"},f={class:"breadcrumb"},y=["onClick"],k={class:"header-right"},C={class:"file-count"},x={key:0,class:"loading-container"},b={key:1,class:"error-container"},L={key:2,class:"gallery-container",ref:"galleryContainer"},I={key:0,class:"folders-section"},M={class:"folders-grid"},F=["onClick"],P={class:"folder-name"},T={class:"waterfall",ref:"waterfall"},S=["onClick"],X=["src","alt","onLoad"],R=["src","onLoadedmetadata"],$={key:2,class:"file-placeholder"},E={class:"overlay"},D={class:"overlay-actions"},B=["onClick"],A=["onClick"],z={ref:"loadTrigger",class:"load-trigger"},H={key:0,class:"loading-more"},V={key:1,class:"no-more"},W=["src"],U=["src"],_={class:"page-indicator"};function Y(t,e,i,n,a,l){const h=u;return(0,s.uX)(),(0,s.CE)("div",p,[(0,s.Lk)("header",m,[(0,s.Lk)("div",g,[(0,s.Lk)("span",v,(0,o.v_)(l.siteName),1)]),(0,s.Lk)("div",w,[(0,s.Lk)("div",f,[(0,s.Lk)("span",{class:"breadcrumb-item",onClick:e[0]||(e[0]=(...t)=>l.goToRoot&&l.goToRoot(...t))},(0,o.v_)(l.rootDirName),1),((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.pathParts,(t,i)=>((0,s.uX)(),(0,s.CE)(s.FK,{key:i},[e[18]||(e[18]=(0,s.Lk)("span",{class:"breadcrumb-sep"},"/",-1)),(0,s.Lk)("span",{class:"breadcrumb-item",onClick:t=>l.goToPath(i)},(0,o.v_)(t),9,y)],64))),128))])]),(0,s.Lk)("div",k,[(0,s.Lk)("span",C,(0,o.v_)(a.totalCount)+" 个文件",1)])]),a.loading&&0===a.files.length?((0,s.uX)(),(0,s.CE)("div",x,[...e[19]||(e[19]=[(0,s.Lk)("div",{class:"loading-spinner"},null,-1),(0,s.Lk)("p",null,"加载中...",-1)])])):a.error?((0,s.uX)(),(0,s.CE)("div",b,[(0,s.Lk)("p",null,(0,o.v_)(a.error),1),a.canRetry?((0,s.uX)(),(0,s.CE)("button",{key:0,onClick:e[1]||(e[1]=(...t)=>l.loadFiles&&l.loadFiles(...t)),class:"retry-btn"},"重试")):(0,s.Q3)("",!0)])):((0,s.uX)(),(0,s.CE)("div",L,[l.folders.length>0?((0,s.uX)(),(0,s.CE)("div",I,[(0,s.Lk)("div",M,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.folders,t=>((0,s.uX)(),(0,s.CE)("div",{key:t.name,class:"folder-card",onClick:e=>l.enterFolder(t.name)},[e[20]||(e[20]=(0,s.Lk)("div",{class:"folder-icon"},[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"})])],-1)),(0,s.Lk)("span",P,(0,o.v_)(l.getFolderName(t.name)),1)],8,F))),128))])])):(0,s.Q3)("",!0),(0,s.Lk)("div",T,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.columns,(t,i)=>((0,s.uX)(),(0,s.CE)("div",{key:i,class:"waterfall-column"},[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(t,t=>((0,s.uX)(),(0,s.CE)("div",{key:t.name,class:"waterfall-item",onClick:e=>l.openPreview(t)},[(0,s.Lk)("div",{class:(0,o.C4)(["image-wrapper",{loaded:t.loaded}])},[l.isImage(t)?((0,s.uX)(),(0,s.CE)("img",{key:0,src:l.getFileUrl(t.name),alt:t.name,loading:"lazy",onLoad:e=>l.onImageLoad(e,t),onError:e[2]||(e[2]=(...t)=>l.handleImageError&&l.handleImageError(...t))},null,40,X)):l.isVideo(t)?((0,s.uX)(),(0,s.CE)("video",{key:1,src:l.getFileUrl(t.name),muted:"",loop:"",preload:"metadata",onLoadedmetadata:e=>l.onVideoLoad(e,t),onMouseenter:e[3]||(e[3]=t=>t.target.play()),onMouseleave:e[4]||(e[4]=t=>t.target.pause())},null,40,R)):((0,s.uX)(),(0,s.CE)("div",$,[...e[21]||(e[21]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13z"})],-1)])])),(0,s.Lk)("div",E,[(0,s.Lk)("div",D,[(0,s.Lk)("button",{class:"action-btn",onClick:(0,r.D$)(e=>l.copyLink(t.name),["stop"]),title:"复制链接"},[...e[22]||(e[22]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})],-1)])],8,B),(0,s.Lk)("button",{class:"action-btn",onClick:(0,r.D$)(e=>l.downloadFile(t.name),["stop"]),title:"下载"},[...e[23]||(e[23]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"})],-1)])],8,A)])])],2)],8,S))),128))]))),128))],512),(0,s.Lk)("div",z,[a.loading&&a.files.length>0?((0,s.uX)(),(0,s.CE)("div",H,[...e[24]||(e[24]=[(0,s.Lk)("div",{class:"loading-spinner-small"},null,-1),(0,s.Lk)("span",null,"加载中...",-1)])])):!a.hasMore&&l.mediaFiles.length>0?((0,s.uX)(),(0,s.CE)("div",V," 已加载全部 ")):(0,s.Q3)("",!0)],512)],512)),a.previewVisible?((0,s.uX)(),(0,s.CE)("div",{key:3,class:"preview-modal",onClick:e[17]||(e[17]=(0,r.D$)((...t)=>l.closePreview&&l.closePreview(...t),["self"]))},[(0,s.Lk)("button",{class:"preview-close",onClick:e[5]||(e[5]=(0,r.D$)((...t)=>l.closePreview&&l.closePreview(...t),["stop"]))},[...e[25]||(e[25]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})],-1)])]),(0,s.Lk)("div",{class:"preview-content desktop-only",onClick:e[6]||(e[6]=(0,r.D$)(()=>{},["stop"]))},[l.currentPreviewFile&&l.isImage(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("img",{key:0,src:l.getFileUrl(l.currentPreviewFile.name),class:"preview-image",style:(0,o.Tr)(l.desktopImageStyle),draggable:"false"},null,12,W)):l.currentPreviewFile&&l.isVideo(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("video",{key:1,src:l.getFileUrl(l.currentPreviewFile.name),controls:"",autoplay:"",class:"preview-video",style:(0,o.Tr)(l.desktopImageStyle)},null,12,U)):(0,s.Q3)("",!0)]),(0,s.Lk)("div",{class:"preview-content mobile-only",onClick:e[13]||(e[13]=(0,r.D$)(()=>{},["stop"]))},[(0,s.Lk)("div",{class:"swipe-viewport",ref:"mobileViewport",onTouchstart:e[10]||(e[10]=(...t)=>l.onSwipeStart&&l.onSwipeStart(...t)),onTouchmove:e[11]||(e[11]=(...t)=>l.onSwipeMove&&l.onSwipeMove(...t)),onTouchend:e[12]||(e[12]=(...t)=>l.onSwipeEnd&&l.onSwipeEnd(...t))},[(0,s.Lk)("div",{class:"swipe-track",style:(0,o.Tr)(l.swipeTrackStyle),onTransitionend:e[9]||(e[9]=(...t)=>l.onSwipeTransitionEnd&&l.onSwipeTransitionEnd(...t))},[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.swipeWindow,(t,i)=>((0,s.uX)(),(0,s.CE)("div",{class:"swipe-slide",key:l.getSlideKey(t,i)},[t?((0,s.uX)(),(0,s.Wv)(h,{key:0,file:t,src:l.getFileUrl(t.name),"is-image":l.isImage(t),"is-video":l.isVideo(t),onLock:e[7]||(e[7]=t=>a.gestureLocked=!0),onUnlock:e[8]||(e[8]=t=>a.gestureLocked=!1)},null,8,["file","src","is-image","is-video"])):(0,s.Q3)("",!0)]))),128))],36)],544)]),a.previewIndex>0?((0,s.uX)(),(0,s.CE)("button",{key:0,class:"preview-prev desktop-only",onClick:e[14]||(e[14]=(0,r.D$)((...t)=>l.prevImage&&l.prevImage(...t),["stop"]))},[...e[26]||(e[26]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})],-1)])])):(0,s.Q3)("",!0),a.previewIndex<l.mediaFiles.length-1?((0,s.uX)(),(0,s.CE)("button",{key:1,class:"preview-next desktop-only",onClick:e[15]||(e[15]=(0,r.D$)((...t)=>l.nextImage&&l.nextImage(...t),["stop"]))},[...e[27]||(e[27]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})],-1)])])):(0,s.Q3)("",!0),(0,s.Lk)("button",{class:"rotate-btn desktop-only",onClick:e[16]||(e[16]=(0,r.D$)((...t)=>l.rotateImage&&l.rotateImage(...t),["stop"])),title:"旋转90°"},[...e[28]||(e[28]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M7.11 8.53L5.7 7.11C4.8 8.27 4.24 9.61 4.07 11h2.02c.14-.87.49-1.72 1.02-2.47zM6.09 13H4.07c.17 1.39.72 2.73 1.62 3.89l1.41-1.42c-.52-.75-.87-1.59-1.01-2.47zm1.01 5.32c1.16.9 2.51 1.44 3.9 1.61V17.9c-.87-.15-1.71-.49-2.46-1.03L7.1 18.32zM13 4.07V1L8.45 5.55 13 10V6.09c2.84.48 5 2.94 5 5.91s-2.16 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93s-3.05-7.44-7-7.93z"})],-1)])]),(0,s.Lk)("div",_,(0,o.v_)(a.previewIndex+1)+" / "+(0,o.v_)(l.mediaFiles.length),1)])):(0,s.Q3)("",!0)])}i(4114),i(8111),i(2489),i(7588),i(1701);var Q=i(4373),K=i(8401),N={name:"PublicBrowse",components:{TransformMedia:u},data(){return{files:[],allowedDirs:[],rootDir:"",currentPath:"",totalCount:0,loading:!1,error:null,canRetry:!0,hasMore:!0,previewVisible:!1,previewIndex:0,observer:null,pageSize:24,columnCount:4,columnHeights:[0,0,0,0],imageRotation:0,swipeX:0,swipeStartX:0,swipeStartY:0,swipeStartT:0,swipeActive:!1,swipeAnimating:!1,swipeDir:0,viewportW:0,gestureLocked:!1}},computed:{...(0,K.L8)(["userConfig"]),siteName(){return this.userConfig?.siteTitle||"公开相册"},rootDirName(){return this.rootDir.split("/").filter(Boolean).pop()||"根目录"},pathParts(){if(!this.currentPath||!this.rootDir)return[];const t=this.currentPath.replace(this.rootDir,"").replace(/^\/+/,"");return t.split("/").filter(Boolean)},folders(){return this.files.filter(t=>t.isFolder)},mediaFiles(){return this.files.filter(t=>!t.isFolder)},columns(){const t=Array.from({length:this.columnCount},()=>[]);for(const e of this.mediaFiles){const i=e.columnIndex??0;i<this.columnCount?t[i].push(e):t[0].push(e)}return t},currentPreviewFile(){return this.mediaFiles[this.previewIndex]},prevPreviewFile(){return this.previewIndex>0?this.mediaFiles[this.previewIndex-1]:null},nextPreviewFile(){return this.previewIndex<this.mediaFiles.length-1?this.mediaFiles[this.previewIndex+1]:null},desktopImageStyle(){return{transform:`rotate(${this.imageRotation}deg)`,transition:"transform 0.3s ease"}},swipeWindow(){return[this.prevPreviewFile,this.currentPreviewFile,this.nextPreviewFile]},swipeTrackStyle(){const t=-this.viewportW,e=t+this.swipeX;return{transform:`translate3d(${e}px, 0, 0)`,transition:this.swipeAnimating?"transform 0.28s ease":"none"}}},watch:{"$route.params.dir":{handler(){this.initFromRoute()}}},mounted(){this.initFromRoute(),this.setupIntersectionObserver(),this.updateColumnCount(),window.addEventListener("resize",this.updateColumnCount)},beforeUnmount(){this.observer&&this.observer.disconnect(),window.removeEventListener("resize",this.updateColumnCount)},methods:{getSlideKey(t,e){return t?1===e?`${t.name}-${this.previewIndex}`:t.name:`empty-${e}`},updateColumnCount(){const t=window.innerWidth;let e;e=t<600?2:t<900?3:4,e!==this.columnCount&&(this.columnCount=e,this.columnHeights=new Array(this.columnCount).fill(0),this.mediaFiles.forEach(t=>{t.columnIndex=void 0,this.assignToColumn(t)}))},getShortestColumn(){let t=0,e=this.columnHeights[0];for(let i=1;i<this.columnCount;i++)this.columnHeights[i]<e&&(e=this.columnHeights[i],t=i);return t},assignToColumn(t,e=200){const i=this.getShortestColumn();t.columnIndex=i,this.columnHeights[i]+=e},onImageLoad(t,e){const i=t.target,s=i.naturalHeight/i.naturalWidth,r=280*s;void 0===e.columnIndex&&this.assignToColumn(e,r),e.loaded=!0},onVideoLoad(t,e){const i=t.target,s=i.videoHeight/i.videoWidth,r=280*s;void 0===e.columnIndex&&this.assignToColumn(e,r),e.loaded=!0},setupIntersectionObserver(){this.observer=new IntersectionObserver(t=>{const e=t[0];e.isIntersecting&&this.hasMore&&!this.loading&&this.loadMore()},{rootMargin:"200px"})},observeLoadTrigger(){this.$nextTick(()=>{this.$refs.loadTrigger&&this.observer&&this.observer.observe(this.$refs.loadTrigger)})},async initFromRoute(){const t=this.$route.params.dir||"",e=Array.isArray(t)?t.join("/"):t;if(!e)return this.error="请指定要浏览的目录,例如: /browse/landscape",void(this.canRetry=!1);const i=e.split("/").filter(Boolean);this.rootDir=i[0],this.currentPath=e,this.files=[],this.hasMore=!0,this.columnHeights=new Array(this.columnCount).fill(0),await this.loadFiles(),this.observeLoadTrigger()},async loadFiles(){this.loading=!0,this.error=null,this.canRetry=!0;try{const t=await Q.A.get(`/api/public/list?dir=${encodeURIComponent(this.currentPath)}&count=${this.pageSize}`);t.data.allowedDirs&&(this.allowedDirs=t.data.allowedDirs);const e=(t.data.directories||[]).map(t=>({name:t,isFolder:!0})),i=(t.data.files||[]).map(t=>({name:t.name,isFolder:!1,metadata:t.metadata,columnIndex:void 0}));i.forEach(t=>this.assignToColumn(t)),this.files=[...e,...i],this.totalCount=t.data.totalCount||this.files.length,this.hasMore=this.mediaFiles.length<this.totalCount}catch(t){if(403===t.response?.status){const e=t.response?.data?.error||"";e.includes("disabled")?this.error="公开浏览功能未启用":e.includes("not allowed")||e.includes("No public")?this.error="该目录不允许公开访问":this.error="访问被拒绝",this.canRetry=!1}else this.error="加载失败,请重试"}finally{this.loading=!1}},async loadMore(){if(!this.loading&&this.hasMore){this.loading=!0;try{const t=this.mediaFiles.length,e=await Q.A.get(`/api/public/list?dir=${encodeURIComponent(this.currentPath)}&start=${t}&count=${this.pageSize}`),i=(e.data.files||[]).map(t=>({name:t.name,isFolder:!1,metadata:t.metadata,columnIndex:void 0}));i.forEach(t=>this.assignToColumn(t)),this.files.push(...i),this.hasMore=this.mediaFiles.length<this.totalCount}catch(t){console.error("加载更多失败",t)}finally{this.loading=!1}}},enterFolder(t){const e=t.replace(/\/+$/,"");this.$router.push(`/browse/${e}`)},goToRoot(){this.$router.push(`/browse/${this.rootDir}`)},goToPath(t){const e=this.pathParts.slice(0,t+1),i=this.rootDir+(e.length?"/"+e.join("/"):"");this.$router.push(`/browse/${i}`)},getFolderName(t){return t.split("/").filter(Boolean).pop()||t},getFileUrl(t){return`${window.location.origin}/file/${t}`},isImage(t){const e=t.name.split(".").pop().toLowerCase();return["jpg","jpeg","png","gif","webp","bmp","svg"].includes(e)},isVideo(t){const e=t.name.split(".").pop().toLowerCase();return["mp4","webm","ogg","mov"].includes(e)},handleImageError(t){t.target.style.display="none"},copyLink(t){const e=this.getFileUrl(t);navigator.clipboard?.writeText(e).then(()=>{this.showToast("已复制")}).catch(()=>{const t=document.createElement("input");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),this.showToast("已复制")})},showToast(t){const e=document.querySelector(".copy-toast");e&&e.remove();const i=document.createElement("div");i.className="copy-toast",i.textContent=t,document.body.appendChild(i),setTimeout(()=>i.classList.add("show"),10),setTimeout(()=>{i.classList.remove("show"),setTimeout(()=>i.remove(),300)},1500)},downloadFile(t){const e=document.createElement("a");e.href=this.getFileUrl(t),e.download=t.split("/").pop(),e.click()},openPreview(t){if(t.isFolder)return;const e=this.mediaFiles.findIndex(e=>e.name===t.name);e>=0&&(this.previewIndex=e,this.previewVisible=!0,this.imageRotation=0,this.gestureLocked=!1,document.body.style.overflow="hidden",this.$nextTick(()=>{this.viewportW=this.$refs.mobileViewport?.getBoundingClientRect().width||window.innerWidth}))},closePreview(){this.previewVisible=!1,this.imageRotation=0,this.gestureLocked=!1,document.body.style.overflow=""},prevImage(){this.previewIndex>0&&(this.previewIndex--,this.imageRotation=0)},nextImage(){this.previewIndex<this.mediaFiles.length-1&&(this.previewIndex++,this.imageRotation=0)},rotateImage(){this.imageRotation+=90,this.imageRotation>=360&&setTimeout(()=>{const t=this.$el.querySelector(".preview-image, .preview-video");t?(t.style.transition="none",this.imageRotation=0,t.offsetHeight,t.style.transition=""):this.imageRotation=0},300)},onSwipeStart(t){if(this.gestureLocked)return;if(this.swipeAnimating)return;const e=t.touches[0];this.swipeStartX=e.clientX,this.swipeStartY=e.clientY,this.swipeStartT=performance.now(),this.swipeX=0,this.swipeActive=!1,this.viewportW=this.$refs.mobileViewport?.getBoundingClientRect().width||window.innerWidth},onSwipeMove(t){if(this.gestureLocked)return;if(this.swipeAnimating)return;const e=t.touches[0],i=e.clientX-this.swipeStartX,s=e.clientY-this.swipeStartY;if(!this.swipeActive){if(Math.abs(i)<8)return;if(Math.abs(i)<=Math.abs(s))return;this.swipeActive=!0}t.preventDefault();let r=i;0===this.previewIndex&&r>0?r=this.rubberBand(r,this.viewportW,.55):this.previewIndex===this.mediaFiles.length-1&&r<0&&(r=-this.rubberBand(-r,this.viewportW,.55)),this.swipeX=r},onSwipeEnd(){if(this.gestureLocked)return;if(this.swipeAnimating)return;if(!this.swipeActive)return void(this.swipeX=0);const t=Math.max(1,performance.now()-this.swipeStartT),e=this.swipeX/t,i=.2*this.viewportW;let s=0;(this.swipeX<=-i||e<=-.8)&&(s=1),(this.swipeX>=i||e>=.8)&&(s=-1),(-1===s&&0===this.previewIndex||1===s&&this.previewIndex===this.mediaFiles.length-1)&&(s=0),this.swipeDir=s,this.swipeAnimating=!0,this.swipeX=1===s?-this.viewportW:-1===s?+this.viewportW:0},onSwipeTransitionEnd(){this.swipeAnimating&&(1===this.swipeDir&&this.previewIndex++,-1===this.swipeDir&&this.previewIndex--,this.swipeAnimating=!1,this.swipeDir=0,this.swipeX=0)},rubberBand(t,e,i=.55){return t*e*i/(e+i*t)}}};const j=(0,c.A)(N,[["render",Y],["__scopeId","data-v-7aa9aaa3"]]);var q=j}}]);
|
|
//# sourceMappingURL=733.0149a1b8.js.map
|