Skip to content

Commit 7592bea

Browse files
committed
初始化
1 parent 3eed533 commit 7592bea

File tree

8 files changed

+321
-0
lines changed

8 files changed

+321
-0
lines changed

app.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//app.js
2+
App({
3+
onLaunch: function() {
4+
//调用API从本地缓存中获取数据
5+
var logs = wx.getStorageSync('logs') || []
6+
logs.unshift(Date.now())
7+
wx.setStorageSync('logs', logs)
8+
},
9+
10+
getUserInfo: function(cb) {
11+
var that = this
12+
if (this.globalData.userInfo) {
13+
typeof cb == "function" && cb(this.globalData.userInfo)
14+
} else {
15+
//调用登录接口
16+
wx.getUserInfo({
17+
withCredentials: false,
18+
success: function(res) {
19+
that.globalData.userInfo = res.userInfo
20+
typeof cb == "function" && cb(that.globalData.userInfo)
21+
}
22+
})
23+
}
24+
},
25+
26+
globalData: {
27+
userInfo: null
28+
}
29+
})

app.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pages": [
3+
"pages/turntable/turntable"
4+
],
5+
"window": {
6+
"backgroundTextStyle": "light",
7+
"navigationBarBackgroundColor": "#fff",
8+
"navigationBarTitleText": "WeChat",
9+
"navigationBarTextStyle": "black"
10+
}
11+
}

app.wxss

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**app.wxss**/
2+
.container {
3+
height: 100%;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: space-between;
8+
padding: 200rpx 0;
9+
box-sizing: border-box;
10+
}

pages/turntable/turntable.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
let canRoll = true, //加控制,防止用户点击两次
2+
num = 1, //用在动画上,让用户在第二次点击的时候可以接着上次转动的角度继续转
3+
lotteryArrLen = 0, //放奖品的数组的长度
4+
lottery = ['奖品1', '奖品2']; //放奖品
5+
Page({
6+
data: {},
7+
8+
onLoad(opt) {
9+
this.setPlateData(); //执行设置转盘表面的文字
10+
let that = this;
11+
let aniData = wx.createAnimation({ //创建动画对象
12+
duration: 2000,
13+
timingFunction: 'ease'
14+
});
15+
this.aniData = aniData; //将动画对象赋值给this的aniData属性
16+
},
17+
setPlateData() { //设置奖品数组
18+
lotteryArrLen = lottery.length; //获取奖品数组的长度,用来判断
19+
if (lotteryArrLen < 2) { //数组的奖品只有一个,扩展数组的长度到4
20+
let evenArr = new Array(4); //创建一个数组,方便操作。
21+
for (let i = 0; i < 4; i++) {
22+
if (i % 2 == 1) { //这里为什么要取1是为了在默认的界面将指针放在谢谢的地方,防止别人拿着中奖的截图来要奖品
23+
evenArr[i] = lottery[0]; //将原数组的内容赋值到新的数组
24+
} else {
25+
evenArr[i] = '谢谢' //在数组中间隔插入谢谢
26+
}
27+
}
28+
lottery = [...evenArr]; //将整合好的数组赋值给lottery数组
29+
} else { //数组中的奖品超过1个,则正常扩展数组,扩展的数组为原来的2倍
30+
let dataLen = 0; //用来放原来数组的索引
31+
let evenArr = new Array(lotteryArrLen * 2); //创建扩展数组
32+
for (let i = 0; i < (lotteryArrLen * 2); i++) {
33+
if (i % 2 == 1) {
34+
evenArr[i] = lottery[dataLen]; //将原来数组的值赋值给新数组
35+
dataLen++; //原来数组的索引加一
36+
} else {
37+
evenArr[i] = '谢谢'
38+
}
39+
}
40+
lottery = [...evenArr]; //将整合好的数组赋值给lottery数组
41+
}
42+
43+
lotteryArrLen = lottery.length; //获取新的数组长度
44+
this.setData({
45+
lottery: lottery //设置好值,用于页面展示
46+
})
47+
},
48+
startRollTap() { //开始转盘
49+
let that = this;
50+
if (canRoll) {
51+
canRoll = false;
52+
let aniData = this.aniData; //获取this对象上的动画对象
53+
let rightNum = ~~(Math.random() * lotteryArrLen); //生成随机数
54+
console.log(`随机数是${rightNum}`);
55+
console.log(`奖品是:${lottery[rightNum]}`);
56+
aniData.rotate(3600 * num - 360 / lotteryArrLen * rightNum).step(); //设置转动的圈数
57+
this.setData({
58+
aniData: aniData.export()
59+
})
60+
num++;
61+
canRoll = true;
62+
}
63+
}
64+
})

