learing.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. request(
  38. "api/question_bank/question_reception/point/set_point_study_progress",
  39. {
  40. id: getRoute().params.id,
  41. scroll_top: scroll || se.value,
  42. is_done,
  43. }
  44. );
  45. };
  46. const onSubmit = () => {
  47. submitScrollTop(1, 0);
  48. const params = getRoute().params;
  49. // TODO: 提交滚动条位置,并跳转页面
  50. router.push({
  51. url: `/pages/regulations/practice`,
  52. params: {
  53. title: params.name,
  54. id: params.id,
  55. },
  56. });
  57. };
  58. const onBack = () =>
  59. new Promise((resolve) => {
  60. // 提交滚动条位置,并跳转页面
  61. submitScrollTop(0);
  62. resolve(true);
  63. });
  64. onShow(() => {
  65. request("api/question_bank/question_reception/point/get_chapter_point", {
  66. id: getRoute().params.id,
  67. }).then((res) => {
  68. const { point_content, ...data } = res.data;
  69. context.value = point_content.map((item) => {
  70. return {
  71. ...item,
  72. context: normalText(item.detail),
  73. };
  74. });
  75. otherParams.value = data;
  76. // scrollTop.value = data.scroll_top;
  77. });
  78. });
  79. </script>
  80. <template>
  81. <Container
  82. title="法规"
  83. @onScroll="onScroll"
  84. :empty="!context.length"
  85. :scrollTop="scrollTop"
  86. :onBack="onBack"
  87. >
  88. <view>
  89. <view :key="item.id" v-for="(item, index) in context">
  90. <view class="title">考 点{{ index + 1 }} {{ item.name }}</view>
  91. <uv-parse class="text" :content="item.context" selectable />
  92. </view>
  93. <text class="button" @click="onSubmit">已学完, 开启练习模式</text>
  94. </view>
  95. </Container>
  96. </template>
  97. <style scoped lang="scss">
  98. .title {
  99. color: #703060;
  100. font-weight: bold;
  101. text-align: center;
  102. margin: 10rpx 0;
  103. }
  104. .text {
  105. line-height: 1.7;
  106. }
  107. </style>