ProjectMenu.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="menu">
  3. <ul class="menu-list">
  4. <li
  5. v-for="{ key, name } in subMenuList"
  6. :key="key"
  7. :class="['menu-item', { active: activeKey === key }]"
  8. @click="changeSubMenu(key)"
  9. >
  10. {{ name }}
  11. </li>
  12. </ul>
  13. </div>
  14. </template>
  15. <script>
  16. import { getToken } from '@/utils/auth';
  17. export default {
  18. name: 'ProjectMenu',
  19. props: {
  20. curKey: {
  21. type: String,
  22. default: 'project',
  23. },
  24. },
  25. data() {
  26. const token = getToken();
  27. const userType = (token?.user_type ?? 'USER').toUpperCase();
  28. const subMenuMap = {
  29. USER: [
  30. { key: 'project', name: '项目' },
  31. { key: 'book', name: '已上架教材' },
  32. ],
  33. ORG_MANAGER: [
  34. { key: 'org/project', name: '已立项' },
  35. { key: 'org/final', name: '已终审' },
  36. { key: 'org/book', name: '已上架教材' },
  37. { key: 'org/authorization', name: '教程第三方应用授权' },
  38. ],
  39. };
  40. return {
  41. activeKey: this.curKey,
  42. subMenuList: subMenuMap[userType] || [],
  43. };
  44. },
  45. methods: {
  46. /**
  47. * 切换子菜单
  48. * @param {number} key - 子菜单键
  49. */
  50. changeSubMenu(key) {
  51. if (key === this.activeKey) return;
  52. this.activeKey = key;
  53. this.$router.push({ path: `/project_manage/${key}` });
  54. },
  55. },
  56. };
  57. </script>
  58. <style lang="scss" scoped>
  59. .menu {
  60. z-index: 9;
  61. display: flex;
  62. background-color: $main-background-color;
  63. &-list {
  64. display: flex;
  65. justify-content: space-around;
  66. background-color: #f5f5f5;
  67. border-radius: 8px;
  68. .menu-item {
  69. padding: 10px 20px;
  70. cursor: pointer;
  71. background-color: #ebebeb;
  72. border: $border;
  73. border-radius: 4px;
  74. transition: background-color 0.3s ease;
  75. &:hover {
  76. background-color: #e0e0e0;
  77. }
  78. &.active {
  79. font-weight: bold;
  80. background-color: #fff;
  81. box-shadow: 0 2px 4px #e6e6e6;
  82. }
  83. }
  84. }
  85. }
  86. </style>