index.uvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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="scaleToFill"
  101. class="!w-full !h-[28vh] mb-[5px] rounded-xl"></cl-image>
  102. <text class="text-[4vh] font-bold">{{
  103. course.sortNum }}、{{
  104. course.mainTitle }}</text>
  105. <text class="text-[3vh] text-[#666]">{{
  106. course.assistantTitle }}</text>
  107. <view>
  108. <Progress :num="2" :percentage="course.courseUserProgress ? course.courseUserProgress?.status + 1 : 0" />
  109. </view>
  110. <Lock v-if="!course.trialPlay && !course.payFlag" :record="course" isPay />
  111. </view>
  112. </scroll-view>
  113. </view>
  114. <!-- <view class="footer">
  115. <view>
  116. <cl-image src="https://oss.xiaoxiongcode.com/static/home/4.png" mode="heightFix"
  117. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  118. <text class="text-[14px] text-white font-bold text-stroke-custom">虚拟实验</text>
  119. </view>
  120. <view>
  121. <cl-image src="https://oss.xiaoxiongcode.com/static/home/5.png" mode="heightFix"
  122. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  123. <text class="text-[14px] text-white font-bold text-stroke-custom">我的收获</text>
  124. </view>
  125. <view>
  126. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6.png" mode="heightFix"
  127. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  128. <text class="text-[14px] text-white font-bold text-stroke-custom">学习报告</text>
  129. </view>
  130. </view> -->
  131. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  132. <view class="p-4">
  133. <cl-row :gutter="0">
  134. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  135. className: '!p-2'
  136. }" @tap="handleSelect(item)">
  137. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  138. <image :src="config.baseUrl + item?.fileList?.[0]?.url" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  139. <text>{{ item.name }}</text>
  140. </view>
  141. </cl-col>
  142. </cl-row>
  143. </view>
  144. </cl-popup>
  145. </cl-page>
  146. </template>
  147. <style lang="scss" scoped>
  148. .boxs {
  149. @apply w-[calc(100vw-52vh)] h-[57vh] absolute top-1/2 left-[50vh] z-[1];
  150. transform: translateY(-50%);
  151. }
  152. .scroll-view_H {
  153. width: 100%;
  154. height: 100%;
  155. flex-direction: row;
  156. }
  157. .scroll-view-item_H {
  158. @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;
  159. }
  160. .light-tag {
  161. @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;
  162. transform: translateX(-50%);
  163. .light-icon {
  164. width: 20px;
  165. height: 20px;
  166. margin-right: 3px;
  167. }
  168. .light-text {
  169. font-size: 16px;
  170. min-width: 100px;
  171. padding-right: 5px;
  172. }
  173. }
  174. .select-item {
  175. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  176. }
  177. .selected {
  178. @apply border-green-500;
  179. }
  180. .footer {
  181. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  182. }
  183. .text-stroke-custom {
  184. color: white;
  185. text-shadow:
  186. /* 左上角投影 */
  187. -1px -1px 0 #1D4BD9,
  188. /* 右上角投影 */
  189. 1px -1px 0 #1D4BD9,
  190. /* 左下角投影 */
  191. -1px 1px 0 #1D4BD9,
  192. /* 右下角投影 */
  193. 1px 1px 0 #1D4BD9;
  194. }
  195. </style>