bd9d2670782bf204106a939363d556f65a1c21ab.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <global-layout @dynamicRouterShow="dynamicRouterShow">
  3. <!-- update-begin- author:sunjianlei --- date:20191009 --- for: 提升右键菜单的层级 -->
  4. <contextmenu :itemList="menuItemList" :visible.sync="menuVisible" style="z-index: 9999;" @select="onMenuSelect"/>
  5. <!-- update-end- author:sunjianlei --- date:20191009 --- for: 提升右键菜单的层级 -->
  6. <a-tabs
  7. @contextmenu.native="e => onContextmenu(e)"
  8. v-if="multipage"
  9. :active-key="activePage"
  10. class="tab-layout-tabs"
  11. style="height:52px"
  12. :hide-add="true"
  13. type="editable-card"
  14. @change="changePage"
  15. @tabClick="tabCallBack"
  16. @edit="editPage">
  17. <a-tab-pane :id="page.fullPath" :key="page.fullPath" v-for="page in pageList" :closable="!(page.meta.title=='首页')">
  18. <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span>
  19. </a-tab-pane>
  20. </a-tabs>
  21. <div style="padding: 12px 12px 0; height: calc(100vh - 52px - 59px - 21px); overflow-y: auto">
  22. <!-- update-begin-author:taoyan date:20201221 for:此处删掉transition标签 不知道为什么加上后 页面路由切换的时候即1及菜单切到2及菜单的时候 两个菜单页面会同时出现300-500秒左右 -->
  23. <keep-alive v-if="multipage">
  24. <router-view v-if="reloadFlag"/>
  25. </keep-alive>
  26. <template v-else>
  27. <router-view v-if="reloadFlag"/>
  28. </template>
  29. <!-- update-end-author:taoyan date:20201221 for:此处删掉transition标签 不知道为什么加上后 页面路由切换的时候即1及菜单切到2及菜单的时候 两个菜单页面会同时出现300-500秒左右 -->
  30. </div>
  31. </global-layout>
  32. </template>
  33. <script>
  34. import GlobalLayout from '@/components/page/GlobalLayout'
  35. import Contextmenu from '@/components/menu/Contextmenu'
  36. import { mixin, mixinDevice } from '@/utils/mixin.js'
  37. import { triggerWindowResizeEvent } from '@/utils/util'
  38. import Vue from 'vue'
  39. import { CACHE_INCLUDED_ROUTES } from '@/store/mutation-types'
  40. const indexKey = '/dashboard/analysis'
  41. export default {
  42. name: 'TabLayout',
  43. components: {
  44. GlobalLayout,
  45. Contextmenu
  46. },
  47. mixins: [mixin, mixinDevice],
  48. data() {
  49. return {
  50. pageList: [],
  51. linkList: [],
  52. activePage: '',
  53. menuVisible: false,
  54. menuItemList: [
  55. { key: '4', icon: 'reload', text: '刷 新' },
  56. { key: '1', icon: 'arrow-left', text: '关闭左侧' },
  57. { key: '2', icon: 'arrow-right', text: '关闭右侧' },
  58. { key: '3', icon: 'close', text: '关闭其它' }
  59. ],
  60. reloadFlag:true
  61. }
  62. },
  63. /* update_begin author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用 ->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  64. provide(){
  65. return{
  66. closeCurrent:this.closeCurrent
  67. }
  68. },
  69. /* update_end author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  70. computed: {
  71. multipage() {
  72. //判断如果是手机模式,自动切换为单页面模式
  73. if (this.isMobile()) {
  74. return false
  75. } else {
  76. return this.$store.state.app.multipage
  77. }
  78. }
  79. },
  80. created() {
  81. if (this.$route.path != indexKey) {
  82. this.addIndexToFirst()
  83. }
  84. // 复制一个route对象出来,不能影响原route
  85. let currentRoute = Object.assign({}, this.$route)
  86. currentRoute.meta = Object.assign({}, currentRoute.meta)
  87. this.pageList.push(currentRoute)
  88. this.linkList.push(currentRoute.fullPath)
  89. this.activePage = currentRoute.fullPath
  90. },
  91. mounted() {
  92. },
  93. watch: {
  94. '$route': function(newRoute) {
  95. //console.log("新的路由",newRoute)
  96. this.activePage = newRoute.fullPath
  97. if (!this.multipage) {
  98. this.linkList = [newRoute.fullPath]
  99. this.pageList = [Object.assign({},newRoute)]
  100. // update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
  101. } else if(indexKey==newRoute.fullPath) {
  102. //首页时 判断是否缓存 没有缓存 刷新之
  103. if (newRoute.meta.keepAlive === false) {
  104. this.routeReload()
  105. }
  106. // update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
  107. }else if (this.linkList.indexOf(newRoute.fullPath) < 0) {
  108. this.linkList.push(newRoute.fullPath)
  109. this.pageList.push(Object.assign({},newRoute))
  110. //// update-begin-author:sunjianlei date:20200103 for: 如果新增的页面配置了缓存路由,那么就强制刷新一遍 #842
  111. // if (newRoute.meta.keepAlive) {
  112. // this.routeReload()
  113. // }
  114. //// update-end-author:sunjianlei date:20200103 for: 如果新增的页面配置了缓存路由,那么就强制刷新一遍 #842
  115. } else if (this.linkList.indexOf(newRoute.fullPath) >= 0) {
  116. let oldIndex = this.linkList.indexOf(newRoute.fullPath)
  117. let oldPositionRoute = this.pageList[oldIndex]
  118. this.pageList.splice(oldIndex, 1, Object.assign({},newRoute,{meta:oldPositionRoute.meta}))
  119. }
  120. },
  121. 'activePage': function(key) {
  122. let index = this.linkList.lastIndexOf(key)
  123. let waitRouter = this.pageList[index]
  124. // 【TESTA-523】修复:不允许重复跳转路由异常
  125. if (waitRouter.fullPath !== this.$route.fullPath) {
  126. this.$router.push(Object.assign({}, waitRouter))
  127. }
  128. this.changeTitle(waitRouter.meta.title)
  129. },
  130. 'multipage': function(newVal) {
  131. if(this.reloadFlag){
  132. if (!newVal) {
  133. this.linkList = [this.$route.fullPath]
  134. this.pageList = [this.$route]
  135. }
  136. }
  137. },
  138. // update-begin-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  139. device() {
  140. if (this.multipage && this.linkList.indexOf(indexKey) === -1) {
  141. this.addIndexToFirst()
  142. }
  143. },
  144. // update-end-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  145. },
  146. methods: {
  147. // update-begin-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  148. // 将首页添加到第一位
  149. addIndexToFirst() {
  150. this.pageList.splice(0, 0, {
  151. name: 'dashboard-analysis',
  152. path: indexKey,
  153. fullPath: indexKey,
  154. meta: {
  155. icon: 'dashboard',
  156. title: '首页'
  157. }
  158. })
  159. this.linkList.splice(0, 0, indexKey)
  160. },
  161. // update-end-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  162. // update-begin-author:sunjianlei date:20200120 for: 动态更改页面标题
  163. changeTitle(title) {
  164. let projectTitle = "德州市河湖岸线监管"
  165. // 首页特殊处理
  166. if (this.$route.path === indexKey) {
  167. document.title = projectTitle
  168. } else {
  169. document.title = title + ' · ' + projectTitle
  170. }
  171. },
  172. // update-end-author:sunjianlei date:20200120 for: 动态更改页面标题
  173. changePage(key) {
  174. this.activePage = key
  175. },
  176. tabCallBack() {
  177. this.$nextTick(() => {
  178. //update-begin-author:taoyan date: 20201211 for:【新版】online报错 JT-100
  179. setTimeout(()=>{
  180. //省市区组件里面给window绑定了个resize事件 导致切换页面的时候触发了他的resize,但是切换页面,省市区组件还没被销毁前就触发了该事件,导致控制台报错,加个延迟
  181. triggerWindowResizeEvent()
  182. },20)
  183. //update-end-author:taoyan date: 20201211 for:【新版】online报错 JT-100
  184. })
  185. },
  186. editPage(key, action) {
  187. this[action](key)
  188. },
  189. remove(key) {
  190. if (key == indexKey) {
  191. this.$message.warning('首页不能关闭!')
  192. return
  193. }
  194. if (this.pageList.length === 1) {
  195. this.$message.warning('这是最后一页,不能再关闭了啦')
  196. return
  197. }
  198. console.log("this.pageList ",this.pageList );
  199. let removeRoute = this.pageList.filter(item => item.fullPath == key)
  200. this.pageList = this.pageList.filter(item => item.fullPath !== key)
  201. let index = this.linkList.indexOf(key)
  202. this.linkList = this.linkList.filter(item => item !== key)
  203. index = index >= this.linkList.length ? this.linkList.length - 1 : index
  204. this.activePage = this.linkList[index]
  205. //update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
  206. //关闭页面则从缓存cache_included_routes中删除路由,下次点击菜单会重新加载页面
  207. let cacheRouterArray = Vue.ls.get(CACHE_INCLUDED_ROUTES) || []
  208. if (removeRoute && removeRoute[0]) {
  209. let componentName = removeRoute[0].meta.componentName
  210. console.log("key: ", key);
  211. console.log("componentName: ", componentName);
  212. if(cacheRouterArray.includes(componentName)){
  213. cacheRouterArray.splice(cacheRouterArray.findIndex(item => item === componentName), 1)
  214. Vue.ls.set(CACHE_INCLUDED_ROUTES, cacheRouterArray)
  215. }
  216. }
  217. //update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
  218. },
  219. onContextmenu(e) {
  220. const pagekey = this.getPageKey(e.target)
  221. if (pagekey !== null) {
  222. e.preventDefault()
  223. this.menuVisible = true
  224. }
  225. },
  226. getPageKey(target, depth) {
  227. depth = depth || 0
  228. if (depth > 2) {
  229. return null
  230. }
  231. let pageKey = target.getAttribute('pagekey')
  232. pageKey = pageKey || (target.previousElementSibling ? target.previousElementSibling.getAttribute('pagekey') : null)
  233. return pageKey || (target.firstElementChild ? this.getPageKey(target.firstElementChild, ++depth) : null)
  234. },
  235. onMenuSelect(key, target) {
  236. let pageKey = this.getPageKey(target)
  237. switch (key) {
  238. case '1':
  239. this.closeLeft(pageKey)
  240. break
  241. case '2':
  242. this.closeRight(pageKey)
  243. break
  244. case '3':
  245. this.closeOthers(pageKey)
  246. break
  247. case '4':
  248. this.routeReload()
  249. break
  250. default:
  251. break
  252. }
  253. },
  254. /* update_begin author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  255. closeCurrent(){
  256. this.remove(this.activePage);
  257. },
  258. /* update_end author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  259. closeOthers(pageKey) {
  260. let index = this.linkList.indexOf(pageKey)
  261. if (pageKey == indexKey || pageKey.indexOf('?ticke=')>=0) {
  262. this.linkList = this.linkList.slice(index, index + 1)
  263. this.pageList = this.pageList.slice(index, index + 1)
  264. this.activePage = this.linkList[0]
  265. } else {
  266. let indexContent = this.pageList.slice(0, 1)[0]
  267. this.linkList = this.linkList.slice(index, index + 1)
  268. this.pageList = this.pageList.slice(index, index + 1)
  269. this.linkList.unshift(indexContent.fullPath)
  270. this.pageList.unshift(indexContent)
  271. this.activePage = this.linkList[1]
  272. }
  273. },
  274. closeLeft(pageKey) {
  275. if (pageKey == indexKey) {
  276. return
  277. }
  278. let tempList = [...this.pageList]
  279. let indexContent = tempList.slice(0, 1)[0]
  280. let index = this.linkList.indexOf(pageKey)
  281. this.linkList = this.linkList.slice(index)
  282. this.pageList = this.pageList.slice(index)
  283. this.linkList.unshift(indexContent.fullPath)
  284. this.pageList.unshift(indexContent)
  285. if (this.linkList.indexOf(this.activePage) < 0) {
  286. this.activePage = this.linkList[0]
  287. }
  288. },
  289. closeRight(pageKey) {
  290. let index = this.linkList.indexOf(pageKey)
  291. this.linkList = this.linkList.slice(0, index + 1)
  292. this.pageList = this.pageList.slice(0, index + 1)
  293. if (this.linkList.indexOf(this.activePage < 0)) {
  294. this.activePage = this.linkList[this.linkList.length - 1]
  295. }
  296. },
  297. //update-begin-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
  298. dynamicRouterShow(key,title){
  299. let keyIndex = this.linkList.indexOf(key)
  300. if(keyIndex>=0){
  301. let currRouter = this.pageList[keyIndex]
  302. let meta = Object.assign({},currRouter.meta,{title:title})
  303. this.pageList.splice(keyIndex, 1, Object.assign({},currRouter,{meta:meta}))
  304. if (key === this.activePage) {
  305. this.changeTitle(title)
  306. }
  307. }
  308. },
  309. //update-end-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
  310. //update-begin-author:taoyan date:20191008 for:路由刷新
  311. routeReload(){
  312. this.reloadFlag = false
  313. let ToggleMultipage = "ToggleMultipage"
  314. this.$store.dispatch(ToggleMultipage,false)
  315. this.$nextTick(()=>{
  316. this.$store.dispatch(ToggleMultipage,true)
  317. this.reloadFlag = true
  318. })
  319. },
  320. //update-end-author:taoyan date:20191008 for:路由刷新
  321. //新增一个返回方法
  322. excuteCallback(callback){
  323. callback()
  324. },
  325. }
  326. }
  327. </script>
  328. <style lang="less">
  329. /*
  330. * The following styles are auto-applied to elements with
  331. * transition="page-transition" when their visibility is toggled
  332. * by Vue.js.
  333. *
  334. * You can easily play with the page transition by editing
  335. * these styles.
  336. */
  337. .page-transition-enter {
  338. opacity: 0;
  339. }
  340. .page-transition-leave-active {
  341. opacity: 0;
  342. }
  343. .page-transition-enter .page-transition-container,
  344. .page-transition-leave-active .page-transition-container {
  345. -webkit-transform: scale(1.1);
  346. transform: scale(1.1);
  347. }
  348. /*美化弹出Tab样式*/
  349. .ant-tabs-nav-container {
  350. margin-top: 4px;
  351. }
  352. /* 修改 ant-tabs 样式 */
  353. .tab-layout-tabs.ant-tabs {
  354. border-bottom: 1px solid #ccc;
  355. border-left: 1px solid #ccc;
  356. background-color: white;
  357. padding: 0 20px;
  358. .ant-tabs-bar {
  359. margin: 4px 0 0;
  360. border: none;
  361. }
  362. }
  363. .tab-layout-tabs.ant-tabs {
  364. &.ant-tabs-card .ant-tabs-tab {
  365. padding: 0 24px !important;
  366. background-color: white !important;
  367. margin-right: 10px !important;
  368. .ant-tabs-close-x {
  369. width: 12px !important;
  370. height: 12px !important;
  371. opacity: 0 !important;
  372. cursor: pointer !important;
  373. font-size: 12px !important;
  374. margin: 0 !important;
  375. position: absolute;
  376. top: 36%;
  377. right: 6px;
  378. }
  379. &:hover .ant-tabs-close-x {
  380. opacity: 1 !important;
  381. }
  382. }
  383. }
  384. .tab-layout-tabs.ant-tabs.ant-tabs-card > .ant-tabs-bar {
  385. .ant-tabs-tab {
  386. border: none !important;
  387. border-bottom: 1px solid transparent !important;
  388. }
  389. .ant-tabs-tab-active {
  390. border-color: @primary-color!important;
  391. }
  392. }
  393. </style>