Pārlūkot izejas kodu

增加抽奖页面

xiehui 3 gadi atpakaļ
vecāks
revīzija
268797175d

+ 1 - 1
spring-wechars/src/main/java/cn/org/spring/wechar/config/WebConfig.java

@@ -29,7 +29,7 @@ public class WebConfig implements WebMvcConfigurer {
         InterceptorRegistration registration = registry.addInterceptor(loginUserInterceptor);
         System.out.println("loginUserInterceptor:" + loginUserInterceptor);
         registration.addPathPatterns("/**");
-        registration.excludePathPatterns("/**/weChar","/**/weChar/getCode","/**/index","/**/login");
+        registration.excludePathPatterns("/**/weChar","/**/weChar/getCode","/**/index","/**/login","/static/**");
     }
 
 

+ 1 - 1
spring-wechars/src/main/resources/application.yml

@@ -30,7 +30,7 @@ spring:
     password: 123456
     # 连接超时时间
     timeout: 10s
-    lettuce:
+    jedis:
       pool:
         # 连接池中的最小空闲连接
         min-idle: 0

BIN
spring-wechars/src/main/resources/static/images/background.png


BIN
spring-wechars/src/main/resources/static/images/button.png


BIN
spring-wechars/src/main/resources/static/images/turntable.png


+ 313 - 0
spring-wechars/src/main/resources/static/js/jQueryRotate.js

