index.uvue 8.1 KB

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