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