Commit 4a80e7e221f2be6b5e24c21ef4e7c9810cbb4501
1 parent
a5402981
[年会抽奖]调试上传图片
Showing
4 changed files
with
107 additions
and
143 deletions
lottery.html
... | ... | @@ -103,11 +103,11 @@ |
103 | 103 | <div class="avatar"> |
104 | 104 | <div class="avatar-img"> |
105 | 105 | <div class="avatar-list clearfix"> |
106 | - <img class="avatar-item" src="./img/mobile/vote_active.png"> | |
106 | + <img class="avatar-item" src="./img/mobile/default_avatar.png"> | |
107 | 107 | </div> |
108 | 108 | </div> |
109 | 109 | <div class="winner hide"> |
110 | - <img class="avatar-item" src="./img/mobile/vote_active.png"> | |
110 | + <img class="avatar-item" src="./img/mobile/default_avatar.png"> | |
111 | 111 | </div> |
112 | 112 | <div class="avatar-bg"></div> |
113 | 113 | </div> |
... | ... | @@ -116,7 +116,7 @@ |
116 | 116 | <div class="content"> |
117 | 117 | <div class="scroll-wrap"> |
118 | 118 | <div class="scroll-list clearfix"> |
119 | - <span class="scroll-item">赵晨昕</span> | |
119 | + <span class="scroll-item"></span> | |
120 | 120 | </div> |
121 | 121 | </div> |
122 | 122 | <div class="winner-name"></div> |
... | ... | @@ -127,7 +127,7 @@ |
127 | 127 | <div class="content"> |
128 | 128 | <div class="scroll-wrap"> |
129 | 129 | <div class="scroll-list clearfix"> |
130 | - <span class="scroll-item">001</span> | |
130 | + <span class="scroll-item"></span> | |
131 | 131 | </div> |
132 | 132 | </div> |
133 | 133 | <div class="winner-no"></div> | ... | ... |
lottery.js
... | ... | @@ -9,32 +9,7 @@ let prizeList = ['五等奖', '四等奖', '三等奖', '二等奖', '一等奖' |
9 | 9 | // 抽奖页面 |
10 | 10 | let action = { |
11 | 11 | prizeId: '', // 奖项ID |
12 | - userList: [ // 用户列表 | |
13 | - { | |
14 | - "id": "1", | |
15 | - "realname": "张三", | |
16 | - "headimg": "./img/mobile/logo.png", | |
17 | - "prize_no": "001" | |
18 | - }, | |
19 | - { | |
20 | - "id": "2", | |
21 | - "realname": "李四", | |
22 | - "headimg": "./img/mobile/dialog_close.png", | |
23 | - "prize_no": "002" | |
24 | - }, | |
25 | - { | |
26 | - "id": "3", | |
27 | - "realname": "王麻子", | |
28 | - "headimg": "./img/mobile/vote_active.png", | |
29 | - "prize_no": "003" | |
30 | - }, | |
31 | - { | |
32 | - "id": "4", | |
33 | - "realname": "路人甲", | |
34 | - "headimg": "./img/mobile/icon_seat.png", | |
35 | - "prize_no": "004" | |
36 | - } | |
37 | - ], | |
12 | + userList: [], // 用户列表 | |
38 | 13 | currentUser: null, // 当前显示的用户 |
39 | 14 | // 初始化数据 |
40 | 15 | init: function() { |
... | ... | @@ -57,17 +32,25 @@ let action = { |
57 | 32 | } else { |
58 | 33 | $('.select-page').hide(); |
59 | 34 | $('.result-page').css('display', 'flex'); |
60 | - | |
35 | + action.getUserList(); | |
36 | + // 初始化头像部分 | |
61 | 37 | $('.avatar-img, .user-info .scroll-wrap').show(); |
62 | 38 | $('.winner, .winner-name, .winner-no, .result-item').hide(); |
63 | - this.initUserList(); | |
64 | - | |
39 | + // 初始化按钮 | |
65 | 40 | $('.start-btn').show(); |
66 | 41 | $('.stop-btn, .continue-btn').hide(); |
67 | 42 | |
68 | 43 | $('.result-title').html(prizeList[self.prizeId - 1]); |
69 | 44 | } |
70 | 45 | }, |
46 | + // 控制显示弹框 | |
47 | + switchDialog: function(isShow) { | |
48 | + if (isShow) { | |
49 | + $('.dialog').show(); | |
50 | + } else { | |
51 | + $('.dialog').hide(); | |
52 | + } | |
53 | + }, | |
71 | 54 | // 进入抽奖页面 |
72 | 55 | goLottery: function() { |
73 | 56 | if (!this.prizeId) { |
... | ... | @@ -76,13 +59,26 @@ let action = { |
76 | 59 | } |
77 | 60 | this.togglePage(false); |
78 | 61 | }, |
79 | - // 控制显示弹框 | |
80 | - switchDialog: function(isShow) { | |
81 | - if (isShow) { | |
82 | - $('.dialog').show(); | |
83 | - } else { | |
84 | - $('.dialog').hide(); | |
85 | - } | |
62 | + // 获取中奖记录 | |
63 | + getWinnerList: function() { | |
64 | + let url = baseURL + "/apicp.LotteryList.php"; | |
65 | + let data = { | |
66 | + prize_id: action.prizeId | |
67 | + }; | |
68 | + let callback = function(res) { | |
69 | + if (res.data.length > 0) { | |
70 | + | |
71 | + } | |
72 | + }; | |
73 | + baseRquest.get(url, data, callback); | |
74 | + }, | |
75 | + getUserList: function() { | |
76 | + var url = '/apicp.UserList.php'; | |
77 | + var callback = function(res) { | |
78 | + action.userList = res.data; | |
79 | + action.initUserList(); | |
80 | + }; | |
81 | + baseRquest.get(url, '', callback); | |
86 | 82 | }, |
87 | 83 | initUserList() { |
88 | 84 | let imgStr = ''; |
... | ... | @@ -117,25 +113,27 @@ let action = { |
117 | 113 | imgTimer = this.lotteryAnimation($('.avatar-list'), '.avatar-item', 244); |
118 | 114 | nameTimer = this.lotteryAnimation($('.user-name .scroll-list'), '.scroll-item', 146); |
119 | 115 | prizeNoTimer = this.lotteryAnimation($('.user-no .scroll-list'), '.scroll-item', 146); |
120 | - | |
121 | - // 请求抽奖接口 | |
122 | - // let award = $('.user-award select').val(); | |
123 | - // let url = "/apicp.lottery.php"; | |
124 | - // baseRquest.post(url, {award : award}, data =>{ | |
125 | - // console.log(data); | |
126 | - // if (data.length == 0) { | |
127 | - // alert('没有多余的号码可以抽出'); | |
128 | - // location.reload(); | |
129 | - // } | |
130 | - // // 绑定数据到页面 | |
131 | - // this.bindData.winner.realname = data.realname; | |
132 | - // this.bindData.winner.number = data.user_id; | |
133 | - // this.bindData.winner.headimg = data.headimg; | |
134 | - // }); | |
135 | - | |
116 | + }, | |
117 | + // 抽奖动画,speed: 每次移动多少像素 | |
118 | + lotteryAnimation: function(dom, child, speed) { | |
119 | + var i = 0; | |
120 | + var interval = 100; // 定时器的速度 | |
121 | + dom.append(dom.find(child).eq(0).clone()); | |
122 | + var size = dom.find(child).size(); | |
123 | + var itemWidth = parseInt($(child).css('width')); | |
124 | + dom.css('width', itemWidth * size + 'px'); | |
125 | + var timer = setInterval(() => { | |
126 | + var left = speed * i; | |
127 | + if (left >= itemWidth * (size - 1)) { | |
128 | + i = 0; | |
129 | + } | |
130 | + dom.css('left', -left + 'px'); | |
131 | + i += 1; | |
132 | + }, interval); | |
133 | + return timer; | |
136 | 134 | }, |
137 | 135 | // 停止 |
138 | - stop: function(e){ | |
136 | + stop: function(e) { | |
139 | 137 | // 按钮效果 |
140 | 138 | $('.start-btn').hide(); |
141 | 139 | $('.stop-btn').hide(); |
... | ... | @@ -170,24 +168,8 @@ let action = { |
170 | 168 | $('.result-item').show(); |
171 | 169 | // 中奖名单列表重置 |
172 | 170 | }, |
173 | - // 抽奖动画,speed: 每次移动多少像素 | |
174 | - lotteryAnimation: function(dom, child, speed) { | |
175 | - var i = 0; | |
176 | - var interval = 100; // 定时器的速度 | |
177 | - dom.append(dom.find(child).eq(0).clone()); | |
178 | - var size = dom.find(child).size(); | |
179 | - var itemWidth = parseInt($(child).css('width')); | |
180 | - dom.css('width', itemWidth * size + 'px'); | |
181 | - var timer = setInterval(() => { | |
182 | - var left = speed * i; | |
183 | - if (left >= itemWidth * (size - 1)) { | |
184 | - i = 0; | |
185 | - } | |
186 | - dom.css('left', -left + 'px'); | |
187 | - i += 1; | |
188 | - }, interval); | |
189 | - return timer; | |
190 | - }, | |
171 | + // 抽奖请求 | |
172 | + | |
191 | 173 | // 继续抽奖 |
192 | 174 | reset: function() { |
193 | 175 | $('.radio-group .radio-item').removeClass('active'); |
... | ... | @@ -204,22 +186,6 @@ let action = { |
204 | 186 | baseRquest.post(url, {id : item.id}, data => { |
205 | 187 | action.winnerList(); |
206 | 188 | }); |
207 | - }, | |
208 | - // 中奖名单,传入参数:中奖类型(一等,二等),type=2是中奖名单 | |
209 | - winnerList:function(){ | |
210 | - // 获取中奖者名单, | |
211 | - let url = "/apicp.GetUserList.php"; | |
212 | - let award = $('.user-award select').val(); | |
213 | - baseRquest.get(url, {award : award, type : 2}, data => { | |
214 | - this.bindData.lottery.winnerCount = data.length; | |
215 | - this.bindData.lottery.award = $('.user-award select').val(); | |
216 | - for (let i = 1; i <= data.length; i++) { | |
217 | - data[i-1].no = i; | |
218 | - } | |
219 | - action.winnerListData = data; | |
220 | - console.log(data); | |
221 | - dataListBind('winner-bind', 'winner', data); | |
222 | - }); | |
223 | 189 | } |
224 | 190 | } |
225 | 191 | // 系统设置动作 |
... | ... | @@ -429,17 +395,11 @@ let dataBind = { |
429 | 395 | let baseRquest = { |
430 | 396 | // get请求 |
431 | 397 | get: function(url, params, callback) { |
432 | - let token = localStorage["token"]; | |
433 | 398 | axios.defaults.baseURL = baseURL; |
434 | 399 | axios.get(url, { |
435 | - params : params, | |
436 | - headers: { | |
437 | - 'Content-Type': 'application/x-www-form-urlencoded', | |
438 | - token: token | |
439 | - } | |
440 | - }).then(function (response) { | |
441 | - if (response.status == 200) | |
442 | - { | |
400 | + params : params | |
401 | + }).then(function(response) { | |
402 | + if (response.status == 200) { | |
443 | 403 | data = response.data; |
444 | 404 | if (!!data) { |
445 | 405 | // 过滤错误信息,统一抛出 |
... | ... | @@ -449,45 +409,44 @@ let baseRquest = { |
449 | 409 | callback(data.result); |
450 | 410 | } |
451 | 411 | } |
452 | - }else { | |
412 | + } else { | |
453 | 413 | alert('get无法访问接口'); |
454 | 414 | } |
455 | - }) | |
456 | - .catch(function (error) { | |
457 | - }); | |
415 | + }).catch(function(error) { | |
416 | + console.log(error) | |
417 | + }); | |
458 | 418 | }, |
459 | - | |
460 | - // post请求 | |
461 | - post: function(url, params, callback) { | |
462 | - let token = localStorage["token"]; | |
419 | + // post请求 | |
420 | + post: function(url, params, callback) { | |
463 | 421 | axios.defaults.baseURL = baseURL; |
464 | 422 | let data = new URLSearchParams(); |
465 | 423 | Object.keys(params).forEach(function(key){ |
466 | 424 | data.append(key, params[key]); |
467 | 425 | }); |
468 | - axios.post(url, data,{ | |
469 | - headers: { | |
470 | - 'Content-Type': 'application/x-www-form-urlencoded', | |
471 | - token: token | |
426 | + axios.post(url, data, { | |
427 | + headers: { | |
428 | + 'Content-Type': 'application/x-www-form-urlencoded' | |
472 | 429 | } |
473 | - }).then(function (response) { | |
474 | - if (response.status == 200) | |
475 | - { | |
476 | - data = response.data; | |
477 | - if (!!data) { | |
478 | - // 过滤错误信息,统一抛出 | |
479 | - if (data.errcode != 0 && data.errcode != 200) { | |
480 | - alert(data.errmsg); | |
481 | - } else { | |
482 | - callback(data.result); | |
483 | - } | |
430 | + }).then(function(response) { | |
431 | + if (response.status == 200) { | |
432 | + data = response.data; | |
433 | + if (!!data) { | |
434 | + // 过滤错误信息,统一抛出 | |
435 | + if (data.errcode != 0 && data.errcode != 200) { | |
436 | + if (url.search('SignIn') !== -1) { | |
437 | + action.switchDialog('#sign_in_dialog', true); | |
438 | + } else { | |
439 | + alert(data.errmsg); | |
440 | + } | |
441 | + } else { | |
442 | + callback(data.result); | |
443 | + } | |
444 | + } | |
445 | + } else { | |
446 | + alert('post无法访问接口'); | |
484 | 447 | } |
485 | - }else { | |
486 | - alert('post无法访问接口'); | |
487 | - } | |
488 | - }) | |
489 | - .catch(function (error) { | |
448 | + }).catch(function(error) { | |
490 | 449 | console.log(error); |
491 | 450 | }); |
492 | 451 | } |
493 | -} | |
494 | 452 | \ No newline at end of file |
453 | +} | ... | ... |
mobile.html
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | .pic-img-bg {position: absolute;top: 0;left: 0;z-index: 1;width: 100%;height: 100%;background: url('./img/mobile/pic_avatar_bg.png') no-repeat;background-size: 100% 100%;} |
63 | 63 | .pic-avatar {width: 2.84rem;height: 2.84rem;border-radius: 50%;} |
64 | 64 | .pic-btn-wrap {position: absolute;bottom: 1.2rem;left: 50%;transform: translateX(-50%);width: 6.82rem;} |
65 | - .pic-btn-album {display: flex;align-items: center;justify-content: center;margin-top: .3rem;} | |
65 | + .pic-btn-album {width: 3rem;margin: .3rem auto 0; display: flex;align-items: center;justify-content: center;} | |
66 | 66 | .pic-btn-album .album-text {font-size: .28rem;color: #fff;margin-right: .1rem;} |
67 | 67 | .pic-btn-album .pic-arrow {width: .32rem;height: .32rem;background: url('./img/mobile/pic_arrow.png') no-repeat;background-size: contain;} |
68 | 68 | |
... | ... | @@ -152,10 +152,10 @@ |
152 | 152 | </div> |
153 | 153 | <div class="pic-btn-wrap"> |
154 | 154 | <!-- 自拍出境 --> |
155 | - <div class="common-btn" onclick="action.goHome()"> | |
155 | + <div class="common-btn" onclick="action.openCamera(1)"> | |
156 | 156 | <img class="common-btn-bg" src="./img/mobile/pic_btn1.png"> |
157 | 157 | </div> |
158 | - <div class="pic-btn-album"> | |
158 | + <div class="pic-btn-album" onclick="action.openCamera(2)"> | |
159 | 159 | <span class="album-text">还是相册选一张吧</span> |
160 | 160 | <i class="pic-arrow"></i> |
161 | 161 | </div> |
... | ... | @@ -166,10 +166,10 @@ |
166 | 166 | <img class="common-btn-bg" src="./img/mobile/pic_btn2.png"> |
167 | 167 | </div> |
168 | 168 | <!-- 再拍一次 --> |
169 | - <div class="common-btn" onclick="action.openCamera()"> | |
169 | + <div class="common-btn" onclick="action.openCamera(1)"> | |
170 | 170 | <img class="common-btn-bg" src="./img/mobile/pic_btn3.png"> |
171 | 171 | </div> |
172 | - <div class="pic-btn-album"> | |
172 | + <div class="pic-btn-album" onclick="action.openCamera(2)"> | |
173 | 173 | <span class="album-text">再翻翻相册吧</span> |
174 | 174 | <i class="pic-arrow"></i> |
175 | 175 | </div> | ... | ... |
mobile.js
... | ... | @@ -81,16 +81,21 @@ var action = { |
81 | 81 | $('.home').hide(); |
82 | 82 | this.getSeatList(); |
83 | 83 | }, |
84 | - // 打开摄像头 | |
85 | - openCamera: function() { | |
86 | - // if (action.isRun == 0) { | |
87 | - // alert('尚未开启,请稍后尝试'); | |
88 | - // return; | |
89 | - // } | |
84 | + // 打开摄像头,type=1: 唤起摄像头,type=2: 打开相册 | |
85 | + openCamera: function(type = 1) { | |
86 | + console.log('type: ', type) | |
87 | + var sourceType = []; | |
88 | + if (type === 1) { | |
89 | + sourceType = ['camera']; | |
90 | + } else if (type === 2) { | |
91 | + sourceType = ['album']; | |
92 | + } else { | |
93 | + sourceType = ['camera', 'album']; | |
94 | + } | |
90 | 95 | wx.chooseImage({ |
91 | 96 | count: 1, // 默认9 |
92 | 97 | sizeType: ['compressed'], // 'original', 'compressed'指定是原图还是压缩图,默认都有 |
93 | - sourceType: ['camera', 'album'], // 'album', 'camera'指定来源是相册还是相机,默认都有 | |
98 | + sourceType: sourceType, // 'album', 'camera'指定来源是相册还是相机,默认都有 | |
94 | 99 | success: function(res) { |
95 | 100 | var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片 |
96 | 101 | wx.uploadImage({ |
... | ... | @@ -146,8 +151,8 @@ var action = { |
146 | 151 | }; |
147 | 152 | var url = baseURL + '/apicp.UploadHeadImg.php'; |
148 | 153 | var callback = function(data) { |
149 | - // TODO 存储用户头像 | |
150 | 154 | action.userAvatar = data.headimg; |
155 | + localStorage.setItem('userAvatar', action.userAvatar); | |
151 | 156 | action.goHome(); |
152 | 157 | }; |
153 | 158 | baseRquest.post(url, data, callback); |
... | ... | @@ -310,7 +315,7 @@ var action = { |
310 | 315 | } |
311 | 316 | |
312 | 317 | // api接口数据请求,数据交互引用的axios |
313 | -let baseRquest = { | |
318 | +var baseRquest = { | |
314 | 319 | // get请求 |
315 | 320 | get: function(url, params, callback) { |
316 | 321 | axios.defaults.baseURL = baseURL; | ... | ... |