From fde62aaaa857c91f2b1c9d14eab18319bfc3b86b Mon Sep 17 00:00:00 2001 From: jmal Date: Sun, 28 Jun 2020 22:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8:=20=E6=B7=BB=E5=8A=A0tab=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MonacoEditorVue/index.js | 1 - src/components/preview/SimTextPreview.vue | 57 ++++++++++++++--------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/components/MonacoEditorVue/index.js b/src/components/MonacoEditorVue/index.js index 8f836c5..069dd27 100644 --- a/src/components/MonacoEditorVue/index.js +++ b/src/components/MonacoEditorVue/index.js @@ -81,7 +81,6 @@ export default { const isMac = navigator.platform.startsWith('Mac'); const {key, code, keyCode, ctrlKey, metaKey} = event; const isCmd = isMac && metaKey || !isMac && ctrlKey; - console.log('keydown',isCmd) if (!isCmd) { return; } diff --git a/src/components/preview/SimTextPreview.vue b/src/components/preview/SimTextPreview.vue index dff59b5..94f7c65 100644 --- a/src/components/preview/SimTextPreview.vue +++ b/src/components/preview/SimTextPreview.vue @@ -318,14 +318,14 @@ }).then((res)=>{ this.loading.close() if(this.editableTabs.findIndex(tab=> tab.name===row.path) < 0){ - console.log('添加一个tab') // 添加一个tab - this.editableTabs.push({ - title: row.name, - copyTitle: row.name, - name: row.path, - content: res.data.contentText - }) + let tab = {title: row.name,copyTitle: row.name,name: row.path,content: res.data.contentText} + let thisTabIndex = this.editableTabs.findIndex(tab=> tab.name===this.editableTabsValue) + if(this.editableTabs[thisTabIndex].title !== this.editableTabs[thisTabIndex].copyTitle){ + this.editableTabs.push(tab) + }else{ + this.editableTabs[thisTabIndex] = tab + } } this.editableTabsValue = row.path }).catch(() => { @@ -369,19 +369,13 @@ this.isShowUpdateBtn = true } } - // this.isShowUpdateBtn = true - // this.newContent = code - // if(code === this.content){ - // this.isShowUpdateBtn = false - // } }, save(value,index) { if(value !== this.editableTabs[index].content && this.isShowUpdateBtn){ - - this.update(value,this.editableTabs[index].name) + this.update(value,this.editableTabs[index].name,index) } }, - update(value,path) { + update(value,path,index) { this.updating = true markdownApi.editMarkdownByPath({ relativePath: path, @@ -389,8 +383,16 @@ contentText: value }).then(() => { this.updating = false - this.isShowUpdateBtn = false - this.content = this.newContent + if(undefined !== index){ + this.editableTabs[index].content = value + if(this.editableTabs[index].copyTitle !== this.editableTabs[index].title){ + this.editableTabs[index].title = this.editableTabs[index].copyTitle + // 没有任何改变 + if(this.editableTabs.findIndex(tab=>tab.title !== tab.copyTitle) < 0){ + this.isShowUpdateBtn = false + } + } + } this.$message({ message: "更新成功", type: 'success', @@ -447,9 +449,11 @@ removeTab(targetName) { let tabs = this.editableTabs; let activeName = this.editableTabsValue; + let removeIndex = 0 if (activeName === targetName) { tabs.forEach((tab, index) => { if (tab.name === targetName) { + removeIndex = index let nextTab = tabs[index + 1] || tabs[index - 1]; if (nextTab) { activeName = nextTab.name; @@ -457,8 +461,15 @@ } }); } - this.editableTabsValue = activeName; - this.editableTabs = tabs.filter(tab => tab.name !== targetName); + if(!this.editableTabs[index].copyTitle !== this.editableTabs[index].title){ + this.editableTabsValue = activeName; + this.editableTabs = tabs.filter(tab => tab.name !== targetName); + }else{ + this.$confirm('是否保存修改?').then(()=>{ + }).catch(()=>{ + + }) + } } } } @@ -477,11 +488,11 @@ &::-webkit-scrollbar-thumb { border: unset!important; background-color: #c1c1c1 !important; - -webkit-border-radius: unset!important; + border-radius: unset!important; } &::-webkit-scrollbar-track-piece { background-color: unset!important; - -webkit-border-radius: 3px; + border-radius: 3px; } } @@ -493,11 +504,11 @@ &::-webkit-scrollbar-thumb { border: unset!important; background-color: #4b4b4b !important; - -webkit-border-radius: unset!important; + border-radius: unset!important; } &::-webkit-scrollbar-track-piece { background-color: unset!important; - -webkit-border-radius: 3px; + border-radius: 3px; } }