TabLayout.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <global-layout @dynamicRouterShow="dynamicRouterShow" @removeTab="remove">
  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 @contextmenu.native="e => onContextmenu(e)" v-if="multipage" :active-key="activePage"
  7. class="tab-layout-tabs" style="height:52px" :hide-add="true" type="editable-card" @change="changePage"
  8. @tabClick="tabCallBack" @edit="editPage">
  9. <a-tab-pane :id="page.fullPath" :key="page.fullPath" v-for="page in pageList">
  10. <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span>
  11. </a-tab-pane>
  12. </a-tabs>
  13. <div style="margin: 12px 12px 0;">
  14. <transition name="page-toggle">
  15. <keep-alive v-if="multipage">
  16. <router-view v-if="reloadFlag" @removeTab="remove" />
  17. </keep-alive>
  18. <template v-else>
  19. <router-view v-if="reloadFlag" @removeTab="remove" />
  20. </template>
  21. </transition>
  22. </div>
  23. </global-layout>
  24. </template>
  25. <script>
  26. import { mapActions } from 'vuex'
  27. import GlobalLayout from '@/components/page/GlobalLayout'
  28. import Contextmenu from '@/components/menu/Contextmenu'
  29. import {
  30. mixin,
  31. mixinDevice
  32. } from '@/utils/mixin.js'
  33. import {
  34. triggerWindowResizeEvent
  35. } from '@/utils/util'
  36. const indexKey = '/dashboard/analysis'
  37. export default {
  38. name: 'TabLayout',
  39. components: {
  40. GlobalLayout,
  41. Contextmenu
  42. },
  43. mixins: [mixin, mixinDevice],
  44. data() {
  45. return {
  46. pageList: [],
  47. linkList: [],
  48. activePage: '',
  49. menuVisible: false,
  50. menuItemList: [{
  51. key: '4',
  52. icon: 'reload',
  53. text: '刷 新'
  54. },
  55. {
  56. key: '1',
  57. icon: 'arrow-left',
  58. text: '关闭左侧'
  59. },
  60. {
  61. key: '2',
  62. icon: 'arrow-right',
  63. text: '关闭右侧'
  64. },
  65. {
  66. key: '3',
  67. icon: 'close',
  68. text: '关闭其它'
  69. }
  70. ],
  71. reloadFlag: true
  72. }
  73. },
  74. /* update_begin author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用 ->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  75. provide() {
  76. return {
  77. closeCurrent: this.closeCurrent
  78. }
  79. },
  80. /* update_end author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  81. computed: {
  82. multipage() {
  83. //判断如果是手机模式,自动切换为单页面模式
  84. if (this.isMobile()) {
  85. return false
  86. } else {
  87. return this.$store.state.app.multipage
  88. }
  89. }
  90. },
  91. created() {
  92. this.$bus.$on('remove', this.remove)
  93. if (this.$route.path != indexKey) {
  94. this.addIndexToFirst()
  95. }
  96. // update-begin-author:sunjianlei date:20191223 for: 修复刷新后菜单Tab名字显示异常
  97. let storeKey = 'route:title:' + this.$route.fullPath
  98. let routeTitle = this.$ls.get(storeKey)
  99. if (routeTitle) {
  100. this.$route.meta.title = routeTitle
  101. }
  102. // update-end-author:sunjianlei date:20191223 for: 修复刷新后菜单Tab名字显示异常
  103. this.pageList.push(this.$route)
  104. this.linkList.push(this.$route.fullPath)
  105. this.activePage = this.$route.fullPath
  106. if (!this.linkList.includes("/account/stepForm")) {
  107. localStorage.removeItem("step")
  108. localStorage.removeItem("campaignId")
  109. localStorage.removeItem("pans")
  110. localStorage.removeItem("pansKey")
  111. localStorage.removeItem("appId")
  112. }
  113. if (!this.linkList.includes("/account/advertisingGroup") && !this.linkList.includes("/account/stepForm")) {
  114. localStorage.removeItem("advertisingGroup")
  115. localStorage.removeItem("advertisingGroupKey")
  116. }
  117. if (!this.linkList.includes("/crossAccount/createCreative")) {
  118. localStorage.removeItem("crossAccountUnit")
  119. }
  120. if (!this.linkList.includes("/crossAccount/createUnit")) {
  121. localStorage.removeItem("crossAccountCampaign")
  122. }
  123. },
  124. watch: {
  125. '$route': function (newRoute) {
  126. //console.log("新的路由",newRoute)
  127. this.activePage = newRoute.fullPath
  128. if (!this.multipage) {
  129. this.linkList = [newRoute.fullPath]
  130. this.pageList = [Object.assign({}, newRoute)]
  131. // update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
  132. } else if (indexKey == newRoute.fullPath) {
  133. //首页时 判断是否缓存 没有缓存 刷新之
  134. if (newRoute.meta.keepAlive === false) {
  135. this.routeReload()
  136. }
  137. // update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
  138. } else if (this.linkList.indexOf(newRoute.fullPath) < 0) {
  139. this.linkList.push(newRoute.fullPath)
  140. this.pageList.push(Object.assign({}, newRoute))
  141. // update-begin-author:sunjianlei date:20200103 for: 如果新增的页面配置了缓存路由,那么就强制刷新一遍
  142. // if (newRoute.meta.keepAlive) {
  143. // this.routeReload()
  144. // }
  145. // update-end-author:sunjianlei date:20200103 for: 如果新增的页面配置了缓存路由,那么就强制刷新一遍
  146. } else if (this.linkList.indexOf(newRoute.fullPath) >= 0) {
  147. let oldIndex = this.linkList.indexOf(newRoute.fullPath)
  148. let oldPositionRoute = this.pageList[oldIndex]
  149. this.pageList.splice(oldIndex, 1, Object.assign({}, newRoute, {
  150. meta: oldPositionRoute.meta
  151. }))
  152. }
  153. if (!this.linkList.includes("/account/stepForm")) {
  154. localStorage.removeItem("step")
  155. localStorage.removeItem("campaignId")
  156. localStorage.removeItem("pans")
  157. localStorage.removeItem("pansKey")
  158. localStorage.removeItem("appId")
  159. }
  160. if (!this.linkList.includes("/account/advertisingGroup") && !this.linkList.includes("/account/stepForm")) {
  161. localStorage.removeItem("advertisingGroup")
  162. localStorage.removeItem("advertisingGroupKey")
  163. }
  164. if (!this.linkList.includes("/account/originality") && !this.linkList.includes("/account/stepForm")) {
  165. localStorage.removeItem("originality")
  166. localStorage.removeItem("originalityKey")
  167. }
  168. if (!this.linkList.includes("/crossAccount/createCreative")) {
  169. localStorage.removeItem("crossAccountUnit")
  170. }
  171. if (!this.linkList.includes("/crossAccount/createUnit")) {
  172. localStorage.removeItem("crossAccountCampaign")
  173. }
  174. },
  175. 'activePage': function (key) {
  176. let index = this.linkList.lastIndexOf(key)
  177. let waitRouter = this.pageList[index]
  178. this.$router.push(Object.assign({}, waitRouter));
  179. // this.changeTitle(waitRouter.meta.title)
  180. if(key!='/material/musicMaterial'){
  181. this.clearPlayList()
  182. }
  183. },
  184. 'multipage': function (newVal) {
  185. if (this.reloadFlag) {
  186. if (!newVal) {
  187. this.linkList = [this.$route.fullPath]
  188. this.pageList = [this.$route]
  189. }
  190. }
  191. },
  192. // update-begin-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  193. device() {
  194. if (this.multipage && this.linkList.indexOf(indexKey) === -1) {
  195. this.addIndexToFirst()
  196. }
  197. },
  198. // update-end-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  199. },
  200. methods: {
  201. ...mapActions([ 'clearPlayList']),
  202. // update-begin-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  203. // 将首页添加到第一位
  204. addIndexToFirst() {
  205. this.pageList.splice(0, 0, {
  206. name: 'dashboard-analysis',
  207. path: indexKey,
  208. fullPath: indexKey,
  209. meta: {
  210. icon: 'dashboard',
  211. title: '首页'
  212. }
  213. })
  214. this.linkList.splice(0, 0, indexKey)
  215. },
  216. // update-end-author:sunjianlei date:20191223 for: 修复从单页模式切换回多页模式后首页不居第一位的 BUG
  217. // update-begin-author:sunjianlei date:20200120 for: 动态更改页面标题
  218. changeTitle(title) {
  219. // let projectTitle = "Jeecg-Boot 企业级快速开发平台"
  220. // 首页特殊处理
  221. // if (this.$route.path === indexKey) {
  222. // document.title = projectTitle
  223. // } else {
  224. // document.title = title + ' · ' + projectTitle
  225. // }
  226. },
  227. // update-end-author:sunjianlei date:20200120 for: 动态更改页面标题
  228. changePage(key) {
  229. this.activePage = key
  230. },
  231. tabCallBack() {
  232. this.$nextTick(() => {
  233. triggerWindowResizeEvent()
  234. })
  235. },
  236. editPage(key, action) {
  237. this[action](key)
  238. },
  239. remove(key) {
  240. if (key == indexKey) {
  241. this.$message.warning('首页不能关闭!')
  242. return
  243. }
  244. if (this.pageList.length === 1) {
  245. this.$message.warning('这是最后一页,不能再关闭了啦')
  246. return
  247. }
  248. // console.log("this.pageList ", this.pageList);
  249. // this.pageList = this.pageList.filter(item => item.fullPath !== key)
  250. // let index = this.linkList.indexOf(key)
  251. // this.linkList = this.linkList.filter(item => item !== key)
  252. // index = index >= this.linkList.length ? this.linkList.length - 1 : index
  253. // this.activePage = this.linkList[index]
  254. if (key == "/account/advertisingGroup") {
  255. if (this.linkList.includes("/account/stepForm") || this.linkList.includes("/account/originality")) {
  256. this.$message.error('已开启创意或创建页面,不可关闭组页面')
  257. return
  258. } else {
  259. localStorage.removeItem("advertisingGroup")
  260. localStorage.removeItem("advertisingGroupKey")
  261. }
  262. }
  263. if (key == "/account/stepForm") {
  264. localStorage.removeItem("step")
  265. localStorage.removeItem("pans")
  266. localStorage.removeItem("pansKey")
  267. }
  268. if (key == "/account/originality") {
  269. localStorage.removeItem("originality")
  270. localStorage.removeItem("originalityKey")
  271. }
  272. if (key == "/modules/material/materialList") {
  273. localStorage.removeItem("key")
  274. }
  275. if (key == "/account/accountIndex") {
  276. if (this.linkList.includes("/account/stepForm") || this.linkList.includes("/account/originality") || this
  277. .linkList.includes("/account/advertisingGroup")) {
  278. this.$message.error('正在操作,不可关闭计划列表')
  279. return
  280. } else {
  281. this.routeReload()
  282. }
  283. }
  284. if (key == '/modules/BatchCreate/TouTiaoBatch' && !(this.linkList.includes('/modules/BatchCreate/newCreate') ||
  285. this.linkList.includes('/modules/BatchCreate/newPlan') || this.linkList.includes(
  286. '/modules/BatchCreate/newGroup'))) {
  287. localStorage.setItem('accountInfo', '')
  288. localStorage.setItem("groupInfo", '')
  289. localStorage.setItem("planInfo", '')
  290. }
  291. // if(!this.linkList.includes('/modules/BatchCreate/newGroup')&&!this.linkList.includes('/modules/BatchCreate/newPlan')&&!this.linkList.includes('/modules/BatchCreate/newCreate')){
  292. // localStorage.setItem("planInfo",'')
  293. // localStorage.setItem("groupInfo",'')
  294. // }
  295. if (key == '/modules/BatchCreate/newGroup' && !(this.linkList.includes('/modules/BatchCreate/newCreate') || this
  296. .linkList.includes('/modules/BatchCreate/newPlan') || this.linkList.includes(
  297. '/modules/BatchCreate/TouTiaoBatch'))) {
  298. // console.log('newGroup')
  299. localStorage.setItem('accountInfo', '')
  300. localStorage.setItem("groupInfo", '')
  301. }
  302. if (key == '/modules/BatchCreate/newPlan' && !(this.linkList.includes('/modules/BatchCreate/newCreate') || this
  303. .linkList.includes('/modules/BatchCreate/newGroup') || this.linkList.includes(
  304. '/modules/BatchCreate/TouTiaoBatch'))) {
  305. // console.log('newPlan')
  306. localStorage.setItem('accountInfo', '')
  307. localStorage.setItem("groupInfo", '')
  308. localStorage.setItem("planInfo", '')
  309. }
  310. if (key == '/modules/BatchCreate/newCreate' && !(this.linkList.includes('/modules/BatchCreate/TouTiaoBatch') ||
  311. this.linkList.includes('/modules/BatchCreate/newPlan') || this.linkList.includes(
  312. '/modules/BatchCreate/newGroup'))) {
  313. // console.log('newCreate')
  314. localStorage.setItem('accountInfo', '')
  315. localStorage.setItem("groupInfo", '')
  316. localStorage.setItem("planInfo", '')
  317. }
  318. // this.pageList = this.pageList.filter(item => item.fullPath !== key)
  319. // let index = this.linkList.indexOf(key)
  320. // this.linkList = this.linkList.filter(item => item !== key)
  321. // index = index >= this.linkList.length ? this.linkList.length - 1 : index
  322. // this.activePage = this.linkList[index]
  323. this.pageList = this.pageList.filter(item => item.fullPath !== key)
  324. let index = this.linkList.indexOf(key)
  325. this.linkList = this.linkList.filter(item => item !== key)
  326. index = index >= this.linkList.length ? this.linkList.length - 1 : index
  327. if (index != -1) {
  328. this.activePage = this.linkList[index]
  329. } else {
  330. this.activePage = this.$route.fullPath
  331. }
  332. },
  333. onContextmenu(e) {
  334. const pagekey = this.getPageKey(e.target)
  335. if (pagekey !== null) {
  336. e.preventDefault()
  337. this.menuVisible = true
  338. }
  339. },
  340. getPageKey(target, depth) {
  341. depth = depth || 0
  342. if (depth > 2) {
  343. return null
  344. }
  345. let pageKey = target.getAttribute('pagekey')
  346. pageKey = pageKey || (target.previousElementSibling ? target.previousElementSibling.getAttribute('pagekey') :
  347. null)
  348. return pageKey || (target.firstElementChild ? this.getPageKey(target.firstElementChild, ++depth) : null)
  349. },
  350. onMenuSelect(key, target) {
  351. let pageKey = this.getPageKey(target)
  352. switch (key) {
  353. case '1':
  354. this.closeLeft(pageKey)
  355. break
  356. case '2':
  357. this.closeRight(pageKey)
  358. break
  359. case '3':
  360. this.closeOthers(pageKey)
  361. break
  362. case '4':
  363. this.routeReload()
  364. break
  365. default:
  366. break
  367. }
  368. },
  369. /* update_begin author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  370. closeCurrent() {
  371. this.remove(this.activePage);
  372. },
  373. /* update_end author:wuxianquan date:20190828 for: 关闭当前tab页,供子页面调用->望菜单能配置外链,直接弹出新页面而不是嵌入iframe #428 */
  374. closeOthers(pageKey) {
  375. let index = this.linkList.indexOf(pageKey)
  376. if (pageKey == indexKey || pageKey.indexOf('?ticke=') >= 0) {
  377. this.linkList = this.linkList.slice(index, index + 1)
  378. this.pageList = this.pageList.slice(index, index + 1)
  379. this.activePage = this.linkList[0]
  380. } else {
  381. let indexContent = this.pageList.slice(0, 1)[0]
  382. this.linkList = this.linkList.slice(index, index + 1)
  383. this.pageList = this.pageList.slice(index, index + 1)
  384. this.linkList.unshift(indexContent.fullPath)
  385. this.pageList.unshift(indexContent)
  386. this.activePage = this.linkList[1]
  387. }
  388. },
  389. closeLeft(pageKey) {
  390. if (pageKey == indexKey) {
  391. return
  392. }
  393. let tempList = [...this.pageList]
  394. let indexContent = tempList.slice(0, 1)[0]
  395. let index = this.linkList.indexOf(pageKey)
  396. this.linkList = this.linkList.slice(index)
  397. this.pageList = this.pageList.slice(index)
  398. this.linkList.unshift(indexContent.fullPath)
  399. this.pageList.unshift(indexContent)
  400. if (this.linkList.indexOf(this.activePage) < 0) {
  401. this.activePage = this.linkList[0]
  402. }
  403. },
  404. closeRight(pageKey) {
  405. let index = this.linkList.indexOf(pageKey)
  406. this.linkList = this.linkList.slice(0, index + 1)
  407. this.pageList = this.pageList.slice(0, index + 1)
  408. if (this.linkList.indexOf(this.activePage < 0)) {
  409. this.activePage = this.linkList[this.linkList.length - 1]
  410. }
  411. },
  412. //update-begin-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
  413. dynamicRouterShow(key, title) {
  414. let keyIndex = this.linkList.indexOf(key)
  415. if (keyIndex >= 0) {
  416. let currRouter = this.pageList[keyIndex]
  417. let meta = Object.assign({}, currRouter.meta, {
  418. title: title
  419. })
  420. this.pageList.splice(keyIndex, 1, Object.assign({}, currRouter, {
  421. meta: meta
  422. }))
  423. if (key === this.activePage) {
  424. this.changeTitle(title)
  425. }
  426. }
  427. },
  428. //update-end-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
  429. //update-begin-author:taoyan date:20191008 for:路由刷新
  430. routeReload() {
  431. this.reloadFlag = false
  432. let ToggleMultipage = "ToggleMultipage"
  433. this.$store.dispatch(ToggleMultipage, false)
  434. this.$nextTick(() => {
  435. this.$store.dispatch(ToggleMultipage, true)
  436. this.reloadFlag = true
  437. })
  438. }
  439. //update-end-author:taoyan date:20191008 for:路由刷新
  440. }
  441. }
  442. </script>
  443. <style lang="less">
  444. /*
  445. * The following styles are auto-applied to elements with
  446. * transition="page-transition" when their visibility is toggled
  447. * by Vue.js.
  448. *
  449. * You can easily play with the page transition by editing
  450. * these styles.
  451. */
  452. .page-transition-enter {
  453. opacity: 0;
  454. }
  455. .page-transition-leave-active {
  456. opacity: 0;
  457. }
  458. .page-transition-enter .page-transition-container,
  459. .page-transition-leave-active .page-transition-container {
  460. -webkit-transform: scale(1.1);
  461. transform: scale(1.1);
  462. }
  463. /*美化弹出Tab样式*/
  464. .ant-tabs-nav-container {
  465. margin-top: 4px;
  466. }
  467. /* 修改 ant-tabs 样式 */
  468. .tab-layout-tabs.ant-tabs {
  469. border-bottom: 1px solid #ccc;
  470. border-left: 1px solid #ccc;
  471. background-color: white;
  472. padding: 0 20px;
  473. .ant-tabs-bar {
  474. margin: 4px 0 0;
  475. border: none;
  476. }
  477. }
  478. .ant-tabs {
  479. &.ant-tabs-card .ant-tabs-tab {
  480. padding: 0 24px !important;
  481. background-color: white !important;
  482. margin-right: 10px !important;
  483. .ant-tabs-close-x {
  484. width: 12px !important;
  485. height: 12px !important;
  486. opacity: 0 !important;
  487. cursor: pointer !important;
  488. font-size: 12px !important;
  489. margin: 0 !important;
  490. position: absolute;
  491. top: 36%;
  492. right: 6px;
  493. }
  494. &:hover .ant-tabs-close-x {
  495. opacity: 1 !important;
  496. }
  497. }
  498. }
  499. .ant-tabs.ant-tabs-card>.ant-tabs-bar {
  500. .ant-tabs-tab {
  501. border: none !important;
  502. border-bottom: 1px solid transparent !important;
  503. }
  504. // .ant-tabs-tab-active {
  505. // border-color: @primary-color!important;
  506. // }
  507. }
  508. </style>