PinyinText.vue 2.6 KB

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