index.uvue 6.9 KB

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