Commit 708b25dfbf364c41a1017283ef7f19afdcbba5e8

Authored by zouyang0921
1 parent 4f45506f

[年会抽奖]移动端逻辑

img/mobile/dialog_btn_cancel.png 0 → 100644

46.5 KB

img/mobile/dialog_btn_confirm.png 0 → 100644

26.1 KB

js/template.js 0 → 100644
  1 +/*!art-template - Template Engine | http://aui.github.com/artTemplate/*/
  2 +!function(){function a(a){return a.replace(t,"").replace(u,",").replace(v,"").replace(w,"").replace(x,"").split(y)}function b(a){return"'"+a.replace(/('|\\)/g,"\\$1").replace(/\r/g,"\\r").replace(/\n/g,"\\n")+"'"}function c(c,d){function e(a){return m+=a.split(/\n/).length-1,k&&(a=a.replace(/\s+/g," ").replace(/<!--[\w\W]*?-->/g,"")),a&&(a=s[1]+b(a)+s[2]+"\n"),a}function f(b){var c=m;if(j?b=j(b,d):g&&(b=b.replace(/\n/g,function(){return m++,"$line="+m+";"})),0===b.indexOf("=")){var e=l&&!/^=[=#]/.test(b);if(b=b.replace(/^=[=#]?|[\s;]*$/g,""),e){var f=b.replace(/\s*\([^\)]+\)/,"");n[f]||/^(include|print)$/.test(f)||(b="$escape("+b+")")}else b="$string("+b+")";b=s[1]+b+s[2]}return g&&(b="$line="+c+";"+b),r(a(b),function(a){if(a&&!p[a]){var b;b="print"===a?u:"include"===a?v:n[a]?"$utils."+a:o[a]?"$helpers."+a:"$data."+a,w+=a+"="+b+",",p[a]=!0}}),b+"\n"}var g=d.debug,h=d.openTag,i=d.closeTag,j=d.parser,k=d.compress,l=d.escape,m=1,p={$data:1,$filename:1,$utils:1,$helpers:1,$out:1,$line:1},q="".trim,s=q?["$out='';","$out+=",";","$out"]:["$out=[];","$out.push(",");","$out.join('')"],t=q?"$out+=text;return $out;":"$out.push(text);",u="function(){var text=''.concat.apply('',arguments);"+t+"}",v="function(filename,data){data=data||$data;var text=$utils.$include(filename,data,$filename);"+t+"}",w="'use strict';var $utils=this,$helpers=$utils.$helpers,"+(g?"$line=0,":""),x=s[0],y="return new String("+s[3]+");";r(c.split(h),function(a){a=a.split(i);var b=a[0],c=a[1];1===a.length?x+=e(b):(x+=f(b),c&&(x+=e(c)))});var z=w+x+y;g&&(z="try{"+z+"}catch(e){throw {filename:$filename,name:'Render Error',message:e.message,line:$line,source:"+b(c)+".split(/\\n/)[$line-1].replace(/^\\s+/,'')};}");try{var A=new Function("$data","$filename",z);return A.prototype=n,A}catch(B){throw B.temp="function anonymous($data,$filename) {"+z+"}",B}}var d=function(a,b){return"string"==typeof b?q(b,{filename:a}):g(a,b)};d.version="3.0.0",d.config=function(a,b){e[a]=b};var e=d.defaults={openTag:"<%",closeTag:"%>",escape:!0,cache:!0,compress:!1,parser:null},f=d.cache={};d.render=function(a,b){return q(a,b)};var g=d.renderFile=function(a,b){var c=d.get(a)||p({filename:a,name:"Render Error",message:"Template not found"});return b?c(b):c};d.get=function(a){var b;if(f[a])b=f[a];else if("object"==typeof document){var c=document.getElementById(a);if(c){var d=(c.value||c.innerHTML).replace(/^\s*|\s*$/g,"");b=q(d,{filename:a})}}return b};var h=function(a,b){return"string"!=typeof a&&(b=typeof a,"number"===b?a+="":a="function"===b?h(a.call(a)):""),a},i={"<":"&#60;",">":"&#62;",'"':"&#34;","'":"&#39;","&":"&#38;"},j=function(a){return i[a]},k=function(a){return h(a).replace(/&(?![\w#]+;)|[<>"']/g,j)},l=Array.isArray||function(a){return"[object Array]"==={}.toString.call(a)},m=function(a,b){var c,d;if(l(a))for(c=0,d=a.length;d>c;c++)b.call(a,a[c],c,a);else for(c in a)b.call(a,a[c],c)},n=d.utils={$helpers:{},$include:g,$string:h,$escape:k,$each:m};d.helper=function(a,b){o[a]=b};var o=d.helpers=n.$helpers;d.onerror=function(a){var b="Template Error\n\n";for(var c in a)b+="<"+c+">\n"+a[c]+"\n\n";"object"==typeof console&&console.error(b)};var p=function(a){return d.onerror(a),function(){return"{Template Error}"}},q=d.compile=function(a,b){function d(c){try{return new i(c,h)+""}catch(d){return b.debug?p(d)():(b.debug=!0,q(a,b)(c))}}b=b||{};for(var g in e)void 0===b[g]&&(b[g]=e[g]);var h=b.filename;try{var i=c(a,b)}catch(j){return j.filename=h||"anonymous",j.name="Syntax Error",p(j)}return d.prototype=i.prototype,d.toString=function(){return i.toString()},h&&b.cache&&(f[h]=d),d},r=n.$each,s="break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined",t=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|\s*\.\s*[$\w\.]+/g,u=/[^\w$]+/g,v=new RegExp(["\\b"+s.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),w=/^\d[^,]*|,\d[^,]*/g,x=/^,+|,+$/g,y=/^$|,+/;e.openTag="{{",e.closeTag="}}";var z=function(a,b){var c=b.split(":"),d=c.shift(),e=c.join(":")||"";return e&&(e=", "+e),"$helpers."+d+"("+a+e+")"};e.parser=function(a){a=a.replace(/^\s/,"");var b=a.split(" "),c=b.shift(),e=b.join(" ");switch(c){case"if":a="if("+e+"){";break;case"else":b="if"===b.shift()?" if("+b.join(" ")+")":"",a="}else"+b+"{";break;case"/if":a="}";break;case"each":var f=b[0]||"$data",g=b[1]||"as",h=b[2]||"$value",i=b[3]||"$index",j=h+","+i;"as"!==g&&(f="[]"),a="$each("+f+",function("+j+"){";break;case"/each":a="});";break;case"echo":a="print("+e+");";break;case"print":case"include":a=c+"("+b.join(",")+");";break;default:if(/^\s*\|\s*[\w\$]/.test(e)){var k=!0;0===a.indexOf("#")&&(a=a.substr(1),k=!1);for(var l=0,m=a.split("|"),n=m.length,o=m[l++];n>l;l++)o=z(o,m[l]);a=(k?"=":"=#")+o}else a=d.helpers[c]?"=#"+c+"("+b.join(",")+");":"="+a}return a},"function"==typeof define?define(function(){return d}):"undefined"!=typeof exports?module.exports=d:this.template=d}();
0 3 \ No newline at end of file
... ...
mobile.html
... ... @@ -93,14 +93,14 @@
93 93 .seat {min-height: 100vh;background: #F8F8F9;padding-top: .4rem;}
94 94 .stage {width: 6.3rem;height: 2.14rem;margin: 0 auto; background: #FFF8DD; box-sizing: border-box;border: 1px dashed rgba(255, 205, 0, .5);border-top: .16rem solid #FBCE07;font-size: .32rem;font-weight: 500;color: #FBCE07;display: flex;align-items: center;justify-content: center;}
95 95 .entrance {width: .4rem;height: .6rem;margin-top: .5rem;padding: .1rem;background: #E6F7EF;border: 1px dashed #64DCA1;border-left: none;font-size: .28rem;font-weight: 500;color: #64DCA1;display: flex;align-items: center;justify-content: center;}
96   - .seat-list {padding: 0 .94rem;margin-top: .14rem;}
97   - .seat-list .list-item {float: left;width: 1rem;height: 1rem;margin-right: .5rem;margin-bottom: .5rem;border-radius: 50%;background: #EDEDED;line-height: 1rem;text-align: center;font-size: .4rem;color: #ccc;font-family: DINAlternate-Bold,DINAlternate;font-weight: bold;}
98   - .seat-list .list-item.active {position: relative;padding: .12rem;margin-left: -.12rem;margin-top: -.12rem;margin-right: .38rem;margin-bottom: .38rem;background: url('./img/mobile/seat_active.png') no-repeat;background-size: contain;color: #fff;}
99   - .seat-list .list-item:nth-child(4n) {margin-right: 0;}
  96 + .seat-list {padding: 0 .6rem;margin-top: .14rem;}
  97 + .seat-list .list-item {float: left;width: 1rem;height: 1rem;margin-right: .32rem;margin-bottom: .4rem;border-radius: 50%;background: #EDEDED;line-height: 1rem;text-align: center;font-size: .4rem;color: #ccc;font-family: DINAlternate-Bold,DINAlternate;font-weight: bold;}
  98 + .seat-list .list-item.active {position: relative;padding: .12rem;margin: -.12rem .2rem .2rem -.12rem;background: url('./img/mobile/seat_active.png') no-repeat;background-size: contain;color: #fff;}
  99 + .seat-list .list-item:nth-child(5n) {margin-right: 0;}
100 100 .seat-icon {position: absolute;right: -.38rem;top: -.52rem;width: .76rem;height: .76rem;background: url('./img/mobile/icon_seat.png') no-repeat;background-size: contain;}
101 101 .bottom-btn {position: fixed;bottom: 0;left: 0;z-index: 1;width: 100%;height: 1.08rem;background: url('./img/mobile/btn_bg_red.png') no-repeat;background-size: cover;line-height: 1.08rem;text-align: center;font-size: .32rem;color: #fff;}
102 102  
103   - .vote {min-height: 100vh;}
  103 + .vote {min-height: 100vh;padding-bottom: 1.2rem;}
104 104 .vote .tip {width: 100%;height: .84rem;background: #FFE7E4;line-height: .84rem;text-align: center;font-size: .28rem;font-weight: 600;color: #D02E1D;}
105 105 .program-title {margin-top: .3rem;padding-left: .4rem;font-size: .28rem;color: #A6A6A6;}
106 106 .program-list {padding-left: .4rem;}
... ... @@ -119,10 +119,15 @@
119 119 .title-text {font-size: .32rem;font-weight: 600;color: #C93120;}
120 120 .dialog-content {width: 5rem;margin: .4rem auto 0;padding: .2rem;line-height: .46rem;font-size: .28rem;color: #C93120;}
121 121 .content-row {text-align: center;}
122   - .dialog-btn {width: 4.3rem;height: .94rem;margin: 1rem auto 0;background: url('./img/mobile/dialog_btn_bg.png') no-repeat;background-size: 100% 100%;line-height: .94rem;text-align: center; font-size: .32rem;color: #FBDB97;}
  122 + .dialog-btn-single {width: 4.3rem;height: .94rem;margin: 1rem auto 0;background: url('./img/mobile/dialog_btn_bg.png') no-repeat;background-size: cover;line-height: .94rem;text-align: center; font-size: .32rem;color: #FBDB97;}
  123 + .dialog-btn-wrap {width: 4.62rem;margin: 1rem auto;display: flex;justify-content: space-between;}
  124 + .dialog-btn-item {width: 2.12rem;height: .94rem;line-height: .94rem;text-align: center; font-size: .32rem;}
  125 + .dialog-theme-btn {background: url('./img/mobile/dialog_btn_confirm.png') no-repeat;background-size: cover;color: #FBDB97;}
  126 + .dialog-reverse-btn {background: url('./img/mobile/dialog_btn_cancel.png') no-repeat;background-size: cover;color: #CF3727;}
123 127 .dialog-close {position: absolute;top: -.6rem;right: .26rem;width: .76rem;height: .76rem;background: url('./img/mobile/dialog_close.png') no-repeat;background-size: contain;}
124 128  
125   - .clearfix:after {content: " ";display: block;height: 0;visibility: hidden;clear: both}
  129 + .toast-tip {display: none;position: fixed;bottom: 50%;left: 50%;transform: translateX(-50%);z-index: 11;opacity: 0;padding: 0 .5rem;height: .84rem;background: rgba(0, 0, 0, .8);border-radius: .06rem;transition: opacity 1s ease-out;line-height: .84rem;text-align: center;font-size: .28rem;color: #fff;}
  130 + .clearfix:after {content: " ";display: block;height: 0;visibility: hidden;clear: both;}
126 131 .hide {display: none;}
127 132 </style>
128 133 </head>
... ... @@ -146,6 +151,7 @@
146 151 <input type="hidden" class="data-img" />
147 152 </div>
148 153 <div class="pic-btn-wrap">
  154 + <!-- 自拍出境 -->
149 155 <div class="common-btn" onclick="action.goHome()">
150 156 <img class="common-btn-bg" src="./img/mobile/pic_btn1.png">
151 157 </div>
... ... @@ -155,10 +161,12 @@
155 161 </div>
156 162 </div>
157 163 <div class="pic-btn-wrap hide">
158   - <div class="common-btn">
  164 + <!-- 完美提交 -->
  165 + <div class="common-btn" onclick="action.uploadImage()">
159 166 <img class="common-btn-bg" src="./img/mobile/pic_btn2.png">
160 167 </div>
161   - <div class="common-btn">
  168 + <!-- 再拍一次 -->
  169 + <div class="common-btn" onclick="action.openCamera()">
162 170 <img class="common-btn-bg" src="./img/mobile/pic_btn3.png">
163 171 </div>
164 172 <div class="pic-btn-album">
... ... @@ -175,19 +183,19 @@
175 183 <div class="info-lantern"></div>
176 184 <div class="info-center">
177 185 <div class="user-avatar">
178   - <img class="avatar-img" src="./img/mobile/default_avatar.png">
  186 + <img class="avatar-img" id="home_user_avatar" src="./img/mobile/default_avatar.png">
179 187 <div class="avatar-border"></div>
180 188 </div>
181   - <div class="user-name">姓名</div>
  189 + <div class="user-name" id="home_user_name">姓名</div>
182 190 </div>
183 191 <div class="info-main">
184 192 <div class="info-main-item">
185   - <div class="item-content">001</div>
  193 + <div class="item-content" id="home_prize_no">001</div>
186 194 <div class="item-label">奖号</div>
187 195 </div>
188 196 <i class="info-main-space"></i>
189 197 <div class="info-main-item">
190   - <div class="item-content">16桌</div>
  198 + <div class="item-content"><span id="home_table_no">0</span>桌</div>
191 199 <div class="item-label">入座区域</div>
192 200 <div class="enter-btn" onclick="action.goSeat()"></div>
193 201 </div>
... ... @@ -195,7 +203,7 @@
195 203 </div>
196 204 <img class="home-title" src="./img/mobile/home_title.png">
197 205 <img class="home-list" src="./img/mobile/home_program.png">
198   - <div class="home-vote-btn" onclick="action.goVote()">
  206 + <div class="home-vote-btn" onclick="action.getVoteState()">
199 207 <img class="btn-bg" src="./img/mobile/home_vote_btn.png">
200 208 </div>
201 209 <div class="home-barrage-wrap">
... ... @@ -212,60 +220,22 @@
212 220 <div class="seat wrap hide">
213 221 <div class="stage">舞台</div>
214 222 <div class="entrance">入口</div>
215   - <div class="seat-list clearfix">
216   - <div class="list-item">1</div>
217   - <div class="list-item">2</div>
218   - <div class="list-item">3</div>
219   - <div class="list-item">4</div>
220   - <div class="list-item">5</div>
221   - <div class="list-item active">6 <i class="seat-icon"></i></div>
222   - <div class="list-item">7</div>
223   - <div class="list-item">8</div>
224   - <div class="list-item">9</div>
225   - <div class="list-item">10</div>
226   - <div class="list-item">11</div>
227   - <div class="list-item">12</div>
228   - <div class="list-item">13</div>
229   - <div class="list-item">14</div>
230   - <div class="list-item">15</div>
231   - <div class="list-item">16</div>
232   - </div>
  223 + <div class="seat-list clearfix"></div>
233 224 <div class="bottom-btn" onclick="action.goHome()">返回</div>
234 225 </div>
235 226  
236 227 <!-- 投票 -->
237 228 <div class="vote wrap hide">
238   - <div class="tip">最多可以票选5个优秀节目!</div>
  229 + <div class="tip hide">最多可以票选5个优秀节目!</div>
239 230 <div class="program-title">选项(多选)</div>
240   - <ul class="program-list">
241   - <li class="program-item">
242   - <i class="program-item-icon"></i>
243   - <span class="program-item-label">舞蹈:《名字太长容易被记住的一段尬舞》</span>
244   - </li>
245   - <li class="program-item active">
246   - <i class="program-item-icon"></i>
247   - <span class="program-item-label">舞蹈:《名字太长容易被记住的一段尬舞》</span>
248   - </li>
249   - <li class="program-item active">
250   - <i class="program-item-icon"></i>
251   - <span class="program-item-label">舞蹈:《名字太长容易被记住的一段尬舞》</span>
252   - </li>
253   - <li class="program-item">
254   - <i class="program-item-icon"></i>
255   - <span class="program-item-label">舞蹈:《名字太长容易被记住的一段尬舞》</span>
256   - </li>
257   - <li class="program-item">
258   - <i class="program-item-icon"></i>
259   - <span class="program-item-label">舞蹈:《名字太长容易被记住的一段尬舞》</span>
260   - </li>
261   - </ul>
262   - <div class="bottom-btn" onclick="action.submitVote()">确认投票</div>
  231 + <ul class="program-list"></ul>
  232 + <div class="bottom-btn" onclick="action.vote()">确认投票</div>
263 233 </div>
264 234  
265   - <!-- 弹框 -->
266   - <div class="dialog-wrap hide">
  235 + <!-- 姓名不存在 弹框 -->
  236 + <div class="dialog-wrap hide" id="sign_in_dialog">
267 237 <div class="dialog-main">
268   - <div class="dialog-close" onclick="action.switchDialog(false)"></div>
  238 + <div class="dialog-close" onclick="action.switchDialog('#sign_in_dialog', false)"></div>
269 239 <div class="dialog-title">
270 240 <i class="title-icon-left"></i>
271 241 <div class="title-text">温馨提示</div>
... ... @@ -275,7 +245,41 @@
275 245 <p class="content-row">纳尼?您的姓名竟然不存在!</p>
276 246 <p class="content-row">快老实交代,你是卧底还是走丢了!</p>
277 247 </div>
278   - <div class="dialog-btn" onclick="action.switchDialog(false)">速速联系组委会</div>
  248 + <div class="dialog-btn-single" onclick="action.switchDialog('#sign_in_dialog', false)">速速联系组委会</div>
  249 + </div>
  250 + </div>
  251 +
  252 + <!-- 未开启投票 弹框 -->
  253 + <div class="dialog-wrap hide" id="home_dialog">
  254 + <div class="dialog-main">
  255 + <div class="dialog-title">
  256 + <i class="title-icon-left"></i>
  257 + <div class="title-text">温馨提示</div>
  258 + <i class="title-icon-right"></i>
  259 + </div>
  260 + <div class="dialog-content">
  261 + <p class="content-row">投票还没开始,还是专心看节目吧~</p>
  262 + </div>
  263 + <div class="dialog-btn-single" onclick="action.switchDialog('#home_dialog', false)">我知道了</div>
  264 + </div>
  265 + </div>
  266 +
  267 + <!-- 投票确认 弹框 -->
  268 + <div class="dialog-wrap hide" id="vote_dialog">
  269 + <div class="dialog-main">
  270 + <div class="dialog-title">
  271 + <i class="title-icon-left"></i>
  272 + <div class="title-text">温馨提示</div>
  273 + <i class="title-icon-right"></i>
  274 + </div>
  275 + <div class="dialog-content">
  276 + <p class="content-row">投票完成就不能反悔了,</p>
  277 + <p class="content-row">确认投票吗?</p>
  278 + </div>
  279 + <div class="dialog-btn-wrap">
  280 + <div class="dialog-btn-item dialog-reverse-btn" onclick="action.switchDialog('#vote_dialog', false)">取消</div>
  281 + <div class="dialog-btn-item dialog-theme-btn" onclick="action.submitVote()">确认</div>
  282 + </div>
279 283 </div>
280 284 </div>
281 285  
... ... @@ -283,11 +287,33 @@
283 287 <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
284 288 <script src="https://cdn.bootcss.com/jquery/1.7.2/jquery.min.js"></script>
285 289 <script src="//cdn.bootcss.com/socket.io/2.0.3/socket.io.js"></script>
286   - <script src="mobile.js?t=2"></script>
287 290 <script src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
  291 + <script src="./js/qs.js"></script>
  292 + <script src="./js/template.js"></script>
  293 + <script src="mobile.js?t=2"></script>
288 294 <script>
289 295 var vConsole = new VConsole();
290 296 action.init();
291 297 </script>
  298 +
  299 + <script type="text/html" id="seatListTmpl">
  300 + {{each list as item}}
  301 + <div class="list-item {{if item.number == userSeat}}active{{/if}}">
  302 + <span>{{item.number}}</span>
  303 + {{if item.number == userSeat}}
  304 + <i class="seat-icon"></i>
  305 + {{/if}}
  306 + </div>
  307 + {{/each}}
  308 + </script>
  309 +
  310 + <script type="text/html" id="programListTmpl">
  311 + {{each list as item index}}
  312 + <li class="program-item {{if item.checked}}active{{/if}}" onclick="action.selectProgram({{index}})">
  313 + <i class="program-item-icon"></i>
  314 + <span class="program-item-label">{{item.item_name}}</span>
  315 + </li>
  316 + {{/each}}
  317 + </script>
292 318 </body>
293 319 </html>
294 320 \ No newline at end of file
... ...
mobile.js
1 1 // var baseURL = 'http://dsc-b.vchangyi.com/party/phpapi';
2 2 // var baseURL = 'https://yq.vchangyi.com/party/phpapi';
3 3 var baseURL = 'http://party.vchangyi.com/phpapi';
  4 +var toastTimer = null;
  5 +var displayTimer = null;
4 6  
5 7 // 页面数据绑定操作
6 8 var action = {
7   - // 是否开始签到
8   - isRun : 0,
  9 + isRun : 0, // 是否开始签到
  10 + userInfo: null, // 用户信息
  11 + userAvatar: '', // 用户头像
  12 + programList: [], // 节目列表
9 13 init : function() {
10   - this.initBarrage();
11   - // var WECHAT_JS_SIGN_URL = '/api.WechatJsSign.php';
12   - // var USER_DETAIL_URL = '/api.UserDetail.php';
13   - // // 获取微信jsapi签名
14   - // baseRquest.get(WECHAT_JS_SIGN_URL, {'url' : location.href}, action.sign);
15   - // // 用户信息
16   - // baseRquest.get(USER_DETAIL_URL, {}, action.userDetail);
  14 + // 本地获取用户信息,判断跳转页面
  15 + var userInfo = localStorage.getItem('userInfo');
  16 + if (userInfo) {
  17 + this.userInfo = JSON.parse(userInfo);
  18 + var userAvatar = localStorage.getItem('userAvatar');
  19 + if (userAvatar) {
  20 + this.userAvatar = userAvatar;
  21 + this.goHome();
  22 + } else {
  23 + this.goPic();
  24 + }
  25 + }
  26 +
  27 + // this.initBarrage();
  28 +
17 29 },
18 30 // 签到
19 31 signIn: function() {
... ... @@ -23,72 +35,51 @@ var action = {
23 35 }
24 36 var url = baseURL + '/apicp.SignIn.php';
25 37 var data = { realname: realname };
26   - var callback = function() {
  38 + var callback = function(data) {
  39 + action.userInfo = data.data;
  40 + localStorage.setItem('userInfo', JSON.stringify(action.userInfo));
27 41 $('.sign-input').val('');
28   - this.goPic();
  42 + action.goPic();
29 43 };
30   - // baseRquest.post(url, data, callback);
31   - this.goPic();
32   - },
33   - // 配置微信jsapi config,回调触发
34   - sign: function(data) {
35   - wx.config({
36   - debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
37   - appId: data.appId, // 必填,公众号的唯一标识
38   - timestamp: data.timestamp, // 必填,生成签名的时间戳
39   - nonceStr: data.nonceStr, // 必填,生成签名的随机串
40   - signature: data.signature,// 必填,签名
41   - jsApiList: ['chooseImage','uploadImage','getLocalImgData','downloadImage','getLocation'] // 必填,需要使用的JS接口列表
42   - });
  44 + baseRquest.post(url, data, callback);
43 45 },
44   - // 回调触发,获取用户信息
45   - userDetail : function(data) {
46   - // openid不存在
47   - if (!data) {
48   - alert('数据异常,不要搞事情');
49   - return;
50   - }
51   - // 如果数据中有isLogin,有登录流程
52   - if (data.isLogin !== undefined) {
53   - location.href = baseURL + '/api.WechatAuth.php';
54   - }
55   - action.isRun = 1;
56   - // 未提交过资料,展示开场
57   - if (data.realname === undefined || data.realname == '') {
58   - $('#show').show();
59   - $('#index').hide();
60   - $('#detail').hide();
61   - } else {
62   - // 提交过资料,展示个人信息
63   - $('.detail-realname').html(data.realname);
64   - $('.detail-lottery-num').html('NO.' + data.id);
65   - $('.detail-head-img').attr('src', data.headimg);
66   - $('#show').hide();
67   - $('#index').hide();
68   - $('#detail').show();
69   - }
  46 + // 获取微信jsapi签名
  47 + wechatJsSign: function() {
  48 + var WECHAT_JS_SIGN_URL = baseURL + '/apicp.WechatJsSign.php';
  49 + var sign = function(data) {
  50 + wx.config({
  51 + debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  52 + appId: data.appId, // 必填,公众号的唯一标识
  53 + timestamp: data.timestamp, // 必填,生成签名的时间戳
  54 + nonceStr: data.nonceStr, // 必填,生成签名的随机串
  55 + signature: data.signature,// 必填,签名
  56 + jsApiList: ['chooseImage','uploadImage','getLocalImgData','downloadImage'] // 必填,需要使用的JS接口列表
  57 + });
  58 + };
  59 + baseRquest.get(WECHAT_JS_SIGN_URL, {'url' : location.href}, sign);
70 60 },
71 61 // 进入拍照页
72 62 goPic: function() {
73 63 $('.sign-in').hide();
74 64 $('.pic').show();
  65 + // 微信 SDK config
  66 + this.wechatJsSign();
75 67 },
76 68 goHome: function() {
77 69 $('.home').show();
78 70 $('.pic').hide();
79 71 $('.seat').hide();
  72 + if (action.userInfo) {
  73 + $('#home_user_avatar').attr('src', action.userAvatar);
  74 + $('#home_user_name').html(action.userInfo.realname);
  75 + $('#home_prize_no').html(action.userInfo.prize_no);
  76 + $('#home_table_no').html(action.userInfo.table_no);
  77 + }
80 78 },
81 79 goSeat: function() {
82 80 $('.seat').show();
83 81 $('.home').hide();
84   - },
85   - goVote: function() {
86   - $('.vote').show();
87   - $('.home').hide();
88   - },
89   - submitVote: function() {
90   - $('.home').show();
91   - $('.vote').hide();
  82 + this.getSeatList();
92 83 },
93 84 // 打开摄像头
94 85 openCamera: function() {
... ... @@ -106,17 +97,14 @@ var action = {
106 97 localId: localIds.toString(), // 需要上传的图片的ID,由chooseImage接口获得
107 98 isShowProgressTips: 1, // 进度提示
108 99 success: function (res) {
109   - var serverId = res.serverId; // 返回图片的服务器端ID,即mediaId
110   - $(".data-img").val(serverId);
  100 + var serverId = res.serverId; // 返回图片的服务器端ID,即 mediaId
  101 + $('.pic-avatar').val(serverId);
111 102 console.log(serverId);
112 103 wx.downloadImage({
113 104 serverId: serverId, // 需要下载的图片的服务器端ID,由uploadImage接口获得
114 105 isShowProgressTips: 1, // 默认为1,显示进度提示
115 106 success: function (res) {
116 107 var localId = res.localId; // 返回图片下载后的本地ID
117   - $('#show').hide();
118   - $('#index').show();
119   - $('#detail').hide();
120 108 action.wxgetLocalImgData(localId, 1);
121 109 }
122 110 });
... ... @@ -129,69 +117,130 @@ var action = {
129 117 });
130 118 },
131 119 // 展示选中的图片
132   - wxgetLocalImgData : function(e,num){
133   - var headimg = $(".head-img-show");
134   - if(window.__wxjs_is_wkwebview){
  120 + wxgetLocalImgData: function(localId, num){
  121 + if (window.__wxjs_is_wkwebview) {
135 122 wx.getLocalImgData({
136   - localId: e, // 图片的localID
137   - success: function (res) {
  123 + localId: localId,
  124 + success: function(res) {
138 125 var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
139 126 localData = localData.replace('jgp', 'jpeg'); //iOS 系统里面得到的数据,类型为 image/jgp,因此需要替换一下
140   - $(headimg).attr("src", localData);
  127 + $('.pic-avatar').attr("src", localData);
141 128 },
142   - fail:function(res){
  129 + fail: function(res) {
143 130 alert("显示失败");
144 131 }
145 132 });
146   - }else{
147   - $(headimg).attr("src", e);
  133 + } else {
  134 + $('.pic-avatar').attr("src", localId);
148 135 }
149 136 },
150   -
151   - // 提交签到申请
152   - submit : function(){
153   - var mediaId = $(".data-img").val();
154   - var realname = $(".data-realname").val().replace( /^\s*/, '');
155   - if (realname == '' || mediaId == '' || realname == '姓名:陈独秀') {
156   - alert('提交的资料数据不完整');
  137 + // 上传头像
  138 + uploadImage: function() {
  139 + var mediaId = $('.pic-avatar').val();
  140 + if (!mediaId) {
157 141 return;
158 142 }
159   - wx.getLocation({
160   - type: 'gcj02',
161   - success: (res) => {
162   - console.log(res);
163   - let latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
164   - let longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
165   - let data = {
166   - mediaId : mediaId,
167   - realname : realname,
168   - latitude : latitude,
169   - longitude : longitude
170   - }
171   - // 提交签到
172   - let ADD_USER_URL = '/api.AddUser.php';
173   - baseRquest.post(ADD_USER_URL, data, this.addUserResult);
  143 + var data = {
  144 + id: action.userInfo.id,
  145 + mediaId : mediaId
  146 + };
  147 + var url = baseURL + '/apicp.UploadHeadImg.php';
  148 + var callback = function(data) {
  149 + // TODO 存储用户头像
  150 + action.userAvatar = data.headimg;
  151 + action.goHome();
  152 + };
  153 + baseRquest.post(url, data, callback);
  154 + },
  155 + // 获取座位列表
  156 + getSeatList: function() {
  157 + var url = baseURL + '/apicp.TablePositionList.php';
  158 + var callback = function(data) {
  159 + var html = template('seatListTmpl', {
  160 + list: data.data,
  161 + userSeat: action.userInfo.table_no
  162 + });
  163 + $('.seat-list').html(html);
  164 + };
  165 + baseRquest.post(url, '', callback);
  166 + },
  167 + // 判断是否开启投票通道
  168 + getVoteState: function() {
  169 + var url = baseURL + '/apicp.GetSetting.php';
  170 + var callback = function(data) {
  171 + if (data.data.isStartVote == 1) {
  172 + action.getProgramList();
  173 + } else {
  174 + action.switchDialog('#home_dialog', true);
174 175 }
175   - });
  176 + };
  177 + baseRquest.get(url, '', callback);
176 178 },
177   - // 增加成功,重新加载页面,进入用户详情页
178   - addUserResult : function(data) {
179   - console.log(data);
180   - let url = window.location.href; //获取当前url
181   - let key = '?t=';
182   - if (url.indexOf("?") > 0) {
183   - key = '&t=';
  179 + // 获取节目列表
  180 + getProgramList: function() {
  181 + var url = baseURL + '/apicp.ItemList.php';
  182 + var callback = function(data) {
  183 + var user_vote = data.data.user_vote;
  184 + var items = data.data.item;
  185 + if (user_vote && user_vote.length > 0) {
  186 + action.showToast('你已经投过票了哦');
  187 + } else {
  188 + $('.vote').show();
  189 + $('.home').hide();
  190 + items.map(function(item) {
  191 + item.checked = false;
  192 + });
  193 + var html = template('programListTmpl', { list: items });
  194 + $('.program-list').html(html);
  195 + }
  196 + action.programList = items;
  197 +
  198 + };
  199 + baseRquest.post(url, {user_id: action.userInfo.id}, callback);
  200 + },
  201 + // 选择节目
  202 + selectProgram: function(index) {
  203 + if (this.programList[index].checked) {
  204 + $('.program-item').eq(index).removeClass('active');
  205 + $('.vote .tip').hide();
  206 + } else {
  207 + var selectedList = this.programList.filter(item => item.checked);
  208 + if (selectedList.length >= 5) {
  209 + $('.vote .tip').show();
  210 + return;
  211 + }
  212 + $('.program-item').eq(index).addClass('active');
184 213 }
185   -
186   - location.href = url + key + (new Date()).valueOf();
  214 + this.programList[index].checked = !this.programList[index].checked;
187 215 },
188   - // 投票
189   - vote : function(){
190   - let VOTE_URL = '/api.Vote.php';
191   - baseRquest.get(VOTE_URL, {a:'a'}, (data)=>{
192   - console.log(data);
193   - location.href = data.url;
194   - });
  216 + // 点击确认投票
  217 + vote: function() {
  218 + var selectedList = this.programList.filter(item => item.checked);
  219 + console.log('selected: ', selectedList);
  220 + if (selectedList.length === 0) {
  221 + action.showToast('请先选择节目');
  222 + return;
  223 + }
  224 + this.switchDialog('#vote_dialog', true);
  225 + },
  226 + // 投票请求
  227 + submitVote: function() {
  228 + let VOTE_URL = '/apicp.ItemVote.php';
  229 + var itemIds = this.programList.filter(item => item.checked).map(item => item.id).join(',');
  230 + console.log('itemIds: ', itemIds);
  231 + var data = {
  232 + user_id: action.userInfo.id,
  233 + item_ids: itemIds
  234 + };
  235 + var callback = function() {
  236 + action.showToast('投票成功!');
  237 + action.switchDialog('#vote_dialog', false)
  238 + setTimeout(function() {
  239 + $('.home').show();
  240 + $('.vote').hide();
  241 + }, 1000);
  242 + };
  243 + baseRquest.post(VOTE_URL, data, callback);
195 244 },
196 245 // 发送弹幕
197 246 initBarrage: function() {
... ... @@ -224,13 +273,41 @@ var action = {
224 273 $('.send-btn').removeClass('active');
225 274 }
226 275 },
227   - switchDialog: function(isShow) {
  276 + switchDialog: function(dom, isShow) {
228 277 if (isShow) {
229   - $('.dialog-wrap').show()
  278 + $(dom).show();
  279 + $('body').css({
  280 + height: '100vh',
  281 + overflow: 'hidden'
  282 + });
230 283 } else {
231   - $('.dialog-wrap').hide()
  284 + $(dom).hide();
  285 + $('body').css({
  286 + 'min-height': '100%',
  287 + overflow: 'auto'
  288 + });
232 289 }
233   - }
  290 + },
  291 + // toast提示
  292 + showToast: function(content, time = 1000) {
  293 + if (toastTimer != null) {
  294 + clearTimeout(toastTimer);
  295 + clearTimeout(displayTimer);
  296 + }
  297 + if ($('#toast').get().length == 0) {
  298 + $('body').append('<div id="toast" class="toast-tip"></div>');
  299 + }
  300 + $('#toast').show();
  301 + $('#toast').css('opacity', 1);
  302 + $('#toast').html(content);
  303 + toastTimer = setTimeout(function() {
  304 + $('#toast').css('opacity', 0);
  305 + displayTimer = setTimeout(
  306 + function() {
  307 + $('#toast').hide();
  308 + }, 1000);
  309 + }, time);
  310 + },
234 311 }
235 312  
236 313 // api接口数据请求,数据交互引用的axios
... ... @@ -240,9 +317,8 @@ let baseRquest = {
240 317 axios.defaults.baseURL = baseURL;
241 318 axios.get(url, {
242 319 params : params
243   - }).then(function (response) {
244   - if (response.status == 200)
245   - {
  320 + }).then(function(response) {
  321 + if (response.status == 200) {
246 322 data = response.data;
247 323 if (!!data) {
248 324 // 过滤错误信息,统一抛出
... ... @@ -252,39 +328,43 @@ let baseRquest = {
252 328 callback(data.result);
253 329 }
254 330 }
255   - }else {
  331 + } else {
256 332 alert('get无法访问接口');
257 333 }
258   - })
259   - .catch(function (error) {
  334 + }).catch(function(error) {
  335 + console.log(error)
260 336 });
261 337 },
262   -
263   - // post请求
264   - post: function(url, params, callback) {
  338 + // post请求
  339 + post: function(url, params, callback) {
265 340 axios.defaults.baseURL = baseURL;
266 341 let data = new URLSearchParams();
267 342 Object.keys(params).forEach(function(key){
268 343 data.append(key, params[key]);
269 344 });
270   - axios.post(url, data,{headers: { 'Content-Type': 'application/x-www-form-urlencoded','Authorization':'123'}})
271   - .then(function (response) {
272   - if (response.status == 200)
273   - {
  345 + axios.post(url, data, {
  346 + headers: {
  347 + 'Content-Type': 'application/x-www-form-urlencoded'
  348 + }
  349 + }).then(function(response) {
  350 + if (response.status == 200) {
274 351 data = response.data;
275 352 if (!!data) {
276 353 // 过滤错误信息,统一抛出
277 354 if (data.errcode != 0 && data.errcode != 200) {
278   - alert(data.errmsg);
  355 + if (url.search('SignIn') !== -1) {
  356 + action.switchDialog('#sign_in_dialog', true);
  357 + } else {
  358 + alert(data.errmsg);
  359 + }
279 360 } else {
280 361 callback(data.result);
281   - }
  362 + }
282 363 }
283   - }else {
  364 + } else {
284 365 alert('post无法访问接口');
285 366 }
286   - })
287   - .catch(function (error) {
  367 + }).catch(function(error) {
288 368 console.log(error);
289 369 });
290 370 }
... ...