Stem.vue 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 { getStemData } from '@/views/book/courseware/data/stem';
  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. export default {
  31. name: 'StemPage',
  32. components: { RichText, PinyinText },
  33. mixins: [ModuleMixin],
  34. data() {
  35. return {
  36. isEnable,
  37. data: getStemData(),
  38. selectContent: '',
  39. richId: '',
  40. };
  41. },
  42. watch: {
  43. 'data.property': {
  44. handler(val) {
  45. let text = this.data.content.replace(/<[^>]+>/g, '');
  46. if (isEnable(val.view_pinyin) && text) {
  47. this.data.paragraph_list_parameter.text = text;
  48. this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case =
  49. val.is_first_sentence_first_hz_pinyin_first_char_upper_case;
  50. this.crateParsedTextInfoPinyin(text);
  51. }
  52. },
  53. deep: true,
  54. },
  55. },
  56. methods: {
  57. showSetting() {
  58. this.richId = this.$refs.rich.id;
  59. this.$emit('showSetting', this.data.property, this.data.type, this.id, {
  60. richId: this.richId,
  61. });
  62. },
  63. // 获取拼音解析文本
  64. crateParsedTextInfoPinyin(text) {
  65. if (text === '') {
  66. this.data.paragraph_list_parameter.pinyin_proofread_word_list = [];
  67. return;
  68. }
  69. this.data.paragraph_list_parameter.text = text.replace(/<[^>]+>/g, '');
  70. this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case =
  71. this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case;
  72. CrateParsedTextInfo_Pinyin(this.data.paragraph_list_parameter).then((res) => {
  73. if (res.parsed_text) {
  74. this.data.paragraph_list = res.parsed_text.paragraph_list;
  75. }
  76. });
  77. },
  78. // 填充校对后的拼音
  79. fillCorrectPinyin(selectContent, tonePinyin, i, j, k) {
  80. this.data.paragraph_list_parameter.pinyin_proofread_word_list.push({
  81. paragraph_index: i,
  82. sentence_index: j,
  83. word_index: k,
  84. word: selectContent,
  85. pinyin: tonePinyin,
  86. });
  87. this.data.paragraph_list[i][j][k].pinyin = tonePinyin;
  88. },
  89. },
  90. };
  91. </script>