Ver Código Fonte

gesture password web

wangyj18 8 anos atrás
pai
commit
6cd90edf80

+ 2 - 0
display-server/src/main/resources/server-page.xml

@ -168,4 +168,6 @@
168 168
	<action name="OpenSourceComponent" template="template/webapp/more/opensource/OpenSourceComponent.html"></action>
169 169
	<!-- 签名 -->
170 170
	<action name="WriteName" template="template/webapp/more/opensource/WriteName.html"></action>
171
	<!-- web手势锁 -->
172
	<action name="GesturePassword" template="template/webapp/more/opensource/GesturePassword.html"></action>
171 173
</pages>

+ 36 - 0
display-server/src/main/webapp/biz/js/more/opensource/GesturePassword.js

@ -0,0 +1,36 @@
1
require(["domReady!","common","mobile","jquery","gesturePassword"], function(doc,Common,Mobile,jQuery,GesturePasswd) {
2
	
3
	jQuery("#gesturepwd").GesturePasswd({
4
	    backgroundColor:"#ffffff",  //背景色
5
	    color:"#d5d5d5",   //主要的控件颜色
6
	    roundRadii:24,    //大圆点的半径
7
	    pointRadii:7, //大圆点被选中时显示的圆心的半径
8
	    space:38,  //大圆点之间的间隙
9
	    width:260,   //整个组件的宽度
10
	    height:260,  //整个组件的高度
11
	    lineColor:"#9f9f9f",   //用户划出线条的颜色
12
	    zindex :100  //整个组件的css z-index属性
13
	});
14
	jQuery("#gesturepwd").bind("hasPasswd",function(e,passwd){
15
		console.log(passwd)
16
		
17
		if(passwd != "1235789"){
18
          	Mobile.tip("手势锁密码错误,解锁手势为:Z ");
19
          	//显示一下错误的手势线(红色的,只显示一秒)
20
          	jQuery("#gesturepwd").trigger("passwdWrong");
21
          	return;
22
      	} else {
23
      		Mobile.tip("解锁成功~~~~");
24
      		//显示一下正确的手势线(绿色的,只显示一秒)
25
      		jQuery("#gesturepwd").trigger("passwdRight");
26
      		return;
27
      	}
28
		
29
		
30
	});
31
	
32
	//取消鼠标移动拖动页面事件
33
	$("#gesturepwd").bind("touchmove",(function(){
34
	    window.event.preventDefault();
35
	}));
36
});

+ 259 - 0
display-server/src/main/webapp/res/js/base/gesture.password.js

@ -0,0 +1,259 @@
1
;
2
define(["jquery"],function($){
3

4

5
    var GesturePasswd= function (element, options) {
6
        this.$element	= $(element);
7
        this.options	= options;
8
        var that=this;
9
        this.pr=options.pointRadii;
10
        this.rr=options.roundRadii;
11
        this.o=options.space;
12
        this.color=options.color;
13
        //ȫ����ʽ
14
        this.$element.css({
15
            "position":"relation",
16
            "width":this.options.width,
17
            "height":this.options.height,
18
            "background-color":options.backgroundColor,
19
            "overflow":"hidden",
20
            "cursor":"default"
21
        });
22

23

24
        //ѡ�����淶
25
        if(! $(element).attr("id"))
26
            $(element).attr("id",(Math.random()*65535).toString());
27
        this.id="#"+$(element).attr("id");
28

29

30

31
        var Point = function (x,y){
32
            this.x  =x;this.y=y
33
        };
34

35
        this.result="";
36
        this.pList=[];
37
        this.sList=[];
38
        this.tP=new Point(0,0);
39

40

41
        this.$element.append('<canvas class="main-c" width="'+options.width+'" height="'+options.height+'" >');
42
        //this.$element.append('<canvas class="main-p" width="'+options.width+'" height="'+options.height+'" >');
43
        this.$c= $(this.id+" .main-c")[0];
44
        this.$ctx=this.$c.getContext('2d');
45

46

47

48

49
        this.initDraw=function(){
50
            this.$ctx.strokeStyle=this.color;
51
            this.$ctx.lineWidth=2;
52
            for(var j=0; j<3;j++ ){
53
                for(var i =0;i<3;i++){
54
                    this.$ctx.moveTo(this.o/2+this.rr*2+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr));
55
                    this.$ctx.arc(this.o/2+this.rr+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr),this.rr,0,2*Math.PI);
56
                    var tem=new Point(this.o/2+this.rr+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr));
57
                    if (that.pList.length < 9)
58
                        this.pList.push(tem);
59
                }
60
            }
61
            this.$ctx.stroke();
62
            this.initImg=this.$ctx.getImageData(0,0,this.options.width,this.options.height);
63
        };
