StrockplayredlineTable.vue 5.2 KB

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