|
|
@ -8,36 +8,99 @@ |
|
|
|
<!-- 不要缓存,即切换tab页就刷新 --> |
|
|
|
<router-view v-if="$route.meta.keepAlive" :key="key" /> |
|
|
|
</transition> |
|
|
|
<!--iframe页--> |
|
|
|
<!-- <component |
|
|
|
v-for="item in hasOpenComponentsArr" |
|
|
|
:key="item.path" |
|
|
|
:is="item.name" |
|
|
|
v-show="$route.path.indexOf(item.path) > -1" |
|
|
|
></component> --> |
|
|
|
</section> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
// import Vue from 'vue' |
|
|
|
import Bus from '../Bus.js'; |
|
|
|
export default { |
|
|
|
name: "AppMain", |
|
|
|
// data() { |
|
|
|
// return { |
|
|
|
// componentsArr: [] |
|
|
|
// } |
|
|
|
// }, |
|
|
|
computed: { |
|
|
|
cachedViews() { |
|
|
|
return this.$store.state.tagsView.cachedViews; |
|
|
|
}, |
|
|
|
key() { |
|
|
|
return this.$route.fullPath; |
|
|
|
} |
|
|
|
}, |
|
|
|
// 实现懒加载,只渲染已经打开过(hasOpen:true)的iframe页 |
|
|
|
// hasOpenComponentsArr() { |
|
|
|
// return this.componentsArr.filter(item => { |
|
|
|
// return item.hasOpen |
|
|
|
// }); |
|
|
|
// } |
|
|
|
}, |
|
|
|
// watch: { |
|
|
|
// $route() { |
|
|
|
// // 判断当前路由是否iframe页 |
|
|
|
// this.isOpenIframePage(); |
|
|
|
// } |
|
|
|
// }, |
|
|
|
mounted() { |
|
|
|
// 设置iframe页的数组对象 |
|
|
|
// setTimeout(() => { |
|
|
|
// const componentsArr = this.getComponentsArr(); |
|
|
|
// componentsArr.forEach((item) => { |
|
|
|
// Vue.component(item.name, item.component); |
|
|
|
// }); |
|
|
|
// this.componentsArr = componentsArr; |
|
|
|
// // 判断当前路由是否iframe页 |
|
|
|
// this.isOpenIframePage(); |
|
|
|
// }, 1000) |
|
|
|
|
|
|
|
// 关闭标签触发 |
|
|
|
Bus.$on('removeCache', (name, view) => { |
|
|
|
this.removeCache(name, view); |
|
|
|
}); |
|
|
|
//刷新标签触发 |
|
|
|
Bus.$on('removeRedirect', (name, view) => { |
|
|
|
this.removeRedirect(name, view); |
|
|
|
}) |
|
|
|
//刷新标签触发 |
|
|
|
Bus.$on('removeRedirect', (name, view) => { |
|
|
|
this.removeRedirect(name, view); |
|
|
|
}) |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
Bus.$off('removeCache'); |
|
|
|
Bus.$off('removeRedirect'); |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
Bus.$off('removeCache'); |
|
|
|
Bus.$off('removeRedirect'); |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
// iframe 页面 缓存处理-----------------start |
|
|
|
// 根据当前路由设置hasOpen |
|
|
|
// isOpenIframePage() { |
|
|
|
// const target = this.componentsArr.find(item => { |
|
|
|
// return this.$route.path.indexOf(item.path) > -1 |
|
|
|
// }); |
|
|
|
// if (target && !target.hasOpen) { |
|
|
|
// target.hasOpen = true; |
|
|
|
// } |
|
|
|
// }, |
|
|
|
// // 遍历路由的所有页面,把含有iframeComponent标识的收集起来 |
|
|
|
// getComponentsArr() { |
|
|
|
// const activeReportManage = this.$store.getters.permission_routes.find(item => item.path == '/activeReportManage') |
|
|
|
// console.log('permission_routes', this.$store.getters.permission_routes) |
|
|
|
// console.log('activeReportManage', activeReportManage) |
|
|
|
// const reportForm = activeReportManage.children.find(item => item.path == 'reportForm').children |
|
|
|
// console.log('reportForm', reportForm) |
|
|
|
// // const reportForm = this.$store.getters.permission_routes.find(item => item.path == '/activeReportManage').children.find(item => item.path == 'reportForm').children |
|
|
|
// const iframeArr = [] |
|
|
|
// reportForm.forEach(item => { |
|
|
|
// item.component = item.iframeComponent |
|
|
|
// iframeArr.push(item) |
|
|
|
// }) |
|
|
|
// return iframeArr |
|
|
|
// }, |
|
|
|
// iframe 页面 缓存处理-----------------end |
|
|
|
|
|
|
|
// 获取有keep-alive子节点的Vnode |
|
|
|
getVnode() { |
|
|
|
// 判断子集非空 |
|
|
@ -52,14 +115,14 @@ export default { |
|
|
|
} |
|
|
|
return vnode ? vnode : false; |
|
|
|
}, |
|
|
|
//移除redirect组件缓存 |
|
|
|
removeRedirect(view={}){ |
|
|
|
const viewNew = { |
|
|
|
fullPath:`/redirect${view.fullPath}`, |
|
|
|
path:`/redirect${view.path}` |
|
|
|
} |
|
|
|
this.removeCache('closeSelectedTag',viewNew); |
|
|
|
}, |
|
|
|
//移除redirect组件缓存 |
|
|
|
removeRedirect(view={}){ |
|
|
|
const viewNew = { |
|
|
|
fullPath:`/redirect${view.fullPath}`, |
|
|
|
path:`/redirect${view.path}` |
|
|
|
} |
|
|
|
this.removeCache('closeSelectedTag',viewNew); |
|
|
|
}, |
|
|
|
// 移除keep-alive缓存 |
|
|
|
removeCache(name, view = {}) { |
|
|
|
let vnode = this.getVnode(); |
|
|
@ -69,7 +132,6 @@ export default { |
|
|
|
let keyStart = vnode.key.split('/')[0]; |
|
|
|
let thisKey = `${keyStart}${view.fullPath}`; |
|
|
|
let regKey = `${keyStart}${view.path}`; |
|
|
|
|
|
|
|
this[name]({ componentInstance, thisKey, regKey }); |
|
|
|
}, |
|
|
|
// 移除其他 |
|
|
|