|
@@ -9,13 +9,11 @@ import eventBus from "@/utils/eventBus";
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'yvan-print-context',
|
|
name: 'yvan-print-context',
|
|
-
|
|
|
|
provide() {
|
|
provide() {
|
|
return {
|
|
return {
|
|
$$contextmenu: this
|
|
$$contextmenu: this
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-
|
|
|
|
props: {
|
|
props: {
|
|
eventType: {
|
|
eventType: {
|
|
type: String,
|
|
type: String,
|
|
@@ -57,27 +55,20 @@ export default {
|
|
|
|
|
|
watch: {
|
|
watch: {
|
|
visible(value) {
|
|
visible(value) {
|
|
- console.log("watch visible >>>> ", value)
|
|
|
|
if (value) {
|
|
if (value) {
|
|
this.$emit('show', this)
|
|
this.$emit('show', this)
|
|
-
|
|
|
|
document.body.addEventListener('click', this.handleBodyClick)
|
|
document.body.addEventListener('click', this.handleBodyClick)
|
|
} else {
|
|
} else {
|
|
this.$emit('hide', this)
|
|
this.$emit('hide', this)
|
|
-
|
|
|
|
document.body.removeEventListener('click', this.handleBodyClick)
|
|
document.body.removeEventListener('click', this.handleBodyClick)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- console.log('Context menu >>> ', this.$props)
|
|
|
|
-
|
|
|
|
document.body.appendChild(this.$el)
|
|
document.body.appendChild(this.$el)
|
|
-
|
|
|
|
eventBus.on("showContextMenu", (position) => {
|
|
eventBus.on("showContextMenu", (position) => {
|
|
this.show(position)
|
|
this.show(position)
|
|
})
|
|
})
|
|
-
|
|
|
|
if (window.$$VContextmenu) {
|
|
if (window.$$VContextmenu) {
|
|
window.$$VContextmenu[this.$contextmenuId] = this
|
|
window.$$VContextmenu[this.$contextmenuId] = this
|
|
} else {
|
|
} else {
|
|
@@ -86,13 +77,10 @@ export default {
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
document.body.removeChild(this.$el)
|
|
document.body.removeChild(this.$el)
|
|
-
|
|
|
|
delete window.$$VContextmenu[this.$contextmenuId]
|
|
delete window.$$VContextmenu[this.$contextmenuId]
|
|
-
|
|
|
|
this.references.forEach((ref) => {
|
|
this.references.forEach((ref) => {
|
|
ref.el.removeEventListener(this.eventType, this.handleReferenceContextmenu)
|
|
ref.el.removeEventListener(this.eventType, this.handleReferenceContextmenu)
|
|
})
|
|
})
|
|
-
|
|
|
|
document.body.removeEventListener('click', this.handleBodyClick)
|
|
document.body.removeEventListener('click', this.handleBodyClick)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -100,44 +88,33 @@ export default {
|
|
addRef(ref) {
|
|
addRef(ref) {
|
|
// FIXME: 如何处理 removeRef?
|
|
// FIXME: 如何处理 removeRef?
|
|
this.references.push(ref)
|
|
this.references.push(ref)
|
|
-
|
|
|
|
ref.el.addEventListener(this.eventType, this.handleReferenceContextmenu)
|
|
ref.el.addEventListener(this.eventType, this.handleReferenceContextmenu)
|
|
},
|
|
},
|
|
handleReferenceContextmenu(event) {
|
|
handleReferenceContextmenu(event) {
|
|
event.preventDefault()
|
|
event.preventDefault()
|
|
-
|
|
|
|
if (this.disabled) {
|
|
if (this.disabled) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
const reference = this.references.find((ref) => ref.el.contains(event.target))
|
|
const reference = this.references.find((ref) => ref.el.contains(event.target))
|
|
-
|
|
|
|
this.$emit('contextmenu', reference ? reference.vnode : null)
|
|
this.$emit('contextmenu', reference ? reference.vnode : null)
|
|
-
|
|
|
|
const eventX = event.pageX
|
|
const eventX = event.pageX
|
|
const eventY = event.pageY
|
|
const eventY = event.pageY
|
|
-
|
|
|
|
this.show()
|
|
this.show()
|
|
-
|
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
const contextmenuPosition = {
|
|
const contextmenuPosition = {
|
|
top: eventY,
|
|
top: eventY,
|
|
left: eventX
|
|
left: eventX
|
|
}
|
|
}
|
|
-
|
|
|
|
if (this.autoPlacement) {
|
|
if (this.autoPlacement) {
|
|
const contextmenuWidth = this.$refs.contextmenu.clientWidth
|
|
const contextmenuWidth = this.$refs.contextmenu.clientWidth
|
|
const contextmenuHeight = this.$refs.contextmenu.clientHeight
|
|
const contextmenuHeight = this.$refs.contextmenu.clientHeight
|
|
-
|
|
|
|
if (contextmenuHeight + eventY >= window.innerHeight) {
|
|
if (contextmenuHeight + eventY >= window.innerHeight) {
|
|
contextmenuPosition.top -= contextmenuHeight
|
|
contextmenuPosition.top -= contextmenuHeight
|
|
}
|
|
}
|
|
-
|
|
|
|
if (contextmenuWidth + eventX >= window.innerWidth) {
|
|
if (contextmenuWidth + eventX >= window.innerWidth) {
|
|
contextmenuPosition.left -= contextmenuWidth
|
|
contextmenuPosition.left -= contextmenuWidth
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
this.style = {
|
|
this.style = {
|
|
top: `${contextmenuPosition.top}px`,
|
|
top: `${contextmenuPosition.top}px`,
|
|
left: `${contextmenuPosition.left}px`
|
|
left: `${contextmenuPosition.left}px`
|
|
@@ -159,14 +136,12 @@ export default {
|
|
window.$$VContextmenu[key].hide()
|
|
window.$$VContextmenu[key].hide()
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-
|
|
|
|
if (position) {
|
|
if (position) {
|
|
this.style = {
|
|
this.style = {
|
|
top: `${position.top}px`,
|
|
top: `${position.top}px`,
|
|
left: `${position.left}px`
|
|
left: `${position.left}px`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log("position >>>", position, this.style)
|
|
|
|
this.visible = true
|
|
this.visible = true
|
|
},
|
|
},
|
|
hide() {
|
|
hide() {
|