Describe.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <ModuleBase :type="data.type">
  3. <template #content>
  4. <RichText
  5. ref="rich"
  6. v-model="data.content"
  7. :font-size="18"
  8. placeholder="输入描述"
  9. :is-view-pinyin="isEnable(data.property.view_pinyin)"
  10. @crateParsedTextInfoPinyin="crateParsedTextInfoPinyin"
  11. />
  12. <el-divider v-if="isEnable(data.property.view_pinyin)" content-position="left">拼音效果</el-divider>
  13. <PinyinText
  14. v-if="isEnable(data.property.view_pinyin)"
  15. :id="richId + '_pinyin_text'"
  16. :paragraph-list="data.paragraph_list"
  17. :pinyin-position="data.property.pinyin_position"
  18. @fillCorrectPinyin="fillCorrectPinyin"
  19. />
  20. </template>
  21. </ModuleBase>
  22. </template>
  23. <script>
  24. import { getDescribeData } from '@/views/book/courseware/data/describe';
  25. import { CrateParsedTextInfo_Pinyin } from '@/api/book';
  26. import { isEnable } from '@/views/book/courseware/data/common';
  27. import ModuleMixin from '../../common/ModuleMixin';
  28. import RichText from '@/components/RichText.vue';
  29. import PinyinText from '@/components/PinyinText.vue';
  30. import DOMPurify from 'dompurify';
  31. export default {
  32. name: 'DescribePage',
  33. components: { RichText, PinyinText },
  34. mixins: [ModuleMixin],
  35. data() {
  36. return {
  37. isEnable,
  38. data: getDescribeData(),
  39. selectContent: '',
  40. richId: '',
  41. };
  42. },
  43. watch: {
  44. 'data.property': {
  45. handler(val) {
  46. let text = this.data.content.replace(/<[^>]+>/g, '');
  47. if (isEnable(val.view_pinyin) && text) {
  48. this.data.paragraph_list_parameter.text = text;
  49. this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case =
  50. val.is_first_sentence_first_hz_pinyin_first_char_upper_case;
  51. this.crateParsedTextInfoPinyin(text);
  52. }
  53. },
  54. deep: true,
  55. },
  56. 'data.content': {
  57. handler: 'handlerMindMap',
  58. deep: true,
  59. },
  60. },
  61. methods: {
  62. showSetting() {
  63. this.richId = this.$refs.rich.id;
  64. this.$emit('showSetting', this.data.property, this.data.type, this.id, {
  65. richId: this.richId,
  66. });
  67. },
  68. // 获取拼音解析文本
  69. crateParsedTextInfoPinyin(text) {
  70. if (text === '') {
  71. this.data.paragraph_list_parameter.pinyin_proofread_word_list = [];
  72. return;
  73. }
  74. this.data.paragraph_list_parameter.text = text.replace(/<[^>]+>/g, '');
  75. this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case =
  76. this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case;
  77. CrateParsedTextInfo_Pinyin(this.data.paragraph_list_parameter).then((res) => {
  78. if (res.parsed_text) {
  79. this.data.paragraph_list = res.parsed_text.paragraph_list;
  80. }
  81. });
  82. },
  83. // 填充校对后的拼音
  84. fillCorrectPinyin(selectContent, tonePinyin, i, j, k) {
  85. this.data.paragraph_list_parameter.pinyin_proofread_word_list.push({
  86. paragraph_index: i,
  87. sentence_index: j,
  88. word_index: k,
  89. word: selectContent,
  90. pinyin: tonePinyin,
  91. });
  92. this.data.paragraph_list[i][j][k].pinyin = tonePinyin;
  93. },
  94. // 思维导图
  95. handlerMindMap() {
  96. this.$set(this.data.mind_map, 'node_list', [
  97. {
  98. name: `题干:${this.sanitizeHTML(this.data.content)}`,
  99. },
  100. ]);
  101. },
  102. /**
  103. * 过滤 html,防止 xss 攻击
  104. * @param {string} html 需要过滤的html
  105. * @returns {string} 过滤后的html
  106. */
  107. sanitizeHTML(html) {
  108. return DOMPurify.sanitize(html, { ALLOWED_TAGS: [] });
  109. },
  110. },
  111. };
  112. </script>