Strockplayredline.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="strockplay-redInner" :style="{'width':bjIconSize+'px','height':bjIconSize+'px'}">
  3. <view v-if="playStorkes" :class="['strock-play-box']" @click="playHanzi">
  4. <SvgIcon icon-class="hanzi-strock-play" class="strock-play-btn" />
  5. </view>
  6. <view class="character-target-box">
  7. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" :size="bjIconSize" />
  8. <view :id="targetView" class="character-target-div"></view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import HanziWriter from 'hanzi-writer';
  14. export default {
  15. name: 'Strockplayredline',
  16. components: {},
  17. props: {
  18. bookText: {
  19. type: String,
  20. default: '',
  21. },
  22. targetView: {
  23. type: String,
  24. default: '',
  25. },
  26. playStorkes: {
  27. type: Boolean,
  28. default: true,
  29. },
  30. strokeColor: {
  31. type: String,
  32. default: '',
  33. },
  34. bookStrokes: {
  35. type: Object,
  36. default: () => {},
  37. },
  38. bjIconSize: {
  39. type: Number,
  40. default: 64,
  41. }
  42. },
  43. data() {
  44. return {
  45. writer: null,
  46. };
  47. },
  48. computed: {},
  49. watch: {
  50. targetView: {
  51. handler(val, oldVal) {
  52. if (val !== oldVal) {
  53. this.$nextTick(() => {
  54. this.initHanziwrite();
  55. });
  56. }
  57. },
  58. deep: true,
  59. },
  60. // strokeColor: {
  61. // handler(val, oldVal) {
  62. // var that = this;
  63. // if (this.targetView.indexOf('con_') >= 0) {
  64. // if (this.writer) {
  65. // that.writer.updateColor('strokeColor', val);
  66. // }
  67. // }
  68. // },
  69. // immediate: true,
  70. // deep: true,
  71. // },
  72. },
  73. mounted() {
  74. this.$nextTick(() => {
  75. this.initHanziwrite();
  76. });
  77. },
  78. // 方法集合
  79. methods: {
  80. initHanziwrite() {
  81. let that = this;
  82. this.writer = HanziWriter.create(this.targetView, this.bookText, {
  83. charDataLoader(char, onComplete) {
  84. onComplete(that.bookStrokes);
  85. },
  86. width: this.bjIconSize,
  87. height: this.bjIconSize,
  88. padding: 5,
  89. showOutline: true, //是否显示轮廓
  90. strokeColor: this.strokeColor ? this.strokeColor : '#000', //笔画颜色
  91. });
  92. },
  93. playHanzi(event) {
  94. event.stopPropagation();
  95. this.writer.animateCharacter(); //动画
  96. },
  97. },
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .strockplay-redInner {
  102. position: relative;
  103. box-sizing: border-box;
  104. }
  105. .character-target-div {
  106. position: absolute;
  107. top: 0;
  108. left: 0;
  109. z-index: 11;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. width: 100%;
  114. height: 100%;
  115. }
  116. .character-target-box {
  117. position: relative;
  118. width: 100%;
  119. height: 100%;
  120. }
  121. .character-target-bg {
  122. position: absolute;
  123. top: 0;
  124. left: 0;
  125. width: 100%;
  126. height: 100%;
  127. color: #676767;
  128. }
  129. .strock-play-box {
  130. position: absolute;
  131. top: 0;
  132. right: 0;
  133. z-index: 12;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. width: 11px;
  138. height: 11px;
  139. color: red;
  140. }
  141. </style>