index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <!-- 打开的菜单图标显示区 -->
  3. <div class="menu sds-desktop">
  4. <ul class="menushow" v-if="menuList.length" :style="{height:height + 'px',marginTop:marginTop + 'px'}">
  5. <li :class="menu.spacialCls" v-for="(menu,menuIndex) in menuList" :key="menu.index" :style="{background:menu.backgroundColor}"
  6. @click="clickMenuItem(menu.id,menuIndex)">
  7. <div :class="menu.spacialCls" :style="{backgroundImage:`url(${menu.imgUrl})`}"></div>
  8. </li>
  9. </ul>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. menuList:[],
  17. isHaveMenuItem: false,
  18. menuIndex: -1,
  19. height: 0,
  20. marginTop:0
  21. }
  22. },
  23. mounted() {
  24. this.$bus.on('clickShortcutItem',this.clickShortcutItem)
  25. this.$bus.on("changeDialogWindow",this.changeDialogWindow)
  26. this.$bus.on('closeDialogWindow',this.closeDialogWindow)
  27. this.$bus.on('showZindexMaxMenuItem',this.showZindexMaxMenuItem)
  28. },
  29. methods:{
  30. // 点击大图标打开小图标
  31. clickShortcutItem(obj){
  32. let id = obj.id
  33. if(this.menuList.length > 0){
  34. this.menuList.forEach(menu => {
  35. if (menu.id === id) {
  36. menu.backgroundColor = 'rgba(225,225,225,0.5)'
  37. } else {
  38. menu.backgroundColor = 'rgba(50,60,70,0.9)'
  39. }
  40. })
  41. if(this.menuList.length){
  42. this.isHaveMenuItem = this.menuList.some(menu => {
  43. return menu.id === id
  44. })
  45. }
  46. }
  47. if(!this.isHaveMenuItem){
  48. let menuItem = {
  49. id:new Date().getTime(),
  50. spacialCls:obj.spacialCls,
  51. imgUrl:obj.imgUrl,
  52. zIndex:obj.zIndex,
  53. title:obj.title,
  54. id: obj.id,
  55. backgroundColor:'rgba(225,225,225,0.5)'
  56. }
  57. this.menuList.push(menuItem)
  58. }
  59. this.$bus.emit('menuItemChanged',this.menuList)
  60. this.$bus.emit('changeDialogMenuWindow',id)
  61. this.height = document.documentElement.scrollHeight - (document.documentElement.scrollHeight % 70)
  62. this.marginTop = ((document.documentElement.scrollHeight - this.height) / 2 )
  63. },
  64. // 点击小图标切换弹出窗口
  65. clickMenuItem(id,menuIndex){
  66. this.menuList.forEach(menu => {
  67. menu.backgroundColor = 'rgba(50,60,70,0.9)'
  68. })
  69. this.menuList[menuIndex].backgroundColor = 'rgba(225,225,225,0.5)'
  70. // 打开个人设置页面
  71. if(id === 1111){
  72. this.$bus.emit('openUserSetting')
  73. }
  74. },
  75. // 点击弹出窗页面切换小图标选中状态
  76. changeDialogWindow(menu){
  77. if(typeof(menu) == 'string'){
  78. this.getMenuItem(menu)
  79. if(this.menuIndex != -1){
  80. this.menuList.forEach(menu => {
  81. menu.backgroundColor = 'rgba(50,60,70,0.9)'
  82. })
  83. this.menuList[this.menuIndex].backgroundColor = 'rgba(225,225,225,0.5)'
  84. }
  85. }else if (typeof(menu) == 'object'){
  86. this.getMenuItem(menu.id)
  87. this.menuList.forEach(menu => {
  88. menu.backgroundColor = 'rgba(50,60,70,0.9)'
  89. })
  90. if(this.menuIndex == -1){
  91. this.clickShortcutItem(menu)
  92. }else{
  93. this.menuList[this.menuIndex].backgroundColor = 'rgba(225,225,225,0.5)'
  94. }
  95. }
  96. },
  97. // 点击弹出窗页面叉号删去小图标
  98. closeDialogWindow(id){
  99. this.getMenuItem(id)
  100. this.menuList.splice(this.menuIndex,1)
  101. if(!this.menuList.length){
  102. this.isHaveMenuItem = false
  103. }else{
  104. let hasCheckedMenu = this.menuList.some(item=>{
  105. return item.backgroundColor == 'rgba(225,225,225,0.5)'
  106. })
  107. if (!hasCheckedMenu){
  108. this.menuList[this.menuList.length - 1].backgroundColor = 'rgba(225,225,225,0.5)'
  109. }
  110. }
  111. this.height = document.documentElement.scrollHeight - (document.documentElement.scrollHeight % 70)
  112. this.marginTop = ((document.documentElement.scrollHeight - this.height) / 2 )
  113. },
  114. // 通过id获取对应的小图标下标
  115. getMenuItem(id){
  116. this.menuIndex = this.menuList.findIndex(item =>{
  117. return item.id === id
  118. })
  119. },
  120. // 显示zindex最大的menuItem
  121. showZindexMaxMenuItem(){
  122. }
  123. },
  124. beforeDestroy() {
  125. this.$bus.off('clickShortcutItem',this.clickShortcutItem)
  126. this.$bus.off("changeDialogWindow",this.changeDialogWindow)
  127. this.$bus.off('closeDialogWindow',this.closeDialogWindow)
  128. },
  129. name:'Menu',
  130. }
  131. </script>