123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <template>
- <div class="tags-view-container">
- <!-- <scroll-pane class='tags-view-wrapper' ref='scrollPane'>
- <router-link
- ref='tag'
- class="tags-view-item"
- :class="isActive(tag)?'active':''"
- v-for="tag in Array.from(visitedViews)"
- :to="tag"
- :key="tag.path"
- @contextmenu.prevent.native="openMenu(tag,$event)">
- {{generateTitle(tag.title)}}
- <span class='el-icon-close' @click.prevent.stop='closeSelectedTag(tag)'></span>
- </router-link>
- </scroll-pane>
- <ul class='contextmenu' v-show="visible" :style="{left:left+'px',top:top+'px'}">
- <li @click="closeSelectedTag(selectedTag)">{{$t('tagsView.close')}}</li>
- <li @click="closeOthersTags">{{$t('tagsView.closeOthers')}}</li>
- <li @click="closeAllTags">{{$t('tagsView.closeAll')}}</li>
- </ul> -->
- <div class="tags-view-wrapper">
- <div class="tagsBox">
- <div class="tagsOne"
- v-if="permission_routers[newIndex].meta"
- v-for="(item, i) in permission_routers[newIndex].children"
- :key="i"
- >
- <router-link :to="item.path" v-if="!item.hidden && !item.is_menu">
- <p
- class="newTags"
- :class="activeClass == i ? 'active' : ''"
- @click="onClick(i)"
- >{{ generateTitle(item.meta.title) }}</p>
- </router-link>
- </div>
- <div v-else class="tagsOne">
- <p class="newTags" :class="activeClass == i ? 'active' : ''" @click="onClick(i)">
- {{
- generateTitle(permission_routers[newIndex].children[0].meta.title)
- }}
- </p>
- </div>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import ScrollPane from '@/components/ScrollPane'
- import { generateTitle } from '@/utils/i18n'
-
- import { mapGetters } from "vuex";
-
- export default {
- components: { ScrollPane },
- props: {
- index: Number,
- },
- data() {
- return {
- visible: false,
- top: 0,
- left: 0,
- selectedTag: {},
- newIndex: 0,
- activeClass: 0,
- }
- },
- computed: {
- // visitedViews() {
- // return this.$store.state.tagsView.visitedViews
- // },
- ...mapGetters(["permission_routers"])
- },
- watch: {
- // $route() {
- // this.addViewTags()
- // this.moveToCurrentTag()
- // },
- // visible(value) {
- // if (value) {
- // document.body.addEventListener('click', this.closeMenu)
- // } else {
- // document.body.removeEventListener('click', this.closeMenu)
- // }
- // }
- index(newVal) {
- console.log(newVal)
- // if (this.newIndex != newVal) {
- // this.activeClass = 0;
- // }
- this.newIndex = newVal;
- },
- },
- created(){
- console.log(this.permission_routers)
- this.newIndex = 3
- },
- mounted() {
- this.addViewTags()
- },
- methods: {
- generateTitle, // generateTitle by vue-i18n
- generateRoute() {
- if (this.$route.name) {
- return this.$route
- }
- return false
- },
- isActive(route) {
- return route.path === this.$route.path
- },
- addViewTags() {
- const route = this.generateRoute()
- if (!route) {
- return false
- }
- this.$store.dispatch('addVisitedViews', route)
- },
- moveToCurrentTag() {
- const tags = this.$refs.tag
- this.$nextTick(() => {
- for (const tag of tags) {
- if (tag.to.path === this.$route.path) {
- this.$refs.scrollPane.moveToTarget(tag.$el)
- break
- }
- }
- })
- },
- closeSelectedTag(view) {
- this.$store.dispatch('delVisitedViews', view).then((views) => {
- if (this.isActive(view)) {
- const latestView = views.slice(-1)[0]
- if (latestView) {
- this.$router.push(latestView)
- } else {
- this.$router.push('/')
- }
- }
- })
- },
- closeOthersTags() {
- this.$router.push(this.selectedTag)
- this.$store.dispatch('delOthersViews', this.selectedTag).then(() => {
- this.moveToCurrentTag()
- })
- },
- closeAllTags() {
- this.$store.dispatch('delAllViews')
- this.$router.push('/')
- },
- openMenu(tag, e) {
- this.visible = true
- this.selectedTag = tag
- const offsetLeft = this.$el.getBoundingClientRect().left // container margin left
- this.left = e.clientX - offsetLeft + 15 // 15: margin right
- this.top = e.clientY
- },
- closeMenu() {
- this.visible = false
- },
- onClick(index) {
- // console.log(index);
- this.activeClass = index;
- },
- }
- }
- </script>
-
- <style rel="stylesheet/scss" lang="scss" scoped>
- .tags-view-container {
- height: 60px;
- .tags-view-wrapper {
- width: 100%;
- background: #fff;
- height: 50px;
- border-bottom: 1px solid #d8dce5;
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .12), 0 0 3px 0 rgba(0, 0, 0, .04);
- position: fixed;
- z-index: 1000;
- top: 50px;
- overflow-x: scroll;
- /* 针对缺省样式 (必须的) */
- &::-webkit-scrollbar {
- width: 6px;
- height: 2px;
- }
- /* 滚动条的滑轨背景颜色 */
- &::-webkit-scrollbar-track {
- background-color: #fff;
- border-radius: 3px;
- -moz-border-radius: 3px;
- -webkit-border-radius: 3px;
- }
- /* 滑块颜色 */
- &::-webkit-scrollbar-thumb {
- background: #fff;
- border-radius: 3px;
- -moz-border-radius: 3px;
- -webkit-border-radius: 3px;
- }
- /*内层轨道的颜色*/
- &::-webkit-scrollbar-track-piece {
- background-color: #fff;
- border-radius: 3px;
- -moz-border-radius: 3px;
- -webkit-border-radius: 3px;
- }
- /* 滑轨两头的监听按钮颜色 */
- &::-webkit-scrollbar-button {
- background-color: #fff;
- width: 0;
- height: 0;
- }
- /* 横向滚动条和纵向滚动条相交处尖角的颜色 */
- &::-webkit-scrollbar-corner {
- background-color: #fff;
- }
- .tags-view-item {
- display: inline-block;
- position: relative;
- border: 1px solid #d8dce5;
- color: #495060;
- background: #fff;
- padding: 0 4px 0 8px;
- font-size: 12px;
- margin: 12px 0 12px 5px;
- border-radius: 4px;
- height: 28px;
- line-height: 28px;
- &:first-of-type {
- margin-left: 15px;
- }
- &.active {
- background-color: #409efe;
- color: #fff;
- border-color: #409efe;
- &::before {
- content: '';
- background: #fff;
- display: inline-block;
- width: 8px;
- height: 8px;
- border-radius: 50%;
- position: relative;
- margin-right: 2px;
- }
- }
- }
- }
- .contextmenu {
- margin: 0;
- background: #fff;
- z-index: 100;
- position: absolute;
- list-style-type: none;
- padding: 5px 0;
- border-radius: 4px;
- font-size: 12px;
- font-weight: 400;
- color: #333;
- box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, .3);
- li {
- margin: 0;
- padding: 7px 16px;
- cursor: pointer;
- &:hover {
- background: #eee;
- }
- }
- }
- .tagsBox {
- display: flex;
- align-items: center;
- height: 100%;
- .tagsOne {
- .newTags {
- border: 1px solid rgba(235, 238, 240, 1);
- border-radius: 2px;
- padding: 8px 12px;
- margin-left: 10px;
- font-size: 14px;
- }
- }
- .active {
- border: 1px solid rgba(64, 158, 255, 1);
- background: rgba(64, 158, 255, 1);
- border-radius: 2px;
- color: #fff;
- }
- }
- }
- </style>
-
- <style rel="stylesheet/scss" lang="scss">
- //reset element css of el-icon-close
- .tags-view-wrapper {
- .tags-view-item {
- .el-icon-close {
- width: 16px;
- height: 16px;
- vertical-align: 2px;
- border-radius: 50%;
- text-align: center;
- transition: all .3s cubic-bezier(.645, .045, .355, 1);
- transform-origin: 100% 50%;
- &:before {
- transform: scale(.6);
- display: inline-block;
- vertical-align: -3px;
- }
- &:hover {
- background-color: #b4bccc;
- color: #fff;
- }
- }
- }
- }
- </style>
|