Skip to content

Commit

Permalink
feat: change tagsViews
Browse files Browse the repository at this point in the history
  • Loading branch information
zwj-cheer committed Aug 13, 2024
1 parent c950907 commit fbd627d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
42 changes: 21 additions & 21 deletions src/layout/components/TagsView/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { resolve } from 'path-browserify'
import type { RouteRecordRaw } from 'vue-router'
import type { RouteLocationRaw, RouteRecordRaw } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import {
Expand Down Expand Up @@ -140,7 +140,7 @@ function isFirstView() {
try {
return (
selectedTag.value.path === '/dashboard'
|| selectedTag.value.fullPath === tagsViewStore.visitedViews[1].fullPath
|| selectedTag.value.fullPath === tagsViewStore.visitedViews[1]?.fullPath
)
}
catch (err) {
Expand All @@ -152,7 +152,7 @@ function isLastView() {
try {
return (
selectedTag.value.fullPath
=== tagsViewStore.visitedViews[tagsViewStore.visitedViews.length - 1].fullPath
=== tagsViewStore.visitedViews[tagsViewStore.visitedViews.length - 1]?.fullPath
)
}
catch (err) {
Expand All @@ -169,37 +169,37 @@ function refreshSelectedTag(view: TagView) {
}
function closeSelectedTag(view: TagView) {
tagsViewStore.delView(view).then((res: unknown) => {
tagsViewStore.delView(view).then((res) => {
if (tagsViewStore.isActive(view)) {
tagsViewStore.toLastView(res.visitedViews, view)
}
})
}
function closeLeftTags() {
tagsViewStore.delLeftViews(selectedTag.value).then((res: unknown) => {
if (!res.visitedViews.find((item: unknown) => item.path === route.path)) {
tagsViewStore.delLeftViews(selectedTag.value).then((res) => {
if (!res.visitedViews.find(item => item.path === route.path)) {
tagsViewStore.toLastView(res.visitedViews)
}
})
}
function closeRightTags() {
tagsViewStore.delRightViews(selectedTag.value).then((res: unknown) => {
if (!res.visitedViews.find((item: unknown) => item.path === route.path)) {
tagsViewStore.delRightViews(selectedTag.value).then((res) => {
if (!res.visitedViews.find(item => item.path === route.path)) {
tagsViewStore.toLastView(res.visitedViews)
}
})
}
function closeOtherTags() {
router.push(selectedTag.value)
router.push(selectedTag.value as RouteLocationRaw)
tagsViewStore.delOtherViews(selectedTag.value).then(() => {
moveToCurrentTag()
})
}
function closeAllTags(view: TagView) {
tagsViewStore.delAllViews().then((res: unknown) => {
tagsViewStore.delAllViews().then((res) => {
tagsViewStore.toLastView(res.visitedViews, view)
})
}
Expand Down Expand Up @@ -248,29 +248,29 @@ function handleScroll() {
closeContentMenu()
}
function findOutermostParent(tree: unknown[], findName: string) {
const parentMap: unknown = {}
function findOutermostParent(tree: ReadonlyArray<RouteRecordRaw>, findName: string) {
const parentMap: Record<string, RouteRecordRaw | null> = {}
function buildParentMap(node: unknown, parent: unknown) {
parentMap[node.name] = parent
function buildParentMap(node: RouteRecordRaw, parent: RouteRecordRaw | null) {
parentMap[node.name as string] = parent
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
buildParentMap(node.children[i], node)
for (const childItem of node.children) {
buildParentMap(childItem, node)
}
}
}
for (let i = 0; i < tree.length; i++) {
buildParentMap(tree[i], null)
for (const treeItem of tree) {
buildParentMap(treeItem, null)
}
let currentNode = parentMap[findName]
while (currentNode) {
if (!parentMap[currentNode.name]) {
if (!parentMap[currentNode.name as string]) {
return currentNode
}
currentNode = parentMap[currentNode.name]
currentNode = parentMap[currentNode.name as string]
}
return null
Expand All @@ -281,7 +281,7 @@ function againActiveTop(newVal: string) {
return
}
const parent = findOutermostParent(permissionStore.routes, newVal)
if (appStore.activeTopMenu !== parent.path) {
if (parent?.path && appStore.activeTopMenuPath !== parent.path) {
appStore.activeTopMenu(parent.path)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/tagsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
}

function delLeftViews(view: TagView) {
return new Promise<void | { visitedViews: TagView[] }>((resolve) => {
return new Promise<{ visitedViews: TagView[] }>((resolve) => {
const currIndex = visitedViews.value.findIndex(
v => v.path === view.path,
)
Expand All @@ -157,7 +157,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
}

function delRightViews(view: TagView) {
return new Promise<void | { visitedViews: TagView[] }>((resolve) => {
return new Promise<{ visitedViews: TagView[] }>((resolve) => {
const currIndex = visitedViews.value.findIndex(
v => v.path === view.path,
)
Expand Down
4 changes: 3 additions & 1 deletion src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { LocationQueryRaw } from 'vue-router'

declare global {
/**
* 响应数据
Expand Down Expand Up @@ -45,7 +47,7 @@ declare global {
/** 是否开启缓存 */
keepAlive?: boolean
/** 路由查询参数 */
query?: unknown
query?: LocationQueryRaw
}

/**
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import process from 'node:process'

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import type { PreRenderedAsset } from 'rollup'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
Expand All @@ -15,7 +16,6 @@ import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// https://devtools-next.vuejs.org/
import VueDevTools from 'vite-plugin-vue-devtools'
import type { PreRenderedAsset } from 'rollup'

import {
dependencies,
Expand Down

0 comments on commit fbd627d

Please sign in to comment.