index.uvue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <script setup lang='ts'>
  2. import Back from '@/components/back.uvue'
  3. import Loading from '@/components/loading.uvue'
  4. import { ref, onMounted, nextTick } from 'vue'
  5. import { type SubjectCatalogResult, querySubjectCatalog } from '@/services/subject/catalog'
  6. import { type SubjectCourseResult, getSubjectCoursePage } from '@/services/subject/course'
  7. import { config } from '@/config'
  8. import { dict } from '@/.cool/store'
  9. const isLoading = ref(true)
  10. const dataList = ref<SubjectCatalogResult[]>([])
  11. const catalog = ref<SubjectCatalogResult>()
  12. const courseList = ref<SubjectCourseResult[]>()
  13. const cardsScrollView = ref<any>(null)
  14. const pageNum = ref(1)
  15. async function getDataList() {
  16. const id = dict.getValueByLabelMapByType('index_subject_id')['数学']
  17. const res = await querySubjectCatalog({
  18. subjectId: id, dataScope: {
  19. sortBy: 'asc',
  20. sortName: 'sortNum',
  21. }
  22. })
  23. dataList.value = res || []
  24. catalog.value = res?.[0] as SubjectCatalogResult
  25. handleSelect(catalog.value)
  26. }
  27. async function handleSelect(val: SubjectCatalogResult) {
  28. catalog.value = val
  29. pageNum.value = 1
  30. await getInfo()
  31. cardsScrollView.value.scrollTo({
  32. top: 0, // 减去顶部偏移
  33. animated: true
  34. })
  35. }
  36. async function getInfo() {
  37. const res = await getSubjectCoursePage({
  38. catalogId: catalog.value?.id, pageNum: pageNum.value, dataScope: {
  39. sortBy: 'asc',
  40. sortName: 'sort_num',
  41. },
  42. })
  43. courseList.value = res.rows || []
  44. }
  45. async function handleScrollToLower() {
  46. }
  47. onMounted(async () => {
  48. await getDataList()
  49. isLoading.value = false
  50. })
  51. </script>
  52. <template>
  53. <Loading v-show="isLoading" />
  54. <cl-page v-show="!isLoading">
  55. <Back />
  56. <!-- 顶部标题栏 -->
  57. <image mode="aspectFill" src="https://oss.xiaoxiongcode.com/static/home/math-bg.png" alt=""
  58. class="w-full h-full object-cover" />
  59. <view class="content">
  60. <!-- 左侧导航菜单 -->
  61. <view class="w-[20vw] h-[100vh] bg-[#116FE988] pt-[70px] pb-[20px] px-[20px]">
  62. <scroll-view direction="vertical" :show-scrollbar="false" class="sidebar" @scrolltolower="handleScrollToLower">
  63. <view v-for="category in dataList" :key="category.id" class="sidebar-item"
  64. :class="{ active: catalog?.id === category.id }" @tap="handleSelect(category)">
  65. <!-- <cl-image :src="category?.ossIconPath" mode="heightFix" class="!h-[28px]"></cl-image> -->
  66. {{ category.name }}
  67. </view>
  68. </scroll-view>
  69. </view>
  70. <!-- 右侧卡片网格 -->
  71. <view class="cards-container">
  72. <view class="header">
  73. {{ catalog?.name }}
  74. </view>
  75. <scroll-view direction="vertical" :show-scrollbar="false" class="cards" ref="cardsScrollView"
  76. @scroll="onScroll">
  77. <view class="grid grid-cols-4 gap-4">
  78. <view class="card" v-for="card in courseList" :key="card.id" :class="`category-${card.catalogId}`"
  79. ref="categoryRefs">
  80. <view class="w-full h-[11vw] rounded-xl overflow-hidden">
  81. <image :src="card?.ossIconPath" mode="aspectFill" class="w-full h-full object-cover"></image>
  82. </view>
  83. <cl-text ellipsis :pt="{
  84. className: '!text-[1.5vw] !font-bold'
  85. }">{{
  86. card.sortNum }}、{{
  87. card.mainTitle }}</cl-text>
  88. <cl-text ellipsis color="#666" :pt="{
  89. className: '!text-[1.2vw]'
  90. }">{{
  91. card.assistantTitle }}</cl-text>
  92. </view>
  93. </view>
  94. </scroll-view>
  95. </view>
  96. </view>
  97. </cl-page>
  98. </template>
  99. <style lang="scss" scoped>
  100. .header {
  101. @apply absolute left-1/2 top-5 text-[#333] font-bold text-xl px-4 py-1 rounded-full;
  102. transform: translateX(-50%);
  103. text-align: center;
  104. background-color: #fff;
  105. .title-tabs {
  106. @apply flex flex-row items-center justify-center rounded-full;
  107. background-color: #9AD2FA;
  108. .tab {
  109. @apply rounded-full;
  110. padding: 5px 10px;
  111. font-size: 16px;
  112. transition: all 0.3s ease;
  113. &.active {
  114. background-color: white;
  115. color: #1E88E5;
  116. font-weight: bold;
  117. }
  118. }
  119. }
  120. }
  121. .content {
  122. display: flex;
  123. flex-direction: row;
  124. position: absolute;
  125. left: 0;
  126. top: 0;
  127. width: 100%;
  128. height: 100%;
  129. .sidebar {
  130. height: calc(100vh - 90px);
  131. .sidebar-item {
  132. @apply text-white rounded-full py-1 px-2 cursor-pointer flex flex-row items-center;
  133. margin-bottom: 8px;
  134. transition: all 0.3s ease;
  135. font-size: 1.5vw;
  136. overflow: hidden;
  137. text-overflow: ellipsis;
  138. white-space: nowrap;
  139. width: 100%;
  140. &.active {
  141. background-color: rgba(255, 255, 255, 1);
  142. color: #1E88E5;
  143. font-weight: bold;
  144. }
  145. .sidebar-icon {
  146. font-size: 28px;
  147. margin-right: 2px;
  148. }
  149. }
  150. }
  151. .cards-container {
  152. @apply relative;
  153. flex: 1;
  154. width: 100%;
  155. padding: 20px;
  156. padding-top: 70px;
  157. // background: linear-gradient(0deg, #2EB2FD, #0B85F4);
  158. .cards {
  159. height: calc(100vh - 90px);
  160. }
  161. .category-section {
  162. margin-bottom: 40px;
  163. .category-title {
  164. @apply text-white font-bold text-xl mb-4;
  165. }
  166. }
  167. .card {
  168. @apply rounded-2xl border-[3px] border-[#1D4BD9] border-solid border-b-[6px] relative p-1 bg-white pb-3;
  169. // background-color: rgba(255, 255, 255, 0.9);
  170. // border-radius: 16px;
  171. // padding: 16px;
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. justify-content: space-between;
  176. // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  177. aspect-ratio: 8/9;
  178. .card-content {
  179. width: 100%;
  180. height: 120px;
  181. background-color: #E3F2FD;
  182. border-radius: 12px;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. margin-bottom: 12px;
  187. aspect-ratio: 3/4;
  188. .question-mark {
  189. font-size: 60px;
  190. font-weight: bold;
  191. color: #1E88E5;
  192. }
  193. }
  194. .card-title {
  195. @apply text-center font-bold absolute left-0 w-full text-[#0E3E87] text-[1.5vw];
  196. bottom: 13%;
  197. }
  198. }
  199. }
  200. }
  201. </style>