Strockred.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!-- -->
  2. <template>
  3. <div class="strockredBox">
  4. <div class="strockred">
  5. <div @click="resetHanzi" class="strock-play-box" v-if="playStorkes">
  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. ></div>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import { getLogin } from "../../api/ajax";
  18. const HanziWriter = require("hanzi-writer");
  19. export default {
  20. name: "Strockred",
  21. components: {},
  22. props: ["targetDiv", "hanzicolor", "Book_text", "playStorkes", "wordNum"],
  23. data() {
  24. return {
  25. writer: null,
  26. colorsList: ["#404040", "#f65d4d", "#19b068", "#52a1ea", "#ff8c49"],
  27. };
  28. },
  29. computed: {},
  30. watch: {
  31. hanzicolor(newVal, oldVal) {
  32. this.updateColor(newVal);
  33. },
  34. Book_text: {
  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. let options = {
  52. charDataLoader: function (char, onComplete) {
  53. let MethodName = "hz_resource_manager-GetHZStrokesContent";
  54. let data = {
  55. hz: char,
  56. };
  57. getLogin(MethodName, data).then((res) => {
  58. onComplete(res);
  59. });
  60. },
  61. padding: 5,
  62. showCharacter: false,
  63. strokeColor: _this.hanzicolor,
  64. drawingColor: _this.hanzicolor,
  65. drawingWidth: 6,
  66. };
  67. _this.writer = HanziWriter.default.create(
  68. _this.targetDiv,
  69. _this.Book_text,
  70. options
  71. );
  72. _this.writer.quiz();
  73. },
  74. resetHanzi() {
  75. let _this = this;
  76. _this.writer.quiz();
  77. },
  78. updateColor(color) {
  79. let _this = this;
  80. _this.writer.updateColor("strokeColor", color);
  81. _this.writer.updateColor("drawingColor", color);
  82. },
  83. },
  84. //生命周期 - 创建完成(可以访问当前this实例)
  85. created() {},
  86. //生命周期 - 挂载完成(可以访问DOM元素)
  87. mounted() {
  88. let _this = this;
  89. _this.$nextTick(() => {
  90. _this.initHanziwrite();
  91. });
  92. },
  93. beforeCreate() {}, //生命周期 - 创建之前
  94. beforeMount() {}, //生命周期 - 挂载之前
  95. beforeUpdate() {}, //生命周期 - 更新之前
  96. updated() {}, //生命周期 - 更新之后
  97. beforeDestroy() {}, //生命周期 - 销毁之前
  98. destroyed() {}, //生命周期 - 销毁完成
  99. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  100. };
  101. </script>
  102. <style lang='scss' scoped>
  103. //@import url(); 引入公共css类
  104. .strockredBox {
  105. width: 100%;
  106. height: 100%;
  107. }
  108. .strockred {
  109. position: relative;
  110. margin: 0 auto;
  111. width: 100%;
  112. height: 100%;
  113. //chinawrite220.png
  114. .character-target-div {
  115. width: 100%;
  116. height: 100%;
  117. background: url("../../assets/common/bg-field.png") center no-repeat;
  118. background-size: 100% 100%;
  119. border-radius: 24px;
  120. display: flex;
  121. justify-content: center;
  122. align-items: center;
  123. z-index: 99999;
  124. &_220 {
  125. background: url("../../assets/common/chinawrite220.png") center no-repeat;
  126. background-size: 100% 100%;
  127. border-radius: 0;
  128. }
  129. }
  130. .animate-butto {
  131. width: 240px;
  132. height: 160px;
  133. font-size: 28px;
  134. }
  135. }
  136. .questionMiddle {
  137. .strockred {
  138. .character-target-div {
  139. background: url("../../assets/common/bg-field.png") center no-repeat;
  140. background-size: 100% 100%;
  141. border-radius: 16px;
  142. &_220 {
  143. background: url("../../assets/common/chinawrite220.png") center
  144. no-repeat;
  145. background-size: 100% 100%;
  146. border-radius: 0;
  147. }
  148. }
  149. .animate-butto {
  150. width: 160px;
  151. height: 106px;
  152. font-size: 18px;
  153. }
  154. }
  155. }
  156. .questionSmall {
  157. .strockred {
  158. .character-target-div {
  159. background: url("../../assets/common/bg-field.png") center no-repeat;
  160. background-size: 100% 100%;
  161. border-radius: 12px;
  162. &_220 {
  163. background: url("../../assets/common/chinawrite220.png") center
  164. no-repeat;
  165. background-size: 100% 100%;
  166. border-radius: 0;
  167. }
  168. }
  169. .animate-butto {
  170. width: 120px;
  171. height: 80px;
  172. font-size: 14px;
  173. }
  174. }
  175. }
  176. </style>