learing.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, onMounted } from "vue";
  5. import { getRoute, router } from "../../utils/router";
  6. import { request } from "../../utils/request";
  7. const context = ref([]);
  8. const otherParams = ref({});
  9. const scrollTop = ref(0);
  10. let se = ref(0);
  11. const normalText = (text) =>
  12. text
  13. .replace(/<table.*?style="(.*?)*?>/g, (text) =>
  14. text.replace(/(?:\bwidth:[^;]+;|\bmargin-left:[^;]+;)/g, "")
  15. )
  16. .replace(
  17. /<p[^>]*style="[^"]*margin:\s*[^;\s]+\s+[^;\s]+\s+[^;\s]+\s+[^;\s]+;[^"]*">/g,
  18. (text) =>
  19. text
  20. .replace(
  21. /(<p[^>]*style="[^"]*margin:\s*)[^;\s]+\s+[^;\s]+\s+[^;\s]+\s+[^;\s]+;/g,
  22. "$18pt 0;"
  23. )
  24. .replace(/line-height:\s*[^;]+;/g, "line-height: 1.5;")
  25. )
  26. .replace(/(<p[^>]*style="[^"]*margin:\s*)[^;\s]+(\s+[^;]+;)/g, "$17pt$2")
  27. .replace(
  28. /<img([^>]*?)width="[^"]*"([^>]*?)height="[^"]*"([^>]*?)\/>/g,
  29. '<img$1width="100%"$2height="100%"$3/>'
  30. );
  31. const onScroll = (e) => {
  32. se.value = e.detail.scrollTop;
  33. };
  34. const submitScrollTop = (is_done) => {
  35. request(
  36. "api/question_bank/question_reception/point/set_point_study_progress",
  37. {
  38. id: getRoute().params.id,
  39. scroll_top: se.value,
  40. is_done,
  41. }
  42. );
  43. };
  44. const onSubmit = () => {
  45. submitScrollTop(1);
  46. const params = getRoute().params;
  47. // TODO: 提交滚动条位置,并跳转页面
  48. router.push({
  49. url: `/pages/regulations/practice`,
  50. params: {
  51. title: params.name,
  52. id: params.id,
  53. },
  54. });
  55. };
  56. const onBack = () =>
  57. new Promise((resolve) => {
  58. // 提交滚动条位置,并跳转页面
  59. submitScrollTop(0);
  60. resolve(true);
  61. });
  62. onMounted(() => {
  63. request("api/question_bank/question_reception/point/get_chapter_point", {
  64. id: getRoute().params.id,
  65. }).then((res) => {
  66. const { point_content, ...data } = res.data;
  67. context.value = point_content.map((item) => {
  68. return {
  69. ...item,
  70. context: normalText(item.detail),
  71. };
  72. });
  73. otherParams.value = data;
  74. scrollTop.value = data.scroll_top;
  75. });
  76. });
  77. </script>
  78. <template>
  79. <Container
  80. title="法规"
  81. @onScroll="onScroll"
  82. :empty="!context.length"
  83. :scrollTop="scrollTop"
  84. :onBack="onBack"
  85. >
  86. <view :key="item.id" v-for="(item, index) in context">
  87. <view class="title">考 点{{ index + 1 }} {{ item.name }}</view>
  88. <uv-parse :content="item.context" :selectable="true" />
  89. </view>
  90. <text class="button" @click="onSubmit">已学完, 开启练习模式</text>
  91. </Container>
  92. </template>
  93. <style scoped lang="scss">
  94. .title {
  95. color: #703060;
  96. font-weight: bold;
  97. text-align: center;
  98. }
  99. </style>