Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
圆滚滚核心
vue-element-admin
提交
48e47e86
V
vue-element-admin
项目概览
圆滚滚核心
/
vue-element-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-element-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
48e47e86
编写于
2月 15, 2019
作者:
花
花裤衩
提交者:
GitHub
2月 15, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fearure[TagsView]: add affix option (#1577)
上级
4e055983
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
25 deletion
+69
-25
src/router/index.js
src/router/index.js
+3
-2
src/store/modules/tagsView.js
src/store/modules/tagsView.js
+6
-7
src/views/layout/components/TagsView.vue
src/views/layout/components/TagsView.vue
+60
-16
未找到文件。
src/router/index.js
浏览文件 @
48e47e86
...
...
@@ -29,6 +29,7 @@ import nestedRouter from './modules/nested'
icon: 'svg-name' the icon show in the sidebar
noCache: true if true, the page will no be cached(default is false)
breadcrumb: false if false, the item will hidden in breadcrumb(default is true)
affix: true if true, the tag will affix in the tags-view
}
**/
export
const
constantRouterMap
=
[
...
...
@@ -72,7 +73,7 @@ export const constantRouterMap = [
path
:
'
dashboard
'
,
component
:
()
=>
import
(
'
@/views/dashboard/index
'
),
name
:
'
Dashboard
'
,
meta
:
{
title
:
'
dashboard
'
,
icon
:
'
dashboard
'
,
noCache
:
true
}
meta
:
{
title
:
'
dashboard
'
,
icon
:
'
dashboard
'
,
noCache
:
true
,
affix
:
true
}
}
]
},
...
...
@@ -85,7 +86,7 @@ export const constantRouterMap = [
path
:
'
index
'
,
component
:
()
=>
import
(
'
@/views/documentation/index
'
),
name
:
'
Documentation
'
,
meta
:
{
title
:
'
documentation
'
,
icon
:
'
documentation
'
,
noCache
:
true
}
meta
:
{
title
:
'
documentation
'
,
icon
:
'
documentation
'
,
affix
:
true
}
}
]
},
...
...
src/store/modules/tagsView.js
浏览文件 @
48e47e86
...
...
@@ -38,12 +38,9 @@ const tagsView = {
},
DEL_OTHERS_VISITED_VIEWS
:
(
state
,
view
)
=>
{
for
(
const
[
i
,
v
]
of
state
.
visitedViews
.
entries
())
{
if
(
v
.
path
===
view
.
path
)
{
state
.
visitedViews
=
state
.
visitedViews
.
slice
(
i
,
i
+
1
)
break
}
}
state
.
visitedViews
=
state
.
visitedViews
.
filter
(
v
=>
{
return
v
.
meta
.
affix
||
v
.
path
===
view
.
path
})
},
DEL_OTHERS_CACHED_VIEWS
:
(
state
,
view
)
=>
{
for
(
const
i
of
state
.
cachedViews
)
{
...
...
@@ -56,7 +53,9 @@ const tagsView = {
},
DEL_ALL_VISITED_VIEWS
:
state
=>
{
state
.
visitedViews
=
[]
// keep affix tags
const
affixTags
=
state
.
visitedViews
.
filter
(
tag
=>
tag
.
meta
.
affix
)
state
.
visitedViews
=
affixTags
},
DEL_ALL_CACHED_VIEWS
:
state
=>
{
state
.
cachedViews
=
[]
...
...
src/views/layout/components/TagsView.vue
浏览文件 @
48e47e86
...
...
@@ -12,14 +12,15 @@
@click.middle.native="closeSelectedTag(tag)"
@contextmenu.prevent.native="openMenu(tag,$event)">
{{
generateTitle
(
tag
.
title
)
}}
<span
class=
"el-icon-close"
@
click.prevent.stop=
"closeSelectedTag(tag)"
/>
<span
v-if=
"!tag.meta.affix"
class=
"el-icon-close"
@
click.prevent.stop=
"closeSelectedTag(tag)"
/>
</router-link>
</scroll-pane>
<ul
v-show=
"visible"
:style=
"
{left:left+'px',top:top+'px'}" class="contextmenu">
<li
@
click=
"refreshSelectedTag(selectedTag)"
>
{{
$t
(
'
tagsView.refresh
'
)
}}
</li>
<li
@
click=
"closeSelectedTag(selectedTag)"
>
{{
$t
(
'
tagsView.close
'
)
}}
</li>
<li
v-if=
"!(selectedTag.meta&&selectedTag.meta.affix)"
@
click=
"closeSelectedTag(selectedTag)"
>
{{
$t
(
'
tagsView.close
'
)
}}
</li>
<li
@
click=
"closeOthersTags"
>
{{
$t
(
'
tagsView.closeOthers
'
)
}}
</li>
<li
@
click=
"closeAllTags"
>
{{
$t
(
'
tagsView.closeAll
'
)
}}
</li>
<li
@
click=
"closeAllTags
(selectedTag)
"
>
{{
$t
(
'
tagsView.closeAll
'
)
}}
</li>
</ul>
</div>
</
template
>
...
...
@@ -27,6 +28,7 @@
<
script
>
import
ScrollPane
from
'
@/components/ScrollPane
'
import
{
generateTitle
}
from
'
@/utils/i18n
'
import
path
from
'
path
'
export
default
{
components
:
{
ScrollPane
},
...
...
@@ -35,17 +37,21 @@ export default {
visible
:
false
,
top
:
0
,
left
:
0
,
selectedTag
:
{}
selectedTag
:
{},
affixTags
:
[]
}
},
computed
:
{
visitedViews
()
{
return
this
.
$store
.
state
.
tagsView
.
visitedViews
},
routers
()
{
return
this
.
$store
.
state
.
permission
.
routers
}
},
watch
:
{
$route
()
{
this
.
add
View
Tags
()
this
.
addTags
()
this
.
moveToCurrentTag
()
},
visible
(
value
)
{
...
...
@@ -57,14 +63,44 @@ export default {
}
},
mounted
()
{
this
.
addViewTags
()
this
.
initTags
()
this
.
addTags
()
},
methods
:
{
generateTitle
,
// generateTitle by vue-i18n
isActive
(
route
)
{
return
route
.
path
===
this
.
$route
.
path
},
addViewTags
()
{
filterAffixTags
(
routes
,
basePath
=
'
/
'
)
{
let
tags
=
[]
routes
.
forEach
(
route
=>
{
if
(
route
.
meta
&&
route
.
meta
.
affix
)
{
tags
.
push
({
path
:
path
.
resolve
(
basePath
,
route
.
path
),
name
:
route
.
name
,
meta
:
{
...
route
.
meta
}
})
}
if
(
route
.
children
)
{
const
tempTags
=
this
.
filterAffixTags
(
route
.
children
,
route
.
path
)
if
(
tempTags
.
length
>=
1
)
{
tags
=
[...
tags
,
...
tempTags
]
}
}
})
return
tags
},
initTags
()
{
const
affixTags
=
this
.
affixTags
=
this
.
filterAffixTags
(
this
.
routers
)
for
(
const
tag
of
affixTags
)
{
// Must have tag name
if
(
tag
.
name
)
{
this
.
$store
.
dispatch
(
'
addVisitedView
'
,
tag
)
}
}
},
addTags
()
{
const
{
name
}
=
this
.
$route
if
(
name
)
{
this
.
$store
.
dispatch
(
'
addView
'
,
this
.
$route
)
...
...
@@ -101,12 +137,7 @@ export default {
closeSelectedTag
(
view
)
{
this
.
$store
.
dispatch
(
'
delView
'
,
view
).
then
(({
visitedViews
})
=>
{
if
(
this
.
isActive
(
view
))
{
const
latestView
=
visitedViews
.
slice
(
-
1
)[
0
]
if
(
latestView
)
{
this
.
$router
.
push
(
latestView
)
}
else
{
this
.
$router
.
push
(
'
/
'
)
}
this
.
toLastView
(
visitedViews
)
}
})
},
...
...
@@ -116,9 +147,22 @@ export default {
this
.
moveToCurrentTag
()
})
},
closeAllTags
()
{
this
.
$store
.
dispatch
(
'
delAllViews
'
)
this
.
$router
.
push
(
'
/
'
)
closeAllTags
(
view
)
{
this
.
$store
.
dispatch
(
'
delAllViews
'
).
then
(({
visitedViews
})
=>
{
if
(
this
.
affixTags
.
some
(
tag
=>
tag
.
path
===
view
.
path
))
{
return
}
this
.
toLastView
(
visitedViews
)
})
},
toLastView
(
visitedViews
)
{
const
latestView
=
visitedViews
.
slice
(
-
1
)[
0
]
if
(
latestView
)
{
this
.
$router
.
push
(
latestView
)
}
else
{
// You can set another route
this
.
$router
.
push
(
'
/
'
)
}
},
openMenu
(
tag
,
e
)
{
const
menuMinWidth
=
105
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录