index.uvue 7.8 KB

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