index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div
  3. ref="myContextMenu"
  4. class="context-menu"
  5. v-show="contextMenu.displayContextMenu"
  6. :style="{
  7. left: contextMenu.clientX + 'px',
  8. top: contextMenu.clientY + 'px',
  9. }"
  10. >
  11. <div class="contentMenu">
  12. <!-- <div class="dropbtn" :style='{"background-color":mark.color,"border-radius":"50%","width":"12px","height":"12px","margin-top":"1px"}'>
  13. <el-input type="color" v-model="mark.color" style="opacity: 0;user-select:none;" @input="changeColor()"/>
  14. </div> -->
  15. <div class="color_item" :style='{"background-color":contextMenu.mark.color}'>
  16. <el-input type="color" v-model="contextMenu.mark.color" @input="changeColor()"/>
  17. <!-- <el-color-picker popper-class="menu_color" v-model="contextMenu.mark.color" size="mini" @change="changeColor"></el-color-picker> -->
  18. </div>
  19. <div
  20. class="item"
  21. v-for="(item, i) in contextMenu.menuContent"
  22. :key="i"
  23. :class="item.disabled ? 'disabled' : ''"
  24. @click="emitEvent(item.method)">
  25. {{ item.name }}
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { mapGetters } from "vuex";
  32. export default {
  33. name: "ContextMenu",
  34. data() {
  35. return {
  36. };
  37. },
  38. computed: {
  39. ...mapGetters(["contextMenu"]),
  40. displayContextMenu(){
  41. return this.$store.state.contextMenu.displayContextMenu
  42. }
  43. },
  44. watch:{
  45. displayContextMenu(val){
  46. if(val){
  47. this.$nextTick(()=>{
  48. var maxWidth = document.body.clientWidth
  49. var menuWidth = this.$refs.myContextMenu.clientWidth
  50. if(this.contextMenu.clientX + menuWidth > (maxWidth-10)){
  51. this.$refs.myContextMenu.style.width = menuWidth + 'px'
  52. this.contextMenu.clientX -= (this.contextMenu.clientX + menuWidth - maxWidth + 10)
  53. }
  54. })
  55. }else{
  56. this.$refs.myContextMenu.style.width = ''
  57. }
  58. }
  59. },
  60. mounted(){
  61. this.$nextTick(()=>{
  62. window.addEventListener('mousedown',()=>{
  63. this.$store.commit("SET_CONTEXT_MENU",
  64. {
  65. displayContextMenu: false,
  66. }
  67. )
  68. })
  69. })
  70. },
  71. methods: {
  72. emitEvent(type) {
  73. this.$emit("operateDirectory", type);
  74. },
  75. changeColor(){
  76. this.$emit("operateDirectory", 'changeColor');
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="scss">
  82. .menu_color{
  83. .el-button--text{
  84. display: none;
  85. }
  86. }
  87. .context-menu{
  88. .el-color-picker__trigger{
  89. height: 22px;
  90. width: 22px;
  91. border:none;
  92. .el-color-picker__color{
  93. border-radius: 50%;
  94. border:none;
  95. }
  96. }
  97. }
  98. </style>
  99. <style lang="scss" scoped>
  100. .context-menu {
  101. height: 30px;
  102. user-select:none;
  103. position: absolute;
  104. left: 0;
  105. bottom: 0;
  106. top: 0;
  107. background: #fff;
  108. color: #34495e;
  109. min-width: 100px;
  110. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.2);
  111. border-radius: 15px;
  112. cursor: pointer;
  113. z-index: 1002;
  114. .color_item{
  115. border-radius:50%;
  116. width:12px;
  117. height:12px;
  118. margin-top:1px;
  119. cursor: pointer;
  120. }
  121. .color_item>*{
  122. cursor: pointer;
  123. opacity: 0;
  124. user-select: none;
  125. }
  126. .contentMenu {
  127. text-align: center;
  128. padding: 5px 10px;
  129. display: flex;
  130. align-items: center;
  131. .item {
  132. min-width: 54px !important;
  133. white-space: nowrap;
  134. padding: 3px 8px;
  135. font-size: 12px;
  136. list-style: none;
  137. display: inline-block;
  138. text-align-last: justify;
  139. justify-content: space-between;
  140. border-right:1px solid #E4E7ED;
  141. cursor: pointer;
  142. &:hover {
  143. background: #edf6ff;
  144. }
  145. }
  146. .item:last-child{
  147. border-right:none;
  148. }
  149. .disabled {
  150. color: #888585;
  151. pointer-events: none;
  152. }
  153. }
  154. }
  155. </style>