64
        this.initDraw();
65
        //this.$ctx.stroke();
66
        this.isIn=function(x,y){
67

68
            for (var p in that.pList){
69
                //console.log(that.pList[p][x]);
70
                //  console.log(( Math.pow((x-that.pList[p][x]),2)+Math.pow((y-that.pList[p][y]),2)));
71
                if(( Math.pow((x-that.pList[p]["x"]),2)+Math.pow((y-that.pList[p]["y"]),2) ) < Math.pow(this.rr,2)){
72
                    return that.pList[p];
73
                }
74
            }
75
            return 0;
76
        };
77

78
        this.pointDraw =function(c){
79
            if (arguments.length>0){
80
                that.$ctx.strokeStyle=c;
81
                that.$ctx.fillStyle=c;
82
            }
83
            for (var p in that.sList){
84
                that.$ctx.moveTo(that.sList[p]["x"]+that.pr,that.sList[p]["y"]);
85
                that.$ctx.arc(that.sList[p]["x"],that.sList[p]["y"],that.pr,0,2*Math.PI);
86
                that.$ctx.fill();
87
            }
88
        };
89
        this.lineDraw=function (c){
90
            if (arguments.length>0){
91
                that.$ctx.strokeStyle=c;
92
                that.$ctx.fillStyle=c;
93
            }
94
            if(that.sList.length > 0){
95
                for( var p in that.sList){
96
                    if(p == 0){
97
                        //console.log(that.sList[p]["x"],that.sList[p]["y"]);
98
                        that.$ctx.moveTo(that.sList[p]["x"],that.sList[p]["y"]);
99
                        continue;
100
                    }
101
                    that.$ctx.lineTo(that.sList[p]["x"],that.sList[p]["y"]);
102
                    //console.log(that.sList[p]["x"],that.sList[p]["y"]);
103
                }
104

105
            }
106
        };
107

108
        this.allDraw =function(c){
109
            if (arguments.length>0){
110
                this.pointDraw(c);
111
                this.lineDraw(c);
112
                that.$ctx.stroke();
113
            }
114
            else {
115
                this.pointDraw();
116
                this.lineDraw();
117
            }
118

119
        };
120

121

122
        this.draw=function(x,y){
123
            that.$ctx.clearRect(0,0,that.options.width,that.options.height);
124
            that.$ctx.beginPath();
125
            //that.initDraw();
126
            that.$ctx.putImageData(this.initImg,0,0);
127
            that.$ctx.lineWidth=4;
128
            that.pointDraw(that.options.lineColor);
129
            that.lineDraw(that.options.lineColor);
130
            that.$ctx.lineTo(x,y);
131
            that.$ctx.stroke();
132
        };
133

134

135

136
        this.pointInList=function(poi,list){
137
            for (var p in list){
138
                if( poi["x"] == list[p]["x"] && poi["y"] == list[p]["y"]){
139
                    return ++p;
140
                }
141
            }
142
            return false;
143
        };
144

145
        this.touched=false;
146
        $(this.id).on ("mousedown touchstart",{that:that},function(e){
147
            e.data.that.touched=true;
148
        });
149
        $(this.id).on ("mouseup touchend",{that:that},function(e){
150
            e.data.that.touched=false;
151
            that.$ctx.clearRect(0,0,that.options.width,that.options.height);
152
            that.$ctx.beginPath();
153
            that.$ctx.putImageData(e.data.that.initImg,0,0);
154
            that.allDraw(that.options.lineColor);
155
            // that.$ctx.stroke();
156
            for(var p in that.sList){
157
                if(e.data.that.pointInList(that.sList[p], e.data.that.pList)){
158
                    e.data.that.result= e.data.that.result+(e.data.that.pointInList(that.sList[p], e.data.that.pList)).toString();
159
                }
160
            }
161
            $(element).trigger("hasPasswd",that.result);
162
        });
163

164
        //
165
        $(this.id).on('touchmove mousemove',{that:that}, function(e) {
166
            if(e.data.that.touched){
167
                var x= e.pageX || e.originalEvent.targetTouches[0].pageX ;
168
                var y = e.pageY || e.originalEvent.targetTouches[0].pageY;
169
                x=x-that.$element.offset().left;
170
                y=y-that.$element.offset().top;
171
                var p = e.data.that.isIn(x, y);
172
                //console.log(x)
173
                if(p != 0 ){
174
                    if ( !e.data.that.pointInList(p,e.data.that.sList)){
175
                        e.data.that.sList.push(p);
176
                    }
177
                }
178
               //console.log( e.data.that.sList);
179
                e.data.that.draw(x, y);
180
            }
181

182
        });
