index.uvue 7.8 KB

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