瀏覽代碼

最近打开

mxd 3 年之前
父節點
當前提交
b89c5eeb50

+ 3 - 2
magic-editor/src/console/src/components/editor/magic-script-editor.vue

@@ -34,7 +34,8 @@
           代码提示<em>Alt + /</em><br/>
           恢复断点<em>F8</em><br/>
           步进<em>F6</em><br/>
-          代码格式化<em>Ctrl + Alt + L</em>
+          代码格式化<em>Ctrl + Alt + L</em><br/>
+          最近打开<em>Ctrl + E</em>
         </p>
       </div>
     </div>
@@ -932,7 +933,7 @@ export default {
 .ma-hot-key {
   position: absolute;
   top: 50%;
-  margin-top: -60px;
+  margin-top: -105px;
   text-align: center;
   color: var(--empty-color);
   font-size: 16px;

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

@@ -19,6 +19,8 @@
       <!-- 底部区域 -->
       <magic-options />
     </div>
+    <!-- 最近打开 -->
+    <magic-recent-opened />
     <!-- 状态条 -->
     <magic-status-bar :config="config" />
   </div>
@@ -37,6 +39,7 @@ import MagicApiList from './resources/magic-api-list.vue'
 import MagicFunctionList from './resources/magic-function-list.vue'
 import MagicDatasourceList from './resources/magic-datasource-list.vue'
 import MagicScriptEditor from './editor/magic-script-editor.vue'
+import MagicRecentOpened from './resources/magic-recent-opened.vue'
 import request from '@/api/request.js'
 import contants from '@/scripts/contants.js'
 import MagicWebSocket from '@/scripts/websocket.js'
@@ -75,7 +78,8 @@ export default {
     MagicOptions,
     MagicLoading,
     MagicLogin,
-    MagicDatasourceList
+    MagicDatasourceList,
+    MagicRecentOpened
   },
   data() {
     return {

+ 1 - 22
magic-editor/src/console/src/components/resources/magic-api-list.vue

@@ -92,17 +92,6 @@
         <button class="ma-button active" @click="copyGroup">复制</button>
       </template>
     </magic-dialog>
-    <magic-dialog v-model="recentlyOpenedVisible" title="最近打开" align="right" :moveable="false" width="340px" height="390px"
-                  className="ma-tree-wrapper">
-      <template #content>
-        <div v-for="(it, i) in recentlyOpenedScripts" :key="i" @click="recentlyOpened(it)" class="ma-tree-item">
-          <div :title="it.method + ':' + it.groupName + '/' + it.name + '(' + it.groupPath + '/' + it.path + ')'" class="ma-tree-hover" style="padding-left: 17px;">
-            <i :class="'ma-svg-icon request-method-' + it.method"></i>
-            <label>{{ it.groupName + '/' + it.name }}({{ it.groupPath + '/' + it.path }})</label>
-          </div>
-        </div>
-      </template>
-    </magic-dialog>
   </div>
 </template>
 
@@ -164,9 +153,7 @@ export default {
       // 是否展示tree-loading
       showLoading: true,
       // 缓存一个openId
-      tmpOpenId: [],
-      // 最近打开
-      recentlyOpenedScripts: []
+      tmpOpenId: []
     }
   },
   methods: {
@@ -915,17 +902,9 @@ export default {
       this.initCreateGroupObj()
       this.changeForceUpdate()
     })
-    this.bus.$on('close', item => {
-      console.log(item)
-      this.recentlyOpenedScripts.push(item)
-    })
     let element = document.getElementsByClassName('ma-container')[0]
     // 新建分组快捷键
     Key.bind(element, Key.Alt | Key.G, () => this.openCreateGroupModal())
-    // 显示最近打开的文件记录列表
-    Key.bind(element, Key.Ctrl | Key.E, () => {
-      this.recentlyOpenedVisible = true
-    })
   }
 }
 </script>

+ 100 - 0
magic-editor/src/console/src/components/resources/magic-recent-opened.vue

@@ -0,0 +1,100 @@
+<template>
+  <magic-dialog v-model="visible" title="最近打开" align="right" :moveable="false" width="340px" height="420px" padding="0"
+                className="ma-tree-wrapper">
+    <template #content>
+      <div style="height: 380px; overflow: auto">
+        <div v-for="(it, i) in fullScripts" :key="i" @click="open(it)" class="ma-tree-item">
+          <div class="ma-tree-hover" style="padding-left: 5px;">
+            <i v-if="it._type === 'api'" :class="'ma-svg-icon request-method-' + it.method"></i>
+            <i v-if="it._type === 'function'" class="ma-svg-icon icon-function"></i>
+            <label>{{ displayText(it.groupName + '/' + it.name) }}({{ displayText(it.groupPath + '/' + it.path) }})</label>
+          </div>
+        </div>
+        <div v-show="fullScripts.length === 0" class="no-data-tip">
+          最近没有打开过的接口或函数
+        </div>
+      </div>
+    </template>
+  </magic-dialog>
+</template>
+<script>
+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'
+
+export default {
+  name: 'MagicRecentOpened',
+  components: {MagicDialog},
+  data() {
+    return {
+      visible: false,
+      scripts: []
+    }
+  },
+  mounted() {
+    bus.$on('close', item => {
+      if (item.id) {
+        let index = this.scripts.findIndex(it => it.id === item.id)
+        if (index > -1) {
+          this.scripts.splice(index, 1)
+        }
+        this.scripts.unshift([item._type, item.id])
+        if(this.scripts.length > 30){
+          this.scripts.splice(30, this.scripts.length)
+        }
+        store.set('recent_opened', this.scripts)
+      }
+    })
+    let element = document.getElementsByClassName('ma-container')[0]
+    // 最近快捷键
+    Key.bind(element, Key.Ctrl | Key.E, () => this.show())
+  },
+  computed: {
+    fullScripts() {
+      const $parent = this.$parent.$refs
+      let list = this.scripts.map(item => {
+        if (item[0] === 'api') {
+          return $parent.apiList.getItemById(item[1])
+        } else if (item[0] === 'function') {
+          return $parent.functionList.getItemById(item[1])
+        }
+      })
+      let filtered = list.filter(it => it)
+      if (filtered.length !== this.scripts.length) {
+        this.$nextTick(() => {
+          this.scripts = filtered.map(it => [it._type, it.id]);
+          store.set('recent_opened', this.scripts)
+        })
+      }
+      return list.filter(it => it);
+    }
+  },
+  methods: {
+    show() {
+      let str = store.get('recent_opened')
+      if (str) {
+        try {
+          this.scripts = JSON.parse(str)
+        } catch (e) {
+        }
+      }
+      this.visible = true
+    },
+    open(item) {
+      bus.$emit('open', item)
+      this.visible = false
+    },
+    displayText(str) {
+      return str.replace(/\/+/g, '/')
+    }
+  }
+}
+</script>
+<style>
+@import './magic-resource.css';
+.ma-dialog-content .no-data-tip {
+  line-height: 380px;
+  text-align: center;
+}
+</style>