types: update vue-router type
This commit is contained in:
parent
8d4588b029
commit
73fa762052
@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ElScrollbar } from "element-plus"
|
||||
import type { RouteRecordName, RouteRecordRaw } from "vue-router"
|
||||
import type { RouteRecordNameGeneric, RouteRecordRaw } from "vue-router"
|
||||
import { usePermissionStore } from "@/pinia/stores/permission"
|
||||
import { useDevice } from "@@/composables/useDevice"
|
||||
import { isExternal } from "@@/utils/validate"
|
||||
@ -20,7 +20,7 @@ const resultRef = ref<InstanceType<typeof Result> | null>(null)
|
||||
|
||||
const keyword = ref<string>("")
|
||||
const result = shallowRef<RouteRecordRaw[]>([])
|
||||
const activeRouteName = ref<RouteRecordName | undefined>(undefined)
|
||||
const activeRouteName = ref<RouteRecordNameGeneric | undefined>(undefined)
|
||||
/** 是否按下了上键或下键(用于解决和 mouseenter 事件的冲突) */
|
||||
const isPressUpOrDown = ref<boolean>(false)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import type { RouteRecordName, RouteRecordRaw } from "vue-router"
|
||||
import type { RouteRecordNameGeneric, RouteRecordRaw } from "vue-router"
|
||||
|
||||
interface Props {
|
||||
data: RouteRecordRaw[]
|
||||
@ -9,7 +9,7 @@ interface Props {
|
||||
const props = defineProps<Props>()
|
||||
|
||||
/** 选中的菜单 */
|
||||
const modelValue = defineModel<RouteRecordName | undefined>({ required: true })
|
||||
const modelValue = defineModel<RouteRecordNameGeneric | undefined>({ required: true })
|
||||
|
||||
const instance = getCurrentInstance()
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
import type { Handler } from "mitt"
|
||||
import type { RouteLocationNormalized } from "vue-router"
|
||||
import type { RouteLocationNormalizedGeneric } from "vue-router"
|
||||
import mitt from "mitt"
|
||||
|
||||
/** 回调函数的类型 */
|
||||
type Callback = (route: RouteLocationNormalized) => void
|
||||
type Callback = (route: RouteLocationNormalizedGeneric) => void
|
||||
|
||||
const emitter = mitt()
|
||||
|
||||
const key = Symbol("ROUTE_CHANGE")
|
||||
|
||||
let latestRoute: RouteLocationNormalized
|
||||
let latestRoute: RouteLocationNormalizedGeneric
|
||||
|
||||
/** 设置最新的路由信息,触发路由变化事件 */
|
||||
export function setRouteChange(to: RouteLocationNormalized) {
|
||||
export function setRouteChange(to: RouteLocationNormalizedGeneric) {
|
||||
// 触发事件
|
||||
emitter.emit(key, to)
|
||||
// 缓存最新的路由信息
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { TagView } from "@/pinia/stores/tags-view"
|
||||
import type { RouteLocationNormalizedLoaded, RouteRecordRaw, RouterLink } from "vue-router"
|
||||
import type { RouteLocationNormalizedGeneric, RouteRecordRaw, RouterLink } from "vue-router"
|
||||
import { usePermissionStore } from "@/pinia/stores/permission"
|
||||
import { useTagsViewStore } from "@/pinia/stores/tags-view"
|
||||
import { useRouteListener } from "@@/composables/useRouteListener"
|
||||
@ -77,7 +77,7 @@ function initTags() {
|
||||
}
|
||||
|
||||
/** 添加标签页 */
|
||||
function addTags(route: RouteLocationNormalizedLoaded) {
|
||||
function addTags(route: RouteLocationNormalizedGeneric) {
|
||||
if (route.name) {
|
||||
tagsViewStore.addVisitedView(route)
|
||||
tagsViewStore.addCachedView(route)
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type { RouteLocationNormalized } from "vue-router"
|
||||
import type { RouteLocationNormalizedGeneric } from "vue-router"
|
||||
import { pinia } from "@/pinia"
|
||||
import { getCachedViews, getVisitedViews, setCachedViews, setVisitedViews } from "@@/utils/cache/local-storage"
|
||||
import { useSettingsStore } from "./settings"
|
||||
|
||||
export type TagView = Partial<RouteLocationNormalized>
|
||||
export type TagView = Partial<RouteLocationNormalizedGeneric>
|
||||
|
||||
export const useTagsViewStore = defineStore("tags-view", () => {
|
||||
const { cacheTagsView } = useSettingsStore()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { RouteLocationNormalized, RouteRecordNameGeneric } from "vue-router"
|
||||
import type { RouteLocationNormalizedGeneric, RouteRecordNameGeneric } from "vue-router"
|
||||
|
||||
/** 免登录白名单(匹配路由 path) */
|
||||
const whiteListByPath: string[] = ["/login"]
|
||||
@ -7,7 +7,7 @@ const whiteListByPath: string[] = ["/login"]
|
||||
const whiteListByName: RouteRecordNameGeneric[] = []
|
||||
|
||||
/** 判断是否在白名单 */
|
||||
export function isWhiteList(to: RouteLocationNormalized) {
|
||||
export function isWhiteList(to: RouteLocationNormalizedGeneric) {
|
||||
// path 和 name 任意一个匹配上即可
|
||||
return whiteListByPath.includes(to.path) || whiteListByName.includes(to.name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user