index.uvue 7.1 KB

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