wip: 继续修复

main
NoahLan 7 months ago
parent 6edcbbf0ab
commit 1df12e5ea0

@ -1,4 +1,4 @@
import type { RouteLocationNormalized, Router } from 'vue-router' import type { RouteLocationNormalized, Router } from 'vue-router/auto'
import { TabActionEnum } from '~/constants' import { TabActionEnum } from '~/constants'
export function useTabs(_router?: Router) { export function useTabs(_router?: Router) {
@ -8,7 +8,7 @@ export function useTabs(_router?: Router) {
const { show } = unref(appStore.tabTar) const { show } = unref(appStore.tabTar)
if (!show) { if (!show) {
throw new Error( throw new Error(
'The multi-tab page is currently not open, please open it in the settings', 'The multi-tab page is currently not open, please open it in the settings!',
) )
} }
return !!show return !!show

@ -1,4 +1,4 @@
import type { RouteLocationRaw, Router } from 'vue-router' import type { RouteLocationRaw, Router } from 'vue-router/auto'
import { PageEnum, REDIRECT_NAME } from '~/constants' import { PageEnum, REDIRECT_NAME } from '~/constants'
export type PathAsPageEnum<T> = T extends { path: string } ? T & { path: PageEnum } : T export type PathAsPageEnum<T> = T extends { path: string } ? T & { path: PageEnum } : T
@ -29,13 +29,18 @@ export function useRedo(_router?: Router) {
return return
} }
if (name && Object.keys(params).length > 0) { if (name && Object.keys(params).length > 0) {
// @ts-expect-error tstype
params._redirect_type = 'name' params._redirect_type = 'name'
// @ts-expect-error tstype
params.path = String(name) params.path = String(name)
} }
else { else {
// @ts-expect-error tstype
params._redirect_type = 'path' params._redirect_type = 'path'
// @ts-expect-error tstype
params.path = fullPath params.path = fullPath
} }
// @ts-expect-error tstype
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true)) push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true))
}) })
} }

