소스 검색

bug 修复

lilei 3 년 전
부모
커밋
98b2b23e2a
1개의 변경된 파일29개의 추가작업 그리고 17개의 파일을 삭제
  1. 29 17
      src/components/MultiTab/MultiTab.vue

+ 29 - 17
src/components/MultiTab/MultiTab.vue

@@ -9,7 +9,8 @@ export default {
       tabsList: [], // 已打开页签
       pages: [], // 已打开页面
       activeKey: '', // 当前页面
-      newTabIndex: 0
+      newTabIndex: 0,
+      maxTabNums: 5
     }
   },
   inject: ['reloadView'],
@@ -35,11 +36,13 @@ export default {
       } catch (e) {
       }
     })
-
-    this.pages.push(this.$route)
-    this.tabsList.push(this.$route.name)
-    this.pagesRecordList.push(this.$route.name)
-    this.selectedLastPath()
+    console.log('rename')
+    if (this.pages.length <= this.maxTabNums) {
+      this.pages.push(this.$route)
+      this.tabsList.push(this.$route.name)
+      this.pagesRecordList.push(this.$route.name)
+      this.selectedLastPath()
+    }
   },
   methods: {
     onEdit (targetKey, action) {
@@ -175,34 +178,43 @@ export default {
           this.$store.state.app.isNewTab = na || nb || nc
           // 从编辑,新增返回列表,刷新列表
           this.$store.state.app.updateList = ob || oc
+          this.activeKey = newVal.name
         } else {
           // 新打开的页签
-          this.tabsList.push(newVal.name)
-          this.pages.push(newVal)
-          this.pagesRecordList.push(newVal.name)
-          this.$store.state.app.isNewTab = true
-          this.$store.state.app.updateList = false
+          if (this.pages.length < this.maxTabNums) {
+            this.tabsList.push(newVal.name)
+            this.pages.push(newVal)
+            this.pagesRecordList.push(newVal.name)
+            this.$store.state.app.isNewTab = true
+            this.$store.state.app.updateList = false
+            this.activeKey = newVal.name
+          } else {
+            this.$message.info('您当前打开窗口太多,请关闭一些,窗口不能超过' + this.maxTabNums + '个')
+            this.$router.go(-1)
+          }
         }
       } else { // 已存在
+        console.log(1, '已存在')
         this.pages.splice(index, 1, newVal)
         this.tabsList.splice(index, 1, newVal.name)
         this.$store.state.app.isNewTab = false
-        console.log(1, '已存在')
+        this.activeKey = newVal.name
       }
-      this.activeKey = newVal.name
     },
     activeKey: function (newPathKey) {
+      console.log('-----' + newPathKey)
       const pages = this.pages.find(item => item.name == newPathKey)
-      this.$router.push({ name: newPathKey, params: pages.params })
+      this.$router.push({ name: newPathKey, params: pages.params, query: pages.query })
     }
   },
   render () {
-    const { onEdit, onChange, refashThat, $data: { pages } } = this
-    const panes = pages.map(page => {
+    const { onEdit, onChange, refashThat, $data: { pages, maxTabNums } } = this
+    const tabPanel = pages.length > maxTabNums ? pages.slice(0, maxTabNums - 1) : pages
+    const panes = tabPanel.map(page => {
       return (
         <a-tab-pane
           style={{ height: 0 }}
-          key={page.name} closable={pages.length > 1}
+          key={page.name} closable={tabPanel.length > 1}
         >
           <span slot="tab">
             {this.renderTabPane(page.meta.customTitle || page.meta.title, page.name)}