-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from bhabgs/master
添加自定义右键
- Loading branch information
Showing
9 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { App } from 'vue'; | ||
|
||
export default { | ||
install(app: App) { | ||
app.directive('contextmenu', { | ||
beforeMount(el, b) { | ||
const ul = document.createElement('ul'); | ||
ul.id = 'contextmenu_box'; | ||
const createdMenuElement = () => { | ||
ul.className = 'contextmenu'; | ||
for (let i of b.value.menus) { | ||
const text = document.createTextNode(i.name); | ||
const li = document.createElement('li'); | ||
|
||
li.onclick = (e) => { | ||
e.preventDefault(); | ||
b.value.callBack(i); | ||
}; | ||
li.appendChild(text); | ||
ul.appendChild(li); | ||
} | ||
el.appendChild(ul); | ||
}; | ||
createdMenuElement(); | ||
|
||
el.style.position = 'relative'; | ||
}, | ||
mounted(el, b) { | ||
let ul: HTMLElement; | ||
setTimeout(() => { | ||
ul = document.getElementById('contextmenu_box') as HTMLElement; | ||
}, 10); | ||
|
||
// 右键触发展示 | ||
el.addEventListener('contextmenu', (e: any) => { | ||
const { x, y } = { | ||
x: el.offsetLeft, | ||
y: el.offsetTop, | ||
}; | ||
e.preventDefault(); | ||
ul.className = 'contextmenu active'; | ||
ul.style.left = e.x - x + 'px'; | ||
ul.style.top = e.y - y + 'px'; | ||
}); | ||
|
||
// 单击box 隐藏 | ||
el.addEventListener('click', (e: any) => { | ||
e.preventDefault(); | ||
ul.className = 'contextmenu'; | ||
}); | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* @abstract: JianJie | ||
* @version: 0.0.1 | ||
* @Author: bhabgs | ||
* @Date: 2021-03-18 11:52:08 | ||
* @LastEditors: bhabgs | ||
* @LastEditTime: 2021-03-19 13:39:29 | ||
*/ | ||
import { App } from 'vue'; | ||
import contextmenu from './contextmenu'; | ||
|
||
export default { | ||
install(app: App) { | ||
app.use(contextmenu); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.contextmenu { | ||
background-color: @white; | ||
position: absolute; | ||
opacity: 0; | ||
margin: 0; | ||
padding: 0; | ||
width: 150px; | ||
border-radius: 0.5rem; | ||
z-index: -5; | ||
.animate3(); | ||
&.active { | ||
opacity: 1; | ||
z-index: 99; | ||
} | ||
li { | ||
list-style: none; | ||
display: block; | ||
font-size: 1.2rem; | ||
padding: 0.3rem 1rem; | ||
cursor: pointer; | ||
.animate3(); | ||
&:hover { | ||
color: @white; | ||
background-color: @blue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import './reset.less'; | ||
@import './layout.less'; | ||
@import './button.less'; | ||
@import './directive.less'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters