File size: 2,993 Bytes
89ce340 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
<template>
<ul class="menu-content">
<template v-for="(menu, index) in menus" :key="menu.text || index">
<li
v-if="!menu.hide"
class="menu-item"
@click.stop="handleClickMenuItem(menu)"
:class="{'divider': menu.divider, 'disable': menu.disable}"
>
<div
class="menu-item-content"
:class="{
'has-children': menu.children,
'has-handler': menu.handler,
}"
v-if="!menu.divider"
>
<span class="text">{{menu.text}}</span>
<span class="sub-text" v-if="menu.subText && !menu.children">{{menu.subText}}</span>
<menu-content
class="sub-menu"
:menus="menu.children"
v-if="menu.children && menu.children.length"
:handleClickMenuItem="handleClickMenuItem"
/>
</div>
</li>
</template>
</ul>
</template>
<script lang="ts" setup>
import type { ContextmenuItem } from './types'
defineProps<{
menus: ContextmenuItem[]
handleClickMenuItem: (item: ContextmenuItem) => void
}>()
</script>
<style lang="scss" scoped>
$menuWidth: 180px;
$menuHeight: 30px;
$subMenuWidth: 120px;
.menu-content {
width: $menuWidth;
padding: 5px 0;
background: #fff;
border: 1px solid $borderColor;
box-shadow: $boxShadow;
border-radius: $borderRadius;
list-style: none;
margin: 0;
}
.menu-item {
padding: 0 20px;
color: #555;
font-size: 12px;
transition: all $transitionDelayFast;
white-space: nowrap;
height: $menuHeight;
line-height: $menuHeight;
background-color: #fff;
cursor: pointer;
&:not(.disable):hover > .menu-item-content > .sub-menu {
display: block;
}
&:not(.disable):hover > .has-children.has-handler::after {
transform: scale(1);
}
&:hover:not(.disable) {
background-color: rgba($color: $themeColor, $alpha: .2);
}
&.divider {
height: 1px;
overflow: hidden;
margin: 5px;
background-color: #e5e5e5;
line-height: 0;
padding: 0;
}
&.disable {
color: #b1b1b1;
cursor: no-drop;
}
}
.menu-item-content {
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
&.has-children::before {
content: '';
display: inline-block;
width: 8px;
height: 8px;
border-width: 1px;
border-style: solid;
border-color: #666 #666 transparent transparent;
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%) rotate(45deg);
}
&.has-children.has-handler::after {
content: '';
display: inline-block;
width: 1px;
height: 24px;
background-color: rgba($color: #fff, $alpha: .3);
position: absolute;
right: 18px;
top: 3px;
transform: scale(0);
transition: transform $transitionDelay;
}
.sub-text {
opacity: 0.6;
}
.sub-menu {
width: $subMenuWidth;
position: absolute;
display: none;
left: 112%;
top: -6px;
}
}
</style> |