Pārlūkot izejas kodu

新增自动打开上次未关闭的`tab`页的功能

mxd 3 gadi atpakaļ
vecāks
revīzija
9c85960bcf

+ 5 - 0
magic-editor/src/console/src/components/editor/magic-script-editor.vue

@@ -409,12 +409,16 @@ export default {
           this.editor.setValue(item.script)
           this.editor.setScrollTop(item.ext.scrollTop);
           bus.$emit('opened', item)
+          this.resetRecentOpenedTab()
         }).end(() => {
           item.ext.loading = false;
         })
       }
       // this.layout()
     },
+    resetRecentOpenedTab(){
+      store.set(contants.RECENT_OPENED_TAB, this.scripts.filter(it => it.id).map(it => it.id))
+    },
     deleteWrapperProperties(obj){
       delete obj.ext
       delete obj.groupName
@@ -751,6 +755,7 @@ export default {
           it.displayName = it.name
         }
       })
+      this.resetRecentOpenedTab()
     },
     closeAll() {
       let items = [...this.scripts]

+ 9 - 1
magic-editor/src/console/src/components/magic-editor.vue

@@ -45,7 +45,7 @@ import contants from '@/scripts/contants.js'
 import MagicWebSocket from '@/scripts/websocket.js'
 import store from '@/scripts/store.js'
 import Key from '@/scripts/hotkey.js'
-import {replaceURL,getQueryVariable} from '@/scripts/utils.js'
+import {getQueryVariable, replaceURL} from '@/scripts/utils.js'
 import {defineTheme} from '@/scripts/editor/theme.js'
 import defaultTheme from '@/scripts/editor/default-theme.js'
 import darkTheme from '@/scripts/editor/dark-theme.js'
@@ -344,6 +344,14 @@ export default {
      * 传入id来打开对应api或者function
      */
     open(openIds) {
+      try {
+        JSON.parse(store.get(contants.RECENT_OPENED_TAB)).forEach(id => {
+          this.$refs.apiList.openItemById(id)
+          this.$refs.functionList.openItemById(id)
+        })
+      } catch (e) {
+        // ignore
+      }
       openIds = openIds || getQueryVariable('openIds')
       if (openIds) {
         if (typeof openIds === 'string') {

+ 4 - 3
magic-editor/src/console/src/components/resources/magic-recent-opened.vue

@@ -22,6 +22,7 @@ import bus from '../../scripts/bus.js'
 import Key from '@/scripts/hotkey.js'
 import MagicDialog from '@/components/common/modal/magic-dialog.vue'
 import store from '@/scripts/store.js'
+import contants from "@/scripts/contants.js"
 
 export default {
   name: 'MagicRecentOpened',
@@ -43,7 +44,7 @@ export default {
         if(this.scripts.length > 30){
           this.scripts.splice(30, this.scripts.length)
         }
-        store.set('recent_opened', this.scripts)
+        store.set(contants.RECENT_OPENED, this.scripts)
       }
     })
     let element = document.getElementsByClassName('ma-container')[0]
@@ -64,7 +65,7 @@ export default {
       if (filtered.length !== this.scripts.length) {
         this.$nextTick(() => {
           this.scripts = filtered.map(it => [it._type, it.id]);
-          store.set('recent_opened', this.scripts)
+          store.set(contants.RECENT_OPENED, this.scripts)
         })
       }
       return list.filter(it => it);
@@ -72,7 +73,7 @@ export default {
   },
   methods: {
     show() {
-      let str = store.get('recent_opened')
+      let str = store.get(contants.RECENT_OPENED)
       if (str) {
         try {
           this.scripts = JSON.parse(str)

+ 2 - 0
magic-editor/src/console/src/scripts/contants.js

@@ -18,6 +18,8 @@ const contants = {
   HEADER_MAGIC_TOKEN: 'magic-token',
   HEADER_MAGIC_TOKEN_VALUE: 'unauthorization',
   IGNORE_VERSION: 'ignore-version',
+  RECENT_OPENED_TAB: 'recent_opened_tab',
+  RECENT_OPENED: 'recent_opened',
   RESPONSE_CODE_DEBUG: 1000,
   RESPONSE_CODE_SCRIPT_ERROR: -1000,
   RESPONSE_NO_PERMISSION: -10,