@@ -0,0 +1,313 @@
+// VERSION: 2.2 LAST UPDATE: 13.03.2012
+/* 
+ * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+ * 
+ * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
+ * Website: http://code.google.com/p/jqueryrotate/ 
+ */
+
+// Documentation removed from script file (was kinda useless and outdated)
+
+(function($) {
+var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" ");
+for (var a=0;a<toCheck.length;a++) if (styles[toCheck[a]] !== undefined) supportedCSS = toCheck[a];
+// Bad eval to preven google closure to remove it from code o_O
+// After compresion replace it back to var IE = 'v' == '\v'
+var IE = eval('"v"=="\v"');
+
+jQuery.fn.extend({
+    rotate:function(parameters)
+    {
+        if (this.length===0||typeof parameters=="undefined") return;
+            if (typeof parameters=="number") parameters={angle:parameters};
+        var returned=[];
+        for (var i=0,i0=this.length;i<i0;i++)
+            {
+                var element=this.get(i);	
+                if (!element.Wilq32 || !element.Wilq32.PhotoEffect) {
+
+                    var paramClone = $.extend(true, {}, parameters); 
+                    var newRotObject = new Wilq32.PhotoEffect(element,paramClone)._rootObj;
+
+                    returned.push($(newRotObject));
+                }
+                else {
+                    element.Wilq32.PhotoEffect._handleRotation(parameters);
+                }
+            }
+            return returned;
+    },
+    getRotateAngle: function(){
+        var ret = [];
+        for (var i=0,i0=this.length;i<i0;i++)
+            {
+                var element=this.get(i);	
+                if (element.Wilq32 && element.Wilq32.PhotoEffect) {
+                    ret[i] = element.Wilq32.PhotoEffect._angle;
+                }
+            }
+            return ret;
+    },
+    stopRotate: function(){
+        for (var i=0,i0=this.length;i<i0;i++)
+            {
+                var element=this.get(i);	
+                if (element.Wilq32 && element.Wilq32.PhotoEffect) {
+                    clearTimeout(element.Wilq32.PhotoEffect._timer);
+                }
+            }
+    }
+});
+
+// Library agnostic interface
+
+Wilq32=window.Wilq32||{};
+Wilq32.PhotoEffect=(function(){
+
+	if (supportedCSS) {
+		return function(img,parameters){
+			img.Wilq32 = {
+				PhotoEffect: this
+			};
+            
+            this._img = this._rootObj = this._eventObj = img;
+            this._handleRotation(parameters);
+		}
+	} else {
+		return function(img,parameters) {
+			// Make sure that class and id are also copied - just in case you would like to refeer to an newly created object
+            this._img = img;
+
+			this._rootObj=document.createElement('span');
+			this._rootObj.style.display="inline-block";
+			this._rootObj.Wilq32 = 
+				{
+					PhotoEffect: this
+				};
+			img.parentNode.insertBefore(this._rootObj,img);
+			
+			if (img.complete) {
+				this._Loader(parameters);
+			} else {
+				var self=this;
+				// TODO: Remove jQuery dependency
+				jQuery(this._img).bind("load", function()
+				{
+					self._Loader(parameters);
+				});
+			}
+		}
+	}
+})();
+
+Wilq32.PhotoEffect.prototype={
+    _setupParameters : function (parameters){
+		this._parameters = this._parameters || {};
+        if (typeof this._angle !== "number") this._angle = 0 ;
+        if (typeof parameters.angle==="number") this._angle = parameters.angle;
+        this._parameters.animateTo = (typeof parameters.animateTo==="number") ? (parameters.animateTo) : (this._angle); 
+
+        this._parameters.step = parameters.step || this._parameters.step || null;
+		this._parameters.easing = parameters.easing || this._parameters.easing || function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }
+		this._parameters.duration = parameters.duration || this._parameters.duration || 1000;
+        this._parameters.callback = parameters.callback || this._parameters.callback || function(){};
+        if (parameters.bind && parameters.bind != this._parameters.bind) this._BindEvents(parameters.bind); 
+	},
+	_handleRotation : function(parameters){
+          this._setupParameters(parameters);
+          if (this._angle==this._parameters.animateTo) {
+              this._rotate(this._angle);
+          }
+          else { 
+              this._animateStart();          
+          }
+	},
+
+	_BindEvents:function(events){
+		if (events && this._eventObj) 
+		{
+            // Unbinding previous Events
+            if (this._parameters.bind){
+                var oldEvents = this._parameters.bind;
+                for (var a in oldEvents) if (oldEvents.hasOwnProperty(a)) 
+                        // TODO: Remove jQuery dependency
+                        jQuery(this._eventObj).unbind(a,oldEvents[a]);
+            }
+
+            this._parameters.bind = events;
+			for (var a in events) if (events.hasOwnProperty(a)) 
+				// TODO: Remove jQuery dependency
+					jQuery(this._eventObj).bind(a,events[a]);
+		}
+	},
+
+	_Loader:(function()
+	{
+		if (IE)
+		return function(parameters)
+		{
+			var width=this._img.width;
+			var height=this._img.height;
+			this._img.parentNode.removeChild(this._img);
+							
+			this._vimage = this.createVMLNode('image');
+			this._vimage.src=this._img.src;
+			this._vimage.style.height=height+"px";
+			this._vimage.style.width=width+"px";
+			this._vimage.style.position="absolute"; // FIXES IE PROBLEM - its only rendered if its on absolute position!
+			this._vimage.style.top = "0px";
+			this._vimage.style.left = "0px";
+
+			/* Group minifying a small 1px precision problem when rotating object */
+			this._container =  this.createVMLNode('group');
+			this._container.style.width=width;
+			this._container.style.height=height;
+			this._container.style.position="absolute";
+			this._container.setAttribute('coordsize',width-1+','+(height-1)); // This -1, -1 trying to fix ugly problem with small displacement on IE
+			this._container.appendChild(this._vimage);
+			
+			this._rootObj.appendChild(this._container);
+			this._rootObj.style.position="relative"; // FIXES IE PROBLEM
+			this._rootObj.style.width=width+"px";
+			this._rootObj.style.height=height+"px";
+			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
+			this._rootObj.className=this._img.className;			
+		    this._eventObj = this._rootObj;	
+		    this._handleRotation(parameters);	
+		}
+		else
+		return function (parameters)
+		{
+			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
+			this._rootObj.className=this._img.className;
+			
+			this._width=this._img.width;
+			this._height=this._img.height;
+			this._widthHalf=this._width/2; // used for optimisation
+			this._heightHalf=this._height/2;// used for optimisation
+			
+			var _widthMax=Math.sqrt((this._height)*(this._height) + (this._width) * (this._width));
+
+			this._widthAdd = _widthMax - this._width;
+			this._heightAdd = _widthMax - this._height;	// widthMax because maxWidth=maxHeight
+			this._widthAddHalf=this._widthAdd/2; // used for optimisation
+			this._heightAddHalf=this._heightAdd/2;// used for optimisation
+			
+			this._img.parentNode.removeChild(this._img);	
+			
+			this._aspectW = ((parseInt(this._img.style.width,10)) || this._width)/this._img.width;
+			this._aspectH = ((parseInt(this._img.style.height,10)) || this._height)/this._img.height;
+			
+			this._canvas=document.createElement('canvas');
+			this._canvas.setAttribute('width',this._width);
+			this._canvas.style.position="relative";
+			this._canvas.style.left = -this._widthAddHalf + "px";
+			this._canvas.style.top = -this._heightAddHalf + "px";
+			this._canvas.Wilq32 = this._rootObj.Wilq32;
+			
+			this._rootObj.appendChild(this._canvas);
+			this._rootObj.style.width=this._width+"px";
+			this._rootObj.style.height=this._height+"px";
+            this._eventObj = this._canvas;
+			
+			this._cnv=this._canvas.getContext('2d');
+            this._handleRotation(parameters);
+		}
+	})(),
+
+	_animateStart:function()
+	{	
+		if (this._timer) {
+			clearTimeout(this._timer);
+		}
+		this._animateStartTime = +new Date;
+		this._animateStartAngle = this._angle;
+		this._animate();
+	},
+    _animate:function()
+    {
+         var actualTime = +new Date;
+         var checkEnd = actualTime - this._animateStartTime > this._parameters.duration;
+
+         // TODO: Bug for animatedGif for static rotation ? (to test)
+         if (checkEnd && !this._parameters.animatedGif) 
+         {
+             clearTimeout(this._timer);
+         }
+         else 
+         {
+             if (this._canvas||this._vimage||this._img) {
+                 var angle = this._parameters.easing(0, actualTime - this._animateStartTime, this._animateStartAngle, this._parameters.animateTo - this._animateStartAngle, this._parameters.duration);
+                 this._rotate((~~(angle*10))/10);
+             }
+             if (this._parameters.step) {
+                this._parameters.step(this._angle);
+             }
+             var self = this;
+             this._timer = setTimeout(function()
+                     {
+                     self._animate.call(self);
+                     }, 10);
+         }
+
+         // To fix Bug that prevents using recursive function in callback I moved this function to back
+         if (this._parameters.callback && checkEnd){
+             this._angle = this._parameters.animateTo;
+             this._rotate(this._angle);
+             this._parameters.callback.call(this._rootObj);
+         }
+     },
+
+	_rotate : (function()
+	{
+		var rad = Math.PI/180;
+		if (IE)
+		return function(angle)
+		{
+            this._angle = angle;
+			this._container.style.rotation=(angle%360)+"deg";
+		}
+		else if (supportedCSS)
+		return function(angle){
+            this._angle = angle;
+			this._img.style[supportedCSS]="rotate("+(angle%360)+"deg)";
+		}
+		else 
+		return function(angle)
+		{
+            this._angle = angle;
+			angle=(angle%360)* rad;
+			// clear canvas	
+			this._canvas.width = this._width+this._widthAdd;
+			this._canvas.height = this._height+this._heightAdd;
+						
+			// REMEMBER: all drawings are read from backwards.. so first function is translate, then rotate, then translate, translate..
+			this._cnv.translate(this._widthAddHalf,this._heightAddHalf);	// at least center image on screen
+			this._cnv.translate(this._widthHalf,this._heightHalf);			// we move image back to its orginal 
+			this._cnv.rotate(angle);										// rotate image
+			this._cnv.translate(-this._widthHalf,-this._heightHalf);		// move image to its center, so we can rotate around its center
+			this._cnv.scale(this._aspectW,this._aspectH); // SCALE - if needed ;)
+			this._cnv.drawImage(this._img, 0, 0);							// First - we draw image
+		}
+
+	})()
+}
+
+if (IE)
+{
+Wilq32.PhotoEffect.prototype.createVMLNode=(function(){
+document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
+		try {
+			!document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
+			return function (tagName) {
+				return document.createElement('<rvml:' + tagName + ' class="rvml">');
+			};
+		} catch (e) {
+			return function (tagName) {
+				return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
+			};
+		}		
+})();
+}
+
+})(jQuery);

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 5 - 0
spring-wechars/src/main/resources/static/js/jquery-1.11.3.min.js


