index.uvue 8.8 KB

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