index.uvue 7.0 KB

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