Strockplayredline.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!-- -->
  2. <template>
  3. <div
  4. :class="['strockplayRedInner']"
  5. >
  6. <!-- <div
  7. @click="playHanzi"
  8. :class="[
  9. 'strock-play-box',
  10. themeColor == 'green'
  11. ? 'green-border'
  12. : themeColor == 'red'
  13. ? 'red-border'
  14. : themeColor == 'brown'
  15. ? 'brown-border'
  16. : 'blue-border',
  17. ]"
  18. v-if="playStorkes"
  19. ></div> -->
  20. <template v-if="Book_text != '〇'">
  21. <div :id="targetDivGray" class="character-target-div character-target-div-gray"></div>
  22. <div :id="targetDiv" class="character-target-div"></div>
  23. </template>
  24. <template v-else>
  25. <span class="book-text">{{ Book_text }}</span>
  26. </template>
  27. <svg-icon
  28. icon-class="tian"
  29. className="tian-bg"
  30. v-if="BoxbgType==0"
  31. :style="{color:'#DEDEDE'}"
  32. />
  33. <svg-icon
  34. icon-class="mi"
  35. className="tian-bg"
  36. v-if="BoxbgType==1"
  37. :style="{color:'#DEDEDE'}"
  38. />
  39. <!-- <svg-icon
  40. icon-class="tian"
  41. :className="tianColor ? 'tian-bg-red' : 'tian-bg'"
  42. /> -->
  43. </div>
  44. </template>
  45. <script>
  46. import { getContentFile } from "@/api/api";
  47. const HanziWriter = require("hanzi-writer");
  48. export default {
  49. name: "Strockplayredline",
  50. components: {},
  51. props: [
  52. "targetDiv",
  53. "Book_text",
  54. "playStorkes",
  55. "strokeColor",
  56. "strokeColorgray",
  57. "curItem",
  58. "strokeNumber",
  59. "targetDivGray",
  60. "BoxbgType"
  61. ],
  62. data() {
  63. return {
  64. writer: null,
  65. };
  66. },
  67. computed: {},
  68. watch: {
  69. targetDiv: {
  70. handler: function (val, oldVal) {
  71. if (val != oldVal) {
  72. let _this = this;
  73. _this.$nextTick(() => {
  74. _this.initHanziwrite();
  75. });
  76. }
  77. },
  78. // 深度观察监听
  79. deep: true,
  80. },
  81. },
  82. //方法集合
  83. methods: {
  84. initHanziwrite() {
  85. let _this = this;
  86. if (_this.Book_text == "〇") return false;
  87. _this.writer = null;
  88. //var ren = require("hanzi-writer-data/国");
  89. _this.writer = HanziWriter.default.create(
  90. _this.targetDiv,
  91. _this.Book_text,
  92. {
  93. padding: 5,
  94. showOutline: true,
  95. strokeColor: _this.strokeColor,
  96. charDataLoader: function (char, onComplete) {
  97. let charData = _this.handleData(_this.strokeNumber);
  98. onComplete(charData);
  99. },
  100. }
  101. );
  102. _this.writer = HanziWriter.default.create(
  103. _this.targetDivGray,
  104. _this.Book_text,
  105. {
  106. padding: 5,
  107. showOutline: true,
  108. strokeColor: _this.strokeColorgray,
  109. charDataLoader: function (char, onComplete) {
  110. onComplete(JSON.parse(JSON.stringify(_this.curItem)));
  111. },
  112. }
  113. );
  114. },
  115. handleData(stroke_num) {
  116. if (this.curItem) {
  117. let charData = JSON.parse(JSON.stringify(this.curItem));
  118. if (stroke_num) {
  119. let stroke_arr = [];
  120. for(let i = 0; i<stroke_num;i++){
  121. stroke_arr.push(i+1)
  122. }
  123. stroke_arr = stroke_arr.map((item) => (item = Number(item) - 1));
  124. let strokes = [],
  125. medians = [];
  126. for (let i = 0; i < stroke_arr.length; i++) {
  127. let stroke_num = stroke_arr[i];
  128. strokes.push(charData.strokes[stroke_num]);
  129. medians.push(charData.medians[stroke_num]);
  130. }
  131. charData.strokes = strokes;
  132. charData.medians = medians;
  133. } else if (charData) {
  134. charData.radStrokes = [];
  135. }
  136. return charData;
  137. }
  138. },
  139. playHanzi(event) {
  140. let _this = this;
  141. _this.writer.animateCharacter();
  142. event.stopPropagation();
  143. },
  144. },
  145. //生命周期 - 创建完成(可以访问当前this实例)
  146. created() {},
  147. //生命周期 - 挂载完成(可以访问DOM元素)
  148. mounted() {
  149. let _this = this;
  150. _this.$nextTick(() => {
  151. _this.initHanziwrite();
  152. });
  153. },
  154. beforeCreate() {}, //生命周期 - 创建之前
  155. beforeMount() {}, //生命周期 - 挂载之前
  156. beforeUpdate() {}, //生命周期 - 更新之前
  157. updated() {}, //生命周期 - 更新之后
  158. beforeDestroy() {}, //生命周期 - 销毁之前
  159. destroyed() {}, //生命周期 - 销毁完成
  160. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  161. };
  162. </script>
  163. <style lang='scss' scoped>
  164. //@import url(); 引入公共css类
  165. // @import "../common.scss";
  166. .strockplayRedInner {
  167. position: relative;
  168. width: 100%; //444px
  169. height: 100%; //480px
  170. }
  171. .character-target-div {
  172. width: 100%;
  173. height: 100%;
  174. z-index: 99999;
  175. position: absolute;
  176. }
  177. .character-target-div-gray{
  178. top: 0;
  179. left: 0;
  180. }
  181. .tian-bg {
  182. width: 100%;
  183. height: 100%;
  184. position: absolute;
  185. left: 0;
  186. top: 0;
  187. }
  188. .animate-butto {
  189. width: 240px;
  190. height: 160px;
  191. font-size: 28px;
  192. }
  193. .book-text {
  194. font-size: 96px;
  195. display: block;
  196. width: 100%;
  197. height: 100%;
  198. text-align: center;
  199. line-height: 128px;
  200. }
  201. </style>