index.uvue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <script lang="ts" setup>
  2. import { ref, onMounted } from 'vue'
  3. import { fetchSubjectAppInfo } from '@/services/subject/info'
  4. import type { SubjectCatalogResult } from '@/services/subject/catalog'
  5. import type { SubjectCourseResult } from '@/services/subject/course'
  6. import Lock from '@/components/lock.uvue'
  7. import Progress from './components/progress.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 courseList = ref<SubjectCourseResult>()
  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. courseList.value = res?.courseList || []
  24. }
  25. onMounted(async () => {
  26. try {
  27. await getDataList()
  28. isLoading.value = false
  29. } catch (err) {
  30. console.log(err);
  31. isLoading.value = false
  32. }
  33. })
  34. const cardsScrollView = ref<any>(null)
  35. const categoryRefs = ref<any>()
  36. function handleDetail(item: SubjectCatalogResult) {
  37. // if (!item.payFlag && !item.trialPlay) {
  38. // uni.showToast({
  39. // title: '请先购买',
  40. // icon: 'none'
  41. // })
  42. // return
  43. // }
  44. router.push({
  45. path: "/pages/catalog/detail",
  46. query: {
  47. id: item.id,
  48. }
  49. });
  50. }
  51. function handleSelect(val: SubjectCatalogResult) {
  52. catalog.value = val
  53. visible.value = false
  54. uni.createSelectorQuery().select(`.category-${val.id}`).boundingClientRect().exec((rect) => {
  55. if (cardsScrollView.value && rect[0]) {
  56. cardsScrollView.value.scrollTo({
  57. left: rect[0].left - dict.getWindowHeight() / 2, // 减去顶部偏移
  58. animated: true
  59. })
  60. }
  61. })
  62. }
  63. async function onScroll(e: any) {
  64. console.log();
  65. dataList.value.forEach(async (category) => {
  66. const selector = `.category-${category.id}`
  67. await uni.createSelectorQuery().selectAll(selector).boundingClientRect().exec((rects) => {
  68. // 检查元素是否在可视区域内
  69. for (const rect of rects[0]) {
  70. if (rect.left <= (dict.getWindowHeight() / 2)) {
  71. catalog.value = category
  72. }
  73. }
  74. })
  75. })
  76. }
  77. </script>
  78. <template>
  79. <Loading v-show="isLoading" />
  80. <cl-page v-show="!isLoading">
  81. <Back />
  82. <img src="https://oss.xiaoxiongcode.com/static/home/2.png" alt="" class="w-full h-full object-cover" />
  83. <!-- 精灵图动画 -->
  84. <cl-image src="https://oss.xiaoxiongcode.com/static/home/3.gif" mode="heightFix"
  85. class="!absolute bottom-0 left-0 !w-[44vh] !h-[55vh] z-[1]" />
  86. <view>
  87. </view>
  88. <!-- 顶部右侧光标签 -->
  89. <view class="light-tag" @tap="visible = true">
  90. <image class="light-icon" v-if="catalog?.fileList?.[0]?.url" :src="config.baseUrl + catalog?.fileList?.[0]?.url">
  91. </image>
  92. <text class="light-text">{{ catalog?.name }}</text>
  93. <cl-icon name="arrow-left-right-line" color="primary"></cl-icon>
  94. </view>
  95. <view class="boxs">
  96. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false" ref="cardsScrollView"
  97. @scroll="onScroll">
  98. <view class="scroll-view-item_H bg-[white]" v-for="course in courseList || []"
  99. :class="`category-${course.catalogId}`" :key="course.id" @tap="handleDetail(course)" ref="categoryRefs">
  100. <cl-image :src="config.baseUrl + course?.fileList?.[0]?.url" mode="heightFix"
  101. class="!w-full !h-[26vh] mb-[2px] rounded-xl"></cl-image>
  102. <text class="text-[16px] font-bold">{{
  103. course.mainTitle }}</text>
  104. <text class="text-[14px] text-[#666]">{{
  105. course.assistantTitle }}</text>
  106. <view>
  107. <Progress :num="2" :percentage="course.courseUserProgress?.mainProgress || 0" />
  108. </view>
  109. <Lock v-if="!course.trialPlay && !course.payFlag" :record="course" isPay />
  110. </view>
  111. </scroll-view>
  112. </view>
  113. <!-- <view class="footer">
  114. <view>
  115. <cl-image src="https://oss.xiaoxiongcode.com/static/home/4.png" mode="heightFix"
  116. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  117. <text class="text-[14px] text-white font-bold text-stroke-custom">虚拟实验</text>
  118. </view>
  119. <view>
  120. <cl-image src="https://oss.xiaoxiongcode.com/static/home/5.png" mode="heightFix"
  121. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  122. <text class="text-[14px] text-white font-bold text-stroke-custom">我的收获</text>
  123. </view>
  124. <view>
  125. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6.png" mode="heightFix"
  126. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  127. <text class="text-[14px] text-white font-bold text-stroke-custom">学习报告</text>
  128. </view>
  129. </view> -->
  130. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  131. <view class="p-4">
  132. <cl-row :gutter="0">
  133. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  134. className: '!p-2'
  135. }" @tap="handleSelect(item)">
  136. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  137. <image :src="config.baseUrl + item?.fileList?.[0]?.url" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  138. <text>{{ item.name }}</text>
  139. </view>
  140. </cl-col>
  141. </cl-row>
  142. </view>
  143. </cl-popup>
  144. </cl-page>
  145. </template>
  146. <style lang="scss" scoped>
  147. .boxs {
  148. @apply w-[calc(100vw-52vh)] h-[50vh] absolute top-1/2 left-[50vh] z-[1];
  149. transform: translateY(-50%);
  150. }
  151. .scroll-view_H {
  152. width: 100%;
  153. height: 100%;
  154. flex-direction: row;
  155. }
  156. .scroll-view-item_H {
  157. @apply w-[40vh] h-[50vh] mr-[20px] rounded-2xl border-[5px] border-[#1D4BD9] border-solid border-b-[10px] p-1 flex items-center relative;
  158. }
  159. .light-tag {
  160. @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;
  161. transform: translateX(-50%);
  162. .light-icon {
  163. width: 20px;
  164. height: 20px;
  165. margin-right: 3px;
  166. }
  167. .light-text {
  168. font-size: 16px;
  169. min-width: 100px;
  170. padding-right: 5px;
  171. }
  172. }
  173. .select-item {
  174. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  175. }
  176. .selected {
  177. @apply border-green-500;
  178. }
  179. .footer {
  180. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  181. }
  182. .text-stroke-custom {
  183. color: white;
  184. text-shadow:
  185. /* 左上角投影 */
  186. -1px -1px 0 #1D4BD9,
  187. /* 右上角投影 */
  188. 1px -1px 0 #1D4BD9,
  189. /* 左下角投影 */
  190. -1px 1px 0 #1D4BD9,
  191. /* 右下角投影 */
  192. 1px 1px 0 #1D4BD9;
  193. }
  194. </style>