learing.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <script setup name="regulations">
  2. import Container from "../../components/Container/Container.vue";
  3. import uvParse from "../../uni_modules/uv-parse/components/uv-parse/uv-parse.vue";
  4. import { ref } from "vue";
  5. import { onShow } from "@dcloudio/uni-app";
  6. import { getRoute, router } from "../../utils/router";
  7. import { request } from "../../utils/request";
  8. const context = ref([]);
  9. const otherParams = ref({});
  10. const scrollTop = ref(0);
  11. let se = ref(0);
  12. const normalText = (text) =>
  13. text
  14. .replace(/<table.*?style="(.*?)*?>/g, (text) =>
  15. text.replace(/(?:\bwidth:[^;]+;|\bmargin-left:[^;]+;)/g, "")
  16. )
  17. .replace(
  18. /<p[^>]*style="[^"]*margin:\s*[^;\s]+\s+[^;\s]+\s+[^;\s]+\s+[^;\s]+;[^"]*">/g,
  19. (text) =>
  20. text
  21. .replace(
  22. /(<p[^>]*style="[^"]*margin:\s*)[^;\s]+\s+[^;\s]+\s+[^;\s]+\s+[^;\s]+;/g,
  23. "$18pt 0;"
  24. )
  25. .replace(/line-height:\s*[^;]+;/g, "line-height: 1.5;")
  26. )
  27. .replace(/(<p[^>]*style="[^"]*margin:\s*)[^;\s]+(\s+[^;]+;)/g, "$17pt$2")
  28. .replace(
  29. /<img([^>]*?)width="[^"]*"([^>]*?)height="[^"]*"([^>]*?)\/>/g,
  30. '<img$1width="100%"$2height="100%"$3/>'
  31. );
  32. const onScroll = (e) => {
  33. se.value = e.detail.scrollTop;
  34. scrollTop.value = e.detail.scrollTop;
  35. };
  36. const submitScrollTop = (is_done, scroll) => {
  37. if (otherParams.value.is_done) return;
  38. request(
  39. "api/question_bank/question_reception/point/set_point_study_progress",
  40. {
  41. id: getRoute().params.id,
  42. scroll_top: scroll || se.value,
  43. is_done,
  44. }
  45. );
  46. };
  47. const onSubmit = () => {
  48. submitScrollTop(1, 0);
  49. const params = getRoute().params;
  50. // TODO: 提交滚动条位置,并跳转页面
  51. router.push({
  52. url: `/pages/regulations/practice`,
  53. params: {
  54. title: params.name,
  55. id: params.id,
  56. },
  57. });
  58. };
  59. const onBack = () =>
  60. new Promise((resolve) => {
  61. // 提交滚动条位置,并跳转页面
  62. submitScrollTop(0);
  63. resolve(true);
  64. });
  65. onShow(() => {
  66. request("api/question_bank/question_reception/point/get_chapter_point", {
  67. id: getRoute().params.id,
  68. }).then((res) => {
  69. const { point_content, ...data } = res.data;
  70. context.value = point_content.map((item) => {
  71. return {
  72. ...item,
  73. context: normalText(item.detail),
  74. };
  75. });
  76. otherParams.value = data;
  77. });
  78. });
  79. const onClick = (e, index) => {
  80. scrollTop.value = e.currentTarget.offsetTop
  81. };
  82. </script>
  83. <template>
  84. <Container
  85. :title="getRoute().params?.name"
  86. @onScroll="onScroll"
  87. :empty="!context.length"
  88. :scrollTop="scrollTop"
  89. :onBack="onBack"
  90. >
  91. <view>
  92. <view :key="item.id" v-for="(item, index) in context">
  93. <view
  94. class="title"
  95. :class="{
  96. 'mt-40': index !== 0,
  97. [`title-${index}`]: true,
  98. }"
  99. @click="(e) => onClick(e, index)"
  100. >考 点{{ index + 1 }} {{ item.name }}</view
  101. >
  102. <uv-parse class="text" :content="item.context" selectable />
  103. </view>
  104. <text class="button mt-30" @click="onSubmit">已学完, 开启练习模式</text>
  105. </view>
  106. </Container>
  107. </template>
  108. <style scoped lang="scss">
  109. .title {
  110. color: #703060;
  111. font-weight: bold;
  112. text-align: center;
  113. padding: 30rpx 0;
  114. font-size: 40rpx;
  115. // position: sticky;
  116. top: 0;
  117. background-color: #fff;
  118. z-index: 999;
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. }
  123. .text {
  124. line-height: 2;
  125. }
  126. .mt-30 {
  127. margin-top: 30rpx;
  128. }
  129. </style>