index.vue 4.5 KB

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