@cloudbase/weda-ui 1.0.21 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -3
- package/src/configs/components/dataView.json +1 -1
- package/src/configs/components/listView.json +1 -1
- package/src/configs/components/lottery.json +151 -0
- package/src/configs/index.js +2 -0
- package/src/index.js +2 -0
- package/src/mp/components/button/index.wxml +1 -2
- package/src/mp/components/form/form/index.wxml +1 -2
- package/src/mp/components/form/select/index.js +8 -20
- package/src/mp/components/form/select/region/index.js +6 -3
- package/src/mp/components/listView/index.js +5 -16
- package/src/mp/components/lottery/index.js +270 -0
- package/src/mp/components/lottery/index.json +4 -0
- package/src/mp/components/lottery/index.wxml +43 -0
- package/src/mp/components/lottery/index.wxss +317 -0
- package/src/mp/components/wxOpenApi/phone/index.js +1 -1
- package/src/mp/index.json +4 -3
- package/src/mp/utils/constant.js +15 -0
- package/src/mp/utils/lodash.js +2 -0
- package/src/web/components/chart/common/config/line.js +1 -1
- package/src/web/components/form/checkbox/index.tsx +6 -0
- package/src/web/components/form/formcell/index.tsx +10 -5
- package/src/web/components/form/radio/index.tsx +6 -0
- package/src/web/components/form/select/h5.tsx +5 -24
- package/src/web/components/form/select/index.tsx +4 -17
- package/src/web/components/form/tips/index.css +4 -0
- package/src/web/components/form/tips/index.tsx +4 -3
- package/src/web/components/index.js +1 -0
- package/src/web/components/listView/index.tsx +4 -17
- package/src/web/components/lottery/index.css +327 -0
- package/src/web/components/lottery/index.tsx +567 -0
- package/src/web/components/lottery/lotteryUtil.ts +130 -0
- package/src/web/utils/{constant.js → constant.ts} +17 -2
- package/src/web/utils/lodash.ts +2 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-key */
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import { usePlatform } from '../../utils/platform';
|
|
4
|
+
import classNames from '../../utils/classnames';
|
|
5
|
+
import './index.css';
|
|
6
|
+
import { CommonPropsType } from '../../types';
|
|
7
|
+
import { ConfigProvider } from 'tea-component';
|
|
8
|
+
import LotteryAction from './lotteryUtil';
|
|
9
|
+
|
|
10
|
+
const CLASS_PREFIX = 'weda-lottery';
|
|
11
|
+
const lotteryAction = new LotteryAction();
|
|
12
|
+
export default function Lottery({
|
|
13
|
+
className,
|
|
14
|
+
id,
|
|
15
|
+
style,
|
|
16
|
+
prizeList,
|
|
17
|
+
enablePrize,
|
|
18
|
+
prizeResult,
|
|
19
|
+
events,
|
|
20
|
+
}: PropsType) {
|
|
21
|
+
const platform = usePlatform();
|
|
22
|
+
const [activedId, setActivedId] = useState(-1);
|
|
23
|
+
const [isStartLottery, setIsStartLottery] = useState(false);
|
|
24
|
+
const [lotteryList, setLotteryList] = useState([]);
|
|
25
|
+
const [btnActived, setBtnActived] = useState(false);
|
|
26
|
+
|
|
27
|
+
//获取初始化默认数据,数据不足8条设置默认,超过8条获取前8条
|
|
28
|
+
const lotteryListDefault = () => {
|
|
29
|
+
let list = [];
|
|
30
|
+
if (prizeList == null) {
|
|
31
|
+
return list;
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < 8; i++) {
|
|
34
|
+
if (i < prizeList.length) {
|
|
35
|
+
let prize = prizeList[i];
|
|
36
|
+
list.push({
|
|
37
|
+
idx: i + 1,
|
|
38
|
+
selected: false,
|
|
39
|
+
desc: prize.title,
|
|
40
|
+
src: prize.image,
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
list.push({
|
|
44
|
+
idx: i + 1,
|
|
45
|
+
selected: false,
|
|
46
|
+
desc: '',
|
|
47
|
+
src: '',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return list;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const startLottery = () => {
|
|
55
|
+
setLotteryList(lotteryListDefault());
|
|
56
|
+
setBtnActived(true);
|
|
57
|
+
if (lotteryAction.isStart) return;
|
|
58
|
+
events?.clickLotteryButton();
|
|
59
|
+
setIsStartLottery(true);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
setLotteryList(lotteryListDefault());
|
|
64
|
+
}, [prizeList]);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
lotteryAction.animationCallback = ({ idx, isEnd }) => {
|
|
68
|
+
setActivedId(idx == -1 ? 0 : idx);
|
|
69
|
+
if (isEnd) {
|
|
70
|
+
setBtnActived(false);
|
|
71
|
+
let list = lotteryList.map((item, index) => {
|
|
72
|
+
if (index === idx - 1) {
|
|
73
|
+
item.selected = true;
|
|
74
|
+
} else {
|
|
75
|
+
item.selected = false;
|
|
76
|
+
}
|
|
77
|
+
return item;
|
|
78
|
+
});
|
|
79
|
+
setLotteryList(list);
|
|
80
|
+
setActivedId(-1);
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
events.finishLottery({
|
|
83
|
+
prize: idx,
|
|
84
|
+
result: list[idx - 1],
|
|
85
|
+
});
|
|
86
|
+
//延迟700毫秒显示的视觉效果更好,否则看不清结果就弹出dialog盖住了
|
|
87
|
+
}, 700);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, [lotteryList]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
// 当满足开启抽奖条件并且点击了开奖开关时,启用抽奖
|
|
94
|
+
if (enablePrize && isStartLottery) {
|
|
95
|
+
lotteryAction.start(prizeResult, () => {
|
|
96
|
+
window.app.showToast({
|
|
97
|
+
title: '网络异常',
|
|
98
|
+
icon: 'none',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
// 当不选取变量作为结果的时候,按照设置给定结果
|
|
102
|
+
lotteryAction.end(prizeResult);
|
|
103
|
+
setIsStartLottery(false);
|
|
104
|
+
} else if (!enablePrize) {
|
|
105
|
+
//立马停止抽奖
|
|
106
|
+
lotteryAction.stop();
|
|
107
|
+
}
|
|
108
|
+
}, [isStartLottery, enablePrize]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
// 设置抽奖结果
|
|
112
|
+
lotteryAction.end(prizeResult);
|
|
113
|
+
}, [prizeResult]);
|
|
114
|
+
|
|
115
|
+
const [widthRatio, setWidthRatio] = useState(1);
|
|
116
|
+
const [heightRatio, setHeightRatio] = useState(1);
|
|
117
|
+
|
|
118
|
+
// 上下5个球的宽度
|
|
119
|
+
const [dotWidth, setDotWidth] = useState(217 / 14);
|
|
120
|
+
// 左右5个球的高度
|
|
121
|
+
const [dotHeight, setDotHeight] = useState(217 / 14);
|
|
122
|
+
|
|
123
|
+
const standardWidth = 326;
|
|
124
|
+
const standardHeight = 326;
|
|
125
|
+
|
|
126
|
+
const cls = classNames({
|
|
127
|
+
[CLASS_PREFIX]: true,
|
|
128
|
+
[className]: className,
|
|
129
|
+
[`${CLASS_PREFIX}-mobile`]: platform === 'h5',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 将获取的style 转化为 px, 用户输入的单位可能有(纯数字,px, rem, %, rpx)
|
|
133
|
+
// 注: 前端输入宽高,不带单位和带rem单位,code 中获取的都是rem 单位,也就是输入1304,输出‘46.5714rem’; 输入‘1304rem’, 输出‘1304rem’, 所以rem目前不支持正常的比列
|
|
134
|
+
// 带上px单位和不带单位,输出的都是rem,且转化的值一样的,所以不需要特殊处理,也就是 输入 1304 和 1304px ,前端拿到的都是‘46.5714rem’
|
|
135
|
+
// rpx 是小程序的单位,并且在pc 上加病没作用,所以rpx 不处理
|
|
136
|
+
// % 暂时也不处理,因为不确定用户的百分比是以什么为标准的
|
|
137
|
+
const getStyleUnit = (targetValue: string | number) => {
|
|
138
|
+
if (!targetValue) return -1;
|
|
139
|
+
let value = targetValue.toString();
|
|
140
|
+
|
|
141
|
+
// 获取单位
|
|
142
|
+
const fotData = value.match(/^\d+(?:\.\d+)?([a-zA-Z%]+)?$/);
|
|
143
|
+
let unit = 'rem';
|
|
144
|
+
if (fotData && fotData[1]) {
|
|
145
|
+
unit = fotData[1];
|
|
146
|
+
}
|
|
147
|
+
return unit;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const getRatio = (value: number, unit: string | number) => {
|
|
151
|
+
let actualValue;
|
|
152
|
+
if (unit.toString() === 'rem') {
|
|
153
|
+
actualValue = value * 14 * 2;
|
|
154
|
+
}
|
|
155
|
+
return actualValue;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// 通过页面配置拿到用户设置的宽,高,直接获取的宽和高,会被转化为rem, 需要将rem 转为 px. 规则: e/2/14
|
|
159
|
+
// css 输出的px到页面rem, 转化规则为: e/14
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!style || style == undefined || platform === 'h5') {
|
|
162
|
+
setWidthRatio(1);
|
|
163
|
+
setDotWidth(217 / 14);
|
|
164
|
+
setHeightRatio(1);
|
|
165
|
+
setDotHeight(217 / 14);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (style && style !== undefined) {
|
|
169
|
+
// 如果宽和高不存在,则还远吗比例为默认值-1,也就是保持视觉稿默认的宽和高
|
|
170
|
+
if (!style.width) {
|
|
171
|
+
setWidthRatio(1);
|
|
172
|
+
setDotWidth(217 / 14);
|
|
173
|
+
}
|
|
174
|
+
if (!style.height) {
|
|
175
|
+
setHeightRatio(1);
|
|
176
|
+
setDotHeight(217 / 14);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (style.width) {
|
|
180
|
+
// 现将获取的rem 转化为px
|
|
181
|
+
const actualValue = getRatio(
|
|
182
|
+
parseFloat(style.width.toString()),
|
|
183
|
+
getStyleUnit(style.width)
|
|
184
|
+
);
|
|
185
|
+
// setWidthRatio();
|
|
186
|
+
const setValue =
|
|
187
|
+
Math.floor((actualValue / (standardWidth * 2)) * 1000) / 1000;
|
|
188
|
+
setWidthRatio(setValue);
|
|
189
|
+
const dotWidth = (setValue * 43 * 4 + setValue * 9 * 5) / 14;
|
|
190
|
+
setDotWidth(dotWidth);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (style.height) {
|
|
194
|
+
// 现将获取的rem 转化为px
|
|
195
|
+
const actualValue = getRatio(
|
|
196
|
+
parseFloat(style.height.toString()),
|
|
197
|
+
getStyleUnit(style.height)
|
|
198
|
+
);
|
|
199
|
+
const setValue =
|
|
200
|
+
Math.floor((actualValue / (standardHeight * 2)) * 1000) / 1000;
|
|
201
|
+
setHeightRatio(setValue);
|
|
202
|
+
const dotHeight = (setValue * 43 * 4 + setValue * 9 * 5) / 14;
|
|
203
|
+
setDotHeight(dotHeight);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}, [style]);
|
|
207
|
+
|
|
208
|
+
const renderDot = (direction: string, list: string[]) => {
|
|
209
|
+
return (
|
|
210
|
+
<>
|
|
211
|
+
<div
|
|
212
|
+
className={classNames(
|
|
213
|
+
`${CLASS_PREFIX}__dot`,
|
|
214
|
+
`${CLASS_PREFIX}__dot-${direction}`
|
|
215
|
+
)}
|
|
216
|
+
>
|
|
217
|
+
{list.map((item, index) => {
|
|
218
|
+
return (
|
|
219
|
+
<div
|
|
220
|
+
key={index}
|
|
221
|
+
className={`${CLASS_PREFIX}__dot-item`}
|
|
222
|
+
style={{
|
|
223
|
+
width: `${(9 * widthRatio) / 14}rem`,
|
|
224
|
+
height: `${(9 * heightRatio) / 14}rem`,
|
|
225
|
+
marginBottom:
|
|
226
|
+
`${direction}` === 'vertical'
|
|
227
|
+
? `${(43 * heightRatio) / 14}rem`
|
|
228
|
+
: '0',
|
|
229
|
+
marginRight:
|
|
230
|
+
`${direction}` === 'horizontal'
|
|
231
|
+
? `${(43 * widthRatio) / 14}rem`
|
|
232
|
+
: '0',
|
|
233
|
+
}}
|
|
234
|
+
></div>
|
|
235
|
+
);
|
|
236
|
+
})}
|
|
237
|
+
</div>
|
|
238
|
+
</>
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const dotList = [
|
|
243
|
+
{
|
|
244
|
+
single: true,
|
|
245
|
+
position: 'left-top',
|
|
246
|
+
direction: '',
|
|
247
|
+
list: [],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
single: true,
|
|
251
|
+
position: 'left-bottom',
|
|
252
|
+
direction: '',
|
|
253
|
+
list: [],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
single: true,
|
|
257
|
+
position: 'right-top',
|
|
258
|
+
direction: '',
|
|
259
|
+
list: [],
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
single: true,
|
|
263
|
+
position: 'right-bottom',
|
|
264
|
+
direction: '',
|
|
265
|
+
list: [],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
single: false,
|
|
269
|
+
position: 'top',
|
|
270
|
+
direction: 'horizontal',
|
|
271
|
+
list: ['1', '2', '3', '4', '5'],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
single: false,
|
|
275
|
+
position: 'bottom',
|
|
276
|
+
direction: 'horizontal',
|
|
277
|
+
list: ['1', '2', '3', '4', '5'],
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
single: false,
|
|
281
|
+
position: 'left',
|
|
282
|
+
direction: 'vertical',
|
|
283
|
+
list: ['1', '2', '3', '4', '5'],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
single: false,
|
|
287
|
+
position: 'right',
|
|
288
|
+
direction: 'vertical',
|
|
289
|
+
list: ['1', '2', '3', '4', '5'],
|
|
290
|
+
},
|
|
291
|
+
];
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<ConfigProvider classPrefix="wedatea2td">
|
|
295
|
+
<div className="body" key="lottery" data-testid="lottery">
|
|
296
|
+
<div className={cls} id={id} style={style}>
|
|
297
|
+
<div className={`${CLASS_PREFIX}__wrap`}>
|
|
298
|
+
{dotList.map((dot, index) => {
|
|
299
|
+
return (
|
|
300
|
+
<>
|
|
301
|
+
{dot.single && (
|
|
302
|
+
<div
|
|
303
|
+
key={`${dot.direction}-${index}`}
|
|
304
|
+
className={classNames(
|
|
305
|
+
`${CLASS_PREFIX}__dot-single`,
|
|
306
|
+
`${CLASS_PREFIX}__dot-${dot.position}`
|
|
307
|
+
)}
|
|
308
|
+
style={{
|
|
309
|
+
width: `${(9 * widthRatio) / 14}rem`,
|
|
310
|
+
height: `${(9 * heightRatio) / 14}rem`,
|
|
311
|
+
top:
|
|
312
|
+
`${dot.position}` === 'left-top' ||
|
|
313
|
+
`${dot.position}` === 'right-top'
|
|
314
|
+
? `${(9 * heightRatio) / 14}rem`
|
|
315
|
+
: '',
|
|
316
|
+
bottom:
|
|
317
|
+
`${dot.position}` === 'left-bottom' ||
|
|
318
|
+
`${dot.position}` === 'right-bottom'
|
|
319
|
+
? `${(9 * heightRatio) / 14}rem`
|
|
320
|
+
: '',
|
|
321
|
+
left:
|
|
322
|
+
`${dot.position}` === 'left-top' ||
|
|
323
|
+
`${dot.position}` === 'left-bottom'
|
|
324
|
+
? `${(6 * widthRatio) / 14}rem`
|
|
325
|
+
: '',
|
|
326
|
+
right:
|
|
327
|
+
`${dot.position}` === 'right-top' ||
|
|
328
|
+
`${dot.position}` === 'right-bottom'
|
|
329
|
+
? `${(6 * widthRatio) / 14}rem`
|
|
330
|
+
: '',
|
|
331
|
+
}}
|
|
332
|
+
></div>
|
|
333
|
+
)}
|
|
334
|
+
{!dot.single && (
|
|
335
|
+
<div
|
|
336
|
+
key={`${dot.direction}-${index}`}
|
|
337
|
+
className={`${CLASS_PREFIX}__dot-${dot.position}`}
|
|
338
|
+
style={{
|
|
339
|
+
left:
|
|
340
|
+
`${dot.position}` === 'top' ||
|
|
341
|
+
`${dot.position}` === 'bottom'
|
|
342
|
+
? `calc((${'100%'} - ${dotWidth}rem) / 2)`
|
|
343
|
+
: `${dot.position}` === 'left'
|
|
344
|
+
? `${
|
|
345
|
+
(widthRatio * 18 - widthRatio * 9) / 2 / 14
|
|
346
|
+
}rem`
|
|
347
|
+
: '',
|
|
348
|
+
top:
|
|
349
|
+
`${dot.position}` === 'left' ||
|
|
350
|
+
`${dot.position}` === 'right'
|
|
351
|
+
? `calc((100% - ${dotHeight}rem) / 2)`
|
|
352
|
+
: `${dot.position}` === 'top'
|
|
353
|
+
? `${
|
|
354
|
+
(heightRatio * 18 - heightRatio * 9) / 2 / 14
|
|
355
|
+
}rem`
|
|
356
|
+
: '',
|
|
357
|
+
bottom:
|
|
358
|
+
`${dot.position}` === 'bottom'
|
|
359
|
+
? `${
|
|
360
|
+
(heightRatio * 18 - heightRatio * 9) / 2 / 14
|
|
361
|
+
}rem`
|
|
362
|
+
: '',
|
|
363
|
+
right:
|
|
364
|
+
`${dot.position}` === 'right'
|
|
365
|
+
? `${
|
|
366
|
+
(widthRatio * 18 - widthRatio * 9) / 2 / 14
|
|
367
|
+
}rem`
|
|
368
|
+
: '',
|
|
369
|
+
}}
|
|
370
|
+
>
|
|
371
|
+
{true && renderDot(dot.direction, dot.list)}
|
|
372
|
+
</div>
|
|
373
|
+
)}
|
|
374
|
+
</>
|
|
375
|
+
);
|
|
376
|
+
})}
|
|
377
|
+
<div
|
|
378
|
+
className={`${CLASS_PREFIX}__inner`}
|
|
379
|
+
style={{
|
|
380
|
+
paddingTop: `${(18 * heightRatio) / 14}rem`,
|
|
381
|
+
paddingBottom: `${(18 * heightRatio) / 14}rem`,
|
|
382
|
+
paddingLeft: `${(18 * widthRatio) / 14}rem`,
|
|
383
|
+
paddingRight: `${(18 * widthRatio) / 14}rem`,
|
|
384
|
+
}}
|
|
385
|
+
>
|
|
386
|
+
<div className={`${CLASS_PREFIX}__inner-wrap`}>
|
|
387
|
+
<ul className={`${CLASS_PREFIX}__list`}>
|
|
388
|
+
{lotteryList.map((item, index) => {
|
|
389
|
+
return (
|
|
390
|
+
<li
|
|
391
|
+
data-testid="lottery-item"
|
|
392
|
+
key={index}
|
|
393
|
+
className={classNames(
|
|
394
|
+
`${CLASS_PREFIX}__turntable-item`,
|
|
395
|
+
item.idx === activedId ? 'is-actived' : '',
|
|
396
|
+
item.selected ? 'is-selected' : ''
|
|
397
|
+
)}
|
|
398
|
+
style={{
|
|
399
|
+
width: `calc((${'100%'} - ${
|
|
400
|
+
(widthRatio * 8 * 4) / 14
|
|
401
|
+
}rem) / 3)`,
|
|
402
|
+
height: `calc((${'100%'} - ${
|
|
403
|
+
(heightRatio * 8 * 4) / 14
|
|
404
|
+
}rem) / 3)`,
|
|
405
|
+
top:
|
|
406
|
+
`${index}` == '0' ||
|
|
407
|
+
`${index}` == '1' ||
|
|
408
|
+
`${index}` == '2'
|
|
409
|
+
? `${(heightRatio * 8) / 14}rem`
|
|
410
|
+
: `${index}` == '3'
|
|
411
|
+
? `calc((${'100%'} - ${
|
|
412
|
+
(heightRatio * 8 * 4) / 14
|
|
413
|
+
}rem) / 3 + ${(heightRatio * 8 * 2) / 14}rem)`
|
|
414
|
+
: '',
|
|
415
|
+
bottom:
|
|
416
|
+
`${index}` == '4' ||
|
|
417
|
+
`${index}` == '5' ||
|
|
418
|
+
`${index}` == '6'
|
|
419
|
+
? `${(heightRatio * 8) / 14}rem`
|
|
420
|
+
: `${index}` == '7'
|
|
421
|
+
? `calc((${'100%'} - ${
|
|
422
|
+
(heightRatio * 8 * 4) / 14
|
|
423
|
+
}rem) / 3 + ${(heightRatio * 8 * 2) / 14}rem)`
|
|
424
|
+
: '',
|
|
425
|
+
right:
|
|
426
|
+
`${index}` == '2' ||
|
|
427
|
+
`${index}` == '3' ||
|
|
428
|
+
`${index}` == '4'
|
|
429
|
+
? `${(widthRatio * 8) / 14}rem`
|
|
430
|
+
: '',
|
|
431
|
+
left:
|
|
432
|
+
`${index}` == '0' ||
|
|
433
|
+
`${index}` == '6' ||
|
|
434
|
+
`${index}` == '7'
|
|
435
|
+
? `${(widthRatio * 8) / 14}rem`
|
|
436
|
+
: `${index}` == '1' || `${index}` == '5'
|
|
437
|
+
? `calc((${'100%'} - ${
|
|
438
|
+
(widthRatio * 8 * 4) / 14
|
|
439
|
+
}rem) / 3 + ${(widthRatio * 8 * 2) / 14}rem)`
|
|
440
|
+
: '',
|
|
441
|
+
}}
|
|
442
|
+
>
|
|
443
|
+
<div
|
|
444
|
+
className={`${CLASS_PREFIX}__turntable-cell`}
|
|
445
|
+
style={{
|
|
446
|
+
borderLeftWidth: `${(4 * widthRatio) / 14}rem`,
|
|
447
|
+
borderRightWidth: `${(4 * widthRatio) / 14}rem`,
|
|
448
|
+
borderTopWidth: `${(4 * heightRatio) / 14}rem`,
|
|
449
|
+
borderBottomWidth: `${(4 * heightRatio) / 14}rem`,
|
|
450
|
+
paddingTop: `${(8 * heightRatio) / 14}rem`,
|
|
451
|
+
paddingBottom: `${(8 * heightRatio) / 14}rem`,
|
|
452
|
+
paddingLeft: `${(2 * widthRatio) / 14}rem`,
|
|
453
|
+
paddingRight: `${(2 * widthRatio) / 14}rem`,
|
|
454
|
+
}}
|
|
455
|
+
>
|
|
456
|
+
{item.src && (
|
|
457
|
+
<div
|
|
458
|
+
className={`${CLASS_PREFIX}__turntable-cell-image`}
|
|
459
|
+
style={{
|
|
460
|
+
height: `${(heightRatio * 40) / 14}rem`,
|
|
461
|
+
}}
|
|
462
|
+
>
|
|
463
|
+
<img
|
|
464
|
+
src={item.src}
|
|
465
|
+
alt={item.desc}
|
|
466
|
+
className={`${CLASS_PREFIX}__turntable-cell-icon`}
|
|
467
|
+
style={{
|
|
468
|
+
width: `${(widthRatio * 40) / 14}rem`,
|
|
469
|
+
height: `${(heightRatio * 40) / 14}rem`,
|
|
470
|
+
}}
|
|
471
|
+
/>
|
|
472
|
+
</div>
|
|
473
|
+
)}
|
|
474
|
+
{item.desc && (
|
|
475
|
+
<div
|
|
476
|
+
className={`${CLASS_PREFIX}__turntable-cell-desc`}
|
|
477
|
+
style={{
|
|
478
|
+
marginTop: `${(heightRatio * 6) / 14}rem`,
|
|
479
|
+
fontSize: `${(widthRatio * 12) / 14}rem`,
|
|
480
|
+
lineHeight: `${(heightRatio * 17) / 14}rem`,
|
|
481
|
+
}}
|
|
482
|
+
>
|
|
483
|
+
{item.desc}
|
|
484
|
+
</div>
|
|
485
|
+
)}
|
|
486
|
+
</div>
|
|
487
|
+
</li>
|
|
488
|
+
);
|
|
489
|
+
})}
|
|
490
|
+
</ul>
|
|
491
|
+
<div
|
|
492
|
+
className={classNames(
|
|
493
|
+
`${CLASS_PREFIX}__turntable-btn`,
|
|
494
|
+
btnActived ? 'is-actived' : ''
|
|
495
|
+
)}
|
|
496
|
+
style={{
|
|
497
|
+
width: `calc((${'100%'} - ${
|
|
498
|
+
(widthRatio * 8 * 4) / 14
|
|
499
|
+
}rem) / 3)`,
|
|
500
|
+
height: `calc((${'100%'} - ${
|
|
501
|
+
(heightRatio * 8 * 4) / 14
|
|
502
|
+
}rem) / 3)`,
|
|
503
|
+
top: `calc((${'100%'} - ${
|
|
504
|
+
(heightRatio * 8 * 4) / 14
|
|
505
|
+
}rem) / 3 + ${(heightRatio * 8 * 2) / 14}rem)`,
|
|
506
|
+
left: `calc((${'100%'} - ${
|
|
507
|
+
(heightRatio * 8 * 4) / 14
|
|
508
|
+
}rem) / 3 + ${(heightRatio * 8 * 2) / 14}rem)`,
|
|
509
|
+
}}
|
|
510
|
+
>
|
|
511
|
+
<div
|
|
512
|
+
className={`${CLASS_PREFIX}__btn-inner`}
|
|
513
|
+
style={{
|
|
514
|
+
paddingTop: `${(9 * heightRatio) / 14}rem`,
|
|
515
|
+
paddingBottom: `${(9 * heightRatio) / 14}rem`,
|
|
516
|
+
paddingLeft: `${(9 * widthRatio) / 14}rem`,
|
|
517
|
+
paddingRight: `${(9 * widthRatio) / 14}rem`,
|
|
518
|
+
}}
|
|
519
|
+
>
|
|
520
|
+
<div className={`${CLASS_PREFIX}__btn`}>
|
|
521
|
+
<a
|
|
522
|
+
data-testid="start-lottery"
|
|
523
|
+
className={`${CLASS_PREFIX}__btn-image`}
|
|
524
|
+
style={{
|
|
525
|
+
paddingTop: `${(11 * heightRatio) / 14}rem`,
|
|
526
|
+
paddingBottom: `${(11 * heightRatio) / 14}rem`,
|
|
527
|
+
paddingLeft: `${(15 * widthRatio) / 14}rem`,
|
|
528
|
+
paddingRight: `${(15 * widthRatio) / 14}rem`,
|
|
529
|
+
}}
|
|
530
|
+
onClick={startLottery}
|
|
531
|
+
>
|
|
532
|
+
<p
|
|
533
|
+
className={`${CLASS_PREFIX}__btn-text`}
|
|
534
|
+
style={{
|
|
535
|
+
fontSize: `${(widthRatio * 18) / 14}rem`,
|
|
536
|
+
lineHeight: `${(widthRatio * 22) / 14}rem`,
|
|
537
|
+
}}
|
|
538
|
+
>
|
|
539
|
+
开始抽奖
|
|
540
|
+
</p>
|
|
541
|
+
</a>
|
|
542
|
+
</div>
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
</div>
|
|
548
|
+
</div>
|
|
549
|
+
</div>
|
|
550
|
+
</ConfigProvider>
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export interface PropsType extends CommonPropsType {
|
|
555
|
+
/**
|
|
556
|
+
* 奖品列表
|
|
557
|
+
*/
|
|
558
|
+
prizeList: any;
|
|
559
|
+
/**
|
|
560
|
+
* 启动抽奖
|
|
561
|
+
*/
|
|
562
|
+
enablePrize: boolean;
|
|
563
|
+
/**
|
|
564
|
+
* 抽奖结果
|
|
565
|
+
*/
|
|
566
|
+
prizeResult: string;
|
|
567
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export default class LotteryAction {
|
|
2
|
+
idx: number;
|
|
3
|
+
// 开始抽奖
|
|
4
|
+
isStart: boolean;
|
|
5
|
+
// 结束位置
|
|
6
|
+
endId: any;
|
|
7
|
+
// 抽奖速度
|
|
8
|
+
speed: number;
|
|
9
|
+
// 持续时长
|
|
10
|
+
duration: number;
|
|
11
|
+
maxIdx: number;
|
|
12
|
+
// 回调动作
|
|
13
|
+
animationCallback: ({ idx, isEnd }: { idx: any; isEnd: any }) => void;
|
|
14
|
+
// 是否异常
|
|
15
|
+
isError: boolean;
|
|
16
|
+
// 是否加速
|
|
17
|
+
isSpeedUp: boolean;
|
|
18
|
+
// 超时时间
|
|
19
|
+
timeout: number;
|
|
20
|
+
|
|
21
|
+
timer: any;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
// 当前位置
|
|
25
|
+
this.idx = -1;
|
|
26
|
+
// 开始抽奖
|
|
27
|
+
this.isStart = false;
|
|
28
|
+
// 结束位置
|
|
29
|
+
this.endId = undefined;
|
|
30
|
+
// 抽奖速度
|
|
31
|
+
this.speed = 0;
|
|
32
|
+
// 持续时长
|
|
33
|
+
this.duration = 2000;
|
|
34
|
+
// 长度
|
|
35
|
+
this.maxIdx = 8;
|
|
36
|
+
// 回调动作
|
|
37
|
+
this.animationCallback = ({ idx, isEnd }) => {};
|
|
38
|
+
// 是否异常
|
|
39
|
+
this.isError = false;
|
|
40
|
+
// 是否加速
|
|
41
|
+
this.isSpeedUp = false;
|
|
42
|
+
//超时时间
|
|
43
|
+
this.timeout = 6000;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
start(prizeResult, errorCallback) {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
this.isStart = false;
|
|
49
|
+
let reg = /^\+?[1-9]\d*$/;
|
|
50
|
+
if (!reg.test(prizeResult)) {
|
|
51
|
+
this.isError = true;
|
|
52
|
+
if (errorCallback) {
|
|
53
|
+
errorCallback();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, this.duration);
|
|
57
|
+
// 在转动时长的一半,开始减速转动
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
this.isSpeedUp = false;
|
|
60
|
+
}, this.duration / 2);
|
|
61
|
+
// 超时,当出现一些意外的情况终止动画
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
if (this.endId === undefined) {
|
|
64
|
+
this.end(prizeResult);
|
|
65
|
+
}
|
|
66
|
+
}, this.timeout);
|
|
67
|
+
this.isStart = true;
|
|
68
|
+
this.isError = false;
|
|
69
|
+
this.isSpeedUp = true;
|
|
70
|
+
this.loop();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
end(prizeResult) {
|
|
74
|
+
this.endId = prizeResult;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
error() {
|
|
78
|
+
this.isError = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
stop() {
|
|
82
|
+
this.isStart = false;
|
|
83
|
+
this.end(-1);
|
|
84
|
+
clearTimeout(this.timer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pointOnCubicBezier(cp, t) {
|
|
88
|
+
let x =
|
|
89
|
+
Math.pow(1 - t, 2) * cp[0] +
|
|
90
|
+
2 * t * (1 - t) * cp[1] +
|
|
91
|
+
Math.pow(t, 2) * cp[2];
|
|
92
|
+
return x;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
loop() {
|
|
96
|
+
const { animationCallback } = this;
|
|
97
|
+
this.timer = setTimeout(() => {
|
|
98
|
+
const over = !this.isStart && this.endId !== undefined;
|
|
99
|
+
// emit
|
|
100
|
+
animationCallback({ idx: this.idx, isEnd: false });
|
|
101
|
+
// compare
|
|
102
|
+
if (this.idx < this.maxIdx) {
|
|
103
|
+
this.idx++;
|
|
104
|
+
} else {
|
|
105
|
+
this.idx = 1;
|
|
106
|
+
}
|
|
107
|
+
// continue
|
|
108
|
+
if (!(over && String(this.idx) === String(this.endId)) && !this.isError) {
|
|
109
|
+
if (this.isSpeedUp) {
|
|
110
|
+
const point = this.pointOnCubicBezier([500, 50, 100], 1 / 10);
|
|
111
|
+
this.speed = point;
|
|
112
|
+
if (this.speed < 100) {
|
|
113
|
+
this.speed = 100;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
const point = this.pointOnCubicBezier([100, 50, 500], 1 / 10);
|
|
117
|
+
this.speed = point;
|
|
118
|
+
if (this.speed > 1000) {
|
|
119
|
+
this.speed = 1000;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
this.loop();
|
|
123
|
+
} else {
|
|
124
|
+
if (this.isError) return;
|
|
125
|
+
animationCallback({ idx: this.idx, isEnd: true });
|
|
126
|
+
this.idx = -1;
|
|
127
|
+
}
|
|
128
|
+
}, this.speed);
|
|
129
|
+
}
|
|
130
|
+
}
|