Skip to content

Commit

Permalink
chore: migration rightClickMenuVisible (doocs#178)
Browse files Browse the repository at this point in the history
从 vuex 当中抽离 `rightClickMenuVisible`,该值并不需要放入 Vuex 当中共享
  • Loading branch information
YangFong authored Aug 9, 2022
1 parent 0542f26 commit bbf47a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
9 changes: 3 additions & 6 deletions src/components/CodemirrorEditor/RightClickMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div
id="menu"
class="menu"
v-show="value"
v-show="visible"
:style="`left: ${left}px;top: ${top}px;`"
>
<ul class="menu__group" v-for="(menuItem, index) in menu" :key="index">
<li
class="menu_item"
v-for="{ key, text } of menuItem"
v-for="{ key, text } in menuItem"
:key="key"
@mousedown="onMouseDown(key)"
>
Expand All @@ -21,7 +21,7 @@
<script>
export default {
props: {
value: {
visible: {
type: Boolean,
default: false,
},
Expand Down Expand Up @@ -73,9 +73,6 @@ export default {
}
},
methods: {
closeCB() {
this.$emit(`input`, false)
},
onMouseDown(key) {
this.$emit(`menuTick`, key)
this.$emit(`closeMenu`, false)
Expand Down
6 changes: 1 addition & 5 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { marked } from 'marked'
import CodeMirror from 'codemirror/lib/codemirror'
import DEFAULT_CONTENT from '@/assets/example/markdown.md'
import DEFAULT_CSS_CONTENT from '@/assets/example/theme-css.txt'
import { setColor, formatDoc, formatCss } from '../assets/scripts/util'
import { setColor, formatDoc, formatCss } from '@/assets/scripts/util'

Vue.use(Vuex)

Expand All @@ -22,7 +22,6 @@ const state = {
citeStatus: 0,
nightMode: false,
codeTheme: config.codeThemeOption[0].value,
rightClickMenuVisible: false,
}
const mutations = {
setEditorValue(state, data) {
Expand Down Expand Up @@ -54,9 +53,6 @@ const mutations = {
state.codeTheme = data
localStorage.setItem(`codeTheme`, data)
},
setRightClickMenuVisible(state, data) {
state.rightClickMenuVisible = data
},
themeChanged(state) {
state.nightMode = !state.nightMode
localStorage.setItem(`nightMode`, state.nightMode)
Expand Down
16 changes: 8 additions & 8 deletions src/views/CodemirrorEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:span="12"
class="codeMirror-wrapper"
ref="codeMirrorWrapper"
@contextmenu.prevent.native="openMenu($event)"
@contextmenu.prevent.native="openMenu"
>
<textarea
id="editor"
Expand Down Expand Up @@ -96,7 +96,7 @@
<insert-form-dialog v-model="dialogFormVisible"></insert-form-dialog>

<right-click-menu
v-model="rightClickMenuVisible"
:visible="rightClickMenuVisible"
:left="mouseLeft"
:top="mouseTop"
@menuTick="onMenuEvent"
Expand Down Expand Up @@ -144,6 +144,7 @@ export default {
source: ``,
mouseLeft: 0,
mouseTop: 0,
rightClickMenuVisible: false,
}
},
components: {
Expand All @@ -163,7 +164,6 @@ export default {
currentSize: (state) => state.currentSize,
currentColor: (state) => state.currentColor,
nightMode: (state) => state.nightMode,
rightClickMenuVisible: (state) => state.rightClickMenuVisible,
codeTheme: (state) => state.codeTheme,
}),
},
Expand Down Expand Up @@ -304,14 +304,14 @@ export default {
})
this.editor.on(`mousedown`, () => {
this.$store.commit(`setRightClickMenuVisible`, false)
this.rightClickMenuVisible = false
})
this.editor.on(`blur`, () => {
//!影响到右键菜单的点击事件,右键菜单的点击事件在组件内通过mousedown触发
this.$store.commit(`setRightClickMenuVisible`, false)
this.rightClickMenuVisible = false
})
this.editor.on(`scroll`, () => {
this.$store.commit(`setRightClickMenuVisible`, false)
this.rightClickMenuVisible = false
})
},
initCssEditor() {
Expand Down Expand Up @@ -575,10 +575,10 @@ export default {
const left = e.clientX - offsetLeft
this.mouseLeft = Math.min(maxLeft, left)
this.mouseTop = e.clientY + 10
this.$store.commit(`setRightClickMenuVisible`, true)
this.rightClickMenuVisible = true
},
closeRightClickMenu() {
this.$store.commit(`setRightClickMenuVisible`, false)
this.rightClickMenuVisible = false
},
onMenuEvent(type, info = {}) {
switch (type) {
Expand Down

0 comments on commit bbf47a5

Please sign in to comment.