index copy.uvue 7.2 KB

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