| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <script lang="ts" setup>
- import { ref, onMounted } from 'vue'
- import { fetchSubjectAppInfo } from '@/services/subject/info'
- import { querySubjectCourseTest } from '@/services/subject/test'
- import type { SubjectCatalogResult } from '@/services/subject/catalog'
- import type { SubjectCourseTestResult } from '@/services/subject/test'
- import Lock from '@/components/lock.uvue'
- import Back from '@/components/back.uvue'
- import Loading from '@/components/loading.uvue'
- import { config } from '@/config'
- import { dict } from '@/.cool/store'
- import { router } from "@/.cool";
- const isLoading = ref(true)
- const visible = ref<boolean>(false)
- const dataList = ref<SubjectCatalogResult[]>([])
- const catalog = ref<SubjectCatalogResult>()
- const testList = ref<SubjectCourseTestResult[]>()
- async function getDataList() {
- const id = dict.getValueByLabelMapByType('index_subject_id')['物理']
- const res = await fetchSubjectAppInfo({ id })
- dataList.value = res.catalogList || []
- catalog.value = res?.catalogList?.[0]
- const testRes = await querySubjectCourseTest()
- testList.value = testRes || []
- }
- onMounted(async () => {
- try {
- await getDataList()
- isLoading.value = false
- } catch (err) {
- console.log(err);
- isLoading.value = false
- }
- })
- const cardsScrollView = ref<any>(null)
- function handleDetail(item: SubjectCourseTestResult) {
- router.push({
- path: "/pages/catalog/web-view",
- query: {
- src: item.animationPath,
- progress: 2,
- }
- });
- }
- function handleSelect(val: SubjectCatalogResult) {
- catalog.value = val
- visible.value = false
- uni.createSelectorQuery().select(`.category-${val.id}`).boundingClientRect().exec((rect) => {
- if (cardsScrollView.value && rect[0]) {
- cardsScrollView.value.scrollTo({
- left: rect[0].left - 50, // 减去顶部偏移
- animated: true
- })
- }
- })
- }
- async function onScroll(e: any) {
- console.log();
- dataList.value.forEach(async (category) => {
- const selector = `.category-${category.id}`
- await uni.createSelectorQuery().selectAll(selector).boundingClientRect().exec((rects) => {
- // 检查元素是否在可视区域内
- for (const rect of rects[0]) {
- if (rect.left <= 50) {
- catalog.value = category
- }
- }
- })
- })
- }
- </script>
- <template>
- <Loading v-show="isLoading" />
- <cl-page v-show="!isLoading">
- <Back />
- <img src="https://oss.xiaoxiongcode.com/static/home/2.png" alt="" class="w-full h-full object-cover" />
- <!-- 顶部右侧光标签 -->
- <view class="light-tag" @tap="visible = true">
- <image class="light-icon" v-if="catalog?.fileList?.[0]?.url" :src="config.baseUrl + catalog?.fileList?.[0]?.url">
- </image>
- <text class="light-text">{{ catalog?.name }}</text>
- <cl-icon name="arrow-left-right-line" color="primary"></cl-icon>
- </view>
- <view class="boxs">
- <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false" ref="cardsScrollView"
- @scroll="onScroll">
- <view class="scroll-view-item_H bg-[white]" v-for="test in testList || []" :class="`category-${test.catalogId}`"
- :key="test.id" @tap="handleDetail(test)" ref="categoryRefs">
- <cl-image :src="test.animationJavascriptPath" mode="heightFix"
- class="!w-full !h-[26vh] mb-[2px] rounded-xl"></cl-image>
- <text class="text-[16px] font-bold">{{
- test.name }}</text>
- <text class="text-[14px] text-[#666]">{{
- test.remark }}</text>
- <Lock v-if="!test.lockFlag" :record="test" />
- </view>
- </scroll-view>
- </view>
- <cl-popup v-model="visible" :show-header="false" direction="center" :size="600">
- <view class="p-4">
- <cl-row :gutter="0">
- <cl-col :span="6" v-for="item in dataList || []" :key="item.id" :pt="{
- className: '!p-2'
- }" @tap="handleSelect(item)">
- <view class="select-item" :class="{ selected: item.id === catalog?.id }">
- <image :src="config.baseUrl + item?.fileList?.[0]?.url" class="w-[30rpx] h-[30rpx] mb-[2px]"></image>
- <text>{{ item.name }}</text>
- </view>
- </cl-col>
- </cl-row>
- </view>
- </cl-popup>
- </cl-page>
- </template>
- <style lang="scss" scoped>
- .boxs {
- @apply w-[calc(100vw-100px)] h-[50vh] absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[1];
- }
- .scroll-view_H {
- width: 100%;
- height: 100%;
- flex-direction: row;
- }
- .scroll-view-item_H {
- @apply w-[40vh] h-[50vh] mr-[20px] rounded-2xl border-[5px] border-[#1D4BD9] border-solid border-b-[10px] p-1 flex items-center relative;
- }
- .light-tag {
- @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;
- transform: translateX(-50%);
- .light-icon {
- width: 20px;
- height: 20px;
- margin-right: 3px;
- }
- .light-text {
- font-size: 16px;
- min-width: 100px;
- padding-right: 5px;
- }
- }
- .select-item {
- @apply flex items-center justify-center rounded-xl border-[3px] border-[#1D4BD9] border-solid border-b-[5px] px-4 py-2 font-bold;
- }
- .selected {
- @apply border-green-500;
- }
- .footer {
- @apply absolute bottom-2 right-5 z-[1] flex flex-row items-center justify-center gap-4;
- }
- .text-stroke-custom {
- color: white;
- text-shadow:
- /* 左上角投影 */
- -1px -1px 0 #1D4BD9,
- /* 右上角投影 */
- 1px -1px 0 #1D4BD9,
- /* 左下角投影 */
- -1px 1px 0 #1D4BD9,
- /* 右下角投影 */
- 1px 1px 0 #1D4BD9;
- }
- </style>
|