1
0

index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="shortcut" :style="{ height: moreStatus ? 'auto' : '50px' }" @mouseleave="moreClose">
  3. <div class="tags" @mouseenter="moreOpen">
  4. <router-link v-for="item in shortcutMenuList" :key="item.menuId" :to="'/' + item.path + '/'" class="tag">
  5. <span class="font_name">{{ item.menuName }}</span>
  6. <i class="el-icon-error" v-show="delStatus" @click.prevent="deleteShortcutMenu(item)"></i>
  7. </router-link>
  8. </div>
  9. <div class="btns">
  10. <a href="javascript:void(0);" title="删除" @click="delStatus = !delStatus">
  11. <i class="el-icon-delete"></i>
  12. </a>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import { getUserShortcutMenuList, deleteUserShortcutMenu, addUserShortcutMenu } from '@/api/system/menu'
  18. import EventBus from '@/utils/eventBus'
  19. export default {
  20. data() {
  21. return {
  22. moreStatus: false,
  23. delStatus: false,
  24. shortcutMenuList: [], // 快捷菜单列表
  25. userId: '' // 用户ID
  26. }
  27. },
  28. computed: {
  29. theme() {
  30. return this.$store.state.settings.theme
  31. }
  32. },
  33. mounted() {
  34. this.$nextTick(() => {
  35. EventBus.$on('addShortcutMenu', obj => {
  36. const existence = this.shortcutMenuList.some((item) => obj.menuId == item.menuId)
  37. if (existence) {
  38. this.$msg({ type: 'warning', message: '该菜单已存在' })
  39. } else {
  40. let param = {menuId: obj.menuId, userId: this.userId}
  41. addUserShortcutMenu(param).then(res => {
  42. if (res.code === 200) {
  43. this.getUserShortcutMenuList()
  44. }
  45. })
  46. }
  47. })
  48. })
  49. },
  50. created() {
  51. this.getUserShortcutMenuList()
  52. },
  53. methods: {
  54. // 快捷菜单列表
  55. getUserShortcutMenuList() {
  56. this.userId = this.$store.state.user.userId
  57. getUserShortcutMenuList(this.userId).then(res => {
  58. this.shortcutMenuList = res.data
  59. })
  60. },
  61. // 删除快捷菜单
  62. deleteShortcutMenu(menu) {
  63. let obj = {
  64. menuId: menu.menuId,
  65. userId: this.userId
  66. }
  67. this.$modal
  68. .confirm('是否确认删除菜单名称为"' + menu.menuName + '"的数据项?')
  69. .then(function () {
  70. return deleteUserShortcutMenu(obj)
  71. })
  72. .then(res => {
  73. this.getUserShortcutMenuList()
  74. this.$modal.msgSuccess('删除成功')
  75. this.delStatus = false
  76. })
  77. .catch(() => {})
  78. },
  79. isActive(route) {
  80. return route.path === this.$route.path
  81. },
  82. activeStyle(tag) {
  83. if (!this.isActive(tag)) return {}
  84. return {
  85. 'background-color': this.theme,
  86. 'border-color': this.theme
  87. }
  88. },
  89. moreOpen() {
  90. this.moreStatus = true
  91. },
  92. moreClose() {
  93. this.moreStatus = false
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped lang="scss">
  99. .shortcut {
  100. height: 40px;
  101. line-height: 40px;
  102. padding: 0 10px;
  103. overflow: hidden;
  104. display: flex;
  105. justify-content: space-between;
  106. .tags {
  107. flex: 1;
  108. .tag {
  109. font-size: 14px;
  110. color: #fff;
  111. margin-right: 5px;
  112. display: inline-block;
  113. position: relative;
  114. background: #4c9898;
  115. border: #4c9898 1px solid;
  116. border-radius: 5px;
  117. margin-top: 7px;
  118. padding: 0 15px;
  119. i {
  120. position: absolute;
  121. top: 20%;
  122. right: -10px;
  123. }
  124. }
  125. }
  126. .btns {
  127. height: 50px;
  128. display: flex;
  129. align-items: center;
  130. i {
  131. font-size: 18px;
  132. color: #fff;
  133. }
  134. // .more-open i {
  135. // transform: rotate(-90deg);
  136. // -webkit-transform: rotate(-90deg);
  137. // -moz-transform: rotate(-90deg);
  138. // -o-transform: rotate(-90deg);
  139. // -mz-transform: rotate(-90deg);
  140. // }
  141. // .more-close i {
  142. // transform: rotate(90deg);
  143. // -webkit-transform: rotate(90deg);
  144. // -moz-transform: rotate(90deg);
  145. // -o-transform: rotate(90deg);
  146. // -mz-transform: rotate(90deg);
  147. // }
  148. }
  149. }
  150. </style>