Strockred.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!-- -->
  2. <template>
  3. <div class="strockredBox">
  4. <div class="strockred">
  5. <div @click="resetHanzi" class="strock-play-box" v-if="1 == 2">
  6. <!-- <img src="../../assets/common/strock-play.png" class="strock-play" /> -->
  7. </div>
  8. <div
  9. :class="wordNum == '2' ? 'character-target-div_220' : ''"
  10. :id="targetDiv"
  11. class="character-target-div"
  12. >
  13. <svg-icon
  14. icon-class="tian"
  15. className="tian-bg"
  16. v-if="BoxbgType == 0"
  17. :style="{ color: '#DEDEDE' }"
  18. />
  19. <svg-icon
  20. icon-class="mi"
  21. className="tian-bg"
  22. v-if="BoxbgType == 1"
  23. :style="{ color: '#DEDEDE' }"
  24. />
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import { getContentFile } from "@/api/api";
  31. const HanziWriter = require("hanzi-writer");
  32. export default {
  33. name: "Strockred",
  34. components: {},
  35. props: [
  36. "targetDiv",
  37. "hanzicolor",
  38. "Book_text",
  39. "wordNum",
  40. "tianColor",
  41. "drawingColor",
  42. "BoxbgType",
  43. ],
  44. data() {
  45. return {
  46. writer: null,
  47. colorsList: ["#404040", "#f65d4d", "#19b068", "#52a1ea", "#ff8c49"],
  48. };
  49. },
  50. computed: {},
  51. watch: {
  52. hanzicolor(newVal, oldVal) {
  53. this.updateColor(newVal);
  54. },
  55. Book_text: {
  56. handler: function (val, oldVal) {
  57. if (val != oldVal) {
  58. let _this = this;
  59. _this.$nextTick(() => {
  60. _this.initHanziwrite();
  61. });
  62. }
  63. },
  64. // 深度观察监听
  65. deep: true,
  66. },
  67. },
  68. //方法集合
  69. methods: {
  70. initHanziwrite() {
  71. let _this = this;
  72. let node = document.getElementById(`${_this.targetDiv}`);
  73. node.removeChild(node.children[0]);
  74. let options = {
  75. charDataLoader: function (char, onComplete) {
  76. let MethodName = "hz_resource_manager-GetHZStrokesContent";
  77. let data = {
  78. hz: char,
  79. };
  80. getContentFile(MethodName, data).then((res) => {
  81. onComplete(res);
  82. });
  83. },
  84. padding: 5,
  85. showCharacter: false,
  86. outlineColor: _this.hanzicolor,
  87. strokeColor: _this.drawingColor,
  88. drawingWidth: 6,
  89. };
  90. _this.writer = HanziWriter.default.create(
  91. _this.targetDiv,
  92. _this.Book_text,
  93. options
  94. );
  95. _this.writer.quiz();
  96. },
  97. resetHanzi() {
  98. let _this = this;
  99. _this.writer.quiz();
  100. },
  101. updateColor(color) {
  102. let _this = this;
  103. _this.writer.updateColor("strokeColor", color);
  104. _this.writer.updateColor("drawingColor", color);
  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 "../../assets/Scss/_handle.scss";
  127. //@import url(); 引入公共css类
  128. .strockredBox {
  129. width: 100%;
  130. height: 100%;
  131. }
  132. .tian-bg {
  133. width: 100%;
  134. height: 100%;
  135. position: absolute;
  136. left: 0;
  137. top: 0;
  138. z-index: -1;
  139. }
  140. .strockred {
  141. position: relative;
  142. margin: 0 auto;
  143. width: 100%;
  144. height: 100%;
  145. //chinawrite220.png
  146. .character-target-div {
  147. position: relative;
  148. width: 100%;
  149. height: 100%;
  150. background: #fff;
  151. // background-size: 100% 100%;
  152. border-radius: 24px;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. z-index: 99999;
  157. }
  158. .animate-butto {
  159. width: 240px;
  160. height: 160px;
  161. font-size: 28px;
  162. }
  163. }
  164. </style>