index.uvue 7.8 KB

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