PinyinText.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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="(item, k) in sentence" :key="k" class="pinyin-text">
  11. <span
  12. :class="{ active: visible && word_index == k }"
  13. :title="isPreview ? '' : '点击校对'"
  14. :style="{
  15. ...item.activeTextStyle,
  16. cursor: isPreview ? '' : 'pointer',
  17. }"
  18. @click="correctPinyin(item, i, j, k)"
  19. >
  20. <ruby
  21. v-for="(word, w) in item.text.split('')"
  22. :key="w"
  23. :style="{ 'ruby-position': pinyinPosition === 'top' ? 'over' : 'under' }"
  24. class="py-char"
  25. >{{ word
  26. }}<rt class="pinyin" :class="{ active: visible && word_index == k }">{{ item.pinyin.split(' ')[w] }}</rt>
  27. </ruby>
  28. </span>
  29. </div>
  30. </div>
  31. </div>
  32. <CorrectPinyin :visible.sync="visible" :select-content="selectContent" @fillTonePinyin="fillTonePinyin" />
  33. </div>
  34. </template>
  35. <script>
  36. import CorrectPinyin from '@/views/book/courseware/create/components/base/common/CorrectPinyin.vue';
  37. export default {
  38. name: 'PinyinText',
  39. components: {
  40. CorrectPinyin,
  41. },
  42. props: {
  43. paragraphList: {
  44. type: Array,
  45. required: true,
  46. },
  47. pinyinPosition: {
  48. type: String,
  49. required: true,
  50. },
  51. isPreview: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. },
  56. data() {
  57. return {
  58. paragraph_list: [],
  59. visible: false,
  60. selectContent: {},
  61. paragraph_index: 0,
  62. sentence_index: 0,
  63. word_index: 0,
  64. };
  65. },
  66. methods: {
  67. // 校对拼音
  68. correctPinyin(item, i, j, k) {
  69. if (this.isPreview) return; // 如果是预览模式,不操作
  70. if (item) {
  71. this.visible = true;
  72. this.selectContent = item;
  73. this.paragraph_index = i;
  74. this.sentence_index = j;
  75. this.word_index = k;
  76. }
  77. },
  78. // 回填校对后的拼音
  79. fillTonePinyin(dataContent) {
  80. this.$emit('fillCorrectPinyin', {
  81. selectContent: dataContent,
  82. i: this.paragraph_index,
  83. j: this.sentence_index,
  84. k: this.word_index,
  85. });
  86. },
  87. },
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .pinyin-area {
  92. .pinyin-paragraph {
  93. display: flex;
  94. flex-direction: column;
  95. .pinyin-sentence {
  96. display: flex;
  97. flex-wrap: wrap;
  98. column-gap: 4px;
  99. .pinyin-text {
  100. font-size: 24px;
  101. .py-char {
  102. ruby-align: center;
  103. }
  104. .pinyin {
  105. margin-bottom: 4px;
  106. font-family: 'League';
  107. font-size: 12px;
  108. color: $font-color;
  109. }
  110. }
  111. }
  112. }
  113. .active {
  114. color: rgb(242, 85, 90) !important;
  115. }
  116. }
  117. </style>
  118. <style lang="scss">
  119. .pinyin-area + .pinyin-area {
  120. margin-top: 4px;
  121. }
  122. </style>