index.uvue 6.9 KB

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