refactor: simplify wrapper storage

This commit is contained in:
张传龙
2022-07-01 23:27:05 +08:00
parent 90aa54d4a4
commit 57bc68e7b0
7 changed files with 34 additions and 37 deletions

View File

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

View File

@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { tagsSS, activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
import { activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
import { router } from '@/router'
import { sStorage } from '@/utils/cache'
export const useTagsStore = defineStore('tag', {
state() {
@@ -12,11 +13,11 @@ export const useTagsStore = defineStore('tag', {
actions: {
setActiveTag(path) {
this.activeTag = path
tagsSS.set('activeTag', path)
sStorage.set('activeTag', path)
},
setTags(tags) {
this.tags = tags
tagsSS.set('tags', tags)
sStorage.set('tags', tags)
},
addTag(tag = {}) {
this.setActiveTag(tag.path)