index.uvue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 id = dict.getValueByLabelMapByType('index_subject_id')['语文']
  21. const res = await querySubjectCatalog({
  22. subjectId: id, dataScope: {
  23. sortBy: 'asc',
  24. sortName: 'sort_num',
  25. }
  26. })
  27. dataList.value = res || []
  28. catalog.value = res?.[0] as SubjectCatalogResult
  29. handleSelect(catalog.value)
  30. }
  31. async function handleSelect(val: SubjectCatalogResult) {
  32. catalog.value = val
  33. courseList.value = []
  34. finish.value = false
  35. pageNum.value = 1
  36. await getInfo()
  37. cardsScrollView.value.scrollTo({
  38. top: 0, // 减去顶部偏移
  39. animated: true
  40. })
  41. }
  42. async function getInfo() {
  43. loading.value = true
  44. const res = await getSubjectCoursePage({
  45. catalogId: catalog.value?.id, pageSize: 12, pageNum: pageNum.value, dataScope: {
  46. sortBy: 'asc',
  47. sortName: 'sort_num',
  48. },
  49. })
  50. courseList.value = [...courseList.value, ...(res.rows || [])]
  51. loading.value = false
  52. finish.value = res.pages === pageNum.value
  53. }
  54. async function handleScrollToLower() {
  55. if (loading.value || finish.value) {
  56. return
  57. }
  58. pageNum.value++
  59. await getInfo()
  60. }
  61. const handleScrollToLowerDebounce = debounce(handleScrollToLower, 1000)
  62. onMounted(async () => {
  63. await getDataList()
  64. isLoading.value = false
  65. })
  66. function handleDetail(item: SubjectCatalogResult) {
  67. // if (!item.payFlag && !item.trialPlay) {
  68. // uni.showToast({
  69. // title: '请先购买',
  70. // icon: 'none'
  71. // })
  72. // return
  73. // }
  74. router.push({
  75. path: "/pages/english/detail",
  76. query: {
  77. id: item.id,
  78. }
  79. });
  80. }
  81. const userInfo = computed(() => user.info.value?.userInfo)
  82. </script>
  83. <template>
  84. <Loading v-show="isLoading" />
  85. <cl-page v-show="!isLoading">
  86. <Back />
  87. <!-- 顶部标题栏 -->
  88. <image mode="aspectFill" src="https://oss.xiaoxiongcode.com/static/语文/图层 4.png" alt=""
  89. class="w-full h-full object-cover" />
  90. <view class="content">
  91. <!-- 左侧导航菜单 -->
  92. <view class="w-[20vw] h-[100vh] bg-[#33333388] pt-[70px] pb-[20px] px-[20px]">
  93. <scroll-view direction="vertical" :show-scrollbar="false" class="sidebar">
  94. <view v-for="category in dataList" :key="category.id" class="sidebar-item"
  95. :class="{ active: catalog?.id === category.id }" @tap="handleSelect(category)">
  96. <!-- <cl-image :src="category?.ossIconPath" mode="heightFix" class="!h-[28px]"></cl-image> -->
  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. .title-tabs {
  141. @apply flex flex-row items-center justify-center rounded-full;
  142. background-color: #9AD2FA;
  143. .tab {
  144. @apply rounded-full;
  145. padding: 5px 10px;
  146. font-size: 16px;
  147. transition: all 0.3s ease;
  148. &.active {
  149. background-color: white;
  150. color: #1E88E5;
  151. font-weight: bold;
  152. }
  153. }
  154. }
  155. }
  156. .content {
  157. display: flex;
  158. flex-direction: row;
  159. position: absolute;
  160. left: 0;
  161. top: 0;
  162. width: 100%;
  163. height: 100%;
  164. .sidebar {
  165. height: calc(100vh - 90px);
  166. .sidebar-item {
  167. @apply text-white rounded-full py-1 px-2 cursor-pointer flex flex-row items-center;
  168. margin-bottom: 8px;
  169. transition: all 0.3s ease;
  170. overflow: hidden;
  171. text-overflow: ellipsis;
  172. white-space: nowrap;
  173. width: 100%;
  174. .we {
  175. color: #fff !important;
  176. font-size: 1.6vw !important;
  177. }
  178. &.active {
  179. background-color: rgba(255, 255, 255, 1);
  180. color: #1E88E5;
  181. font-weight: bold;
  182. .we {
  183. color: #333 !important;
  184. }
  185. }
  186. .sidebar-icon {
  187. font-size: 28px;
  188. margin-right: 2px;
  189. }
  190. }
  191. }
  192. .cards-container {
  193. @apply relative;
  194. flex: 1;
  195. width: 100%;
  196. padding: 20px;
  197. padding-top: 70px;
  198. // background: linear-gradient(0deg, #2EB2FD, #0B85F4);
  199. .cards {
  200. height: calc(100vh - 90px);
  201. }
  202. .category-section {
  203. margin-bottom: 40px;
  204. .category-title {
  205. @apply text-white font-bold text-xl mb-4;
  206. }
  207. }
  208. .card {
  209. @apply rounded-2xl border-[3px] border-[#1D4BD9] border-solid border-b-[6px] relative p-1 bg-white pb-3;
  210. // background-color: rgba(255, 255, 255, 0.9);
  211. // border-radius: 16px;
  212. // padding: 16px;
  213. display: flex;
  214. flex-direction: column;
  215. align-items: center;
  216. justify-content: space-between;
  217. // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  218. aspect-ratio: 8/9;
  219. .card-content {
  220. width: 100%;
  221. height: 120px;
  222. background-color: #E3F2FD;
  223. border-radius: 12px;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. margin-bottom: 12px;
  228. aspect-ratio: 3/4;
  229. .question-mark {
  230. font-size: 60px;
  231. font-weight: bold;
  232. color: #1E88E5;
  233. }
  234. }
  235. .card-title {
  236. @apply text-center font-bold absolute left-0 w-full text-[#0E3E87] text-[1.5vw];
  237. bottom: 13%;
  238. }
  239. }
  240. }
  241. }
  242. </style>