index.uvue 6.7 KB

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