@ -1,4 +1,4 @@
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router/auto'
export function useFullContent() { export function useFullContent() {
const configStore = useAppConfigStore() const configStore = useAppConfigStore()

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { RouteLocationMatched } from 'vue-router' import type { RouteLocationMatched } from 'vue-router/auto'
import { REDIRECT_NAME } from '~/constants' import { REDIRECT_NAME } from '~/constants'
import { filterTree, getAllParentPath, isString } from '~/utils' import { filterTree, getAllParentPath, isString } from '~/utils'

@ -1,7 +1,7 @@
<script setup lang="ts" name="LayoutMenu"> <script setup lang="ts" name="LayoutMenu">
import type { MenuInst } from 'naive-ui' import type { MenuInst } from 'naive-ui'
import type { RouteLocationNormalizedLoaded } from 'vue-router' import type { RouteLocationNormalizedLoaded } from 'vue-router/auto'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router/auto'
import type { MenuMixedOption } from 'naive-ui/es/menu/src/interface' import type { MenuMixedOption } from 'naive-ui/es/menu/src/interface'
import Logo from '../logo/index.vue' import Logo from '../logo/index.vue'
import FooterTrigger from '../trigger/footer-trigger.vue' import FooterTrigger from '../trigger/footer-trigger.vue'
@ -190,30 +190,13 @@ function clickMenu(key: any) {
<Logo v-if="showSidebarLogo" :class="bem('logo')" :show-title="getCollapsedShowTitle" /> <Logo v-if="showSidebarLogo" :class="bem('logo')" :show-title="getCollapsedShowTitle" />
<NScrollbar :class="bem('scrollbar')"> <NScrollbar :class="bem('scrollbar')">
<NMenu <NMenu
v-if="options && options.length > 0" v-if="options && options.length > 0" ref="menuRef" v-model:value="activeKey" class="w-full" :style="{
ref="menuRef"
v-model:value="activeKey"
class="w-full"
:style="{
justifyContent: getTopMenuAlign === 'center' ? 'center' : `flex-${getTopMenuAlign}`, justifyContent: getTopMenuAlign === 'center' ? 'center' : `flex-${getTopMenuAlign}`,
}" }" :options="options" :collapsed="getMenuCollapsed" :collapsed-width="48" :collapsed-icon-size="22" :indent="18"
:options="options" :root-indent="18" :mode="props.mode" :accordion="menu.accordion" :inverted="inverted"
:collapsed="getMenuCollapsed"
:collapsed-width="48"
:collapsed-icon-size="22"
:indent="18"
:root-indent="18"
:mode="props.mode"
:accordion="menu.accordion"
:inverted="inverted"
@update:value="clickMenu" @update:value="clickMenu"
/> />
<NEmpty <NEmpty v-else class="py-8" :size="getCollapsed ? 'small' : 'huge'" description="当前主菜单下无子菜单">
v-else
class="py-8"
:size="getCollapsed ? 'small' : 'huge'"
description="当前主菜单下无子菜单"
>
<template #icon> <template #icon>
<LIcon icon="ant-design:unordered-list-outlined" :size="getCollapsed ? 24 : 42" /> <LIcon icon="ant-design:unordered-list-outlined" :size="getCollapsed ? 24 : 42" />
</template> </template>

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { CSSProperties } from 'vue' import type { CSSProperties } from 'vue'
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
import Logo from '../logo/index.vue' import Logo from '../logo/index.vue'
import SiderTrigger from '../trigger/sider-trigger.vue' import SiderTrigger from '../trigger/sider-trigger.vue'
import MixSubMenu from './mix-sub-menu.vue' import MixSubMenu from './mix-sub-menu.vue'

@ -1,8 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import type { MenuInst } from 'naive-ui' import type { MenuInst } from 'naive-ui'
import type { MenuMixedOption } from 'naive-ui/es/menu/src/interface' import type { MenuMixedOption } from 'naive-ui/es/menu/src/interface'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router/auto'
import type { RouteLocationNormalizedLoaded } from 'vue-router' import type { RouteLocationNormalizedLoaded } from 'vue-router/auto'
import { REDIRECT_NAME } from '~/constants' import { REDIRECT_NAME } from '~/constants'
import { createNamespace, listenerRouteChange, mapTree } from '~/utils' import { createNamespace, listenerRouteChange, mapTree } from '~/utils'
@ -86,16 +86,8 @@ const { isSidebarDark } = useAppTheme()
<div :class="bem()"> <div :class="bem()">
<NScrollbar :class="bem('scrollbar')"> <NScrollbar :class="bem('scrollbar')">
<NMenu <NMenu
ref="menuRef" ref="menuRef" v-model:value="activeKey" :options="menuListRef" :collapsed-width="48" :collapsed="false"
v-model:value="activeKey" :collapsed-icon-size="22" :indent="18" :root-indent="18" :accordion="getAccordion" :inverted="isSidebarDark"
:options="menuListRef"
:collapsed-width="48"
:collapsed="false"
:collapsed-icon-size="22"
:indent="18"
:root-indent="18"
:accordion="getAccordion"
:inverted="isSidebarDark"
/> />
</NScrollbar> </NScrollbar>
</div> </div>
@ -106,6 +98,7 @@ const { isSidebarDark } = useAppTheme()
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; height: 100%;
&__scrollbar { &__scrollbar {
flex: 1; flex: 1;
flex-basis: auto; flex-basis: auto;

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
import { TabActionEnum } from '~/constants' import { TabActionEnum } from '~/constants'
const { t } = useI18n() const { t } = useI18n()

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { PropType } from 'vue' import type { PropType } from 'vue'
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
import { TabActionEnum } from '~/constants' import { TabActionEnum } from '~/constants'
const props = defineProps({ const props = defineProps({

@ -1,4 +1,4 @@
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
export interface TabDropDownInst { export interface TabDropDownInst {
openDropdown: (e: MouseEvent, tabItem: RouteLocationNormalized) => void openDropdown: (e: MouseEvent, tabItem: RouteLocationNormalized) => void

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
import TabRedo from './components/tab-redo.vue' import TabRedo from './components/tab-redo.vue'
import TabQuick from './components/tab-quick.vue' import TabQuick from './components/tab-quick.vue'
import TabFoldButton from './components/tab-foldbutton.vue' import TabFoldButton from './components/tab-foldbutton.vue'

@ -17,7 +17,7 @@ export function initRouter(path: string): Router {
scrollBehavior: () => ({ left: 0, top: 0 }), scrollBehavior: () => ({ left: 0, top: 0 }),
extendRoutes: (routes: RouteRecordRaw[]) => { extendRoutes: (routes: RouteRecordRaw[]) => {
const initialRoutes = routeStore.initRoutes(routes) const initialRoutes = routeStore.initRoutes(routes)
console.log('🚀 ~ initRouter ~ setupLayouts(initialRoutes):', initialRoutes, setupLayouts(initialRoutes)) // console.log('🚀 ~ initRouter ~ setupLayouts(initialRoutes):', initialRoutes, setupLayouts(initialRoutes))
return setupLayouts(initialRoutes) return setupLayouts(initialRoutes)
}, },
}) })

@ -1,4 +1,4 @@
import type { RouteRecordRaw } from 'vue-router' import type { RouteRecordRaw } from 'vue-router/auto'
import { PAGE_NOT_FOUND_NAME, REDIRECT_NAME } from '~/constants' import { PAGE_NOT_FOUND_NAME, REDIRECT_NAME } from '~/constants'
const PAGE_NOT_FOUND_ROUTE: RouteRecordRaw = { const PAGE_NOT_FOUND_ROUTE: RouteRecordRaw = {

@ -2,6 +2,13 @@
defineOptions({ defineOptions({
name: 'IndexPage', name: 'IndexPage',
}) })
definePage({
meta: {
title: 'menu.home',
order: 1,
icon: 'carbon-home',
},
})
useHead({ useHead({
title: '首页', title: '首页',
}) })
@ -10,6 +17,7 @@ useHead({
<template> <template>
<div> <div>
<NInput /> <NInput />
<NButton>Button</NButton>
<div>placeholder</div> <div>placeholder</div>
<div>placeholder</div> <div>placeholder</div>
<div>placeholder</div> <div>placeholder</div>
@ -73,13 +81,6 @@ useHead({
</div> </div>
</template> </template>
<route lang="yaml">
meta:
title: menu.home
order: 1
icon: carbon-home
</route>
<style lang="less" scoped> <style lang="less" scoped>
.setting-btn { .setting-btn {
background: var(--card-color); background: var(--card-color);

@ -1,5 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import type { RouteLocationNormalized, RouteLocationRaw, Router } from 'vue-router' import type { RouteLocationNormalized, RouteLocationRaw, Router } from 'vue-router/auto'
import { PAGE_NOT_FOUND_NAME, PageEnum, REDIRECT_NAME, TabActionEnum } from '~/constants' import { PAGE_NOT_FOUND_NAME, PageEnum, REDIRECT_NAME, TabActionEnum } from '~/constants'
import { getRawRoute } from '~/utils' import { getRawRoute } from '~/utils'

@ -25,6 +25,7 @@ declare module 'vue-router/auto-routes' {
'/login/components/account': RouteRecordInfo<'/login/components/account', '/login/components/account', Record<never, never>, Record<never, never>>, '/login/components/account': RouteRecordInfo<'/login/components/account', '/login/components/account', Record<never, never>, Record<never, never>>,
'/login/components/sms': RouteRecordInfo<'/login/components/sms', '/login/components/sms', Record<never, never>, Record<never, never>>, '/login/components/sms': RouteRecordInfo<'/login/components/sms', '/login/components/sms', Record<never, never>, Record<never, never>>,
'/README': RouteRecordInfo<'/README', '/README', Record<never, never>, Record<never, never>>, '/README': RouteRecordInfo<'/README', '/README', Record<never, never>, Record<never, never>>,
'Redirect': RouteRecordInfo<'Redirect', '/redirect/:path(.*):_redirect_type(.*)', { path: ParamValue<true>, _redirect_type: ParamValue<true> }, { path: ParamValue<false>, _redirect_type: ParamValue<false> }>,
'/register': RouteRecordInfo<'/register', '/register', Record<never, never>, Record<never, never>>, '/register': RouteRecordInfo<'/register', '/register', Record<never, never>, Record<never, never>>,
'/register/': RouteRecordInfo<'/register/', '/register', Record<never, never>, Record<never, never>>, '/register/': RouteRecordInfo<'/register/', '/register', Record<never, never>, Record<never, never>>,
'/register/components/account': RouteRecordInfo<'/register/components/account', '/register/components/account', Record<never, never>, Record<never, never>>, '/register/components/account': RouteRecordInfo<'/register/components/account', '/register/components/account', Record<never, never>, Record<never, never>>,

@ -1,5 +1,5 @@
import type { RemovableRef } from '@vueuse/core' import type { RemovableRef } from '@vueuse/core'
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
declare global { declare global {
interface DefineMultipleTabOptions { interface DefineMultipleTabOptions {

@ -1,4 +1,4 @@
import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router' import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router/auto'
export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormalized { export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormalized {
if (!route) if (!route)

@ -1,4 +1,4 @@
import type { RouteRecordNormalized, RouteRecordRaw } from 'vue-router' import type { RouteRecordNormalized, RouteRecordRaw } from 'vue-router/auto'
import { pathToRegexp } from 'path-to-regexp' import { pathToRegexp } from 'path-to-regexp'
import { cloneDeep, findParentPath, isUrl, mapTree } from '~/utils' import { cloneDeep, findParentPath, isUrl, mapTree } from '~/utils'

@ -1,4 +1,4 @@
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router/auto'
import { getRawRoute, mitt } from '~/utils' import { getRawRoute, mitt } from '~/utils'
export const emitter = mitt() export const emitter = mitt()

@ -21,6 +21,7 @@ import Layouts from 'vite-plugin-vue-layouts'
// vue-router // vue-router
import VueRouter from 'unplugin-vue-router/vite' import VueRouter from 'unplugin-vue-router/vite'
import type { EditableTreeNode } from 'unplugin-vue-router'
import { VueRouterAutoImports } from 'unplugin-vue-router' import { VueRouterAutoImports } from 'unplugin-vue-router'
import WebFontDownload from 'vite-plugin-webfont-dl' import WebFontDownload from 'vite-plugin-webfont-dl'
@ -52,6 +53,8 @@ import pkg from './package.json'
type Algorithm = 'gzip' | 'brotliCompress' | 'deflate' | 'deflateRaw' type Algorithm = 'gzip' | 'brotliCompress' | 'deflate' | 'deflateRaw'
let routeExtended = false
export default defineConfig(({ command, mode }: ConfigEnv) => { export default defineConfig(({ command, mode }: ConfigEnv) => {
console.log('command', command) console.log('command', command)
const viteEnv = loadEnv(mode, process.cwd()) const viteEnv = loadEnv(mode, process.cwd())
@ -69,6 +72,31 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
// 忽略 pages 中的所有 components 下的组件路由 // 忽略 pages 中的所有 components 下的组件路由
// exclude: ['**/components/*'], // exclude: ['**/components/*'],
dts: 'src/typed-router.d.ts', dts: 'src/typed-router.d.ts',
extendRoute: (route: EditableTreeNode) => {
if (routeExtended) {
return
}
const findRoot = (route: EditableTreeNode): EditableTreeNode => {
if (route.parent) {
return findRoot(route.parent)
}
return route
}
const root = findRoot(route)
const redirectRoute = root.insert('/redirect/:path(.*):_redirect_type(.*)', '~/layouts/page/redirect.vue')
redirectRoute.name = 'Redirect'
redirectRoute.path = '/redirect/:path(.*):_redirect_type(.*)'
redirectRoute.meta = {
title: 'Redirect',
hideInMenu: true,
hideInBreadcrumb: true,
}
routeExtended = true
},
}), }),
VueMacros({ VueMacros({

Loading…
Cancel
Save