menu.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <script setup lang="ts">
  2. import { useCommonStoreHook } from "@/store";
  3. const { currentMenu, currentProjectId, currentExecutionId } =
  4. toRefs(useCommonStoreHook());
  5. interface MenuItem {
  6. name: string;
  7. icon: string;
  8. route: string;
  9. }
  10. const menus = ref<MenuItem[]>([
  11. {
  12. name: "首页",
  13. icon: "home",
  14. route: "/main/home",
  15. },
  16. {
  17. name: "测试执行",
  18. icon: "run-test",
  19. route: "/main/run-test",
  20. },
  21. {
  22. name: "数据管理",
  23. icon: "data-manager",
  24. route: "/main/data-manager",
  25. },
  26. {
  27. name: "工程配置",
  28. icon: "project-config",
  29. route: "/main/project-config",
  30. },
  31. {
  32. name: "报告模版",
  33. icon: "report-template",
  34. route: "/main/report-template",
  35. },
  36. {
  37. name: "人员管理",
  38. icon: "person-manager",
  39. route: "/main/person-manager",
  40. },
  41. ]);
  42. const router = useRouter();
  43. const handleMenuClick = (menu: MenuItem) => {
  44. if (menu.route != currentMenu.value.route) {
  45. // 如果工程配置没有值,就不跳转,并提示 && !currentProjectId.value
  46. if (menu.route === "/main/project-config" && !currentProjectId.value) {
  47. ElMessage.warning("请先在首页选择工程");
  48. return;
  49. }
  50. if (menu.route === "/main/run-test" && !currentExecutionId.value) {
  51. ElMessage.warning("请先在首页执行工程");
  52. return;
  53. }
  54. currentMenu.value = menu;
  55. router.push(menu.route);
  56. }
  57. };
  58. </script>
  59. <template>
  60. <div class="menu">
  61. <div
  62. class="menu-box"
  63. v-for="menu in menus"
  64. :key="menu.name"
  65. @click="handleMenuClick(menu)"
  66. >
  67. <!-- 这里的图标可以用可变色的svg 传过去一个color属性,然后根据当前路由的颜色来显示不同的颜色-->
  68. <svg-icon
  69. :icon-class="menu.icon"
  70. size="24"
  71. :style="{
  72. color: menu.route === currentMenu.route ? 'white' : '#AFB9D0',
  73. }"
  74. />
  75. <div
  76. class="name"
  77. :class="[menu.route === currentMenu.route ? 'selected' : 'normal']"
  78. >
  79. {{ menu.name }}
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <style scoped lang="scss">
  85. .menu {
  86. height: calc(100vh - $main-header-height);
  87. width: 79px;
  88. display: flex;
  89. flex-direction: column;
  90. justify-content: start;
  91. align-items: center;
  92. padding: 12px 6px;
  93. background-color: $hj-black-1;
  94. .menu-box {
  95. width: 64px;
  96. height: 64px;
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: center;
  100. align-items: center;
  101. margin-bottom: 12px;
  102. .name {
  103. margin-top: 10px;
  104. font-weight: bold;
  105. font-size: 12px;
  106. line-height: 19px;
  107. text-align: center;
  108. }
  109. .normal {
  110. color: #afb9d0;
  111. }
  112. .selected {
  113. color: $hj-white-1;
  114. }
  115. }
  116. }
  117. </style>