183

184

185

186
        $(this.id).on('passwdWrong',{that:that}, function(e) {
187
            that.$ctx.clearRect(0,0,that.options.width,that.options.height);
188
            that.$ctx.beginPath();
189
            that.$ctx.putImageData(that.initImg,0,0);
190
            that.allDraw("#cc1c21");
191
            that.result="";
192
            that.pList=[];
193
            that.sList=[];
194

195
            setTimeout(function(){
196
                that.$ctx.clearRect(0,0,that.options.width,that.options.height);
197
                that.$ctx.beginPath();
198
                that.initDraw()
199
            },500)
200

201
        });
202

203

204
        $(this.id).on('passwdRight',{that:that}, function(e) {
205
            that.$ctx.clearRect(0,0,that.options.width,that.options.height);
206
            that.$ctx.beginPath();
207
            that.$ctx.putImageData(that.initImg,0,0);
208
            that.allDraw("#00a254");
209
            that.result="";
210
            that.pList=[];
211
            that.sList=[];
212
            setTimeout(function(){
213
                that.$ctx.clearRect(0,0,that.options.width,that.options.height);
214
                that.$ctx.beginPath();
215
                that.initDraw()
216
            },500)
217
        });
218

219

220
    };
221

222

223
    GesturePasswd.DEFAULTS = {
224
        zindex :100,
225
        roundRadii:25,
226
        pointRadii:6,
227
        space:30,
228
        width:240,
229
        height:240,
230
        lineColor:"#00aec7",
231
        backgroundColor:"#252736",
232
        color:"#FFFFFF"
233
    };
234

235

236

237

238

239

240

241

242
    function Plugin(option,arg) {
243
        return this.each(function () {
244
            var $this   = $(this);
245
            var options = $.extend({}, GesturePasswd.DEFAULTS, typeof option == 'object' && option);
246
            var data    = $this.data('GesturePasswd');
247
            var action  = typeof option == 'string' ? option : NaN;
248
            if (!data) $this.data('danmu', (data = new GesturePasswd(this, options)));
249
            if (action)	data[action](arg);
250
        })
251
    }
252

253

254
    $.fn.GesturePasswd             = Plugin;
255
    $.fn.GesturePasswd.Constructor = GesturePasswd;
256

257

258

259
});

+ 2 - 1
display-server/src/main/webapp/res/js/require-config.js

@ -55,7 +55,8 @@ require.config({
55 55
		"echarts": 'http://echarts.baidu.com/build/dist',
56 56
		"icharts": 'base/chart/ichart/ichart.1.2.1.min',
57 57
		
58
		"fastclick":"base/fastclick/fastclick"
58
		"fastclick":"base/fastclick/fastclick",
59
		"gesturePassword":"base/gesture.password"
59 60
	},
60 61
	deps: [],
61 62
	callback: function(){

+ 43 - 0
display-server/src/main/webapp/template/webapp/more/opensource/GesturePassword.html

@ -0,0 +1,43 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
	<meta charset="utf-8" />
5
	<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
6
	<title>手势锁</title>
7
	{%>template/common/Head.html%}
8
	<script src="biz/js/more/opensource/GesturePassword.js"></script>
9
    <style type="text/css">
10
    .m_content {
11
        text-align: center;
12
    	background: #fff;
13
    }
14
    .user-avatar {
15
    	margin:10px auto;
16
    }
17
    .user-avatar img {
18
    	border-radius:50%;
19
    	width: 1rem;
20
    }
21
    </style>
22
</head>
23
<body>
24
<div class="c_navBar">
25
	<div class="left">
26
		<div class="back">
27
			<span class="e_ico-back"></span>
28
			<span class="text">手势锁</span>
29
		</div>
30
	</div>
31
</div>
32

33
<div class="m_content m_content-nofooter" id="content">
34
	<div class="user-avatar"><img src="biz/img/temp/female.png" /></div> 
35
	<div class="c_title">欢迎回来,绘制解锁图案:Z</div>
36
	<div id="gesturepwd" style="margin:0 auto"></div>
37
	<div class="e_space"></div>
38
</div>
39
</body>
40
<script type="text/javascript">
41

42
</script>
43
</html>

+ 1 - 1
display-server/src/main/webapp/template/webapp/more/opensource/OpenSourceComponent.html

@ -36,7 +36,7 @@
36 36
					</div>
37 37
				</div>
38 38
			</li>
39
			<li action="">
39
			<li action="GesturePassword">
40 40
				<div class="content">
41 41
					<div class="main">
42 42
						<div class="title">手势密码</div>