pages/turntable/turntable.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

pages/turntable/turntable.wxml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<view class="container">
2+
<view class="plate-wrap-box">
3+
<view class="plate-border" animation="{{ aniData }}">
4+
<!-- 转盘以及文字 -->
5+
<view class="plate-wrap">
6+
<view class="plate-box" wx:for="{{ lottery }}" wx:key="" style="top:-{{ (lottery.length - 6)<=2?(36+4*(lottery.length - 6)):50 }}rpx;transform-origin: 50% {{ (lottery.length - 6) <=2?(256+4*(lottery.length - 6)):270 }}rpx;border-top: {{ (lottery.length - 6) <=2?(256+4*(lottery.length - 6)):270 }}rpx solid #{{ index % 2==0?'ffeebe':'ffbb04' }};transform:translate(-50%,0) rotate({{ 360 / lottery.length * ( index )}}deg);border-left: {{ 440 / lottery.length * 2 }}rpx solid transparent;border-right: {{ 440 / lottery.length * 2 }}rpx solid transparent;">
7+
<text class="text-box" style="color:#{{ index % 2==0?'ffbb04':'ffeebe' }}">{{ item }}</text>
8+
</view>
9+
</view>
10+
<!-- 边框的小灯泡 -->
11+
<view class="plate-wrap plate-light">
12+
<view class="plate-box" wx:for="{{ lottery }}" wx:key="" style="top:-{{ (lottery.length - 6)<=2?(44+4*(lottery.length - 6)):60 }}rpx; transform-origin: 50% {{ (lottery.length - 6) <=2?(294+4*(lottery.length - 6)):310 }}rpx;border-top: {{ (lottery.length - 6) <=2?(294+4*(lottery.length - 6)):310 }}rpx solid transparent;transform:translate(-50%,0) rotate({{ 360 / lottery.length * ( index )}}deg);border-left: {{ 500 / lottery.length * 2 }}rpx solid transparent;border-right: {{ 500 / lottery.length * 2 }}rpx solid transparent;">
13+
<view class="bulb"></view>
14+
</view>
15+
</view>
16+
</view>
17+
<view class="plate-btn-wrap" bindtap="startRollTap">
18+
<view class="plate-btn-box">
19+
<view class="plate-inner-btn">
20+
<text>开始
21+
抽奖</text>
22+
</view>
23+
</view>
24+
</view>
25+
<view class="lottery-plate-shadow"></view>
26+
</view>
27+
</view>

pages/turntable/turntable.wxss

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
page {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
6+
.container {
7+
z-index: 1;
8+
padding-top: 220rpx;
9+
padding-bottom: 20rpx;
10+
box-sizing: border-box;
11+
height: 100%;
12+
background-color: #e74143;
13+
}
14+
15+
.plate-wrap-box {
16+
position: relative;
17+
z-index: 999;
18+
width: 500rpx;
19+
height: 500rpx;
20+
border-radius: 50%;
21+
margin: 0 auto 60rpx;
22+
}
23+
24+
.plate-border {
25+
position: relative;
26+
z-index: 9;
27+
width: 500rpx;
28+
height: 500rpx;
29+
background-color: #ffbe04;
30+
border-radius: 50%;
31+
}
32+
33+
.plate-wrap {
34+
position: absolute;
35+
left: 50%;
36+
top: 50%;
37+
transform: translate(-50%, -50%);
38+
z-index: 9;
39+
width: 440rpx;
40+
height: 440rpx;
41+
border: 1rpx solid #e88605;
42+
border-radius: 50%;
43+
overflow: hidden;
44+
margin: auto;
45+
}
46+
47+
.plate-light {
48+
z-index: 1;
49+
width: 500rpx;
50+
height: 500rpx;
51+
border: none;
52+
}
53+
54+
.plate-box {
55+
position: absolute;
56+
z-index: 1;
57+
left: 50%;
58+
width: 0;
59+
height: 0;
60+
font-size: 24rpx;
61+
}
62+
63+
.bulb {
64+
position: absolute;
65+
width: 16rpx;
66+
height: 16rpx;
67+
left: 50%;
68+
top: -242rpx;
69+
transform: translate(-50%, 0);
70+
border-radius: 50%;
71+
background-color: #fff0c7;
72+
filter: blur(0.5rpx);
73+
}
74+
75+
.text-box {
76+
position: absolute;
77+
text-align: center;
78+
display: inline-block;
79+
width: 15rpx;
80+
word-break: break-all;
81+
top: -200rpx;
82+
transform: translate(-100%, 0);
83+
font-size: 28rpx;
84+
}
85+
86+
.plate-btn-wrap {
87+
position: absolute;
88+
z-index: 10;
89+
left: 50%;
90+
top: 50%;
91+
transform: translate(-50%, -50%);
92+
width: 110rpx;
93+
height: 110rpx;
94+
border-radius: 50%;
95+
}
96+
97+
.plate-btn-wrap::before {
98+
content: '';
99+
position: absolute;
100+
z-index: 9;
101+
left: calc(50% - 10rpx);
102+
top: -40rpx;
103+
transform: translate(-50%, 0);
104+
width: 0;
105+
height: 0;
106+
border-bottom: 80rpx solid #e7211b;
107+
border-left: 20rpx solid transparent;
108+
}
109+
110+
.plate-btn-wrap::after {
111+
content: '';
112+
position: absolute;
113+
z-index: 9;
114+
left: calc(50% + 10rpx);
115+
top: -40rpx;
116+
transform: translate(-50%, 0);
117+
width: 0;
118+
height: 0;
119+
border-bottom: 80rpx solid #ca1518;
120+
border-right: 20rpx solid transparent;
121+
}
122+
123+
.plate-btn-box {
124+
position: relative;
125+
z-index: 11;
126+
width: 100%;
127+
height: 100%;
128+
border-radius: 50%;
129+
background-color: #e62d2d;
130+
display: flex;
131+
justify-content: center;
132+
align-items: center;
133+
}
134+
135+
.plate-inner-btn {
136+
position: relative;
137+
z-index: 999;
138+
width: 90rpx;
139+
height: 90rpx;
140+
border-radius: 50%;
141+
background-color: #ca1518;
142+
font-size: 28rpx;
143+
color: #fdcf03;
144+
display: flex;
145+
justify-content: center;
146+
align-items: center;
147+
}
148+
149+
.lottery-plate-shadow {
150+
position: absolute;
151+
z-index: 1;
152+
width: 100%;
153+
height: 50rpx;
154+
border-radius: 50%;
155+
background-color: #d50a0c;
156+
filter: blur(4rpx);
157+
bottom: -35rpx;
158+
}

utils/util.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function formatTime(date) {
2+
var year = date.getFullYear()
3+
var month = date.getMonth() + 1
4+
var day = date.getDate()
5+
6+
var hour = date.getHours()
7+
var minute = date.getMinutes()
8+
var second = date.getSeconds()
9+
10+
11+
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12+
}
13+
14+
function formatNumber(n) {
15+
n = n.toString()
16+
return n[1] ? n : '0' + n
17+
}
18+
19+
module.exports = {
20+
formatTime: formatTime
21+
}

0 commit comments

Comments
 (0)