diff --git a/src/components/CodemirrorEditor/rightClickMenu.vue b/src/components/CodemirrorEditor/rightClickMenu.vue index cd3ec0a..5bc2b6f 100644 --- a/src/components/CodemirrorEditor/rightClickMenu.vue +++ b/src/components/CodemirrorEditor/rightClickMenu.vue @@ -1,12 +1,12 @@ @@ -70,14 +70,13 @@ export default { }); return false; }, - }, - watch: { - value(newVal) { - if (newVal) { - document.body.addEventListener('click', this.closeCB.bind(this)); + onMouseDown(key){ + if (key == 'insertPic') { + document.querySelector('.li__upload button').click() } else { - document.body.removeEventListener('click', this.closeCB.bind(this)); + this.$emit('menuTick', key) } + this.$emit('closeMenu',false) } }, } @@ -107,12 +106,22 @@ export default { color: white; background: rgb(139, 146, 148); } - span { + span,.btn-upload { text-align: center; display: inline-block; padding: 4px 0; width: 100%; } + .btn-upload { + margin: 0; + border:none; + outline: none; + background: transparent; + } + .btn-upload:hover { + color: white; + background: rgb(139, 146, 148); + } /deep/ .el-upload { width: 100%; } diff --git a/src/store/index.js b/src/store/index.js index 0d350e6..56adbf7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -23,7 +23,8 @@ const state = { currentSize: '', currentColor: '', citeStatus: 0, - nightMode: false + nightMode: false, + rightClickMenuVisible:false }; const mutations = { setEditorValue(state, data) { @@ -51,6 +52,9 @@ const mutations = { state.currentColor = data; localStorage.setItem('color', data) }, + setRightClickMenuVisible(state,data) { + state.rightClickMenuVisible = data; + }, themeChanged(state) { state.nightMode = !state.nightMode; }, @@ -93,6 +97,7 @@ const mutations = { const doc = formatDoc(DEFAULT_CONTENT) state.editor.setValue(doc) } + }, initCssEditorEntity(state) { state.cssEditor = CodeMirror.fromTextArea( diff --git a/src/view/CodemirrorEditor.vue b/src/view/CodemirrorEditor.vue index 0489f7a..139cddf 100644 --- a/src/view/CodemirrorEditor.vue +++ b/src/view/CodemirrorEditor.vue @@ -57,6 +57,7 @@ :left="mouseLeft" :top="mouseTop" @menuTick="onMenuEvent" + @closeMenu="closeRightClickMenu" /> @@ -82,7 +83,6 @@ export default { showCssEditor: false, aboutDialogVisible: false, dialogFormVisible: false, - rightClickMenuVisible: false, isCoping: false, isImgLoading: false, backLight: false, @@ -107,7 +107,8 @@ export default { cssEditor: state=> state.cssEditor, currentSize: state=> state.currentSize, currentColor: state=> state.currentColor, - nightMode: state=> state.nightMode + nightMode: state=> state.nightMode, + rightClickMenuVisible: state=> state.rightClickMenuVisible }) }, created() { @@ -158,6 +159,18 @@ export default { } } }); + + this.editor.on('mousedown', () => { + this.$store.commit('setRightClickMenuVisible', false); + }); + this.editor.on('blur', () => { + //!影响到右键菜单的点击事件,右键菜单的点击事件在组件内通过mousedown触发 + this.$store.commit('setRightClickMenuVisible', false); + }); + this.editor.on('scroll', () => { + this.$store.commit('setRightClickMenuVisible', false); + }); + }, initCssEditor() { this.initCssEditorEntity(); @@ -267,7 +280,10 @@ export default { const left = e.clientX - offsetLeft; this.mouseLeft = Math.min(maxLeft, left); this.mouseTop = e.clientY + 10; - this.rightClickMenuVisible = true; + this.$store.commit('setRightClickMenuVisible', true); + }, + closeRightClickMenu(){ + this.$store.commit('setRightClickMenuVisible', false); }, onMenuEvent(type, info = {}) { switch (type) {