layoutSilder.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { defineComponent, onMounted, reactive } from 'vue';
  2. import { NImage } from 'naive-ui';
  3. import styles from './index.module.less';
  4. import logo from './images/logo.png';
  5. import classIcon from './images/classIcon.png';
  6. import classNormal from './images/classNormal.png';
  7. import indexIcon from './images/indexIcon.png';
  8. import indexNormal from './images/indexNormal.png';
  9. import kuIcon from './images/kuIcon.png';
  10. import kuNormal from './images/kuNormal.png';
  11. import palyIcon from './images/palyIcon.png';
  12. import palyNormal from './images/palyNormal.png';
  13. import resourceIcon from './images/resourceIcon.png';
  14. import resourceNormal from './images/resourceNormal.png';
  15. import setIcon from './images/setIcon.png';
  16. import setNormal from './images/setNormal.png';
  17. import studentIcon from './images/studentIcon.png';
  18. import studentNormal from './images/studentNormal.png';
  19. import SilderItem from './modals/silderItem';
  20. import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router';
  21. export default defineComponent({
  22. name: 'layoutSilder',
  23. setup() {
  24. const router = useRouter();
  25. const route = useRoute();
  26. const itemInfoList = reactive([
  27. {
  28. activeIcon: indexIcon,
  29. name: '主页',
  30. normalIcon: indexNormal,
  31. isActive: true,
  32. id: 1,
  33. path: '/'
  34. },
  35. {
  36. activeIcon: classIcon,
  37. name: '班级',
  38. normalIcon: classNormal,
  39. isActive: false,
  40. id: 3,
  41. path: '/classList',
  42. lightList: ['/classDetail', '/classStudentRecode', '/afterWorkDetail']
  43. },
  44. {
  45. activeIcon: studentIcon,
  46. name: '学生',
  47. normalIcon: studentNormal,
  48. isActive: false,
  49. id: 2,
  50. path: '/studentList'
  51. },
  52. {
  53. activeIcon: palyIcon,
  54. name: '备课',
  55. normalIcon: palyNormal,
  56. isActive: false,
  57. id: 4,
  58. path: '/prepare-lessons'
  59. },
  60. {
  61. activeIcon: kuIcon,
  62. name: '小酷AI',
  63. normalIcon: kuNormal,
  64. isActive: false,
  65. id: 5,
  66. lightList: ['/xiaoku-music'], //小酷AI的灯光列表
  67. path: '/xiaoku-ai'
  68. },
  69. {
  70. activeIcon: resourceIcon,
  71. name: '资源',
  72. normalIcon: resourceNormal,
  73. isActive: false,
  74. id: 6,
  75. path: '/natural-resources'
  76. },
  77. {
  78. activeIcon: setIcon,
  79. name: '设置',
  80. normalIcon: setNormal,
  81. isActive: false,
  82. id: 7,
  83. path: '/setting'
  84. }
  85. ]);
  86. const checkNavBar = (item: any) => {
  87. itemInfoList.forEach((now: any) => {
  88. now.isActive = false;
  89. if (now.id == item.id) {
  90. now.isActive = true;
  91. // console.log(item.path);
  92. item.path && router.push(item.path);
  93. }
  94. });
  95. };
  96. onBeforeRouteUpdate((to: any) => {
  97. checkPathChange(to.path);
  98. });
  99. const checkPathChange = (path: string) => {
  100. itemInfoList.forEach((now: any) => {
  101. now.isActive = false;
  102. if (now.path === path || now.lightList?.includes(path)) {
  103. now.isActive = true;
  104. }
  105. });
  106. };
  107. onMounted(() => {
  108. checkPathChange(route.path);
  109. });
  110. return () => (
  111. <>
  112. <div class={styles.silder}>
  113. <div class={styles.logoWrap}>
  114. <NImage class={styles.logo} src={logo} preview-disabled></NImage>
  115. </div>
  116. <div class={styles.sliderList}>
  117. {itemInfoList.map((item: any) => (
  118. <SilderItem onCheckNavBar={checkNavBar} item={item} />
  119. ))}
  120. </div>
  121. </div>
  122. </>
  123. );
  124. }
  125. });