File: /www/server/panel/BTPanel/static/js/files-path.js
import{c as H,r as p,H as Z,w as x,o as O,a8 as Q,j as d,k as h,q as o,L as S,J as v,bu as X,K as f,R as g,P as Y,F as E,B,e as L,v as I,s as R,n as j,aW as G,az as ee,b7 as te}from"./base-lib.js?v=1777008528";import{a9 as le}from"./index3.js?v=1777008528";import{du as ae,ds as se,f as oe,cZ as ne}from"./utils-lib.js?v=1777008528";const re=["id"],ie={class:"path-input"},ue={class:"fold-dir-list"},ce=["onClick"],de=["onClick"],he={class:"path-name"},pe=["onClick"],ve={class:"fold-dir-list"},fe=["onClick"],we=H({__name:"files-path",props:{initialPath:{default:"/www/wwwroot"}},emits:["pathChange","refresh"],setup(q,{expose:z,emit:A}){const w=q,T=A,C=oe(),P=p(ae(10,"letter")),s=p(w.initialPath),b=p(),k=p(!0),n=p([]),W=p(0),c=p(!1),u=Z({showMore:!1,showUl:!1,list:[]}),D=async t=>{if(k.value=t,t){if(s.value===w.initialPath)return;const e=s.value;if(e.length>0&&!e.includes("/")){C.error("路径输入不符合规则"),s.value=w.initialPath;return}else if(e.length===0){s.value=w.initialPath;return}try{const l=await F(e);s.value=l||e}catch(l){s.value=w.initialPath}}else se(b.value)},_=(t,e)=>{var l;t===""&&(s.value="/"),(l=b.value)==null||l.blur(),e||F(t)},F=async t=>{const e=t.replace(/\/+$/,"")||"/",l=V(e);return t==="/.Recycle_bin"||t==="/www/.Recycle_bin"?(C.error("此为回收站目录,请在右上角按【回收站】按钮打开"),!1):(s.value=l,T("pathChange",l),l)},V=t=>{let e=t;return e=e.replace(/(\\\/|\/\\)/g,"/"),e=e.replace(/\\\\+/g,"/"),e=e.replace(/\/+/g,"/"),e},$=t=>{if(!t)return;const e=t.split("/");if(t==="/"){n.value=[{name:"根目录",path:"/",show:!0,list:[]}];return}n.value=e.map((l,r)=>({name:l===""?"根目录":l,path:l===""?"/":e.slice(0,r+1).join("/"),show:!0,showFold:!1,loading:!1,list:[]})),y(),j(()=>{u.list=[],u.showMore=!1;const l=document.querySelectorAll("#".concat(P.value," .path-group-item")),r=document.querySelector("#".concat(P.value," .path-list-group")),M=Array.from(l).reduce((a,i)=>a+i.clientWidth+4,0);setTimeout(()=>{if(M>((r==null?void 0:r.clientWidth)||400)){let a=20;for(let i=l.length-1;i>=0;i--)a+=l[i].clientWidth,a>((r==null?void 0:r.clientWidth)||0)&&(n.value[i].show=!1,u.showMore=!0,u.list=n.value.slice(i+1));u.showMore&&(n.value[0].show=!1,u.list=n.value.slice(1))}},100)})},U=()=>{if(c.value)return;if(c.value=!0,s.value==="/")return c.value=!1,C.error("当前目录为根目录");let t=s.value.split("/");t.pop();let e=t.join("/");e===""&&(e="/"),F(e),setTimeout(()=>{c.value=!1},500)},J=async(t,e)=>{try{y(),n.value[e].showFold=!0,n.value[e].loading=!0;const{data:{dir:l}}=await le({path:t,p:1,showRow:2e3});n.value[e].loading=!1,n.value[e].list=l.map(r=>({name:r.nm,path:"".concat(t,"/").concat(r.nm).replace(/\/+/g,"/")})),W.value=e,window.addEventListener("click",y)}catch(l){n.value[e].loading=!1}},y=()=>{u.showUl=!1,n.value[W.value]&&(n.value=n.value.map(t=>({...t,showFold:!1}))),window.removeEventListener("click",y)},K=async()=>{if(!c.value){c.value=!0;try{T("refresh")}catch(t){C.error("刷新失败")}finally{setTimeout(()=>{c.value=!1},500)}}};return x(()=>s.value,t=>{$(t)},{immediate:!0}),x(()=>k.value,()=>{k.value||j(()=>{var t;(t=b.value)==null||t.select()})}),x(()=>w.initialPath,t=>{s.value=t}),O(()=>{$(s.value)}),Q(()=>{y()}),z({dirPath:s,refreshList:K,goBack:U,cutDirPath:_,getPathListGroup:$}),(t,e)=>{const l=G,r=ee,M=te;return d(),h("div",{class:"nav-path",id:P.value},[o("div",{class:"back rounded-l-large relative",onClick:U},[o("i",{class:S(["svgtofont-el-back",{disabledBack:c.value}])},null,2)]),o("div",ie,[v(o("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>s.value=a),ref_key:"pathInputRef",ref:b,type:"text",class:"h-full w-full pl-8px",onBlur:e[1]||(e[1]=a=>D(!0)),onKeydown:e[2]||(e[2]=g(()=>{},["stop"])),onKeyup:e[3]||(e[3]=Y(a=>_(s.value,!0),["enter"]))},null,544),[[X,s.value],[f,!k.value]]),v(o("div",{class:"path-list-group",onClick:e[5]||(e[5]=a=>D(!1))},[v(o("div",{class:"svgtofont-el-arrow-left font-bold px-[.2rem] h-full leading-[2.9rem] cursor-pointer border-l border-r border-lighter relative hover:border-darker hover:bg-light",onClick:e[4]||(e[4]=g(a=>u.showUl=!0,["stop"]))},[v(o("ul",ue,[(d(!0),h(E,null,B(u.list,(a,i)=>(d(),h("li",{class:"fold-dir-item",key:i},[L(l,{effect:"dark",content:a.path,placement:"right","show-after":500},{default:I(()=>[o("div",{class:"w-full flex items-center",onClick:g(m=>_(a.path),["stop"])},[e[6]||(e[6]=o("span",{class:"dir-icon flex-shrink-0 !h-[1.6rem]"},null,-1)),o("span",null,R(a.name),1)],8,ce)]),_:2},1032,["content"])]))),128))],512),[[f,u.showUl]])],512),[[f,u.showMore]]),(d(!0),h(E,null,B(n.value,(a,i)=>v((d(),h("div",{key:i,class:"path-group-item",onClick:g(m=>_(a.path),["stop"])},[L(l,{effect:"dark",content:a.name,placement:"bottom","show-after":500},{default:I(()=>[o("span",he,R(a.name),1)]),_:2},1032,["content"]),o("div",{class:"svgtofont-el-arrow-right path-name-icon",onClick:g(m=>J(a.path,i),["stop"])},[v((d(),h("ul",ve,[(d(!0),h(E,null,B(a.list,(m,N)=>(d(),h("li",{class:"fold-dir-item",key:N},[L(l,{effect:"dark",content:m.path,placement:"right","show-after":500},{default:I(()=>[o("div",{class:"w-full flex items-center",onClick:g(me=>_(m.path),["stop"])},[e[7]||(e[7]=o("span",{class:"dir-icon flex-shrink-0 !h-[1.6rem]"},null,-1)),o("span",null,R(m.name),1)],8,fe)]),_:2},1032,["content"])]))),128)),v(L(r,{"image-size":60,description:"暂无数据"},null,512),[[f,!a.list.length]])])),[[f,a.showFold],[M,a.loading]])],8,pe)],8,de)),[[f,a.show]])),128))],512),[[f,k.value]])]),o("span",{class:"refresh rounded-r-large",onClick:K},[o("i",{class:S({"svgtofont-el-refresh-right":!c.value,"svgtofont-el-loading cursor-not-allowed animate-spin":c.value})},null,2)])],8,re)}}}),ye=ne(we,[["__scopeId","data-v-bad05061"]]);export{ye as F};