Strockplay.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!-- -->
  2. <template>
  3. <div class="strockplayInner" :class="className">
  4. <div @click="playHanzi" class="strock-play-box" v-if="playStorkes">
  5. <!-- <img class="strock-play" src="../../assets/common/strock-play.png"> -->
  6. </div>
  7. <div
  8. :class="wordNum == '2' ? 'morewords' : ''"
  9. :id="targetDiv"
  10. class="character-target-div"
  11. ></div>
  12. </div>
  13. </template>
  14. <script>
  15. import { getLogin } from "../../api/ajax";
  16. const HanziWriter = require("hanzi-writer");
  17. export default {
  18. components: {},
  19. props: [
  20. "targetDiv",
  21. "Book_text",
  22. "playStorkes",
  23. "strokeColor",
  24. "wordNum",
  25. "className",
  26. ],
  27. data() {
  28. return {
  29. writer: null,
  30. };
  31. },
  32. computed: {},
  33. watch: {
  34. targetDiv: {
  35. handler: function (val, oldVal) {
  36. if (val != oldVal) {
  37. let _this = this;
  38. _this.$nextTick(() => {
  39. _this.initHanziwrite();
  40. });
  41. }
  42. },
  43. // 深度观察监听
  44. deep: true,
  45. },
  46. },
  47. //方法集合
  48. methods: {
  49. initHanziwrite() {
  50. let _this = this;
  51. //var ren = require("hanzi-writer-data/国");
  52. _this.writer = HanziWriter.default.create(
  53. _this.targetDiv,
  54. _this.Book_text,
  55. {
  56. charDataLoader: function (char, onComplete) {
  57. let MethodName = "hz_resource_manager-GetHZStrokesContent";
  58. let data = {
  59. hz: char,
  60. };
  61. getLogin(MethodName, data).then((res) => {
  62. onComplete(res);
  63. });
  64. },
  65. padding: 5,
  66. showOutline: true,
  67. strokeColor: _this.strokeColor ? _this.strokeColor : "#000",
  68. }
  69. );
  70. },
  71. playHanzi() {
  72. let _this = this;
  73. _this.writer.animateCharacter();
  74. },
  75. },
  76. //生命周期 - 创建完成(可以访问当前this实例)
  77. created() {},
  78. //生命周期 - 挂载完成(可以访问DOM元素)
  79. mounted() {
  80. let _this = this;
  81. _this.$nextTick(() => {
  82. _this.initHanziwrite();
  83. });
  84. },
  85. beforeCreate() {}, //生命周期 - 创建之前
  86. beforeMount() {}, //生命周期 - 挂载之前
  87. beforeUpdate() {}, //生命周期 - 更新之前
  88. updated() {}, //生命周期 - 更新之后
  89. beforeDestroy() {}, //生命周期 - 销毁之前
  90. destroyed() {}, //生命周期 - 销毁完成
  91. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  92. };
  93. </script>
  94. <style lang='scss' scoped>
  95. //@import url(); 引入公共css类
  96. .strockplayInner {
  97. position: relative;
  98. margin: 0 auto;
  99. width: 100%; //444px
  100. height: 100%; //480px
  101. }
  102. .character-target-div {
  103. width: 100%; //444px
  104. height: 100%; //480px
  105. background: #fff url("../../assets/common/bg-rice.png") center no-repeat;
  106. background-size: 100% 100%;
  107. border-radius: 24px;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. z-index: 99999;
  112. &.morewords {
  113. background: url("../../assets/common/chinaTina220.png") center no-repeat;
  114. background-size: 100% 100%;
  115. }
  116. }
  117. .animate-butto {
  118. width: 240px;
  119. height: 160px;
  120. font-size: 28px;
  121. }
  122. .questionMiddle {
  123. .character-target-div {
  124. border-radius: 16px;
  125. &.morewords {
  126. background: url("../../assets/common/chinaTina220.png") center no-repeat;
  127. background-size: 100% 100%;
  128. }
  129. }
  130. .animate-butto {
  131. width: 160px;
  132. height: 106px;
  133. font-size: 18px;
  134. }
  135. }
  136. .questionSmall {
  137. .character-target-div {
  138. border-radius: 12px;
  139. &.morewords {
  140. background: url("../../assets/common/chinaTina220.png") center no-repeat;
  141. background-size: 100% 100%;
  142. }
  143. }
  144. .animate-butto {
  145. width: 120px;
  146. height: 80px;
  147. font-size: 14px;
  148. }
  149. }
  150. // .adult-strockplay {
  151. // .character-target-div {
  152. // background: #fff url("../../assets/adult/adult-hz-tian.png") center
  153. // no-repeat;
  154. // background-size: 100% 100%;
  155. // }
  156. // .strock-play-box {
  157. // position: absolute;
  158. // top: 0;
  159. // right: 0;
  160. // width: 20px;
  161. // height: 20px;
  162. // background: #fff url("../../assets/adult/adult-play-strock.png") center
  163. // no-repeat;
  164. // background-size: 100% 100%;
  165. // }
  166. // }
  167. </style>