mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2025-12-28 12:10:20 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40d5106c6b | ||
|
|
094a9dcb3b | ||
|
|
db5089d92e | ||
|
|
a41ccad2d0 | ||
|
|
8973e39566 | ||
|
|
8c1191ece2 |
@@ -3,7 +3,8 @@
|
|||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
}
|
},
|
||||||
|
"jsx": "preserve"
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 .",
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
7
src/store/modules/tags/helpers.js
Normal file
7
src/store/modules/tags/helpers.js
Normal 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']
|
||||||
26
src/store/modules/tags/index.js
Normal file
26
src/store/modules/tags/index.js
Normal 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)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user