layoutSilder.tsx 3.9 KB

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