mod: 文件名模块修改

This commit is contained in:
张传龙 2022-04-11 22:12:00 +08:00
parent b3aa8147b1
commit 8c1191ece2
4 changed files with 21 additions and 17 deletions

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

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