index.uvue 7.8 KB

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