+ 219 - 31
spring-wechars/src/main/resources/templates/index.html

@@ -1,63 +1,251 @@
+
+<!--<div class="head" th:if="${user != null }">-->
+    <!--<img th:src="@{${user.headimgurl}}"/>-->
+    <!--<p>[[${user.nickname}]]</p>-->
+<!--</div>-->
+
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org">
-
 <head>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
     <meta name="viewport"
           content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=no"
           charset="UTF-8"/>
-    <title></title>
+    <title>话费抽奖</title>
     <style type="text/css">
+
         * {
             padding: 0;
             margin: 0;
         }
-
         a {
             text-decoration: none
         }
-
         body {
             background-color: #EE9611;
             position: relative;
         }
-
-        .head {
-            width: 95%;
-            height: 40px;
-            /*border: 1px solid white;*/
-            margin-top: 2%;
-            margin-left: 50%;
-            transform: translateX(-50%);
+        .main{
+            position:relative;
+            height: 100vh;
+            width: 100%;
+        }
+        .lottery_bg{
+            position:absolute;
+            height: 100%;
+        }
+        .lottery_tba{
+            position:absolute;
+            width: 80%;
+            margin: 0 10%;
+            top: 30%
+        }
+        .lottery_btn{
+            position:absolute;
+            width: 30%;
+            margin: 0 35%;
+            top: 40%
+        }
+        .tanchuang {
+            width: 100%;
+            height: 100%;
+            display: none;
+            position: fixed;
+            top: 0;
+            left: 0;
+            background-color: rgba(0, 0, 0, .5);
+            z-index: 9999;
+        }
+        .model{
+            width: 80%;
+            height: 246px;
+            margin: 50% 10%;
             border-radius: 10px;
-            color: white;
-            font-weight: 600;
-            font-family: "microsoft yahei";
-            display: flex;
-            justify-content: flex-start;
-            align-items: center;
+            background:-moz-linear-gradient(left,rgba(255,47,88,1),rgba(243,102,74,1));
+            background:-ms-linear-gradient(left,rgba(255,47,88,1),rgba(243,102,74,1));
+            background:-o-linear-gradient(left,rgba(255,47,88,1),rgba(243,102,74,1));
+            background:-webkit-linear-gradient(left,rgba(255,47,88,1),rgba(243,102,74,1));
         }
-
-        .head > img {
-            width: 40px;
-            height: 40px;
-            display: inline-block;
-            border-radius: 50%;
+        .model>#title{
+            text-align: center;
+            color: #ffedc9;
+            font-weight: 400;
+            line-height: 70px;
+            font-size: 20px;
+            letter-spacing: 2px;
         }
+        .model>.message{
+            width: 85%;
+            height: 100px;
+            border: 4px solid #f74a44;
+            border-radius: 10px;
+            margin: 0 7%;
+            background-color: #ffedc9;
+        }
+        .message>.leftMessage{
+            width: 40%;
+            float: left;
+            line-height: 100px;
+            color: #f23737;
+            text-align: center;
+        }
+        .leftMessage>b{
+            font-size: 50px;
+        }
+        .message>.rightMessage{
+            width: 59%;
+            float: left;
+            color: #f23737;
+        }
+        .rightMessage>p{
+            font-size: 16px;
+            margin-top: 35px;
+        }
+        .rightMessage>span{
+            font-size: 12px;
+            -webkit-transform: scale(0.8,0.8);
+            -moz-transform: scale(0.8,0.8);
+            -o-transform: scale(0.8,0.8);
+            transform: scale(0.8,0.8);
+            display:block;
+            margin-left: -16px;
+        }
+        #money, #remark, #notice{
+            font-family: "Microsoft YaHei","微软雅黑","Microsoft JhengHei","华文细黑","STHeiti","MingLiu";
+        }
+        .model>button{
+            width: 87%;
+            height: 35px;
+            border: 4px solid #fece36;
+            border-radius: 5px;
+            margin: 10px 7%;
+            background-color: #fece36;
+            color: #e25f2e;
 
-        .head > p {
-            margin-left: 20px;
         }
     </style>
 </head>
+<body class="main">
+<img src="/static/images/background.png" class="lottery_bg"/>
+<img src="/static/images/turntable.png" class="lottery_tba"/>
+<img id="tupBtn" src="/static/images/button.png" class="lottery_btn"/>
 
-<body>
-<div class="head" th:if="${user != null }">
-    <img th:src="@{${user.headimgurl}}"/>
-    <p>[[${user.nickname}]]</p>
+
+<div class="tanchuang" id="bulletFrame">
+    <div class="model">
+        <h2 id="title">恭喜您获得!</h2>
+        <div class="message">
+            <div class="leftMessage">
+                ¥<b id="money">4</b>
+            </div>
+            <div class="rightMessage">
+                <p id="remark">话费券</p>
+                <span id="notice">充值满100元及以上可使用</span>
+            </div>
+        </div>
+        <button>去使用</button>
+    </div>
 </div>
 </body>
+<script type="text/javascript" src="/static/js/jquery-1.11.3.min.js"></script>
+<script type="text/javascript" src="/static/js/jQueryRotate.js"></script>
 <script type="text/javascript">
-</script>
+    $(document).ready(function(){
+        //旋转角度
+        var angles;
+        //可抽奖次数
+        var clickNum = 1;
+        //旋转次数
+        var rotNum = 1;
+        //重复点击
+        var isDisable = true;
+        //弹框选择 (1: 谢谢参与     2: 抽得话费券)
+        var showModel = 1;
+        var info = ["谢谢参与","4元券","3元券","1元券","4元券","3元券"];
+
+        $("#tupBtn").click(function(){
+            if(isDisable){
+                if(clickNum > 0){
+                    //可抽奖次数减一
+                    clickNum = clickNum-1;
+                    //转盘旋转
+                    runCup();
+                    //转盘旋转过程“开始抽奖”按钮无法点击
+                    isDisable = false;
+                    //旋转次数加一
+                    rotNum = rotNum + 1;
+                    //“开始抽奖”按钮无法点击恢复点击
+                    setTimeout(function(){
+                        if(showModel == 2){
+                            $("#bulletFrame").show();
+                        }else{
+                            alert("谢谢参与")
+                        }
 
+                        isDisable = true;
+                    },6000);
+                }else{
+                    alert("亲,抽奖次数已用光!");
+                }
+            }
+        })
+        //转盘旋转
+        function runCup(){
+            probability();
+            $(".lottery_tba").rotate({
+                animateTo:angles,
+                duration:6000
+            })
+        }
+        //各奖项对应的旋转角度及中奖公告内容
+        function probability(){
+            //获取随机数
+            var num = parseInt(Math.random()*(100 - 0 + 0) + 0);
+            console.log(num)
+            //概率	1/101
+            if ( num == 0 ) {
+                angles = 2160 * rotNum + 1800;
+                notice = info[0];
+            }
+            //概率	49/101
+            else if ( num > 0 && num < 50 ) {
+                showModel = 2;
+                $("#money").html(4);
+                angles = 2160 * rotNum + 2100;
+                notice = info[1];
+            }
+            //概率	2/101
+            else if ( num == 50 || num == 51) {
+                showModel = 2;
+                $("#money").html(3);
+                angles = 2160 * rotNum + 2040;
+                notice = info[2];
+            }
+            //概率	1/101
+            else if ( num == 52) {
+                showModel = 2;
+                $("#money").html(1);
+                angles = 2160 * rotNum + 1980;
+                notice = info[3];
+            }
+            //概率	46/101
+            else if ( num > 52 && num < 99 ) {
+                showModel = 2;
+                $("#money").html(4);
+                angles = 2160 * rotNum + 1920;
+                notice = info[4];
+            }
+            //概率	2/101
+            else if ( num >= 99) {
+                showModel = 2;
+                $("#money").html(3);
+                angles = 2160 * rotNum + 1860;
+                notice = info[5];
+            }
+        }
+        // $("body").click(function(){
+        //     $(".tanchuang").hide();
+        // });
+    })
+</script>
 </html>