index.uvue 8.1 KB

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