index.uvue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <script lang="ts" setup>
  2. import { user } from '@/.cool'
  3. import { ref, onMounted, computed } from 'vue'
  4. import { fetchSubjectAppInfo } from '@/services/subject/info'
  5. import { querySubjectCourseTest, querySubjectCourseTestNoLogin } from '@/services/subject/test'
  6. import { type SubjectCatalogResult, querySubjectCatalog, querySubjectCatalogNoLogin } from '@/services/subject/catalog'
  7. import type { SubjectCourseTestResult } from '@/services/subject/test'
  8. import Lock from '@/components/lock.uvue'
  9. import Back from '@/components/back.uvue'
  10. import Loading from '@/components/loading.uvue'
  11. import { config } from '@/config'
  12. import { dict } from '@/.cool/store'
  13. import { router } from "@/.cool";
  14. const userInfo = computed(() => user.info.value?.userInfo)
  15. const isLoading = ref(true)
  16. const visible = ref<boolean>(false)
  17. const dataList = ref<SubjectCatalogResult[]>([])
  18. const catalog = ref<SubjectCatalogResult>()
  19. const testList = ref<SubjectCourseTestResult[]>()
  20. async function getDataList() {
  21. let res: SubjectCatalogResult[] = []
  22. const id = '69c49329091547710d451f9d'
  23. if (user.token === 'Basic ZW5kOmVuZA==') {
  24. res = await querySubjectCatalogNoLogin({
  25. subjectId: id
  26. })
  27. } else {
  28. res = await querySubjectCatalog({
  29. subjectId: id
  30. })
  31. }
  32. dataList.value = res || []
  33. catalog.value = res?.[0] as SubjectCatalogResult
  34. handleSelect(catalog.value)
  35. }
  36. onMounted(async () => {
  37. try {
  38. await getDataList()
  39. isLoading.value = false
  40. } catch (err) {
  41. console.log(err);
  42. isLoading.value = false
  43. }
  44. })
  45. const cardsScrollView = ref<any>(null)
  46. function handleDetail(item: SubjectCourseTestResult) {
  47. if (item?.lockFlag) return
  48. router.push({
  49. path: "/pages/catalog/web-view",
  50. query: {
  51. src: item.animationPath,
  52. progress: 2,
  53. }
  54. });
  55. }
  56. // const scrollLeft = ref<any>(0)
  57. async function handleSelect(val: SubjectCatalogResult) {
  58. catalog.value = val
  59. visible.value = false
  60. testList.value = []
  61. let res: SubjectCourseTestResult[] = []
  62. if (user.token === 'Basic ZW5kOmVuZA==') {
  63. res = await querySubjectCourseTestNoLogin({
  64. catalogId: val.id, pageSize: 20
  65. })
  66. } else {
  67. res = await querySubjectCourseTest({
  68. catalogId: val.id, pageSize: 20
  69. })
  70. }
  71. testList.value = res || []
  72. cardsScrollView.value.scrollTo({
  73. left: 0, // 减去顶部偏移
  74. animated: true
  75. })
  76. }
  77. // async function onScroll(e: any) {
  78. // scrollLeft.value = e.detail.scrollLeft
  79. // dataList.value.forEach(async (category) => {
  80. // const selector = `.category-${category.id}`
  81. // await uni.createSelectorQuery().selectAll(selector).boundingClientRect().exec((rects) => {
  82. // // 检查元素是否在可视区域内
  83. // for (const rect of rects[0]) {
  84. // if (rect.left <= 50 && rect.left > 0) {
  85. // catalog.value = category
  86. // }
  87. // }
  88. // })
  89. // })
  90. // }
  91. </script>
  92. <template>
  93. <Loading v-show="isLoading" />
  94. <cl-page v-show="!isLoading">
  95. <Back />
  96. <image mode="aspectFill" src="https://oss.xiaoxiongcode.com/static/home/2.png" alt=""
  97. class="w-full h-full object-cover" />
  98. <!-- 顶部右侧光标签 -->
  99. <view class="light-tag" @tap="visible = true">
  100. <image class="light-icon" lazy-load v-if="catalog?.ossIconPath" :src="catalog?.ossIconPath">
  101. </image>
  102. <text class="light-text">{{ catalog?.name }}</text>
  103. <cl-icon name="arrow-left-right-line" color="primary"></cl-icon>
  104. </view>
  105. <view class="boxs">
  106. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false" ref="cardsScrollView">
  107. <view class="scroll-view-item_H bg-[white]" v-for="test in testList || []" :class="`category-${test.catalogId}`"
  108. :key="test.id" @tap="handleDetail(test)" ref="categoryRefs">
  109. <cl-image :src="test.animationImagePath" mode="heightFix"
  110. class="!w-full !h-[28vh] mb-[10px] rounded-xl"></cl-image>
  111. <text class="text-[4vh] font-bold">{{
  112. test.name }}</text>
  113. <Lock v-if="test?.lockFlag" :record="test" type="course" :finish="!test.lockFlag" />
  114. </view>
  115. </scroll-view>
  116. </view>
  117. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  118. <view class="p-4">
  119. <cl-row :gutter="0">
  120. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  121. className: '!p-2'
  122. }" @tap="handleSelect(item)">
  123. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  124. <image :src="item?.ossIconPath" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  125. <text>{{ item.name }}</text>
  126. </view>
  127. </cl-col>
  128. </cl-row>
  129. </view>
  130. </cl-popup>
  131. </cl-page>
  132. </template>
  133. <style lang="scss" scoped>
  134. .boxs {
  135. @apply w-[calc(100vw-100px)] h-[50vh] absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[1];
  136. }
  137. .scroll-view_H {
  138. width: 100%;
  139. height: 100%;
  140. flex-direction: row;
  141. }
  142. .scroll-view-item_H {
  143. @apply w-[50vh] h-[50vh] mr-[20px] rounded-2xl border-[5px] border-[#1D4BD9] border-solid border-b-[10px] p-1 flex items-center relative;
  144. }
  145. .light-tag {
  146. @apply absolute top-3 left-1/2 z-[1] flex flex-row items-center bg-white px-3 py-2 font-bold rounded-full shadow-md;
  147. transform: translateX(-50%);
  148. .light-icon {
  149. width: 20px;
  150. height: 20px;
  151. margin-right: 3px;
  152. }
  153. .light-text {
  154. font-size: 16px;
  155. min-width: 100px;
  156. padding-right: 5px;
  157. }
  158. }
  159. .select-item {
  160. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  161. }
  162. .selected {
  163. @apply border-green-500;
  164. }
  165. .footer {
  166. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  167. }
  168. .text-stroke-custom {
  169. color: white;
  170. text-shadow:
  171. /* 左上角投影 */
  172. -1px -1px 0 #1D4BD9,
  173. /* 右上角投影 */
  174. 1px -1px 0 #1D4BD9,
  175. /* 左下角投影 */
  176. -1px 1px 0 #1D4BD9,
  177. /* 右下角投影 */
  178. 1px 1px 0 #1D4BD9;
  179. }
  180. </style>