index.vue 3.9 KB

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