md/src/components/CodemirrorEditor/rightClickMenu.vue

148 lines
2.5 KiB
Vue
Raw Normal View History

2020-07-13 00:26:29 +08:00
<template>
<ul
v-show="value"
id="menu"
class="menu"
:style="`left: ${left}px;top: ${top}px;`"
>
<div class="menu__group" v-for="(menuItem, index) in menu" :key="index">
<li
v-for="item of menuItem"
:key="item.key"
class="menu_item"
@mousedown="onMouseDown(item.key)"
>
<span>{{ item.text }}</span>
</li>
</div>
</ul>
2020-07-13 00:26:29 +08:00
</template>
<script>
export default {
props: {
value: {
type: Boolean,
default: false,
2020-07-13 00:26:29 +08:00
},
top: {
type: Number,
default: 0,
2020-07-13 00:26:29 +08:00
},
left: {
type: Number,
default: 0,
2020-07-13 00:26:29 +08:00
},
},
data() {
return {
menu: [
[
{
text: `上传图片`,
key: `insertPic`,
},
{
text: `插入表格`,
key: `insertTable`,
},
{
text: `恢复默认样式`,
key: `resetStyle`,
},
],
[
{
text: `导入 Markdown 文档`,
key: `importMarkdown`,
},
{
text: `导出 Markdown 文档`,
key: `download`,
},
2021-10-14 20:12:19 +08:00
{
text: `导出 HTML 页面`,
key: `export`,
2021-10-14 20:12:19 +08:00
},
{
text: `格式化 Markdown 文档`,
key: `formatMarkdown`,
},
],
],
}
},
methods: {
closeCB() {
this.$emit(`input`, false)
},
onMouseDown(key) {
this.$emit(`menuTick`, key)
this.$emit(`closeMenu`, false)
},
},
}
2020-07-13 00:26:29 +08:00
</script>
<style lang="less" scoped>
.menu {
position: absolute;
border-radius: 4px;
background-color: #ffffff;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.08);
z-index: 9999;
2020-07-13 00:26:29 +08:00
}
.menu_item {
margin-top: 10px;
min-width: 200px;
font-size: 12px;
line-height: 20px;
color: #333333;
cursor: pointer;
&:first-of-type {
margin-top: 0;
}
&:hover {
background: #f0f0f0;
}
span,
.btn-upload {
display: inline-block;
padding: 4px 0;
padding-left: 24px;
width: 100%;
}
.btn-upload {
margin: 0;
border: none;
outline: none;
background: transparent;
}
.btn-upload:hover {
background: #aaaaaa;
}
::v-deep .el-upload {
width: 100%;
}
2020-07-13 00:26:29 +08:00
}
2020-11-22 20:33:04 +08:00
.menu__group {
padding-top: 6px;
padding-bottom: 6px;
border-bottom: 1px solid #eeeeee;
&:last-of-type {
border-bottom: none;
}
2020-11-22 20:33:04 +08:00
}
2020-07-13 00:26:29 +08:00
li:hover {
background-color: #1790ff;
2020-07-13 00:26:29 +08:00
}
li {
font-size: 15px;
list-style: none;
2020-07-13 00:26:29 +08:00
}
</style>