layoutSilder.tsx 4.3 KB

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