question-wrap.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <scroll-view v-if="visible" scroll-y class="question-wrap" :scroll-into-view="scrollIntoView"
  3. :scroll-with-animation="true">
  4. <view class="h-20"></view>
  5. <question-item :question="question" :readonly="readonly" @update:question="emit('update:question', $event)"
  6. @scrollTo="handleScrollTo" />
  7. <view class="h-20"></view>
  8. </scroll-view>
  9. </template>
  10. <script lang="ts" setup>
  11. import { Study } from '@/types';
  12. import QuestionItem from './question-item.vue';
  13. const props = defineProps<{
  14. question: Study.Question;
  15. readonly?: boolean;
  16. currentIndex: number;
  17. index: number;
  18. }>();
  19. const visible = computed(() => {
  20. return Math.abs(props.currentIndex - props.index) <= 2;
  21. });
  22. const emit = defineEmits<{
  23. (e: 'update:question', question: Study.Question): void;
  24. }>();
  25. const scrollIntoView = ref('');
  26. const handleScrollTo = (selector: string) => {
  27. console.log('收到子组件滚动请求', selector)
  28. scrollIntoView.value = '';
  29. setTimeout(() => {
  30. if (selector) {
  31. scrollIntoView.value = selector;
  32. }
  33. }, 200);
  34. }
  35. </script>
  36. <style lang="scss" scoped>
  37. .question-wrap {
  38. @apply h-full box-border;
  39. }
  40. </style>