123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <template>
- <div
- ref="myContextMenu"
- class="context-menu"
- v-show="contextMenu.displayContextMenu"
- :style="{
- left: contextMenu.clientX + 'px',
- top: contextMenu.clientY + 'px',
- }"
- >
- <div class="contentMenu">
- <!-- <div class="dropbtn" :style='{"background-color":mark.color,"border-radius":"50%","width":"12px","height":"12px","margin-top":"1px"}'>
- <el-input type="color" v-model="mark.color" style="opacity: 0;user-select:none;" @input="changeColor()"/>
- </div> -->
- <div class="color_item" ref="context_menu_color" :style='{"background-color":contextMenu.mark.color}'>
- <el-input type="color" v-model="contextMenu.mark.color" @input="changeColor()"/>
- <!-- <el-color-picker popper-class="menu_color" v-model="contextMenu.mark.color" size="mini" @change="changeColor"></el-color-picker> -->
- </div>
- <div
- class="item"
- ref="context_menu_item"
- v-for="(item, i) in contextMenu.menuContent"
- :key="i"
- :class="item.disabled ? 'disabled' : ''"
- @click="emitEvent(item.method)">
- {{ item.name }}
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import { mapGetters } from "vuex";
- export default {
- name: "ContextMenu",
- data() {
- return {
- };
- },
- computed: {
- ...mapGetters(["contextMenu"]),
- displayContextMenu(){
- return this.$store.state.contextMenu.displayContextMenu
- }
- },
- watch:{
- displayContextMenu(val){
- if(val){
- this.$nextTick(()=>{
- var maxWidth = document.body.clientWidth
- var menuWidth = this.$refs.myContextMenu.clientWidth
- if(this.contextMenu.clientX + menuWidth > (maxWidth-10)){
- this.$refs.myContextMenu.style.width = menuWidth + 'px'
- this.contextMenu.clientX -= (this.contextMenu.clientX + menuWidth - maxWidth + 10)
- }
- })
- }else{
- this.$refs.myContextMenu.style.width = ''
- }
- }
- },
- mounted(){
- this.$nextTick(()=>{
- window.addEventListener('mousedown',(e)=>{
- var div = this.$refs.myContextMenu
- if(div && div.style && div.style.display!='none'){
- if (!div.contains(e.target)) {
- this.$store.commit("SET_CONTEXT_MENU",
- {
- displayContextMenu: false,
- }
- )
- }
- }
- })
- window.addEventListener('beforeunload',(e)=>{
- this.$store.commit("SET_CONTEXT_MENU",
- {
- displayContextMenu: false,
- }
- )
- })
- })
-
- },
- methods: {
- emitEvent(type) {
- this.$emit("operateDirectory", type);
- this.$store.commit("SET_CONTEXT_MENU",
- {
- displayContextMenu: false,
- }
- )
- },
- changeColor(){
- this.$emit("operateDirectory", 'changeColor');
- },
- },
- destroyed(){
- window.removeEventListener('mousedown',()=>{})
- window.removeEventListener('beforeunload',()=>{})
- },
- };
- </script>
-
- <style lang="scss">
- .menu_color{
- .el-button--text{
- display: none;
- }
- }
- .context-menu{
- .el-color-picker__trigger{
- height: 22px;
- width: 22px;
- border:none;
- .el-color-picker__color{
- border-radius: 50%;
- border:none;
- }
- }
- }
- </style>
- <style lang="scss" scoped>
- .context-menu {
- height: 30px;
- user-select:none;
- position: absolute;
- background: #fff;
- color: #34495e;
- min-width: 100px;
- box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.2);
- border-radius: 15px;
- // cursor: pointer;
- // z-index: 998;
- .color_item{
- border-radius:50%;
- width:12px;
- height:12px;
- margin-top:1px;
- cursor: pointer;
- }
- .color_item>*{
- cursor: pointer;
- opacity: 0;
- user-select: none;
- }
- .contentMenu {
- text-align: center;
- padding: 5px 10px;
- display: flex;
- align-items: center;
- // z-index: 9999999;
- .item {
- min-width: 54px !important;
- white-space: nowrap;
- padding: 3px 8px;
- font-size: 12px;
- list-style: none;
- display: inline-block;
- text-align-last: justify;
- justify-content: space-between;
- border-right:1px solid #E4E7ED;
- // z-index: 9999999;
- cursor: pointer;
- &:hover {
- background: #edf6ff;
- }
- }
- .item:last-child{
- border-right:none;
- }
- .disabled {
- color: #888585;
- pointer-events: none;
- }
- }
- }
- </style>
|