Преглед на файлове

北京蜂行动手势密码

wangkang3 преди 6 години
родител
ревизия
271537b80e

+ 27 - 1
static-res/bj-skymarketing/biz/css/base.css

@ -676,4 +676,30 @@
676 676
}
677 677
.user-help-link p{
678 678
  margin-left: 40%;
679
}
679
}
680
681
/*手势密码*/
682
.gesture-msg {
683
  padding: 0rem .1rem .2rem;
684
  text-align: center;
685
  font-size: .15rem;;
686
}
687
.gesture-info {
688
  margin: 0 auto;
689
  top: 40%;
690
  left: 50%;
691
  position: absolute;
692
  transform: translate(-50%, -50%);
693
  -webkit-transform: translate(-50%, -50%);
694
}
695
.pass-footer{
696
  text-align: center;
697
  height: .3rem;
698
  color: #0F76FD;
699
}
700
.gesture-error-msg{
701
  padding: 0rem .1rem .2rem;
702
  text-align: center;
703
  color: #F04134;
704
  font-size: .14rem;;
705
}

+ 36 - 0
static-res/bj-skymarketing/biz/js/gp.js

@ -0,0 +1,36 @@
1
require(['jquery', 'gp'], function ($) {
2
    var winWidth = $(window).width()*.9;
3
    if(winWidth == 0){
4
        winWidth = 320*.9;
5
    }
6
    var winHeight = winWidth;
7
8
9
10
    $("#gesturepwd").GesturePasswd({
11
        backgroundColor:"transparent",  //背景色
12
        color:"#008bcc",   //主要的控件颜色
13
        roundRadii:winWidth*.1,    //大圆点的半径
14
        pointRadii:winWidth*.03, //大圆点被选中时显示的圆心的半径
15
        space:winWidth*.133,  //大圆点之间的间隙
16
        width:winWidth,   //整个组件的宽度
17
        height:winHeight,  //整个组件的高度
18
        lineColor:"#008bcc",   //用户划出线条的颜色
19
        zindex :100  //整个组件的css z-index属性
20
    });
21
22
    $("#gesturepwd").bind("hasPasswd",function(e,passwd){
23
        if(passwd == "1234"){
24
            $("#gesturepwd").trigger("passwdDIY", ["#008bcc"]); // 可自己传颜色
25
        } else if(passwd != "1235789"){
26
            //显示一下错误的手势线(红色的,只显示一秒)
27
            $("#gesturepwd").trigger("passwdWrong");
28
            alert("手势锁密码错误,解锁手势为:Z ");
29
        } else {
30
            //显示一下正确的手势线(绿色的,只显示一秒)
31
            $("#gesturepwd").trigger("passwdRight");
32
            window.location.href="index.html";
33
        }
34
    });
35
36
});

+ 2 - 1
static-res/bj-skymarketing/biz/js/require-config.js

@ -8,7 +8,8 @@ require.config({
8 8
        'ipuUI':'../ipu/ui/js/ipuUI',
9 9
10 10
        'dragsort': '../biz/lib/dragsort/jquery.dragsort-0.5.2',
11
        'commonUtil': '../biz/js/common/commonUtil'
11
        'commonUtil': '../biz/js/common/commonUtil',
12
      'gp': '../biz//lib/gesture/gesture.password'
12 13
    },
13 14
    shim:{
14 15
        'dragsort': { deps: ['jquery'] }

+ 274 - 0
static-res/bj-skymarketing/biz/lib/gesture/gesture.password.js

@ -0,0 +1,274 @@
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
        $(this.id).on('passwdDIY',{that:that}, function(e, color) {
220
            that.$ctx.clearRect(0,0,that.options.width,that.options.height);
221
            that.$ctx.beginPath();
222
            that.$ctx.putImageData(that.initImg,0,0);
223
            that.allDraw(color || that.options.lineColor);
224
            that.result="";
225
            that.pList=[];
226
            that.sList=[];
227
            setTimeout(function(){
228
                that.$ctx.clearRect(0,0,that.options.width,that.options.height);
229
                that.$ctx.beginPath();
230
                that.initDraw()
231
            },500)
232
        });
233
234
235
    };
236
237
238
    GesturePasswd.DEFAULTS = {
239
        zindex :100,
240
        roundRadii:25,
241
        pointRadii:6,
242
        space:30,
243
        width:240,
244
        height:240,
245
        lineColor:"#00aec7",
246
        backgroundColor:"#252736",
247
        color:"#FFFFFF"
248
    };
249
250
251
252
253
254
255
256
257
    function Plugin(option,arg) {
258
        return this.each(function () {
259
            var $this   = $(this);
260
            var options = $.extend({}, GesturePasswd.DEFAULTS, typeof option == 'object' && option);
261
            var data    = $this.data('GesturePasswd');
262
            var action  = typeof option == 'string' ? option : NaN;
263
            if (!data) $this.data('danmu', (data = new GesturePasswd(this, options)));
264
            if (action)	data[action](arg);
265
        })
266
    }
267
268
269
    $.fn.GesturePasswd             = Plugin;
270
    $.fn.GesturePasswd.Constructor = GesturePasswd;
271
272
273
274
});

+ 47 - 0
static-res/bj-skymarketing/gesture-pass.html

@ -0,0 +1,47 @@
1
<!doctype html>
2
<html>
3
<head>
4
    <meta charset="utf-8">
5
    <title>手势密码</title>
6
7
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1"><!-- 宽度自动适配 -->
8
    <meta content="telephone=no" name="format-detection"/>
9
10
    <link rel="stylesheet" type="text/css" href="ipu/ui/css/ipuUI.css">
11
    <link rel="stylesheet" type="text/css" href="ipu/lib/mdi/css/mdi.css">
12
    <link rel="stylesheet" type="text/css" href="biz/css/base.css">
13
14
    <script src="ipu/lib/requirejs/require.min.js"></script>
15
    <script src="biz/js/require-config.js"></script>
16
    <script src="biz/js/gp.js"></script>
17
</head>
18
<body class="pages-gesture-pass">
19
<div class="ipu-flex-row ipu-flex-vertical">
20
    <div class="ipu-flex-col">
21
        <div class="pages-header">
22
            <header class="ipu-toolbar">
23
                <a class="ipu-fn-left link-back" href="javascript:history.back(-1);">
24
                    <i class="ipu-icon mdi mdi-chevron-left"></i>返回
25
                </a>
26
                <h1 class="ipu-toolbar-title">手势密码</h1>
27
            </header>
28
        </div>
29
    </div>
30
    <div class="ipu-flex-col ipu-flex-col-auto">
31
        <div class="gesture-info">
32
            <div class="gesture-msg">请设置手势密码,最少四位数字</div>
33
            <div class="gesture-error-msg">手势密码不正确,剩余尝试次数4次</div>
34
            <div id="gesturepwd"></div>
35
        </div>
36
37
    </div>
38
    <div class="ipu-flex-col">
39
        <div class="pass-footer">
40
            <a href="login.html">
41
                账号密码登录
42
            </a>
43
        </div>
44
    </div>
45
</div>
46
</body>
47
</html>