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. },
  43. {
  44. activeIcon: studentIcon,
  45. name: '学生',
  46. normalIcon: studentNormal,
  47. isActive: false,
  48. id: 2,
  49. path: '/studentList'
  50. },
  51. {
  52. activeIcon: palyIcon,
  53. name: '备课',
  54. normalIcon: palyNormal,
  55. isActive: false,
  56. id: 4,
  57. path: '/prepare-lessons'
  58. },
  59. {
  60. activeIcon: kuIcon,
  61. name: '小酷AI',
  62. normalIcon: kuNormal,
  63. isActive: false,
  64. id: 5,
  65. lightList: ['/xiaoku-music'], //小酷AI的灯光列表
  66. path: '/xiaoku-ai'
  67. },
  68. {
  69. activeIcon: resourceIcon,
  70. name: '资源',
  71. normalIcon: resourceNormal,
  72. isActive: false,
  73. id: 6,
  74. path: '/natural-resources'
  75. },
  76. {
  77. activeIcon: setIcon,
  78. name: '设置',
  79. normalIcon: setNormal,
  80. isActive: false,
  81. id: 7,
  82. path: '/setting'
  83. }
  84. ]);
  85. const checkNavBar = (item: any) => {
  86. itemInfoList.forEach((now: any) => {
  87. now.isActive = false;
  88. if (now.id == item.id) {
  89. now.isActive = true;
  90. // console.log(item.path);
  91. item.path && router.push(item.path);
  92. }
  93. });
  94. };
  95. onBeforeRouteUpdate((to: any) => {
  96. console.log(to, 'to');
  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. });