index.uvue 8.1 KB

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