feat: add tab drag and drop sort

This commit is contained in:
vben
2020-11-25 22:28:58 +08:00
parent 5cabbac757
commit cedba37e4c
23 changed files with 255 additions and 228 deletions

View File

@@ -33,7 +33,7 @@ export function useMenuSetting() {
const getMenuBgColor = computed(() => unref(getMenuSetting).bgColor);
const getHasDrag = computed(() => unref(getMenuSetting).hasDrag);
const getCanDrag = computed(() => unref(getMenuSetting).canDrag);
const getAccordion = computed(() => unref(getMenuSetting).accordion);
@@ -117,7 +117,7 @@ export function useMenuSetting() {
getTrigger,
getSplit,
getMenuTheme,
getHasDrag,
getCanDrag,
getIsHorizontal,
getShowSearch,
getCollapsedShowTitle,

View File

@@ -1,14 +1,6 @@
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { PageEnum } from '/@/enums/pageEnum';
import { TabItem, tabStore } from '/@/store/modules/tab';
import { appStore } from '/@/store/modules/app';
import router from '/@/router';
import { ref } from 'vue';
import { pathToRegexp } from 'path-to-regexp';
const activeKeyRef = ref<string>('');
type Fn = () => void;
type RouteFn = (tabItem: TabItem) => void;
interface TabFn {
@@ -28,6 +20,7 @@ let closeOther: RouteFn;
let closeCurrent: RouteFn;
export let isInitUseTab = false;
export function useTabs() {
function initTabFn({
refreshPageFn,
@@ -38,6 +31,7 @@ export function useTabs() {
closeCurrentFn,
}: TabFn) {
if (isInitUseTab) return;
refreshPageFn && (refreshPage = refreshPageFn);
closeAllFn && (closeAll = closeAllFn);
closeLeftFn && (closeLeft = closeLeftFn);
@@ -58,29 +52,13 @@ export function useTabs() {
}
function canIUseFn(): boolean {
const { getProjectConfig } = appStore;
const { multiTabsSetting: { show } = {} } = getProjectConfig;
const { multiTabsSetting: { show } = {} } = appStore.getProjectConfig;
if (!show) {
throw new Error('当前未开启多标签页,请在设置中打开!');
}
return !!show;
}
function getTo(path: string): any {
const routes = router.getRoutes();
const fn = (p: string): any => {
const to = routes.find((item) => {
if (item.path === '/:path(.*)*') return;
const regexp = pathToRegexp(item.path);
return regexp.test(p);
});
if (!to) return '';
if (!to.redirect) return to;
if (to.redirect) {
return getTo(to.redirect as string);
}
};
return fn(path);
}
return {
initTabFn,
refreshPage: () => canIUseFn() && refreshPage(tabStore.getCurrentTab),
@@ -90,26 +68,5 @@ export function useTabs() {
closeOther: () => canIUseFn() && closeOther(tabStore.getCurrentTab),
closeCurrent: () => canIUseFn() && closeCurrent(tabStore.getCurrentTab),
resetCache: () => canIUseFn() && resetCache(),
addTab: (
path: PageEnum | string,
goTo = false,
opt?: { replace?: boolean; query?: any; params?: any }
) => {
const to = getTo(path);
if (!to) return;
useTimeoutFn(() => {
tabStore.addTabByPathAction();
}, 0);
const { replace, query = {}, params = {} } = opt || {};
activeKeyRef.value = path;
const data = {
path,
query,
params,
};
goTo && replace ? router.replace(data) : router.push(data);
},
activeKeyRef,
};
}