index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div style="overflow-y: auto; display: flex">
  3. <!-- 主要内容区域 -->
  4. <div style="flex: 1; margin-left: 0px">
  5. <a-layout>
  6. <Header @onChangeCurrent="onChangeCurrent" />
  7. <div style="width: 90%; margin-left: 5%; display: flex">
  8. <div class="sidebar-menu">
  9. <ul>
  10. <li
  11. v-for="item in menuItems"
  12. :class="{ active: activeKey === item.key }"
  13. :key="item.key"
  14. @click="handleClick(item)"
  15. >
  16. <component :is="item.icon" />
  17. <!-- <AliwangwangOutlined /> -->
  18. {{ item.label }}
  19. </li>
  20. </ul>
  21. </div>
  22. <div style="width: 90%">
  23. <component :is="currentComponent"></component>
  24. </div>
  25. </div>
  26. </a-layout>
  27. <Footer />
  28. </div>
  29. </div>
  30. </template>
  31. <script setup>
  32. import Header from '@/views/portal/components/Header.vue'
  33. import Footer from '@/views/portal/components/Footer.vue'
  34. import myResources from '../myResources.vue'
  35. import { ref, reactive, computed, onMounted, defineAsyncComponent } from 'vue'
  36. import { useRouter, useRoute } from 'vue-router'
  37. import {
  38. HomeOutlined,
  39. FolderOutlined,
  40. StarOutlined,
  41. BookOutlined,
  42. QuestionCircleOutlined,
  43. BankOutlined,
  44. SolutionOutlined,
  45. ScheduleOutlined
  46. } from '@ant-design/icons-vue'
  47. const router = useRouter()
  48. const route = useRoute()
  49. const indexType = ref('resources') // 默认选中“我的主页”
  50. const activeKey = ref('resources') // 当前选中项
  51. const itemData = ref({})
  52. const VideoDetailsRef = ref(null)
  53. const selectedKeys = ref(['resources'])
  54. const openKeys = ref(['resources'])
  55. const menuItems = ref([
  56. {
  57. key: 'home',
  58. icon: HomeOutlined,
  59. label: '我的主页',
  60. title: '我的主页'
  61. },
  62. {
  63. key: 'resources',
  64. icon: FolderOutlined,
  65. label: '我的资源',
  66. title: '我的资源'
  67. },
  68. {
  69. key: 'favorites',
  70. icon: StarOutlined,
  71. label: '我的收藏',
  72. title: '我的收藏'
  73. },
  74. {
  75. key: 'albums',
  76. icon: BookOutlined,
  77. label: '我的课程专辑',
  78. title: '我的课程专辑'
  79. },
  80. {
  81. key: 'questionBank',
  82. icon: QuestionCircleOutlined,
  83. label: '我的题库',
  84. title: '我的题库'
  85. },
  86. {
  87. key: 'classroom',
  88. icon: BankOutlined,
  89. label: '我的教室',
  90. title: '我的教室'
  91. },
  92. {
  93. key: 'courses',
  94. label: '我的课程',
  95. icon: SolutionOutlined,
  96. title: '我的课程'
  97. },
  98. {
  99. key: 'tasks',
  100. label: '我的任务',
  101. icon: ScheduleOutlined,
  102. title: '我的任务'
  103. }
  104. ])
  105. const handleClick = (e) => {
  106. selectedKeys.value = [e.key]
  107. activeKey.value = e.key
  108. indexType.value = e.key
  109. }
  110. const currentComponent = computed(() => {
  111. // if (indexType.value !== 'resources') {
  112. // return false
  113. // }
  114. switch (indexType.value) {
  115. // case 'home':
  116. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/Home.vue'))
  117. case 'resources':
  118. return myResources
  119. case 'favorites':
  120. return defineAsyncComponent(() => import('@/views/myFavorites/index.vue'))
  121. // case 'albums':
  122. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/Albums.vue'))
  123. // case 'questionBank':
  124. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/QuestionBank.vue'))
  125. // case 'classroom':
  126. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/Classroom.vue'))
  127. // case 'courses':
  128. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/Courses.vue'))
  129. // case 'tasks':
  130. // return defineAsyncComponent(() => import('@/views/myResources/personalResources/Tasks.vue'))
  131. default:
  132. return myResources
  133. }
  134. })
  135. const handlerItemSidebar = (item) => {
  136. // emit('handlerItemSidebar', item)
  137. }
  138. const onChangeCurrent = (current) => {
  139. indexType.value = current
  140. router.push({
  141. path: '/' + current
  142. })
  143. }
  144. const setData = (item) => {
  145. getData(item)
  146. }
  147. const getData = (item) => {
  148. detail({ id: item.id })
  149. .then((res) => {
  150. if (res.code == 200) {
  151. itemData.value = res.data
  152. }
  153. })
  154. .catch((err) => {})
  155. }
  156. onMounted(() => {
  157. const id = route.query.id
  158. if (id != undefined && id != '') {
  159. addViewCount({ id: id })
  160. getData({ id: id })
  161. }
  162. })
  163. defineExpose({
  164. setData
  165. })
  166. </script>
  167. <style scoped>
  168. .a-menu {
  169. width: 256px;
  170. height: 600px;
  171. background-color: #fff;
  172. border-right: 1px solid #e8e8e8;
  173. }
  174. .content {
  175. border: 1px solid #00000011;
  176. /* 灰色细边框 */
  177. }
  178. .scroll-container {
  179. height: 100vh;
  180. overflow-y: auto;
  181. }
  182. .sidebar-menu {
  183. flex: 1;
  184. background-color: #ffff;
  185. color: #0000007c;
  186. }
  187. .sidebar-menu ul {
  188. list-style-type: none;
  189. padding: 0;
  190. }
  191. .sidebar-menu li {
  192. padding: 10px;
  193. cursor: pointer;
  194. }
  195. .sidebar-menu li:hover {
  196. background-color: #e6f7ff;
  197. color: #ccc;
  198. }
  199. .active {
  200. color: #ffff;
  201. background-color: #1073cff7;
  202. }
  203. </style>