PinyinText.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="pinyin-area">
  3. <div v-for="(paragraph, i) in paragraphList" :key="i" class="pinyin-paragraph">
  4. <div
  5. v-for="(sentence, j) in paragraph"
  6. :key="j"
  7. class="pinyin-sentence"
  8. :style="{ 'align-items': pinyinPosition === 'top' ? 'flex-end' : 'flex-start' }"
  9. >
  10. <div v-for="(text, k) in sentence" :key="k" class="pinyin-text">
  11. <span v-if="pinyinPosition === 'top'" class="pinyin">
  12. {{ text.pinyin.replace(/\s+/g, '') }}
  13. </span>
  14. <span class="text" title="点击校对拼音" @click="correctPinyin1(text.text, i, j, k)">{{ text.text }}</span>
  15. <span v-if="pinyinPosition === 'bottom'" class="pinyin">{{ text.pinyin.replace(/\s+/g, '') }}</span>
  16. </div>
  17. </div>
  18. </div>
  19. <CorrectPinyin :visible.sync="visible" :select-content="selectContent" @fillTonePinyin="fillTonePinyin" />
  20. </div>
  21. </template>
  22. <script>
  23. import CorrectPinyin from '@/views/book/courseware/create/components/base/common/CorrectPinyin.vue';
  24. export default {
  25. name: 'PinyinText',
  26. components: {
  27. CorrectPinyin,
  28. },
  29. props: {
  30. paragraphList: {
  31. type: Array,
  32. required: true,
  33. },
  34. pinyinPosition: {
  35. type: String,
  36. required: true,
  37. },
  38. },
  39. data() {
  40. return {
  41. paragraph_list: [],
  42. visible: false,
  43. selectContent: '',
  44. paragraph_index: 0,
  45. sentence_index: 0,
  46. word_index: 0,
  47. };
  48. },
  49. methods: {
  50. // 校对拼音
  51. correctPinyin1(text, i, j, k) {
  52. if (text) {
  53. this.visible = true;
  54. this.selectContent = text;
  55. this.paragraph_index = i;
  56. this.sentence_index = j;
  57. this.word_index = k;
  58. }
  59. },
  60. // 回填校对后的拼音
  61. fillTonePinyin(tonePinyin) {
  62. this.$emit(
  63. 'fillCorrectPinyin',
  64. this.selectContent,
  65. tonePinyin,
  66. this.paragraph_index,
  67. this.sentence_index,
  68. this.word_index,
  69. );
  70. },
  71. },
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. .pinyin-area {
  76. .pinyin-paragraph {
  77. display: flex;
  78. flex-direction: column;
  79. .pinyin-sentence {
  80. display: flex;
  81. flex-wrap: wrap;
  82. column-gap: 4px;
  83. .pinyin-text {
  84. display: flex;
  85. flex-direction: column;
  86. font-size: 24px;
  87. .pinyin {
  88. font-size: 12px;
  89. }
  90. .text {
  91. cursor: pointer;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. </style>