index.uvue 7.9 KB

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