1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-12-28 20:10:22 +08:00

6 Commits

Author SHA1 Message Date
张传龙
40d5106c6b release: v0.3.2 2022-04-15 22:16:10 +08:00
张传龙
094a9dcb3b fix: 修复二次登录后标签页会多出登录标签问题 2022-04-14 15:30:34 +08:00
张传龙
db5089d92e chore: update jsconfig.json 2022-04-13 17:24:27 +08:00
张传龙
a41ccad2d0 style: 修改naive ui主题颜色配置 2022-04-12 17:18:21 +08:00
张传龙
8973e39566 feat: 多标签增加sessionStorage缓存 2022-04-11 22:13:17 +08:00
张传龙
8c1191ece2 mod: 文件名模块修改 2022-04-11 22:12:00 +08:00
9 changed files with 58 additions and 39 deletions

View File

@@ -3,7 +3,8 @@
"baseUrl": "./", "baseUrl": "./",
"paths": { "paths": {
"@/*": ["src/*"] "@/*": ["src/*"]
} },
"jsx": "preserve"
}, },
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "vue-naive-admin", "name": "vue-naive-admin",
"version": "0.0.1", "version": "0.3.2",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"lint": "eslint --ext .js,.vue .", "lint": "eslint --ext .js,.vue .",

View File

@@ -2,10 +2,10 @@
<div class="tags-wrapper" :style="{ height: useTheme.tags.height + 'px' }"> <div class="tags-wrapper" :style="{ height: useTheme.tags.height + 'px' }">
<n-space> <n-space>
<n-tag <n-tag
v-for="tag in useTag.tags" v-for="tag in useTags.tags"
:key="tag.path" :key="tag.path"
:type="useTag.activeTag === tag.path ? 'primary' : 'default'" :type="useTags.activeTag === tag.path ? 'primary' : 'default'"
:closable="useTag.tags.length > 1" :closable="useTags.tags.length > 1"
@click="handleTagClick(tag.path)" @click="handleTagClick(tag.path)"
@close.stop="handleClose(tag.path)" @close.stop="handleClose(tag.path)"
> >
@@ -18,12 +18,12 @@
<script setup name="Tags"> <script setup name="Tags">
import { watch } from 'vue' import { watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useTagStore } from '@/store/modules/tag' import { useTagsStore } from '@/store/modules/tags'
import { useThemeStore } from '@/store/modules/theme' import { useThemeStore } from '@/store/modules/theme'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const useTag = useTagStore() const useTags = useTagsStore()
const useTheme = useThemeStore() const useTheme = useThemeStore()
watch( watch(
@@ -31,27 +31,27 @@ watch(
() => { () => {
const { name, path } = route const { name, path } = route
const title = route.meta?.title const title = route.meta?.title
useTag.addTag({ name, path, title }) useTags.addTag({ name, path, title })
useTag.setActiveTag(path) useTags.setActiveTag(path)
}, },
{ immediate: true } { immediate: true }
) )
const handleTagClick = (path) => { const handleTagClick = (path) => {
useTag.setActiveTag(path) useTags.setActiveTag(path)
router.push(path) router.push(path)
} }
const handleClose = (path) => { const handleClose = (path) => {
if (path === useTag.activeTag) { if (path === useTags.activeTag) {
const activeIndex = useTag.tags.findIndex((item) => item.path === path) const activeIndex = useTags.tags.findIndex((item) => item.path === path)
if (activeIndex > 0) { if (activeIndex > 0) {
router.push(useTag.tags[activeIndex - 1].path) router.push(useTags.tags[activeIndex - 1].path)
} else { } else {
router.push(useTag.tags[activeIndex + 1].path) router.push(useTags.tags[activeIndex + 1].path)
} }
} }
useTag.removeTag(path) useTags.removeTag(path)
} }
</script> </script>

View File

@@ -8,7 +8,14 @@
}, },
"naiveThemeOverrides": { "naiveThemeOverrides": {
"common": { "common": {
"primaryColor": "#316c72" "primaryColor": "#316C72FF",
"primaryColorHover": "#316C72E3",
"primaryColorPressed": "#2B4C59FF",
"primaryColorSuppl": "#316C7263",
"successColor": "#316C72FF",
"successColorHover": "#316C72E3",
"successColorPressed": "#2B4C59FF",
"successColorSuppl": "#316C7263"
} }
} }
} }

View File

@@ -1,22 +0,0 @@
import { defineStore } from 'pinia'
export const useTagStore = defineStore('tag', {
state() {
return {
tags: [],
activeTag: '',
}
},
actions: {
setActiveTag(path) {
this.activeTag = path
},
addTag(tag = {}) {
if (this.tags.some((item) => item.path === tag.path)) return
this.tags.push(tag)
},
removeTag(path) {
this.tags = this.tags.filter((tag) => tag.path !== path)
},
},
})

View File

@@ -0,0 +1,7 @@
import { createSessionStorage } from '@/utils/cache'
export const tagsSS = createSessionStorage({ prefixKey: 'tag_' })
export const activeTag = tagsSS.get('activeTag')
export const tags = tagsSS.get('tags')
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']

View File

@@ -0,0 +1,26 @@
import { defineStore } from 'pinia'
import { tagsSS, activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
export const useTagsStore = defineStore('tag', {
state() {
return {
tags: tags || [],
activeTag: activeTag || '',
}
},
actions: {
setActiveTag(path) {
this.activeTag = path
tagsSS.set('activeTag', path)
},
addTag(tag = {}) {
if (WITHOUT_TAG_PATHS.includes(tag.path) || this.tags.some((item) => item.path === tag.path)) return
this.tags.push(tag)
tagsSS.set('tags', this.tags)
},
removeTag(path) {
this.tags = this.tags.filter((tag) => tag.path !== path)
tagsSS.set('tags', this.tags)
},
},
})

View File

@@ -1,6 +1,6 @@
import { router } from '@/router' import { router } from '@/router'
import { getToken, removeToken } from '@/utils/token' import { getToken, removeToken } from '@/utils/token'
import { isWithoutToken } from './help' import { isWithoutToken } from './helpers'
export function setupInterceptor(service) { export function setupInterceptor(service) {
service.interceptors.request.use( service.interceptors.request.use(