|
|
@ -1,6 +1,9 @@ |
|
|
|
import type { WritableComputedRef } from '@vue/reactivity' |
|
|
|
import type { WritableComputedRef } from '@vue/reactivity' |
|
|
|
import { navigateTo, useProject, useRoute, useState } from '#imports' |
|
|
|
import { navigateTo, useProject, useRoute, useState } from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import type { RouterConfig } from '@nuxt/schema' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export enum TabType { |
|
|
|
export enum TabType { |
|
|
|
TABLE = 'table', |
|
|
|
TABLE = 'table', |
|
|
|
VIEW = 'view', |
|
|
|
VIEW = 'view', |
|
|
@ -29,9 +32,11 @@ export function useTabs() { |
|
|
|
const router = useRouter() |
|
|
|
const router = useRouter() |
|
|
|
const { tables } = useProject() |
|
|
|
const { tables } = useProject() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const projectType = $computed(() => route.params.projectType as string) |
|
|
|
|
|
|
|
|
|
|
|
const activeTabIndex: WritableComputedRef<number> = computed({ |
|
|
|
const activeTabIndex: WritableComputedRef<number> = computed({ |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
if ((route.name as string)?.startsWith('nc-projectId-index-index-type-title-viewTitle') && tables.value?.length) { |
|
|
|
if ((route.name as string)?.startsWith('projectType-projectId-index-index-type-title-viewTitle') && tables.value?.length) { |
|
|
|
const tab: Partial<TabItem> = { type: route.params.type as TabType, title: route.params.title as string } |
|
|
|
const tab: Partial<TabItem> = { type: route.params.type as TabType, title: route.params.title as string } |
|
|
|
|
|
|
|
|
|
|
|
const id = tables.value?.find((t) => t.title === tab.title)?.id |
|
|
|
const id = tables.value?.find((t) => t.title === tab.title)?.id |
|
|
@ -56,7 +61,7 @@ export function useTabs() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
set(index: number) { |
|
|
|
set(index: number) { |
|
|
|
if (index === -1) { |
|
|
|
if (index === -1) { |
|
|
|
navigateTo(`/nc/${route.params.projectId}`) |
|
|
|
navigateTo(`/${projectType}/${route.params.projectId}`) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const tab = tabs.value[index] |
|
|
|
const tab = tabs.value[index] |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +96,7 @@ export function useTabs() { |
|
|
|
let newTabIndex = index - 1 |
|
|
|
let newTabIndex = index - 1 |
|
|
|
if (newTabIndex < 0 && tabs.value?.length > 1) newTabIndex = index + 1 |
|
|
|
if (newTabIndex < 0 && tabs.value?.length > 1) newTabIndex = index + 1 |
|
|
|
if (newTabIndex === -1) { |
|
|
|
if (newTabIndex === -1) { |
|
|
|
await navigateTo(`/nc/${route.params.projectId}`) |
|
|
|
await navigateTo(`/${projectType}/${route.params.projectId}`) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await navigateToTab(tabs.value?.[newTabIndex]) |
|
|
|
await navigateToTab(tabs.value?.[newTabIndex]) |
|
|
|
} |
|
|
|
} |
|
|
@ -102,11 +107,15 @@ export function useTabs() { |
|
|
|
function navigateToTab(tab: TabItem) { |
|
|
|
function navigateToTab(tab: TabItem) { |
|
|
|
switch (tab.type) { |
|
|
|
switch (tab.type) { |
|
|
|
case TabType.TABLE: |
|
|
|
case TabType.TABLE: |
|
|
|
return navigateTo(`/nc/${route.params.projectId}/table/${tab?.title}${tab.viewTitle ? `/${tab.viewTitle}` : ''}`) |
|
|
|
return navigateTo( |
|
|
|
|
|
|
|
`/${projectType}/${route.params.projectId}/table/${tab?.title}${tab.viewTitle ? `/${tab.viewTitle}` : ''}`, |
|
|
|
|
|
|
|
) |
|
|
|
case TabType.VIEW: |
|
|
|
case TabType.VIEW: |
|
|
|
return navigateTo(`/nc/${route.params.projectId}/view/${tab?.title}${tab.viewTitle ? `/${tab.viewTitle}` : ''}`) |
|
|
|
return navigateTo( |
|
|
|
|
|
|
|
`/${projectType}/${route.params.projectId}/view/${tab?.title}${tab.viewTitle ? `/${tab.viewTitle}` : ''}`, |
|
|
|
|
|
|
|
) |
|
|
|
case TabType.AUTH: |
|
|
|
case TabType.AUTH: |
|
|
|
return navigateTo(`/nc/${route.params.projectId}/auth`) |
|
|
|
return navigateTo(`/${projectType}/${route.params.projectId}/auth`) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|