Skip to content

Commit

Permalink
Merge branch 'main' into release/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqing committed Sep 11, 2023
2 parents 5b0e0b4 + 45cafd4 commit a07488b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog


## v1.6.0

[compare changes](https://github.com/yisibell/vue3-admin-starter/compare/v1.5.2...v1.6.0)

### 🚀 Enhancements

- Remove dynamic routes when logout ([0556b26](https://github.com/yisibell/vue3-admin-starter/commit/0556b26))

### ❤️ Contributors

- Wenqing <wenqing@kerrylan.com>

## v1.5.2

[compare changes](https://github.com/yisibell/vue3-admin-starter/compare/v1.5.1...v1.5.2)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue3-admin-starter",
"version": "1.5.2",
"version": "1.6.0",
"description": "A vue admin template powered by vite + typescript + vue3 + vue-router + pinia + element-plus + axios.",
"author": {
"name": "elenh",
Expand Down
28 changes: 28 additions & 0 deletions src/stores/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import type { IGetAllResourceParams, IRouteResourceInfo } from '@/api/resource/i
import { getAllResource } from '@/api/resource'
import cloneDeep from 'lodash/cloneDeep'
import settings from '@/settings'
import router from '@/router'

const flatRouteNames = (routes: IRouteRecord[], res: (string | symbol)[] = []) => {
routes.forEach((v) => {
if (v.name) {
res.push(v.name)
}

if (v.children && v.children.length > 0) {
flatRouteNames(v.children, res)
}
})

return res
}

export const usePermissionStore = defineStore('permission', {
state: () => ({
Expand All @@ -15,6 +30,11 @@ export const usePermissionStore = defineStore('permission', {
resources: [] as IRouteResourceInfo[],
resourceAuthCodes: [] as string[]
}),
getters: {
dynamicRouteNames(): (string | symbol)[] {
return [...new Set([...flatRouteNames(this.dynamicRoutes)])]
}
},
actions: {
SET_ROUTES(routes: IRouteRecord[]) {
this.dynamicRoutes = routes
Expand Down Expand Up @@ -66,6 +86,14 @@ export const usePermissionStore = defineStore('permission', {

this.SET_ROUTES(addRoutes)
this.SET_RESOURCE_AUTH_CODES(createAuthList(this.resources, resourceIds, isAdmin))
},
/** 删除动态路由 */
removeDynamicRoutes() {
this.dynamicRouteNames.forEach((name) => {
if (router.hasRoute(name)) {
router.removeRoute(name)
}
})
}
}
})
3 changes: 3 additions & 0 deletions src/stores/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { useTagsViewStore } from '@/stores/tagsView'
import { usePermissionStore } from '@/stores/permission'
import type { IUserInfo } from '@/api/user/index.interface'
import { getUserInfo } from '@/api/user'

Expand All @@ -16,6 +17,7 @@ export const useUserStore = defineStore(
'user',
() => {
const TagsViewStore = useTagsViewStore()
const PermissionStore = usePermissionStore()

const accessToken = ref('')
const setToken = (token: string = '') => {
Expand All @@ -42,6 +44,7 @@ export const useUserStore = defineStore(
const logout = () => {
setToken('')
TagsViewStore.delAllViews()
PermissionStore.removeDynamicRoutes()
setUserInfo(defaultUserInfo())
}

Expand Down

0 comments on commit a07488b

Please sign in to comment.