index.uvue 7.7 KB

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