index.uvue 6.9 KB

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