index.uvue 7.1 KB

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