index.uvue 5.4 KB

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