index.uvue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. console.log(err);
  36. isLoading.value = false
  37. }
  38. })
  39. const cardsScrollView = ref<any>(null)
  40. function handleDetail(item: SubjectCatalogResult) {
  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. 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. <view>
  122. </view>
  123. <!-- 顶部右侧光标签 -->
  124. <view class="light-tag" @tap="visible = true">
  125. <image class="light-icon" lazy-load v-if="catalog?.ossIconPath" :src="catalog?.ossIconPath">
  126. </image>
  127. <text class="light-text">{{ catalog?.name }}</text>
  128. <cl-icon name="arrow-left-right-line" color="primary"></cl-icon>
  129. </view>
  130. <view class="boxs">
  131. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false" ref="cardsScrollView">
  132. <view class="scroll-view-item_H bg-[white]" v-for="course in courseList || []" :key="course.id"
  133. @tap="handleDetail(course)">
  134. <cl-image lazy-load :src="course?.ossIconPath" mode="scaleToFill"
  135. class="!w-full !h-[28vh] mb-[5px] rounded-xl"></cl-image>
  136. <cl-text ellipsis :pt="{
  137. className: '!text-[4vh] !font-bold'
  138. }">{{
  139. course.sortNum }}、{{
  140. course.mainTitle }}</cl-text>
  141. <text class="text-[3vh] text-[#666]">{{
  142. course.assistantTitle }}</text>
  143. <view>
  144. <Progress :num="6" size="12px"
  145. :percentage="course.courseUserProgress ? course.courseUserProgress?.status == 1 ? 6 : course.courseUserProgress?.assistantProgress : 0" />
  146. </view>
  147. <Lock v-if="(!course.trialPlay && !course.payFlag) || !course.platFormLock || course.studyUnitLock"
  148. :record="course" type="course" :studyUnitLock="course.studyUnitLock" :finish="course.platFormLock"
  149. @close="handleClose" />
  150. </view>
  151. </scroll-view>
  152. </view>
  153. <!-- <view class="footer">
  154. <view>
  155. <cl-image src="https://oss.xiaoxiongcode.com/static/home/4.png" mode="heightFix"
  156. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  157. <text class="text-[14px] text-white font-bold text-stroke-custom">虚拟实验</text>
  158. </view>
  159. <view>
  160. <cl-image src="https://oss.xiaoxiongcode.com/static/home/5.png" mode="heightFix"
  161. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  162. <text class="text-[14px] text-white font-bold text-stroke-custom">我的收获</text>
  163. </view>
  164. <view>
  165. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6.png" mode="heightFix"
  166. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  167. <text class="text-[14px] text-white font-bold text-stroke-custom">学习报告</text>
  168. </view>
  169. </view> -->
  170. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  171. <view class="p-4">
  172. <cl-row :gutter="0">
  173. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  174. className: '!p-2'
  175. }" @tap="handleSelect(item)">
  176. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  177. <image :src="item?.ossIconPath" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  178. <text>{{ item.name }}</text>
  179. </view>
  180. </cl-col>
  181. </cl-row>
  182. </view>
  183. </cl-popup>
  184. </cl-page>
  185. </template>
  186. <style lang="scss" scoped>
  187. .boxs {
  188. @apply w-[calc(100vw-52vh)] h-[57vh] absolute top-1/2 left-[50vh] z-[1];
  189. transform: translateY(-50%);
  190. }
  191. .scroll-view_H {
  192. width: 100%;
  193. height: 100%;
  194. flex-direction: row;
  195. }
  196. .scroll-view-item_H {
  197. @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;
  198. }
  199. .light-tag {
  200. @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;
  201. transform: translateX(-50%);
  202. .light-icon {
  203. width: 20px;
  204. height: 20px;
  205. margin-right: 3px;
  206. }
  207. .light-text {
  208. font-size: 16px;
  209. min-width: 100px;
  210. padding-right: 5px;
  211. }
  212. }
  213. .select-item {
  214. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  215. }
  216. .selected {
  217. @apply border-green-500;
  218. }
  219. .footer {
  220. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  221. }
  222. .text-stroke-custom {
  223. color: white;
  224. text-shadow:
  225. /* 左上角投影 */
  226. -1px -1px 0 #1D4BD9,
  227. /* 右上角投影 */
  228. 1px -1px 0 #1D4BD9,
  229. /* 左下角投影 */
  230. -1px 1px 0 #1D4BD9,
  231. /* 右下角投影 */
  232. 1px 1px 0 #1D4BD9;
  233. }
  234. </style>