index.uvue 7.4 KB

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