Strockplay.vue 4.1 KB

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