Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
saas-manage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chehuidong
saas-manage
Commits
c0e122b5
Commit
c0e122b5
authored
Jul 21, 2025
by
wusiyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 保持首页在第一位
parent
d8fb0797
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
28 deletions
+27
-28
src/store/tags.js
+27
-28
No files found.
src/store/tags.js
View file @
c0e122b5
const
lastSavedTags
=
localStorage
.
getItem
(
'tags'
)
?
JSON
.
parse
(
localStorage
.
getItem
(
'tags'
))
||
[]
:
[]
let
tagId
=
lastSavedTags
.
reduce
(
(
a
,
c
)
=>
Math
.
max
(
a
,
c
.
id
),
0
,
)
const
HOME_TAG
=
{
name
:
'home'
,
path
:
'/saas/home'
,
title
:
'首页'
,
id
:
1
}
const
lastSavedTags
=
localStorage
.
getItem
(
'tags'
)
?
JSON
.
parse
(
localStorage
.
getItem
(
'tags'
))
||
[]
:
[]
let
tagId
=
lastSavedTags
.
reduce
((
a
,
c
)
=>
Math
.
max
(
a
,
c
.
id
),
0
)
// 确保首页始终在第一位
function
ensureHomeFirst
(
tags
)
{
const
filtered
=
tags
.
filter
((
t
)
=>
t
.
name
!==
'home'
)
return
[
HOME_TAG
,
...
filtered
]
}
console
.
log
(
lastSavedTags
)
/**
* @type {import('vuex').StoreOptions}
...
...
@@ -10,32 +15,29 @@ console.log(lastSavedTags)
const
tags
=
{
namespaced
:
true
,
state
:
{
tags
:
lastSavedTags
||
[]
,
activeTag
:
undefined
,
tags
:
ensureHomeFirst
(
lastSavedTags
)
,
activeTag
:
undefined
},
getters
:
{
currentTag
(
state
)
{
return
state
.
tags
.
find
(
(
e
)
=>
e
.
name
===
state
.
activeTag
,
)
},
return
state
.
tags
.
find
((
e
)
=>
e
.
name
===
state
.
activeTag
)
}
},
mutations
:
{
add
(
state
,
tag
)
{
// 禁止添加重复首页tag
if
(
tag
.
name
===
'home'
)
return
HOME_TAG
.
id
const
item
=
{
...
tag
,
id
:
++
tagId
,
id
:
++
tagId
}
const
index
=
state
.
tags
.
findIndex
(
(
t
)
=>
t
.
name
===
tag
.
name
,
)
const
index
=
state
.
tags
.
findIndex
((
t
)
=>
t
.
name
===
tag
.
name
)
if
(
index
===
-
1
)
{
state
.
tags
.
push
(
item
)
}
localStorage
.
setItem
(
'tags'
,
JSON
.
stringify
(
state
.
tags
),
)
// 始终保证首页在第一位
state
.
tags
=
ensureHomeFirst
(
state
.
tags
)
localStorage
.
setItem
(
'tags'
,
JSON
.
stringify
(
state
.
tags
))
return
item
.
id
},
setActive
(
state
,
name
)
{
...
...
@@ -43,9 +45,9 @@ const tags = {
state
.
activeTag
=
name
},
remove
(
state
,
name
)
{
const
index
=
state
.
tags
.
findIndex
(
(
e
)
=>
e
.
name
===
name
,
)
// 禁止移除首页tag
if
(
name
===
'home'
)
return
const
index
=
state
.
tags
.
findIndex
((
e
)
=>
e
.
name
===
name
)
if
(
index
===
-
1
)
return
state
.
tags
.
splice
(
index
,
1
)
...
...
@@ -60,15 +62,12 @@ const tags = {
}
}
localStorage
.
setItem
(
'tags'
,
JSON
.
stringify
(
state
.
tags
),
)
localStorage
.
setItem
(
'tags'
,
JSON
.
stringify
(
state
.
tags
))
},
removeAllTags
(
state
)
{
state
.
tags
=
[]
}
,
}
,
}
}
}
export
default
tags
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment