share_zhuanpan.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  10. <link rel="stylesheet" type="text/css" href="css/style.css" />
  11. <style>
  12. .clear{clear:both;}
  13. /* 大转盘样式 */
  14. .drawbanner{display:block;width:85%;margin:0 auto;}
  15. .drawbanner .turnplate{display:block;width:100%;position:relative;}
  16. .drawbanner .turnplate canvas.item{width:100%;}
  17. .drawbanner .turnplate img.pointer{
  18. position: absolute;
  19. width: 25%;
  20. height: 30%;
  21. left: 37.5%;
  22. top: 32%;
  23. }
  24. #img-box{display:none;}
  25. </style>
  26. </head>
  27. <body style="background: #fff3f4;">
  28. <div class="loading-bg">
  29. <div class="mui-loading">
  30. <div class="mui-spinner">
  31. </div>
  32. &nbsp;&nbsp;加载中...
  33. </div>
  34. </div>
  35. <div class="mui-content" style="background: #fff3f4;">
  36. <div style="margin-bottom: 10px;">
  37. <img width="100%" src="images/wheel-title1.png" />
  38. </div>
  39. <div style="position: relative;">
  40. <div id="img-box">
  41. </div>
  42. <div class="drawbanner">
  43. <div class="turnplate" style="background-image:url(images/turnplate-bg.png);background-size:100% 98%;background-repeat: no-repeat;">
  44. <canvas class="item" id="wheelcanvas" width="422px" height="422px"></canvas>
  45. <img class="pointer" src="images/turnplate-pointer.png"/>
  46. </div>
  47. </div>
  48. <div style="text-align: center;">
  49. <button class="pointer" type="button" style="background: #e9004c;color: #fff;border: 0;border-radius: 5px;display: block;width:70%;margin:20px 15%;padding:11px 0;">立即抽奖</button>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <script src="js/mui.min.js"></script>
  55. <script src="js/jquery-2.1.1.min.js"></script>
  56. <script src="js/awardRotate.js"></script>
  57. <script src="js/main.js"></script>
  58. <script type="text/javascript" src="js/page/wechat-utils-1.0.js"></script>
  59. <script type="text/javascript">
  60. var turnplate={
  61. restaraunts:[], //大转盘奖品名称
  62. colors:[], //大转盘奖品区块对应背景颜色
  63. outsideRadius:166, //大转盘外圆的半径
  64. textRadius:140, //大转盘奖品位置距离圆心的距离
  65. insideRadius:40, //大转盘内圆的半径
  66. startAngle:0, //开始角度
  67. bRotate:false //false:停止;ture:旋转
  68. };
  69. var prizeList = null;
  70. $(document).ready(function(){
  71. window.repleFlag = false;
  72. window.wxFriend = {
  73. "appId": "",
  74. "imgUrl":domanUrl + '/iamberry/common/shop/images/1.png',
  75. "link":"https:" + domanUrl+"/iamberry/wechat/activity/share_luck_draw",
  76. "desc":"哎呀!我差一点就抽到iPhone7了!亮黑版,32G啊!小伙伴你也来试试吧!",//描述
  77. "title":"我离iPhone7亮黑版 32G仅一步之遥,小伙伴你快来一起抽吧!", //标题
  78. "netError":"您的网络异常,请刷新重试!如多次刷新无效,请向我们反应 ~",
  79. "shareTimeSuccess":"分享成功", //这里是分享朋友圈后调用的文字
  80. "shareTimeCancel":"已取消分享", //这里是取消分享给朋友圈后调用的文字
  81. "shareAppSuccess":"分享成功", //这里是分享好友后调用的文字
  82. "shareAppCancel":"已取消分享" //这里是取消分享给好友后调用的文字
  83. };
  84. getConfig();
  85. //动态添加大转盘的奖品与奖品区域背景颜色
  86. $.ajax('/iamberry/wechat/game/get_prize_info',{
  87. data: {
  88. prizeGameId:1
  89. },
  90. dataType:'json',
  91. async:true,
  92. type:'post',
  93. timeout:15000,
  94. xhrFields: {
  95. withCredentials: true
  96. },
  97. crossDomain: true,
  98. success:function(dt){
  99. if (dt.isRedirect) {
  100. location.href = dt.redirectURL;
  101. } else {
  102. if (dt.status) {
  103. prizeList = dt.data;
  104. //console.log(prizeList);
  105. mui(prizeList).each(function(index){
  106. turnplate.restaraunts[index] = this.prizeName;
  107. if ((index + 1) % 2 == 0) {
  108. turnplate.colors[index] = "#ff9c9d";
  109. } else {
  110. if (index == (prizeList.length - 1)) {
  111. turnplate.colors[index] = "#f99eaa";
  112. } else {
  113. turnplate.colors[index] = "#f76f7d";
  114. }
  115. }
  116. //先把图片加载出来
  117. $("#img-box").append('<img src="'+this.prizeImage+'" id="'+this.prizeId+'"/>');
  118. });
  119. //防止图片没加载完设置1秒后再绘制canvas
  120. setTimeout(function(){
  121. drawRouletteWheel()
  122. document.querySelector('.loading-bg').style.display = 'none';
  123. },1000);
  124. } else {
  125. }
  126. }
  127. },
  128. error:function(xhr,type,errorThrown){
  129. }
  130. });
  131. //旋转转盘 item:奖品位置; txt:提示语;
  132. var rotateFn = function (item, txt, to){
  133. var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length*2));
  134. if(angles<270){
  135. angles = 270 - angles;
  136. }else{
  137. angles = 360 - angles + 270;
  138. }
  139. $('#wheelcanvas').stopRotate();
  140. $('#wheelcanvas').rotate({
  141. angle:0,
  142. animateTo:(to == null ? (angles+1800) : to),
  143. duration:3000,
  144. callback:function (){
  145. turnplate.bRotate = !turnplate.bRotate;
  146. }
  147. });
  148. };
  149. $(".pointer").on("click",function(){
  150. //去产品列表
  151. mui.openWindow({
  152. url: base_path + '/index.html' //index.html
  153. });
  154. });
  155. });
  156. function drawRouletteWheel() {
  157. var canvas = dc("wheelcanvas");
  158. if (canvas.getContext) {
  159. //根据奖品个数计算圆周角度
  160. var arc = Math.PI / (turnplate.restaraunts.length/2);
  161. var ctx = canvas.getContext("2d");
  162. //在给定矩形内清空一个矩形
  163. ctx.clearRect(0,0,422,422);
  164. //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式
  165. ctx.strokeStyle = "rgba(0,0,0,0)";//边框颜色
  166. //font 属性设置或返回画布上文本内容的当前字体属性
  167. ctx.font = '17px Arial';
  168. for(var i = 0; i < turnplate.restaraunts.length; i++) {
  169. //添加对应图标
  170. if (prizeList != null) {
  171. var angle = turnplate.startAngle + i * arc;
  172. ctx.fillStyle = turnplate.colors[i];
  173. ctx.beginPath();
  174. //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线(用于创建圆或部分圆)
  175. ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
  176. ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
  177. ctx.stroke();
  178. ctx.fill();
  179. //锁画布(为了保存之前的画布状态)
  180. ctx.save();
  181. //----绘制奖品开始----
  182. ctx.fillStyle = "#fff";
  183. var text = turnplate.restaraunts[i];
  184. var line_height = 17;
  185. //translate方法重新映射画布上的 (0,0) 位置
  186. ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);
  187. //rotate方法旋转当前的绘图
  188. ctx.rotate(angle + arc / 2 + Math.PI / 2);
  189. /** 下面代码根据奖品类型、奖品名称长度渲染不同效果,如字体、颜色、图片效果。(具体根据实际情况改变) **/
  190. //在画布上绘制填色的文本。文本的默认颜色是黑色
  191. //measureText()方法返回包含一个对象,该对象包含以像素计的指定字体宽度
  192. ctx.fillText(text, -ctx.measureText(text).width / 2, 0);
  193. var img= dc(prizeList[i].prizeId);
  194. ctx.drawImage(img,-25,10);
  195. //把当前画布返回(调整)到上一个save()状态之前
  196. }
  197. //----绘制奖品结束----
  198. ctx.restore();
  199. }
  200. }
  201. }
  202. </script>
  203. </body>
  204. </html>