StrockplayredlineTable.vue 4.5 KB

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