| | |
| | | <span v-if="!isAffix(tag)" 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)">刷新</li>--> |
| | | <!-- <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">关闭</li>--> |
| | | <!-- <li @click="closeOthersTags">关闭其他</li>--> |
| | | <!-- <li @click="closeAllTags(selectedTag)">关闭所有</li>--> |
| | | <!-- </ul>--> |
| | | <ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu"> |
| | | <li @click="refreshSelectedTag(selectedTag)">刷新</li> |
| | | <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">关闭</li> |
| | | <li @click="closeOthersTags">关闭其他</li> |
| | | <li @click="closeAllTags(selectedTag)">关闭所有</li> |
| | | </ul> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import ScrollPane from './ScrollPane' |
| | | import path from 'path' |
| | | import { getCookie } from '@/utils/auth' |
| | | |
| | | export default { |
| | | components: { ScrollPane }, |
| | |
| | | mounted() { |
| | | this.initTags() |
| | | this.addTags() |
| | | this.beforeUnload() |
| | | }, |
| | | methods: { |
| | | // 解决 vue-admin-template 刷新页面 TagsView 丢失问题 |
| | | beforeUnload() { |
| | | // 监听页面刷新 |
| | | window.addEventListener('beforeunload', () => { |
| | | // visitedViews数据结构太复杂无法直接JSON.stringify处理,先转换需要的数据 |
| | | const tabViews = this.visitedViews.map(item => { |
| | | return { |
| | | fullPath: item.fullPath, |
| | | hash: item.hash, |
| | | meta: { ...item.meta }, |
| | | name: item.name, |
| | | params: { ...item.params }, |
| | | path: item.path, |
| | | query: { ...item.query }, |
| | | title: item.title |
| | | } |
| | | }) |
| | | sessionStorage.setItem('tabViews', JSON.stringify(tabViews)) |
| | | }) |
| | | |
| | | // 页面初始化加载判断缓存中是否有数据 |
| | | const oldViews = JSON.parse(sessionStorage.getItem('tabViews')) || [] |
| | | if (oldViews.length > 0) { |
| | | this.$store.state.tagsView.visitedViews = oldViews |
| | | } |
| | | }, |
| | | isActive(route) { |
| | | return route.path === this.$route.path |
| | | }, |