index.uvue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. 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/百科/bg.jpg" alt=""
  82. class="w-full h-full object-cover" />
  83. <view class="content">
  84. <!-- 左侧导航菜单 -->
  85. <view class="w-[20vw] h-[100vh] bg-[#a9e3f2bb] 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. <!-- {{ category.name }} -->
  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. white-space: nowrap;
  135. }
  136. .content {
  137. display: flex;
  138. flex-direction: row;
  139. position: absolute;
  140. left: 0;
  141. top: 0;
  142. width: 100%;
  143. height: 100%;
  144. .sidebar {
  145. height: calc(100vh - 90px);
  146. .sidebar-item {
  147. @apply text-white rounded-full py-1 px-2 cursor-pointer flex flex-row items-center;
  148. margin-bottom: 8px;
  149. transition: all 0.3s ease;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. white-space: nowrap;
  153. width: 100%;
  154. .we {
  155. color: #fff !important;
  156. font-size: 1.6vw !important;
  157. }
  158. &.active {
  159. background-color: rgba(255, 255, 255, 1);
  160. color: #f3759b;
  161. font-weight: bold;
  162. .we {
  163. color: #1899b9 !important;
  164. }
  165. }
  166. .sidebar-icon {
  167. font-size: 28px;
  168. margin-right: 2px;
  169. }
  170. }
  171. }
  172. .cards-container {
  173. @apply relative;
  174. flex: 1;
  175. width: 100%;
  176. padding: 20px;
  177. padding-top: 70px;
  178. // background: linear-gradient(0deg, #2EB2FD, #0B85F4);
  179. .cards {
  180. height: calc(100vh - 90px);
  181. }
  182. .category-section {
  183. margin-bottom: 40px;
  184. .category-title {
  185. @apply text-white font-bold text-xl mb-4;
  186. }
  187. }
  188. .card {
  189. @apply rounded-2xl border-[3px] border-[#1D4BD9] border-solid border-b-[6px] relative p-1 bg-white pb-3;
  190. // background-color: rgba(255, 255, 255, 0.9);
  191. // border-radius: 16px;
  192. // padding: 16px;
  193. display: flex;
  194. flex-direction: column;
  195. align-items: center;
  196. justify-content: space-between;
  197. // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  198. aspect-ratio: 8/9;
  199. .card-content {
  200. width: 100%;
  201. height: 120px;
  202. background-color: #E3F2FD;
  203. border-radius: 12px;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. margin-bottom: 12px;
  208. aspect-ratio: 3/4;
  209. .question-mark {
  210. font-size: 60px;
  211. font-weight: bold;
  212. color: #1E88E5;
  213. }
  214. }
  215. .card-title {
  216. @apply text-center font-bold absolute left-0 w-full text-[#0E3E87] text-[1.5vw];
  217. bottom: 13%;
  218. }
  219. }
  220. }
  221. }
  222. </style>