index.uvue 7.8 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. 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. <cl-text ellipsis :pt="{
  129. className: '!text-[4vh] !font-bold'
  130. }">{{
  131. course.sortNum }}、{{
  132. course.mainTitle }}</cl-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" type="course"
  140. :finish="course.platFormLock" @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>