index.uvue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 SubjectKnowledgeCardResult, getSubjectKnowledgeCard } from '@/services/subject/card'
  6. import { fetchSubjectConfigInfo } from '@/services/subject/info'
  7. import type { SubjectCatalogResult } from '@/services/subject/catalog'
  8. import { config } from '@/config'
  9. import { dict } from '@/.cool/store'
  10. const activeCategory = ref<string>()
  11. const activeTab = ref<string>('knowledge')
  12. const isLoading = ref(true)
  13. const categories = ref<SubjectCatalogResult[]>([])
  14. const cards = ref<SubjectKnowledgeCardResult[]>([])
  15. const cardsScrollView = ref<any>(null)
  16. const categoryRefs = ref<any>()
  17. async function getDataList() {
  18. const id = dict.getValueByLabelMapByType('index_subject_id')['物理']
  19. const res = await getSubjectKnowledgeCard({ subjectId: id })
  20. cards.value = res.userCardList || []
  21. categories.value = res.catalogList || []
  22. }
  23. function handleSelect(categoryId: string) {
  24. activeCategory.value = categoryId
  25. uni.createSelectorQuery().select(`.category-${categoryId}`).boundingClientRect().exec((rect) => {
  26. if (cardsScrollView.value && rect[0]) {
  27. cardsScrollView.value.scrollTo({
  28. top: rect[0].top - 70, // 减去顶部偏移
  29. animated: true
  30. })
  31. }
  32. })
  33. }
  34. async function onScroll(e: any) {
  35. categories.value.forEach(async (category) => {
  36. const selector = `.category-${category.id}`
  37. await uni.createSelectorQuery().selectAll(selector).boundingClientRect().exec((rects) => {
  38. // 检查元素是否在可视区域内
  39. for (const rect of rects[0]) {
  40. if (rect.top <= 150 && rect.bottom >= 150) {
  41. activeCategory.value = category.id
  42. }
  43. }
  44. })
  45. })
  46. }
  47. onMounted(async () => {
  48. await getDataList()
  49. isLoading.value = false
  50. nextTick(() => {
  51. handleSelect(categories.value[0].id as string)
  52. })
  53. })
  54. </script>
  55. <template>
  56. <Loading v-show="isLoading" />
  57. <cl-page v-show="!isLoading">
  58. <Back />
  59. <!-- 顶部标题栏 -->
  60. <view class="content">
  61. <!-- 左侧导航菜单 -->
  62. <scroll-view direction="vertical" :show-scrollbar="false" class="sidebar">
  63. <view v-for="category in categories" :key="category.id" class="sidebar-item"
  64. :class="{ active: activeCategory === category.id }" @tap="handleSelect(category.id as string)">
  65. <cl-image :src="config.baseUrl + category?.fileList?.[0]?.url" mode="heightFix" class="!h-[28px]"></cl-image>
  66. <text class="sidebar-text">{{ category.name }}</text>
  67. </view>
  68. </scroll-view>
  69. <!-- 右侧卡片网格 -->
  70. <view class="cards-container">
  71. <view class="header">
  72. <view class="title-tabs">
  73. <view class="tab" :class="{ active: activeTab === 'knowledge' }" @tap="activeTab = 'knowledge'">知识卡
  74. </view>
  75. <view class="tab" :class="{ active: activeTab === 'honor' }" @tap="activeTab = 'honor'">荣誉</view>
  76. </view>
  77. </view>
  78. <scroll-view direction="vertical" :show-scrollbar="false" class="cards" ref="cardsScrollView"
  79. @scroll="onScroll">
  80. <view class="grid grid-cols-5 gap-4">
  81. <view class="card" v-for="card in cards" :key="card.id" :class="`category-${card.catalogId}`"
  82. ref="categoryRefs">
  83. <image v-if="card.userCardId" :src="config.baseUrl + card.iconPath" class="w-full h-full" />
  84. <image v-else src="https://oss.xiaoxiongcode.com/static/home/21.png" class="w-full h-full" />
  85. <view class="card-title">{{ card.cardName }}</view>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </view>
  90. </view>
  91. </cl-page>
  92. </template>
  93. <style lang="scss" scoped>
  94. .header {
  95. @apply absolute left-1/2 top-5;
  96. transform: translateX(-50%);
  97. text-align: center;
  98. .title-tabs {
  99. @apply flex flex-row items-center justify-center rounded-full;
  100. background-color: #9AD2FA;
  101. .tab {
  102. @apply rounded-full;
  103. padding: 5px 10px;
  104. font-size: 16px;
  105. transition: all 0.3s ease;
  106. &.active {
  107. background-color: white;
  108. color: #1E88E5;
  109. font-weight: bold;
  110. }
  111. }
  112. }
  113. }
  114. .content {
  115. display: flex;
  116. flex-direction: row;
  117. .sidebar {
  118. width: 200px;
  119. background-color: #116FE9;
  120. padding: 20px;
  121. padding-top: 70px;
  122. height: 100vh;
  123. .sidebar-item {
  124. @apply text-white rounded-full py-1 cursor-pointer flex flex-row items-center;
  125. margin-bottom: 8px;
  126. transition: all 0.3s ease;
  127. font-size: 12px;
  128. width: 100%;
  129. &.active {
  130. background-color: rgba(255, 255, 255, 1);
  131. color: #1E88E5;
  132. font-weight: bold;
  133. }
  134. .sidebar-icon {
  135. font-size: 28px;
  136. margin-right: 2px;
  137. }
  138. }
  139. }
  140. .cards-container {
  141. @apply relative;
  142. flex: 1;
  143. width: 100%;
  144. padding: 20px;
  145. padding-top: 70px;
  146. background: linear-gradient(0deg, #2EB2FD, #0B85F4);
  147. .cards {
  148. height: calc(100vh - 90px);
  149. }
  150. .category-section {
  151. margin-bottom: 40px;
  152. .category-title {
  153. @apply text-white font-bold text-xl mb-4;
  154. }
  155. }
  156. .card {
  157. // background-color: rgba(255, 255, 255, 0.9);
  158. // border-radius: 16px;
  159. // padding: 16px;
  160. display: flex;
  161. flex-direction: column;
  162. align-items: center;
  163. // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  164. aspect-ratio: 3/4;
  165. .card-content {
  166. width: 100%;
  167. height: 120px;
  168. background-color: #E3F2FD;
  169. border-radius: 12px;
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. margin-bottom: 12px;
  174. aspect-ratio: 3/4;
  175. .question-mark {
  176. font-size: 60px;
  177. font-weight: bold;
  178. color: #1E88E5;
  179. }
  180. }
  181. .card-title {
  182. @apply text-center font-bold absolute left-0 w-full text-[#0E3E87] text-[1.5vw];
  183. bottom: 13%;
  184. }
  185. }
  186. }
  187. }
  188. </style>