index.uvue 7.6 KB

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