moduleMenu.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="layout-items-center" v-if="moduleUnfoldOpen && layout !== layoutEnum.TOP">
  3. <a-menu
  4. v-model:selectedKeys="selectedKeys"
  5. mode="horizontal"
  6. v-if="menu && menu.length > 1 && !isMobile"
  7. class="module-menu"
  8. id="moduleMenu"
  9. >
  10. <a-menu-item
  11. v-for="item in menu"
  12. :key="item.id"
  13. class="xn-pxn-r"
  14. @click="moduleClick(item.id)"
  15. :class="{ 'ant-menu-item-select': item.id === module }"
  16. >
  17. <template #icon>
  18. <component :is="item.meta.icon" />
  19. </template>
  20. <span class="xn-ml-5">{{ item.meta.title }}</span>
  21. </a-menu-item>
  22. </a-menu>
  23. </div>
  24. <div v-else>
  25. <a-popover v-if="menu.length > 1 && !isMobile" placement="bottomLeft">
  26. <template #content>
  27. <a-row :gutter="[0, 5]" class="module-row">
  28. <div v-for="item in menu" :key="item.id">
  29. <a-col :span="6">
  30. <a-tag
  31. class="module-card"
  32. :class="roundedCornerStyleOpen ? 'module-card-radius-round' : 'module-card-radius-default'"
  33. :color="item.color"
  34. @click="moduleClick(item.id)"
  35. >
  36. <component :is="item.meta.icon" class="module-card-icon" />
  37. <div class="module-card-font">{{ item.meta.title }}</div>
  38. </a-tag>
  39. </a-col>
  40. </div>
  41. </a-row>
  42. </template>
  43. <div class="panel-item hidden-sm-and-down module-card-scope">
  44. <appstore-outlined />
  45. </div>
  46. </a-popover>
  47. </div>
  48. </template>
  49. <script setup>
  50. import router from '@/router'
  51. import tool from '@/utils/tool'
  52. import { globalStore } from '@/store'
  53. import { watch } from 'vue'
  54. import { storeToRefs } from 'pinia'
  55. import { layoutEnum } from '@/layout/enum/layoutEnum'
  56. const store = globalStore()
  57. const { moduleUnfoldOpen, topHeaderThemeColorOpen } = storeToRefs(store)
  58. const moduleBackColor = ref(topHeaderThemeColorOpen)
  59. const module = computed(() => {
  60. return store.module
  61. })
  62. const isMobile = computed(() => {
  63. return store.isMobile
  64. })
  65. const themeColor = computed(() => {
  66. return store.themeColor
  67. })
  68. const theme = computed(() => {
  69. return store.theme
  70. })
  71. // 圆角风格
  72. const roundedCornerStyleOpen = computed(() => {
  73. return store.roundedCornerStyleOpen
  74. })
  75. // 监听目录是否折叠
  76. watch(moduleUnfoldOpen, () => {
  77. nextTick(() => {
  78. setModuleBackColor()
  79. })
  80. })
  81. // 切换应用后
  82. watch(module, (newValue) => {
  83. selectedKeys.value = [newValue]
  84. setSelectedKeys()
  85. })
  86. // 颜色变化后
  87. watch(themeColor, () => {
  88. nextTick(() => {
  89. setModuleBackColor()
  90. })
  91. })
  92. // 暗黑明亮变化后
  93. watch(theme, () => {
  94. nextTick(() => {
  95. setModuleBackColor()
  96. })
  97. })
  98. // 屏幕缩小后再放大
  99. watch(isMobile, (newValue) => {
  100. if (!newValue) {
  101. nextTick(() => {
  102. setModuleBackColor()
  103. })
  104. }
  105. })
  106. // 监听是否开启了顶栏颜色
  107. watch(topHeaderThemeColorOpen, (newValue) => {
  108. moduleBackColor.value = newValue
  109. setModuleBackColor()
  110. })
  111. // 监听圆角变化
  112. watch(roundedCornerStyleOpen, () => {
  113. nextTick(() => {
  114. setModuleBackColor()
  115. })
  116. })
  117. const emit = defineEmits({ switchModule: null })
  118. const menu = router.getMenu()
  119. const selectedKeys = ref([module.value])
  120. const moduleClick = (id) => {
  121. emit('switchModule', id)
  122. tool.data.set('SNOWY_MENU_MODULE_ID', id)
  123. nextTick(() => {
  124. setSelectedKeys()
  125. })
  126. }
  127. const layout = computed(() => {
  128. return store.layout
  129. })
  130. onMounted(() => {
  131. setModuleBackColor()
  132. })
  133. // 设置背景色
  134. const setModuleBackColor = () => {
  135. if (moduleUnfoldOpen.value) {
  136. try {
  137. const moduleMenu = document.getElementById('moduleMenu')
  138. moduleBackColor.value
  139. ? moduleMenu.classList.add('module-menu-color')
  140. : moduleMenu.classList.remove('module-menu-color')
  141. // eslint-disable-next-line no-empty
  142. } catch (err) {}
  143. setSelectedKeys()
  144. }
  145. }
  146. // 设置选中
  147. const setSelectedKeys = () => {
  148. // 顶部应用列表让显示出来默认的
  149. moduleBackColor.value
  150. ? (selectedKeys.value = new Array([]))
  151. : (selectedKeys.value = [tool.data.get('SNOWY_MENU_MODULE_ID')])
  152. }
  153. </script>
  154. <style lang="less">
  155. .xn-pxn-r {
  156. position: relative;
  157. }
  158. .module-row {
  159. max-width: 357px;
  160. }
  161. .module-card {
  162. width: 70px;
  163. height: 70px;
  164. background-color: #0d84ff;
  165. text-align: center;
  166. align-items: center;
  167. cursor: pointer;
  168. }
  169. .module-card-radius-default {
  170. border-radius: 2px;
  171. }
  172. .module-card-radius-round {
  173. border-radius: 6px;
  174. }
  175. .module-card-icon {
  176. color: white;
  177. font-size: 16px;
  178. margin-top: 15px;
  179. }
  180. .module-card-font {
  181. color: white;
  182. }
  183. .ant-menu-horizontal > .ant-menu-item::after,
  184. .ant-menu-horizontal > .ant-menu-submenu::after {
  185. content: none;
  186. }
  187. .module-menu {
  188. line-height: 50px;
  189. border-bottom: 0;
  190. width: 105%;
  191. flex: 0 0 auto;
  192. }
  193. .module-menu-color {
  194. color: white;
  195. background-color: var(--primary-color);
  196. }
  197. .module-menu-color .ant-menu-item {
  198. color: white !important;
  199. }
  200. .module-card-scope {
  201. height: 49px;
  202. }
  203. .ant-menu-item-select {
  204. color: #ccc;
  205. background-color: var(--primary-7);
  206. }
  207. .xn-ml-5 {
  208. margin-left: -5px;
  209. }
  210. .ant-menu-horizontal > .ant-menu-item::after,
  211. .ant-menu-horizontal > .ant-menu-submenu::after {
  212. display: none;
  213. }
  214. </style>