index.uvue 6.8 KB

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