2 lines
7.3 KiB
JavaScript
2 lines
7.3 KiB
JavaScript
var C=Object.defineProperty,I=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var y=(e,t,s)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,d=(e,t)=>{for(var s in t||(t={}))x.call(t,s)&&y(e,s,t[s]);if(u)for(var s of u(t))w.call(t,s)&&y(e,s,t[s]);return e},m=(e,t)=>I(e,k(t));var g=(e,t)=>{var s={};for(var a in e)x.call(e,a)&&t.indexOf(a)<0&&(s[a]=e[a]);if(e!=null&&u)for(var a of u(e))t.indexOf(a)<0&&w.call(e,a)&&(s[a]=e[a]);return s};var f=(e,t,s)=>new Promise((a,i)=>{var n=h=>{try{o(s.next(h))}catch(p){i(p)}},c=h=>{try{o(s.throw(h))}catch(p){i(p)}},o=h=>h.done?a(h.value):Promise.resolve(h.value).then(n,c);o((s=s.apply(e,t)).next())});import{cI as K,cJ as _,d5 as R,bX as B,R as S}from"../jse/index-index-CMeVxoEG.js";import{b_ as v}from"./bootstrap-CRjSNGHY.js";const q=v("core-tabbar",{actions:{_bulkCloseByKeys(e){return f(this,null,function*(){const t=new Set(e);this.tabs=this.tabs.filter(s=>!t.has(r(s))),yield this.updateCacheTabs()})},_close(e){if(b(e))return;const t=this.tabs.findIndex(s=>T(s,e));t!==-1&&this.tabs.splice(t,1)},_goToDefaultTab(e){return f(this,null,function*(){if(this.getTabs.length<=0)return;const t=this.getTabs[0];t&&(yield this._goToTab(t,e))})},_goToTab(e,t){return f(this,null,function*(){const{params:s,path:a,query:i}=e,n={params:s||{},path:a,query:i||{}};yield t.replace(n)})},addTab(e){var a,i;let t=A(e);if(t.key||(t.key=l(e)),!O(t))return t;const s=this.tabs.findIndex(n=>T(n,t));if(s===-1){const n=B.tabbar.maxCount,c=(i=(a=e==null?void 0:e.meta)==null?void 0:a.maxNumOfOpenTab)!=null?i:-1;if(c>0&&this.tabs.filter(o=>o.name===e.name).length>=c){const o=this.tabs.findIndex(h=>h.name===e.name);o!==-1&&this.tabs.splice(o,1)}else if(n>0&&this.tabs.length>=n){const o=this.tabs.findIndex(h=>!Reflect.has(h.meta,"affixTab")||!h.meta.affixTab);o!==-1&&this.tabs.splice(o,1)}this.tabs.push(t)}else{const n=S(this.tabs)[s],c=m(d(d({},n),t),{meta:d(d({},n==null?void 0:n.meta),t.meta)});if(n){const o=n.meta;Reflect.has(o,"affixTab")&&(c.meta.affixTab=o.affixTab),Reflect.has(o,"newTabTitle")&&(c.meta.newTabTitle=o.newTabTitle)}t=c,this.tabs.splice(s,1,c)}return this.updateCacheTabs(),t},closeAllTabs(e){return f(this,null,function*(){const t=this.tabs.filter(s=>b(s));this.tabs=t.length>0?t:[...this.tabs].splice(0,1),yield this._goToDefaultTab(e),this.updateCacheTabs()})},closeLeftTabs(e){return f(this,null,function*(){const t=this.tabs.findIndex(i=>T(i,e));if(t<1)return;const s=this.tabs.slice(0,t),a=[];for(const i of s)b(i)||a.push(i.key);yield this._bulkCloseByKeys(a)})},closeOtherTabs(e){return f(this,null,function*(){const t=this.tabs.map(a=>r(a)),s=[];for(const a of t)if(a!==r(e)){const i=this.tabs.find(n=>r(n)===a);if(!i)continue;b(i)||s.push(i.key)}yield this._bulkCloseByKeys(s)})},closeRightTabs(e){return f(this,null,function*(){const t=this.tabs.findIndex(s=>T(s,e));if(t!==-1&&t<this.tabs.length-1){const s=this.tabs.slice(t+1),a=[];for(const i of s)b(i)||a.push(i.key);yield this._bulkCloseByKeys(a)}})},closeTab(e,t){return f(this,null,function*(){const{currentRoute:s}=t;if(l(s.value)!==r(e)){this._close(e),this.updateCacheTabs();return}const a=this.getTabs.findIndex(c=>r(c)===l(s.value)),i=this.getTabs[a-1],n=this.getTabs[a+1];n?(this._close(e),yield this._goToTab(n,t)):i?(this._close(e),yield this._goToTab(i,t)):console.error("Failed to close the tab; only one tab remains open.")})},closeTabByKey(e,t){return f(this,null,function*(){const s=decodeURIComponent(e),a=this.tabs.findIndex(n=>r(n)===s);if(a===-1)return;const i=this.tabs[a];i&&(yield this.closeTab(i,t))})},getTabByKey(e){return this.getTabs.find(t=>r(t)===e)},openTabInNewWindow(e){return f(this,null,function*(){R(e.fullPath||e.path)})},pinTab(e){return f(this,null,function*(){var n;const t=this.tabs.findIndex(c=>T(c,e));if(t===-1)return;const s=this.tabs[t];e.meta.affixTab=!0,e.meta.title=(n=s==null?void 0:s.meta)==null?void 0:n.title,this.tabs.splice(t,1,e);const i=this.tabs.filter(c=>b(c)).findIndex(c=>T(c,e));yield this.sortTabs(t,i)})},refresh(e){return f(this,null,function*(){if(typeof e=="string")return yield this.refreshByName(e);const{currentRoute:t}=e,{name:s}=t.value;this.excludeCachedTabs.add(s),this.renderRouteView=!1,K(),yield new Promise(a=>setTimeout(a,200)),this.excludeCachedTabs.delete(s),this.renderRouteView=!0,_()})},refreshByName(e){return f(this,null,function*(){this.excludeCachedTabs.add(e),yield new Promise(t=>setTimeout(t,200)),this.excludeCachedTabs.delete(e)})},resetTabTitle(e){return f(this,null,function*(){var s;if((s=e==null?void 0:e.meta)!=null&&s.newTabTitle)return;const t=this.tabs.find(a=>T(a,e));t&&(t.meta.newTabTitle=void 0,yield this.updateCacheTabs())})},setAffixTabs(e){for(const t of e)t.meta.affixTab=!0,this.addTab(P(t))},setMenuList(e){this.menuList=e},setTabTitle(e,t){return f(this,null,function*(){const s=this.tabs.find(a=>T(a,e));s&&(s.meta.newTabTitle=t,yield this.updateCacheTabs())})},setUpdateTime(){this.updateTime=Date.now()},sortTabs(e,t){return f(this,null,function*(){const s=this.tabs[e];s&&(this.tabs.splice(e,1),this.tabs.splice(t,0,s),this.dragEndIndex=this.dragEndIndex+1)})},toggleTabPin(e){return f(this,null,function*(){var s,a;yield((a=(s=e==null?void 0:e.meta)==null?void 0:s.affixTab)!=null?a:!1)?this.unpinTab(e):this.pinTab(e)})},unpinTab(e){return f(this,null,function*(){var n;const t=this.tabs.findIndex(c=>T(c,e));if(t===-1)return;const s=this.tabs[t];e.meta.affixTab=!1,e.meta.title=(n=s==null?void 0:s.meta)==null?void 0:n.title,this.tabs.splice(t,1,e);const i=this.tabs.filter(c=>b(c)).length;yield this.sortTabs(t,i)})},updateCacheTabs(){return f(this,null,function*(){var t;const e=new Set;for(const s of this.tabs){if(!((t=s.meta)==null?void 0:t.keepAlive))continue;(s.matched||[]).forEach((n,c)=>{c>0&&e.add(n.name)});const i=s.name;e.add(i)}this.cachedTabs=e})}},getters:{affixTabs(){return this.tabs.filter(t=>b(t)).toSorted((t,s)=>{var n,c,o,h;const a=(c=(n=t.meta)==null?void 0:n.affixTabOrder)!=null?c:0,i=(h=(o=s.meta)==null?void 0:o.affixTabOrder)!=null?h:0;return a-i})},getCachedTabs(){return[...this.cachedTabs]},getExcludeCachedTabs(){return[...this.excludeCachedTabs]},getMenuList(){return this.menuList},getTabs(){const e=this.tabs.filter(t=>!b(t));return[...this.affixTabs,...e].filter(Boolean)}},persist:[{pick:["tabs"],storage:sessionStorage}],state:()=>({cachedTabs:new Set,dragEndIndex:0,excludeCachedTabs:new Set,menuList:["close","affix","maximize","reload","open-in-new-window","close-left","close-right","close-other","close-all"],renderRouteView:!0,tabs:[],updateTime:Date.now()})});function A(e){if(!e)return e;const i=e,{matched:t,meta:s}=i,a=g(i,["matched","meta"]);return m(d({},a),{matched:t?t.map(n=>({meta:n.meta,name:n.name,path:n.path})):void 0,meta:m(d({},s),{newTabTitle:s.newTabTitle})})}function b(e){var t,s;return(s=(t=e==null?void 0:e.meta)==null?void 0:t.affixTab)!=null?s:!1}function O(e){var s;const t=(s=e==null?void 0:e.matched)!=null?s:[];return!e.meta.hideInTab&&t.every(a=>!a.meta.hideInTab)}function l(e){const{fullPath:t,path:s,meta:{fullPathKey:a}={},query:i={}}=e,n=Array.isArray(i.pageKey)?i.pageKey[0]:i.pageKey;let c;n?c=n:c=a===!1?s:t!=null?t:s;try{return decodeURIComponent(c)}catch(o){return c}}function r(e){var t;return(t=e.key)!=null?t:l(e)}function T(e,t){return r(e)===r(t)}function P(e){return{meta:e.meta,name:e.name,path:e.path,key:l(e)}}export{l as g,q as u};
|