index.uvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <script lang="ts" setup>
  2. import { user } from '@/.cool'
  3. import { ref, onMounted, computed } from 'vue'
  4. import { fetchSubjectAppInfo } from '@/services/subject/info'
  5. import type { SubjectCatalogResult } from '@/services/subject/catalog'
  6. import type { SubjectCourseResult } from '@/services/subject/course'
  7. import Progress from '../catalog/components/progress.uvue'
  8. import Back from '@/components/back.uvue'
  9. import Lock from '@/components/lock.uvue'
  10. import Loading from '@/components/loading.uvue'
  11. import { config } from '@/config'
  12. import { dict } from '@/.cool/store'
  13. import { router } from "@/.cool";
  14. const isLoading = ref(true)
  15. const visible = ref<boolean>(false)
  16. const dataList = ref<SubjectCatalogResult[]>([])
  17. const catalog = ref<SubjectCatalogResult>()
  18. const record = ref<any>()
  19. const userInfo = computed(() => user.info.value?.userInfo)
  20. const courseList = ref<SubjectCourseResult[]>()
  21. async function getDataList() {
  22. const res = await fetchSubjectAppInfo({ id: router.query().id,delFlag: false })
  23. record.value = res
  24. dataList.value = res.catalogList || []
  25. catalog.value = res?.catalogList?.[0]
  26. courseList.value = res?.courseList || []
  27. }
  28. onMounted(async () => {
  29. try {
  30. await getDataList()
  31. isLoading.value = false
  32. } catch (err) {
  33. console.log(err);
  34. isLoading.value = false
  35. }
  36. })
  37. const scrollLeft = ref<any>(0)
  38. const cardsScrollView = ref<any>(null)
  39. async function handleSelect(val: SubjectCatalogResult) {
  40. catalog.value = val
  41. visible.value = false
  42. uni.createSelectorQuery().select(`.category-${val.id}`).boundingClientRect().exec(async (rect) => {
  43. if (cardsScrollView.value && rect[0]) {
  44. cardsScrollView.value.scrollTo({
  45. left: scrollLeft.value + rect[0].left - dict.getWindowHeight() / 2, // 减去顶部偏移
  46. animated: true
  47. })
  48. }
  49. })
  50. }
  51. function handleDetail(item: SubjectCatalogResult) {
  52. if (!item.payFlag && !item.trialPlay) {
  53. uni.showToast({
  54. title: '请先购买',
  55. icon: 'none'
  56. })
  57. return
  58. }
  59. router.push({
  60. path: "/pages/english/detail",
  61. query: {
  62. id: item.id,
  63. }
  64. });
  65. }
  66. function debouncedOnScroll(e: any) {
  67. console.log(e);
  68. scrollLeft.value = e.detail.scrollLeft
  69. dataList.value.forEach(async (category) => {
  70. const selector = `.category-${category.id}`
  71. await uni.createSelectorQuery().selectAll(selector).boundingClientRect().exec((rects) => {
  72. for (const rect of rects[0]) {
  73. if (rect.left <= (dict.getWindowHeight() / 2) && rect.left > 0) {
  74. catalog.value = category
  75. return
  76. }
  77. }
  78. })
  79. })
  80. }
  81. </script>
  82. <template>
  83. <Loading v-show="isLoading" />
  84. <cl-page v-show="!isLoading">
  85. <Back />
  86. <image mode="aspectFill" src="https://oss.xiaoxiongcode.com/static/英语/图层 6.png" alt="" class="w-full h-full object-cover" />
  87. <!-- 精灵图动画 -->
  88. <!-- <cl-image src="https://oss.xiaoxiongcode.com/static/home/3.gif" mode="heightFix"
  89. class="!absolute bottom-0 left-0 !w-[44vh] !h-[55vh] z-[1]" /> -->
  90. <view>
  91. </view>
  92. <!-- 顶部右侧光标签 -->
  93. <view class="light-tag" @tap="visible = true">
  94. <image class="light-icon" v-if="catalog?.fileList?.[0]?.url" :src="config.baseUrl + catalog?.fileList?.[0]?.url">
  95. </image>
  96. <text class="light-text">{{ catalog?.name }}</text>
  97. <cl-icon name="arrow-left-right-line" color="primary"></cl-icon>
  98. </view>
  99. <view class="boxs">
  100. <scroll-view class="scroll-view_H" direction="horizontal" ref="cardsScrollView" :show-scrollbar="false" @scroll="debouncedOnScroll">
  101. <view class="scroll-view-item_H bg-[white]" :class="`category-${course.catalogId}`" v-for="course in courseList || []" :key="course.id"
  102. @tap="handleDetail(course)">
  103. <cl-image :src="config.baseUrl + course?.fileList?.[0]?.url" mode="heightFix"
  104. class="!w-full !h-[26vh] mb-[2px] rounded-xl"></cl-image>
  105. <text class="text-[16px] font-bold">{{
  106. course.mainTitle }}</text>
  107. <text class="text-[14px] text-[#666]">{{
  108. course.assistantTitle }}</text>
  109. <!-- <view>
  110. <Progress :progress="30" />
  111. </view> -->
  112. <Lock v-if="userInfo?.memberLevel === 'default'" :record="course" type="vip"/>
  113. </view>
  114. </scroll-view>
  115. </view>
  116. <!-- <view class="footer">
  117. <view>
  118. <cl-image src="https://oss.xiaoxiongcode.com/static/home/4.png" mode="heightFix"
  119. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  120. <text class="text-[14px] text-white font-bold text-stroke-custom">虚拟实验</text>
  121. </view>
  122. <view>
  123. <cl-image src="https://oss.xiaoxiongcode.com/static/home/5.png" mode="heightFix"
  124. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  125. <text class="text-[14px] text-white font-bold text-stroke-custom">我的收获</text>
  126. </view>
  127. <view>
  128. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6.png" mode="heightFix"
  129. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  130. <text class="text-[14px] text-white font-bold text-stroke-custom">学习报告</text>
  131. </view>
  132. </view> -->
  133. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  134. <view class="p-4">
  135. <cl-row :gutter="0">
  136. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  137. className: '!p-2'
  138. }" @tap="handleSelect(item)">
  139. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  140. <image :src="config.baseUrl + item?.fileList?.[0]?.url" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  141. <text>{{ item.name }}</text>
  142. </view>
  143. </cl-col>
  144. </cl-row>
  145. </view>
  146. </cl-popup>
  147. </cl-page>
  148. </template>
  149. <style lang="scss" scoped>
  150. .boxs {
  151. @apply w-[100vw] h-[50vh] absolute top-1/2 left-[50vh] z-[1];
  152. transform: translateY(-50%);
  153. }
  154. .scroll-view_H {
  155. width: 100%;
  156. height: 100%;
  157. flex-direction: row;
  158. }
  159. .scroll-view-item_H {
  160. @apply w-[40vh] h-[50vh] mr-[20px] rounded-2xl border-[5px] border-[#1D4BD9] border-solid border-b-[10px] p-1 flex items-center justify-between pb-[20px];
  161. }
  162. .light-tag {
  163. @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;
  164. transform: translateX(-50%);
  165. .light-icon {
  166. width: 20px;
  167. height: 20px;
  168. margin-right: 3px;
  169. }
  170. .light-text {
  171. font-size: 16px;
  172. min-width: 100px;
  173. padding-right: 5px;
  174. }
  175. }
  176. .select-item {
  177. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  178. }
  179. .selected {
  180. @apply border-green-500;
  181. }
  182. .footer {
  183. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  184. }
  185. .text-stroke-custom {
  186. color: white;
  187. text-shadow:
  188. /* 左上角投影 */
  189. -1px -1px 0 #1D4BD9,
  190. /* 右上角投影 */
  191. 1px -1px 0 #1D4BD9,
  192. /* 左下角投影 */
  193. -1px 1px 0 #1D4BD9,
  194. /* 右下角投影 */
  195. 1px 1px 0 #1D4BD9;
  196. }
  197. </style>