index.uvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. <cl-text ellipsis :pt="{
  100. className: '!text-[4vh] !font-bold'
  101. }">{{
  102. course.sortNum }}、{{
  103. course.mainTitle }}</cl-text>
  104. <text class="text-[3vh] text-[#666]">{{
  105. course.assistantTitle }}</text>
  106. <!-- <view>
  107. <Progress :progress="30" />
  108. </view> -->
  109. <Lock v-if="userInfo?.memberLevel === 'default'" :record="course" type="vip" />
  110. </view>
  111. </scroll-view>
  112. </view>
  113. <!-- <view class="footer">
  114. <view>
  115. <cl-image src="https://oss.xiaoxiongcode.com/static/home/4.png" mode="heightFix"
  116. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  117. <text class="text-[14px] text-white font-bold text-stroke-custom">虚拟实验</text>
  118. </view>
  119. <view>
  120. <cl-image src="https://oss.xiaoxiongcode.com/static/home/5.png" mode="heightFix"
  121. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  122. <text class="text-[14px] text-white font-bold text-stroke-custom">我的收获</text>
  123. </view>
  124. <view>
  125. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6.png" mode="heightFix"
  126. class=" !h-[40px] mb-[2px] rounded-xl"></cl-image>
  127. <text class="text-[14px] text-white font-bold text-stroke-custom">学习报告</text>
  128. </view>
  129. </view> -->
  130. <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
  131. <view class="p-4">
  132. <cl-row :gutter="0">
  133. <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
  134. className: '!p-2'
  135. }" @tap="handleSelect(item)">
  136. <view class="select-item" :class="{ selected: item.id === catalog?.id }">
  137. <image :src="config.baseUrl + item?.fileList?.[0]?.url" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
  138. <text>{{ item.name }}</text>
  139. </view>
  140. </cl-col>
  141. </cl-row>
  142. </view>
  143. </cl-popup>
  144. </cl-page>
  145. </template>
  146. <style lang="scss" scoped>
  147. .boxs {
  148. @apply w-[calc(100vw-52vh)] h-[50vh] absolute top-1/2 left-[50vh] z-[1];
  149. transform: translateY(-50%);
  150. }
  151. .scroll-view_H {
  152. width: 100%;
  153. height: 100%;
  154. flex-direction: row;
  155. }
  156. .scroll-view-item_H {
  157. @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;
  158. }
  159. .light-tag {
  160. @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;
  161. transform: translateX(-50%);
  162. .light-icon {
  163. width: 20px;
  164. height: 20px;
  165. margin-right: 3px;
  166. }
  167. .light-text {
  168. font-size: 16px;
  169. min-width: 100px;
  170. padding-right: 5px;
  171. }
  172. }
  173. .select-item {
  174. @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
  175. }
  176. .selected {
  177. @apply border-green-500;
  178. }
  179. .footer {
  180. @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
  181. }
  182. .text-stroke-custom {
  183. color: white;
  184. text-shadow:
  185. /* 左上角投影 */
  186. -1px -1px 0 #1D4BD9,
  187. /* 右上角投影 */
  188. 1px -1px 0 #1D4BD9,
  189. /* 左下角投影 */
  190. -1px 1px 0 #1D4BD9,
  191. /* 右下角投影 */
  192. 1px 1px 0 #1D4BD9;
  193. }
  194. </style>