index.uvue 5.6 KB

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