|  | @@ -0,0 +1,169 @@
 | 
	
		
			
				|  |  | +<!--  -->
 | 
	
		
			
				|  |  | +<template>
 | 
	
		
			
				|  |  | +  <div class="strockredBox">
 | 
	
		
			
				|  |  | +    <div class="strockred">
 | 
	
		
			
				|  |  | +      <div class="character-target-box">
 | 
	
		
			
				|  |  | +        <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
 | 
	
		
			
				|  |  | +        <div :id="targetDiv" class="character-target-div"></div>
 | 
	
		
			
				|  |  | +      </div>
 | 
	
		
			
				|  |  | +      <div v-if="reset" :class="['reset-box']" @click="resetHanzi">
 | 
	
		
			
				|  |  | +        <SvgIcon icon-class="reset" class="reset-btn" />
 | 
	
		
			
				|  |  | +      </div>
 | 
	
		
			
				|  |  | +    </div>
 | 
	
		
			
				|  |  | +  </div>
 | 
	
		
			
				|  |  | +</template>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +<script>
 | 
	
		
			
				|  |  | +const HanziWriter = require('hanzi-writer');
 | 
	
		
			
				|  |  | +export default {
 | 
	
		
			
				|  |  | +  name: 'Strockred',
 | 
	
		
			
				|  |  | +  components: {},
 | 
	
		
			
				|  |  | +  props: {
 | 
	
		
			
				|  |  | +    bookText: {
 | 
	
		
			
				|  |  | +      type: String,
 | 
	
		
			
				|  |  | +      default: '',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    targetDiv: {
 | 
	
		
			
				|  |  | +      type: String,
 | 
	
		
			
				|  |  | +      default: '',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    reset: {
 | 
	
		
			
				|  |  | +      type: Boolean,
 | 
	
		
			
				|  |  | +      default: true,
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    hanziColor: {
 | 
	
		
			
				|  |  | +      type: String,
 | 
	
		
			
				|  |  | +      default: '',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    bookStrokes: {
 | 
	
		
			
				|  |  | +      type: Object,
 | 
	
		
			
				|  |  | +      default: () => {},
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  data() {
 | 
	
		
			
				|  |  | +    return {
 | 
	
		
			
				|  |  | +      writer: null,
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  computed: {},
 | 
	
		
			
				|  |  | +  watch: {
 | 
	
		
			
				|  |  | +    hanziColor(newVal, oldVal) {
 | 
	
		
			
				|  |  | +      this.updateColor(newVal);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    Book_text: {
 | 
	
		
			
				|  |  | +      handler(val, oldVal) {
 | 
	
		
			
				|  |  | +        if (val !== oldVal) {
 | 
	
		
			
				|  |  | +          let _this = this;
 | 
	
		
			
				|  |  | +          _this.$nextTick(() => {
 | 
	
		
			
				|  |  | +            _this.initHanziwrite();
 | 
	
		
			
				|  |  | +          });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +      // 深度观察监听
 | 
	
		
			
				|  |  | +      deep: true,
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  // 生命周期 - 创建完成(可以访问当前this实例)
 | 
	
		
			
				|  |  | +  created() {},
 | 
	
		
			
				|  |  | +  // 生命周期 - 挂载完成(可以访问DOM元素)
 | 
	
		
			
				|  |  | +  mounted() {
 | 
	
		
			
				|  |  | +    let _this = this;
 | 
	
		
			
				|  |  | +    _this.$nextTick(() => {
 | 
	
		
			
				|  |  | +      _this.initHanziwrite();
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  beforeCreate() {}, // 生命周期 - 创建之前
 | 
	
		
			
				|  |  | +  beforeMount() {}, // 生命周期 - 挂载之前
 | 
	
		
			
				|  |  | +  beforeUpdate() {}, // 生命周期 - 更新之前
 | 
	
		
			
				|  |  | +  updated() {}, // 生命周期 - 更新之后
 | 
	
		
			
				|  |  | +  beforeDestroy() {}, // 生命周期 - 销毁之前
 | 
	
		
			
				|  |  | +  destroyed() {}, // 生命周期 - 销毁完成
 | 
	
		
			
				|  |  | +  activated() {},
 | 
	
		
			
				|  |  | +  // 方法集合
 | 
	
		
			
				|  |  | +  methods: {
 | 
	
		
			
				|  |  | +    initHanziwrite() {
 | 
	
		
			
				|  |  | +      let _this = this;
 | 
	
		
			
				|  |  | +      let options = {
 | 
	
		
			
				|  |  | +        charDataLoader(char, onComplete) {
 | 
	
		
			
				|  |  | +          onComplete(_this.bookStrokes);
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        padding: 5,
 | 
	
		
			
				|  |  | +        showCharacter: false,
 | 
	
		
			
				|  |  | +        strokeColor: _this.hanziColor,
 | 
	
		
			
				|  |  | +        drawingColor: _this.hanziColor,
 | 
	
		
			
				|  |  | +        drawingWidth: 6,
 | 
	
		
			
				|  |  | +      };
 | 
	
		
			
				|  |  | +      _this.writer = HanziWriter.default.create(_this.targetDiv, _this.Book_text, options);
 | 
	
		
			
				|  |  | +      _this.writer.quiz();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    resetHanzi() {
 | 
	
		
			
				|  |  | +      let _this = this;
 | 
	
		
			
				|  |  | +      _this.writer.quiz();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    updateColor(color) {
 | 
	
		
			
				|  |  | +      let _this = this;
 | 
	
		
			
				|  |  | +      _this.writer.updateColor('strokeColor', color);
 | 
	
		
			
				|  |  | +      _this.writer.updateColor('drawingColor', color);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  }, // 如果页面有keep-alive缓存功能,这个函数会触发
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +</script>
 | 
	
		
			
				|  |  | +<style lang="scss" scoped>
 | 
	
		
			
				|  |  | +//@import url(); 引入公共css类
 | 
	
		
			
				|  |  | +.strockredBox {
 | 
	
		
			
				|  |  | +  width: 64px; //444px
 | 
	
		
			
				|  |  | +  height: 64px; //480px
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +.strockred {
 | 
	
		
			
				|  |  | +  position: relative;
 | 
	
		
			
				|  |  | +  width: 100%;
 | 
	
		
			
				|  |  | +  height: 100%;
 | 
	
		
			
				|  |  | +  margin: 0 auto;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  .character-target-div {
 | 
	
		
			
				|  |  | +    position: absolute;
 | 
	
		
			
				|  |  | +    top: 0;
 | 
	
		
			
				|  |  | +    left: 0;
 | 
	
		
			
				|  |  | +    z-index: 99;
 | 
	
		
			
				|  |  | +    display: flex;
 | 
	
		
			
				|  |  | +    align-items: center;
 | 
	
		
			
				|  |  | +    justify-content: center;
 | 
	
		
			
				|  |  | +    width: 100%;
 | 
	
		
			
				|  |  | +    height: 100%;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  .character-target-box {
 | 
	
		
			
				|  |  | +    position: relative;
 | 
	
		
			
				|  |  | +    width: 100%;
 | 
	
		
			
				|  |  | +    height: 100%;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  .character-target-bg {
 | 
	
		
			
				|  |  | +    position: absolute;
 | 
	
		
			
				|  |  | +    top: 0;
 | 
	
		
			
				|  |  | +    left: 0;
 | 
	
		
			
				|  |  | +    width: 100%;
 | 
	
		
			
				|  |  | +    height: 100%;
 | 
	
		
			
				|  |  | +    color: #dedede;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  .reset-box {
 | 
	
		
			
				|  |  | +    position: absolute;
 | 
	
		
			
				|  |  | +    right: 2px;
 | 
	
		
			
				|  |  | +    bottom: 2px;
 | 
	
		
			
				|  |  | +    z-index: 100;
 | 
	
		
			
				|  |  | +    display: flex;
 | 
	
		
			
				|  |  | +    align-items: center;
 | 
	
		
			
				|  |  | +    justify-content: center;
 | 
	
		
			
				|  |  | +    width: 11px;
 | 
	
		
			
				|  |  | +    height: 11px;
 | 
	
		
			
				|  |  | +    color: $text-color;
 | 
	
		
			
				|  |  | +    cursor: pointer;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    &:hover {
 | 
	
		
			
				|  |  | +      color: #000;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +</style>
 |