Skip to content

Commit

Permalink
style: use tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jul 28, 2024
1 parent 17336ef commit fd6191f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/layout/hooks/useTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cloneProxyToRaw } from '@utils/props-util'
import { localCache, TAGS__LOCAL } from '@/utils/storage'

function useTags (menus, options) {
const { homeName, route, router } = options || {}
const { homeName, route, onChange } = options || {}

const homeRoute = getCurrentRoute(menus, homeName)
const cacheTags = localCache.getObj(TAGS__LOCAL)
Expand Down Expand Up @@ -46,17 +46,15 @@ function useTags (menus, options) {
}

function onTagClick (currentRoute) {
const { name, query, params } = currentRoute
router && router.push({ name, query, params })
onChange && onChange(currentRoute || {})
}

function onTagClose (values, toName) {
if (toName) {
const result = values.find((item) => {
return item.name === toName
})
const { name, query, params } = result || {}
router && router.push({ name, query, params })
onChange && onChange(result || {})
}
setTagsValue(values)
}
Expand Down
8 changes: 6 additions & 2 deletions src/layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default defineComponent({
// 过滤没有权限的路由, 权限 access 一般是在后台请求过来放在 store 里面
const menus = getMenuList(routes, [])
const { tags, onTagClick, onTagClose } = useTags(menus, {
homeName: HOME_NAME,
route: route,
router: router,
homeName: HOME_NAME
onChange: onTagsChange
})

const sideTheme = computed(() => {
Expand All @@ -45,6 +45,10 @@ export default defineComponent({
router.push({ name: name })
}

function onTagsChange ({ name, query, params }) {
router.push({ name, query, params })
}

return () => {
const layoutSlots = {
sider: ({ collapsed }) => {
Expand Down

0 comments on commit fd6191f

Please sign in to comment.