index.uvue 8.2 KB

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