组件:
<template>
<div class="masks" v-show="currentValue">
<div class="gesturePwd">
<div class="box">
<h4 ref="gestureTitle" class="gestureTitle">请绘制您的图形密码</h4>
<a class="reset" ref="updatePassword" @click="updatePassword()">重置密码</a>
<a class="close" ref="updatePassword" @click="closePwd(false)">关闭</a>
<canvas ref="canvas"></canvas>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
value: {
type: Boolean,
default: false
},
},
data() {
return {
currentValue: false,
ctx: '',
width: 0,
height: 0,
devicePixelRatio: 0,
chooseType: '',
r: '',// 公式计算
lastPoint: [],
arr: [],
restPoint: [],
pswObj: {step: 2},
canvas: ''
}
},
watch: {
value: {
handler: function (val) {
this.currentValue = val
},
immediate: true
},
currentValue(val) {
this.$emit(val ? 'on-show' : 'on-hide')
this.$emit('input', val)
}
},
created() {
if (typeof this.value !== 'undefined') {
this.currentValue = this.value
}
},
mounted() {
this.setChooseType(3);
},
methods: {
closePwd(bol) {
this.$emit("handPwd",bol);
this.currentValue = false;
},
drawCle(x, y) { // 初始化解锁密码面板 小圆圈
this.ctx.strokeStyle = '#87888a';//密码的点点默认的颜色
this.ctx.lineWidth = 2;
this.ctx.beginPath();
this.ctx.arc(x, y, this.r, 0, Math.PI * 2, true);
this.ctx.closePath();
this.ctx.stroke();
},
drawPoint(style) { // 初始化圆心
for (var i = 0; i < this.lastPoint.length; i++) {
this.ctx.fillStyle = style;
this.ctx.beginPath();
this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r / 2.5, 0, Math.PI * 2, true);
this.ctx.closePath();
this.ctx.fill();
}
},
drawStatusPoint(type) { // 初始化状态线条
for (var i = 0; i < this.lastPoint.length; i++) {
this.ctx.strokeStyle = type;
this.ctx.beginPath();
this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r,