Browse Source

最近打开,定位,接口重名显示组名

吕金泽 3 years ago
parent
commit
0e146cd119

+ 3 - 0
magic-editor/src/console/src/assets/iconfont/iconfont.css

@@ -243,3 +243,6 @@
   content: "\e6e9";
 }
 
+.ma-icon-position:before {
+  content: "\e727";
+}

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

@@ -6,7 +6,7 @@
             v-for="(item, index) in scripts"
             :key="'api_' + item.tmp_id || item.id"
             :class="{ selected: selected === item, draggableTargetItem: item.ext.tabDraggable }"
-            :title="item.name"
+            :title="item.displayName || item.name"
             :id="'ma-tab-item-' + item.tmp_id"
             @click="open(item)" @contextmenu.prevent="e => tabsContextmenuHandle(e, item, index)"
             @mousedown.middle.stop="close(item.id || item.tmp_id)"
@@ -18,7 +18,7 @@
         >
           <i class="ma-svg-icon" v-if="item._type === 'api'" :class="['request-method-' + item.method]" />
           <i class="ma-svg-icon" v-if="item._type !== 'api'" :class="['icon-function']" />
-          {{item.name}}<i class="ma-icon ma-icon-lock" v-if="item.lock === '1'" />
+          {{item.displayName || item.name}}<i class="ma-icon ma-icon-lock" v-if="item.lock === '1'" />
           <span v-show="!item.id || item.script !== item.ext.tmpScript">*</span>
           <i class="ma-icon ma-icon-close" @click.stop="close(item.id || item.tmp_id)"/>
         </li>
@@ -397,6 +397,12 @@ export default {
             item.id = ''
             item.copy = false
           }
+          this.scripts.forEach(it => {
+            if (it.name == item.name) {
+              it.displayName = it.groupName + '/' + it.name
+              item.displayName = item.groupName + '/' + item.name
+            }
+          })
           this.scripts.push(item)
           this.info = item
           this.editor.setValue(item.script)
@@ -714,6 +720,7 @@ export default {
     close(id) {
       this.scripts.forEach((item, index) => {
         if (item.id === id || item.tmp_id === id) {
+          bus.$emit('close', item)
           this.scripts.splice(index, 1)
           if (this.selected === item) {
             let info
@@ -732,6 +739,17 @@ export default {
       if (this.scripts.length === 0) {
         bus.$emit('opened', {empty: true})
       }
+      this.scripts.forEach(it => {
+        var equalIndex = 0
+        this.scripts.forEach(item => {
+          if (it.name == item.name) {
+            equalIndex ++
+          }
+        })
+        if (equalIndex == 1) {
+          it.displayName = it.name
+        }
+      })
     },
     closeAll() {
       let items = [...this.scripts]

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

@@ -5,6 +5,9 @@
                                                                                        @input="e => doSearch(e.target.value)"/>
       </div>
       <div>
+        <div class="ma-tree-toolbar-btn" title="定位" @click="positionApi()">
+          <i class="ma-icon ma-icon-position"></i>
+        </div>
         <div class="ma-tree-toolbar-btn" title="新建分组" @click="openCreateGroupModal()">
           <i class="ma-icon ma-icon-group-add"></i>
         </div>
@@ -92,6 +95,14 @@
         <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)">
+          {{ it.groupName + '/' + it.name }}({{ it.groupPath + '/' + it.path }})
+        </div>
+      </template>
+    </magic-dialog>
   </div>
 </template>
 
@@ -129,6 +140,7 @@ export default {
       // 数据排序规则,true:升序,false:降序
       treeSort: true,
       groupChooseVisible: false,
+      recentlyOpenedVisible: false,
       srcId: '',
       // 新建分组对象
       createGroupObj: {
@@ -152,7 +164,9 @@ export default {
       // 是否展示tree-loading
       showLoading: true,
       // 缓存一个openId
-      tmpOpenId: []
+      tmpOpenId: [],
+      // 最近打开
+      recentlyOpenedScripts: []
     }
   },
   methods: {
@@ -174,6 +188,10 @@ export default {
       bus.$emit('open', item)
       this.currentFileItem = item
     },
+    recentlyOpened(item){
+      this.open(item)
+      this.recentlyOpenedVisible = false
+    },
     // 初始化数据
     initData() {
       bus.$emit('status', '正在初始化接口列表')
@@ -551,6 +569,9 @@ export default {
         }
       })
     },
+    positionApi(){
+      document.querySelector('.ma-tree-select').scrollIntoView(true)
+    },
     // 打开新建分组弹窗
     openCreateGroupModal(item, parentItem) {
       if (item) {
@@ -892,9 +913,16 @@ export default {
       this.initCreateGroupObj()
       this.changeForceUpdate()
     })
+    this.bus.$on('close', 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>