@cloudbase/weda-ui 0.2.16 → 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.
Files changed (194) hide show
  1. package/README.md +41 -169
  2. package/package.json +23 -11
  3. package/src/configs/components/calendar.json +4 -1
  4. package/src/configs/components/chart/bar.json +724 -0
  5. package/src/configs/components/chart/line.json +679 -0
  6. package/src/configs/components/chart/pie.json +497 -0
  7. package/src/configs/components/chart/statisticsCard.json +61 -13
  8. package/src/configs/components/container.json +7 -2
  9. package/src/configs/components/dataView.json +21 -6
  10. package/src/configs/components/form/checkbox.json +97 -5
  11. package/src/configs/components/form/radio.json +96 -4
  12. package/src/configs/components/form/select.json +245 -11
  13. package/src/configs/components/graphicCard.json +84 -73
  14. package/src/configs/components/image.json +7 -2
  15. package/src/configs/components/link.json +19 -3
  16. package/src/configs/components/listView.json +65 -18
  17. package/src/configs/components/lottery.json +151 -0
  18. package/src/configs/components/modal.json +37 -5
  19. package/src/configs/components/navLayout.json +87 -75
  20. package/src/configs/components/navigationBar.json +59 -0
  21. package/src/configs/components/richtextview.json +4 -1
  22. package/src/configs/components/scrollVeiw.json +74 -22
  23. package/src/configs/components/swiper.json +4 -1
  24. package/src/configs/components/tabs.json +51 -8
  25. package/src/configs/components/text.json +33 -25
  26. package/src/configs/components/wxOpenApi/phone.json +141 -0
  27. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  28. package/src/configs/components/wxOpenApi/share.json +167 -0
  29. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  30. package/src/configs/index.js +20 -0
  31. package/src/index.js +2 -0
  32. package/src/mp/components/button/index.wxml +1 -2
  33. package/src/mp/components/chart/bar/index.js +258 -0
  34. package/src/mp/components/chart/bar/index.json +6 -0
  35. package/src/mp/components/chart/bar/index.wxml +3 -0
  36. package/src/mp/components/chart/bar/index.wxss +9 -0
  37. package/src/mp/components/chart/common/config/bar.js +50 -0
  38. package/src/mp/components/chart/common/config/global.js +16 -0
  39. package/src/mp/components/chart/common/config/line.js +48 -0
  40. package/src/mp/components/chart/common/config/pie.js +36 -0
  41. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  42. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  43. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  44. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  45. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  46. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  47. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  48. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  49. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  50. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  51. package/src/mp/components/chart/line/index.js +247 -0
  52. package/src/mp/components/chart/line/index.json +6 -0
  53. package/src/mp/components/chart/line/index.wxml +3 -0
  54. package/src/mp/components/chart/line/index.wxss +9 -0
  55. package/src/mp/components/chart/pie/index.js +182 -0
  56. package/src/mp/components/chart/pie/index.json +6 -0
  57. package/src/mp/components/chart/pie/index.wxml +4 -0
  58. package/src/mp/components/chart/pie/index.wxss +9 -0
  59. package/src/mp/components/chart/statisticsCard/index.js +33 -6
  60. package/src/mp/components/form/checkbox/index.js +41 -2
  61. package/src/mp/components/form/checkbox/index.wxml +1 -1
  62. package/src/mp/components/form/form/index.wxml +1 -2
  63. package/src/mp/components/form/input/index.js +1 -1
  64. package/src/mp/components/form/location/index.js +43 -2
  65. package/src/mp/components/form/radio/index.js +38 -0
  66. package/src/mp/components/form/select/index.js +348 -40
  67. package/src/mp/components/form/select/index.wxml +21 -6
  68. package/src/mp/components/form/select/region/index.js +101 -0
  69. package/src/mp/components/form/textarea/index.wxml +6 -5
  70. package/src/mp/components/form/uploader/index.js +76 -44
  71. package/src/mp/components/form/uploader/index.wxml +15 -3
  72. package/src/mp/components/form/uploaderFile/index.js +61 -29
  73. package/src/mp/components/graphicCard/index.js +26 -28
  74. package/src/mp/components/listView/index.js +52 -64
  75. package/src/mp/components/listView/index.wxml +2 -2
  76. package/src/mp/components/listView/index.wxss +5 -0
  77. package/src/mp/components/lottery/index.js +270 -0
  78. package/src/mp/components/lottery/index.json +4 -0
  79. package/src/mp/components/lottery/index.wxml +43 -0
  80. package/src/mp/components/lottery/index.wxss +317 -0
  81. package/src/mp/components/navLayout/index.js +3 -3
  82. package/src/mp/components/navigationBar/index.js +193 -0
  83. package/src/mp/components/navigationBar/index.json +6 -0
  84. package/src/mp/components/navigationBar/index.wxml +88 -0
  85. package/src/mp/components/navigationBar/index.wxss +1257 -0
  86. package/src/mp/components/tabs/index.js +7 -2
  87. package/src/mp/components/tabs/index.wxml +2 -1
  88. package/src/mp/components/text/index.js +0 -25
  89. package/src/mp/components/text/index.wxml +3 -3
  90. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  91. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  92. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  93. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  94. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  95. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  96. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  97. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  98. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  99. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  100. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  101. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  102. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  103. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  104. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  105. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  106. package/src/mp/index.json +10 -1
  107. package/src/mp/style/weda-ui.wxss +2 -0
  108. package/src/mp/utils/constant.js +15 -0
  109. package/src/mp/utils/destr.js +48 -0
  110. package/src/mp/utils/lodash.js +2 -0
  111. package/src/mp/utils/platform.js +25 -0
  112. package/src/mp/utils/tcb.js +44 -0
  113. package/src/setupTests.js +2 -1
  114. package/src/web/components/button/index.css +8 -1
  115. package/src/web/components/button/index.tsx +3 -2
  116. package/src/web/components/chart/bar/index.tsx +140 -0
  117. package/src/web/components/chart/common/config/bar.js +49 -0
  118. package/src/web/components/chart/common/config/global.js +16 -0
  119. package/src/web/components/chart/common/config/line.js +50 -0
  120. package/src/web/components/chart/common/config/pie.js +37 -0
  121. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  122. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  123. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  124. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  125. package/src/web/components/chart/common/core/type.ts +34 -0
  126. package/src/web/components/chart/common/echart.css +106 -0
  127. package/src/web/components/chart/common/echarts.ts +33 -0
  128. package/src/web/components/chart/common/useChart.tsx +69 -0
  129. package/src/web/components/chart/line/index.tsx +136 -0
  130. package/src/web/components/chart/pie/index.tsx +99 -0
  131. package/src/web/components/chart/statisticsCard/index.tsx +29 -8
  132. package/src/web/components/form/checkbox/index.tsx +61 -23
  133. package/src/web/components/form/formcell/index.tsx +10 -5
  134. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +3 -3
  135. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +2 -2
  136. package/src/web/components/form/radio/index.tsx +90 -53
  137. package/src/web/components/form/select/h5.tsx +371 -72
  138. package/src/web/components/form/select/index.css +10 -0
  139. package/src/web/components/form/select/index.tsx +392 -145
  140. package/src/web/components/form/select/region/index.ts +122 -31
  141. package/src/web/components/form/select/time.jsx +90 -0
  142. package/src/web/components/form/select/year.tsx +170 -0
  143. package/src/web/components/form/tips/index.css +4 -0
  144. package/src/web/components/form/tips/index.tsx +4 -3
  145. package/src/web/components/form/uploader/uploader.h5.tsx +28 -19
  146. package/src/web/components/form/uploader/uploader.pc.tsx +17 -20
  147. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +48 -44
  148. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +28 -26
  149. package/src/web/components/graphicCard/index.css +1 -5
  150. package/src/web/components/graphicCard/index.tsx +4 -3
  151. package/src/web/components/image/image.tsx +1 -1
  152. package/src/web/components/image/index.tsx +1 -1
  153. package/src/web/components/index.js +13 -2
  154. package/src/web/components/link/index.tsx +6 -3
  155. package/src/web/components/listView/index.css +4 -0
  156. package/src/web/components/listView/index.tsx +10 -18
  157. package/src/web/components/lottery/index.css +327 -0
  158. package/src/web/components/lottery/index.tsx +567 -0
  159. package/src/web/components/lottery/lotteryUtil.ts +130 -0
  160. package/src/web/components/modal/index.tsx +3 -1
  161. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  162. package/src/web/components/navigationBar/common.tsx +198 -0
  163. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  164. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  165. package/src/web/components/navigationBar/index.css +762 -0
  166. package/src/web/components/navigationBar/index.tsx +231 -0
  167. package/src/web/components/navigationBar/type.d.ts +111 -0
  168. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  169. package/src/web/components/phone/index.css +0 -0
  170. package/src/web/components/phone/index.tsx +22 -0
  171. package/src/web/components/phoneCode/index.css +0 -0
  172. package/src/web/components/phoneCode/index.tsx +22 -0
  173. package/src/web/components/richTextView/index.tsx +3 -5
  174. package/src/web/components/share/index.css +0 -0
  175. package/src/web/components/share/index.tsx +38 -0
  176. package/src/web/components/tabs/index.tsx +2 -0
  177. package/src/web/components/tabs/tabs.h5.tsx +43 -33
  178. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  179. package/src/web/components/text/index.tsx +6 -14
  180. package/src/web/components/userInfo/index.css +0 -0
  181. package/src/web/components/userInfo/index.tsx +30 -0
  182. package/src/web/utils/{constant.js → constant.ts} +17 -2
  183. package/src/web/utils/lodash.ts +2 -0
  184. package/src/web/utils/platform.js +10 -1
  185. package/src/web/utils/tcb.js +20 -6
  186. package/src/web/weda-ui.css +2 -0
  187. package/CHANGELOG.md +0 -240
  188. package/src/.DS_Store +0 -0
  189. package/src/configs/.DS_Store +0 -0
  190. package/src/mp/.gitignore +0 -10
  191. package/src/web/.DS_Store +0 -0
  192. package/src/web/components/form/select/region/cities.ts +0 -2410
  193. package/src/web/components/form/select/region/provinces.ts +0 -240
  194. package/src/web/components/form/select/region/regions.ts +0 -20645
@@ -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
+ }