menu.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="sw-menu">
  3. <a-menu style="flex:1" v-model:selectedKeys="current" mode="inline" :open-keys="openKeys" @openChange="onOpenChange" active-text-color="#000" @click="itemClick">
  4. <template v-for="item in mods" :key="item.systemmoduleid">
  5. <a-sub-menu v-if="item.apps.length > 1" :key="item.systemmoduleid" @click="modClick(item)">
  6. <template #title>
  7. <div>
  8. <!-- <img width="15" style="margin-top:-2px;margin-right:5px" :src="item.iconurl" alt=""> -->
  9. {{item.systemmodulename}}
  10. </div>
  11. </template>
  12. <template #icon>
  13. <CalendarOutlined />
  14. </template>
  15. <a-menu-item v-for="app in item.apps" :key="app.systemappid" @click="routeChange(app)">
  16. {{app.meta.title}}
  17. </a-menu-item>
  18. </a-sub-menu>
  19. <a-menu-item v-if="item.apps.length == 1" :key="item.systemmoduleid" @click="modClick(item)">
  20. <template #icon>
  21. <CalendarOutlined />
  22. </template>
  23. <span @click="routeChange(item.apps[0])">{{item.apps[0].meta.title}}</span>
  24. </a-menu-item>
  25. </template>
  26. </a-menu>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { ref,onBeforeMount} from 'vue';
  31. import { useAuthStore } from '@/stores/modules/auth'
  32. import { storeToRefs } from 'pinia'
  33. import { useRouter } from "vue-router"
  34. import less from 'less'
  35. import { CalendarOutlined,PieChartOutlined} from '@ant-design/icons-vue'
  36. import {ConfigProvider, Modal } from 'ant-design-vue';
  37. const router = useRouter()
  38. const store = useAuthStore()
  39. let { mods,actMod,system } = storeToRefs(store)
  40. let rootSubmenuKeys = ref([])
  41. let openKeys = ref([])
  42. let selectedKeys = ref([])
  43. const current = ref([])
  44. const onOpenChange = openKey => {
  45. const latestOpenKey = openKey.find(key => openKeys.value.indexOf(key) === -1);
  46. if (rootSubmenuKeys.value.indexOf(latestOpenKey) === -1) {
  47. openKeys.value = openKey;
  48. } else {
  49. openKeys.value = latestOpenKey ? [latestOpenKey] : [];
  50. }
  51. }
  52. const itemClick = (item, key, keyPath)=>{
  53. current.value = item.keyPath
  54. }
  55. const modClick = (item)=>{
  56. actMod.value = item
  57. }
  58. const routeChange = (app)=>{
  59. // store.appData(app)
  60. console.log(app)
  61. router.push({path:app.path})
  62. console.log(app.path);
  63. }
  64. const colorState = ref({})
  65. const setTheme = (themeName)=> {
  66. if (themeName === 'light') {
  67. colorState.value = {
  68. primaryColor: '#f23557',
  69. errorColor: '#eb586f',
  70. warningColor: '#ffde7d',
  71. successColor: '#4aa0d5',
  72. infoColor: '#d8e9f0',
  73. }
  74. ConfigProvider.config({
  75. theme: colorState.value
  76. });
  77. } else if (themeName === 'normal') {
  78. colorState.value = {
  79. primaryColor: '#14317D',
  80. errorColor: '#ff4d4f',
  81. warningColor: '#faad14',
  82. successColor: '#52c41a',
  83. infoColor: '#1890ff',
  84. }
  85. ConfigProvider.config({
  86. theme: colorState.value
  87. });
  88. } else if (themeName === 'caffairs') {
  89. less.modifyVars({
  90. '@base': '#fff' // 要更改为的新颜色值
  91. }).then(() => {
  92. console.log('Primary color has been changed')
  93. }).catch(error => {
  94. console.error(error)
  95. })
  96. colorState.value = {
  97. primaryColor: '#404b69',
  98. errorColor: '#ff5f5f',
  99. warningColor: '#ffc93c',
  100. successColor: '#1fab89',
  101. infoColor: '#dbedf3',
  102. menuBg:'#fff'
  103. }
  104. ConfigProvider.config({
  105. theme: colorState.value
  106. });
  107. }
  108. }
  109. let getKeys = () => {
  110. system.value.forEach(sys => {
  111. sys.modules.forEach(mod => {
  112. rootSubmenuKeys.value.push(mod.systemmoduleid)
  113. })
  114. })
  115. }
  116. onBeforeMount(()=>{
  117. setTheme('normal')
  118. getKeys()
  119. })
  120. </script>
  121. <style scoped>
  122. </style>