@cloudbase/weda-ui 0.2.17 → 2.0.8

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 (269) hide show
  1. package/README.md +3 -0
  2. package/package.json +10 -5
  3. package/src/configs/components/button.json +0 -2
  4. package/src/configs/components/calendar.json +9 -3
  5. package/src/configs/components/carousel.json +18 -9
  6. package/src/configs/components/chart/bar.json +31 -12
  7. package/src/configs/components/chart/line.json +27 -10
  8. package/src/configs/components/chart/pie.json +22 -8
  9. package/src/configs/components/chart/statisticsCard.json +61 -13
  10. package/src/configs/components/container.json +7 -2
  11. package/src/configs/components/dataView.json +31 -11
  12. package/src/configs/components/form/checkbox.json +97 -5
  13. package/src/configs/components/form/radio.json +123 -4
  14. package/src/configs/components/form/select.json +247 -13
  15. package/src/configs/components/graphicCard.json +90 -75
  16. package/src/configs/components/image.json +19 -8
  17. package/src/configs/components/link.json +25 -6
  18. package/src/configs/components/listView.json +83 -27
  19. package/src/configs/components/lottery.json +153 -0
  20. package/src/configs/components/modal.json +37 -5
  21. package/src/configs/components/navLayout.json +97 -79
  22. package/src/configs/components/navigationBar.json +59 -0
  23. package/src/configs/components/richtextview.json +6 -2
  24. package/src/configs/components/scrollVeiw.json +98 -34
  25. package/src/configs/components/swiper.json +22 -10
  26. package/src/configs/components/tabs.json +54 -9
  27. package/src/configs/components/text.json +43 -30
  28. package/src/configs/components/wxOpenApi/phone.json +141 -0
  29. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  30. package/src/configs/components/wxOpenApi/share.json +167 -0
  31. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  32. package/src/configs/index.js +13 -0
  33. package/src/docs/common/format.tsx +112 -0
  34. package/src/docs/common/tableView.css +164 -0
  35. package/src/docs/common/tableView.tsx +273 -0
  36. package/src/docs/compsdocs/chart/Bar.mdx +159 -0
  37. package/src/docs/compsdocs/chart/Line.mdx +100 -0
  38. package/src/docs/compsdocs/chart/Pie.mdx +83 -0
  39. package/src/docs/compsdocs/chart/_category_.json +1 -0
  40. package/src/docs/compsdocs/chart/statisticsCard.mdx +51 -0
  41. package/src/docs/compsdocs/database/DataView.mdx +33 -0
  42. package/src/docs/compsdocs/database/ListView.mdx +33 -0
  43. package/src/docs/compsdocs/database/_category_.json +1 -0
  44. package/src/docs/compsdocs/form/Form.mdx +35 -0
  45. package/src/docs/compsdocs/form/FormCheckbox.mdx +35 -0
  46. package/src/docs/compsdocs/form/FormDate.mdx +30 -0
  47. package/src/docs/compsdocs/form/FormEmail.mdx +30 -0
  48. package/src/docs/compsdocs/form/FormImageUploader.mdx +31 -0
  49. package/src/docs/compsdocs/form/FormInput.mdx +30 -0
  50. package/src/docs/compsdocs/form/FormLocation.mdx +64 -0
  51. package/src/docs/compsdocs/form/FormPhone.mdx +30 -0
  52. package/src/docs/compsdocs/form/FormRadio.mdx +35 -0
  53. package/src/docs/compsdocs/form/FormRegion.mdx +30 -0
  54. package/src/docs/compsdocs/form/FormSelect.mdx +36 -0
  55. package/src/docs/compsdocs/form/FormSwitch.mdx +30 -0
  56. package/src/docs/compsdocs/form/FormTextarea.mdx +30 -0
  57. package/src/docs/compsdocs/form/FormTime.mdx +30 -0
  58. package/src/docs/compsdocs/form/FormUploadFile.mdx +30 -0
  59. package/src/docs/compsdocs/form/FormUrl.mdx +30 -0
  60. package/src/docs/compsdocs/form/_category_.json +1 -0
  61. package/src/docs/compsdocs/grid/Card.mdx +32 -0
  62. package/src/docs/compsdocs/grid/Container.mdx +42 -0
  63. package/src/docs/compsdocs/grid/Footer.mdx +31 -0
  64. package/src/docs/compsdocs/grid/GridLayout.mdx +32 -0
  65. package/src/docs/compsdocs/grid/Header.mdx +31 -0
  66. package/src/docs/compsdocs/grid/Layout.mdx +25 -0
  67. package/src/docs/compsdocs/grid/List.mdx +31 -0
  68. package/src/docs/compsdocs/grid/ScrollView.mdx +37 -0
  69. package/src/docs/compsdocs/grid/Swiper.mdx +58 -0
  70. package/src/docs/compsdocs/grid/_category_.json +1 -0
  71. package/src/docs/compsdocs/media/Icon.mdx +31 -0
  72. package/src/docs/compsdocs/media/Image.mdx +55 -0
  73. package/src/docs/compsdocs/media/_category_.json +1 -0
  74. package/src/docs/compsdocs/model/ModelCreate.mdx +20 -0
  75. package/src/docs/compsdocs/model/ModelDetail.mdx +20 -0
  76. package/src/docs/compsdocs/model/ModelTable.mdx +24 -0
  77. package/src/docs/compsdocs/model/ModelUpdate.mdx +21 -0
  78. package/src/docs/compsdocs/model/PageLayout.mdx +21 -0
  79. package/src/docs/compsdocs/model/_category_.json +1 -0
  80. package/src/docs/compsdocs/navmenu/Classification.mdx +38 -0
  81. package/src/docs/compsdocs/navmenu/NavBar.mdx +43 -0
  82. package/src/docs/compsdocs/navmenu/NavLayout.mdx +30 -0
  83. package/src/docs/compsdocs/navmenu/TabBar.mdx +43 -0
  84. package/src/docs/compsdocs/navmenu/TabBarItem.mdx +29 -0
  85. package/src/docs/compsdocs/navmenu/_category_.json +1 -0
  86. package/src/docs/compsdocs/senior/Lottery.mdx +48 -0
  87. package/src/docs/compsdocs/senior/Modal.mdx +58 -0
  88. package/src/docs/compsdocs/senior/SlotMachine.mdx +52 -0
  89. package/src/docs/compsdocs/senior/_category_.json +1 -0
  90. package/src/docs/compsdocs/show/Calendar.mdx +29 -0
  91. package/src/docs/compsdocs/show/Divider.mdx +31 -0
  92. package/src/docs/compsdocs/show/GraphicCard.mdx +30 -0
  93. package/src/docs/compsdocs/show/Item.mdx +32 -0
  94. package/src/docs/compsdocs/show/ItemList.mdx +47 -0
  95. package/src/docs/compsdocs/show/Media.mdx +25 -0
  96. package/src/docs/compsdocs/show/StatusTip.mdx +25 -0
  97. package/src/docs/compsdocs/show/Swiper.mdx +33 -0
  98. package/src/docs/compsdocs/show/Tabs.mdx +38 -0
  99. package/src/docs/compsdocs/show/_category_.json +1 -0
  100. package/src/docs/compsdocs/show/button.mdx +25 -0
  101. package/src/docs/compsdocs/text/Link.mdx +43 -0
  102. package/src/docs/compsdocs/text/RichTextView.mdx +36 -0
  103. package/src/docs/compsdocs/text/Text.mdx +31 -0
  104. package/src/docs/compsdocs/text/Title.mdx +32 -0
  105. package/src/docs/compsdocs/text/_category_.json +1 -0
  106. package/src/docs/compsdocs/wxOpen/Phone.mdx +60 -0
  107. package/src/docs/compsdocs/wxOpen/Share.mdx +46 -0
  108. package/src/docs/compsdocs/wxOpen/UserInfo.mdx +60 -0
  109. package/src/docs/compsdocs/wxOpen/_category_.json +4 -0
  110. package/src/index.js +2 -0
  111. package/src/mp/components/button/index.js +18 -2
  112. package/src/mp/components/button/index.wxml +7 -4
  113. package/src/mp/components/chart/bar/index.js +6 -2
  114. package/src/mp/components/chart/common/core/eChartBar.js +9 -8
  115. package/src/mp/components/chart/common/core/eChartBase.js +20 -16
  116. package/src/mp/components/chart/common/core/eChartLine.js +6 -5
  117. package/src/mp/components/chart/line/index.js +10 -6
  118. package/src/mp/components/chart/pie/index.js +6 -2
  119. package/src/mp/components/chart/statisticsCard/index.js +33 -6
  120. package/src/mp/components/dataView/index.json +1 -1
  121. package/src/mp/components/form/checkbox/index.js +41 -2
  122. package/src/mp/components/form/checkbox/index.wxml +1 -1
  123. package/src/mp/components/form/form/index.wxml +1 -2
  124. package/src/mp/components/form/formcell/index.wxml +1 -1
  125. package/src/mp/components/form/formcell/index.wxss +17 -0
  126. package/src/mp/components/form/input/index.js +1 -1
  127. package/src/mp/components/form/input/index.wxss +15 -0
  128. package/src/mp/components/form/location/index.js +43 -2
  129. package/src/mp/components/form/location/index.wxss +4 -6
  130. package/src/mp/components/form/radio/index.js +34 -1
  131. package/src/mp/components/form/select/index.js +351 -41
  132. package/src/mp/components/form/select/index.wxml +17 -2
  133. package/src/mp/components/form/select/index.wxss +4 -0
  134. package/src/mp/components/form/select/region/index.js +101 -0
  135. package/src/mp/components/form/textarea/index.js +1 -1
  136. package/src/mp/components/form/textarea/index.wxss +4 -0
  137. package/src/mp/components/form/uploader/index.js +39 -27
  138. package/src/mp/components/form/uploader/index.json +3 -2
  139. package/src/mp/components/form/uploader/index.wxml +11 -7
  140. package/src/mp/components/form/uploader/index.wxss +20 -2
  141. package/src/mp/components/form/uploader/weui-uploader.js +209 -0
  142. package/src/mp/components/form/uploader/weui-uploader.json +7 -0
  143. package/src/mp/components/form/uploader/weui-uploader.wxml +45 -0
  144. package/src/mp/components/form/uploader/weui-uploader.wxss +1 -0
  145. package/src/mp/components/form/uploaderFile/index.js +10 -6
  146. package/src/mp/components/form/uploaderFile/index.wxss +4 -4
  147. package/src/mp/components/image/index.wxss +3 -2
  148. package/src/mp/components/listView/index.js +38 -43
  149. package/src/mp/components/listView/index.wxml +1 -1
  150. package/src/mp/components/listView/index.wxss +5 -0
  151. package/src/mp/components/lottery/index.js +270 -0
  152. package/src/mp/components/{internals/listView → lottery}/index.json +0 -0
  153. package/src/mp/components/lottery/index.wxml +43 -0
  154. package/src/mp/components/lottery/index.wxss +317 -0
  155. package/src/mp/components/navigationBar/index.js +193 -0
  156. package/src/mp/components/navigationBar/index.json +6 -0
  157. package/src/mp/components/navigationBar/index.wxml +88 -0
  158. package/src/mp/components/navigationBar/index.wxss +1257 -0
  159. package/src/mp/components/tabs/index.js +7 -2
  160. package/src/mp/components/tabs/index.wxml +2 -1
  161. package/src/mp/components/text/index.js +0 -25
  162. package/src/mp/components/text/index.wxml +3 -3
  163. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  164. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  165. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  166. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  167. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  168. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  169. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  170. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  171. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  172. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  173. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  174. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  175. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  176. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  177. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  178. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  179. package/src/mp/index.json +7 -1
  180. package/src/mp/style/weda-ui.wxss +16 -0
  181. package/src/mp/utils/constant.js +15 -0
  182. package/src/mp/utils/destr.js +48 -0
  183. package/src/mp/utils/lodash.js +2 -0
  184. package/src/mp/utils/platform.js +10 -0
  185. package/src/mp/utils/tcb.js +44 -0
  186. package/src/web/components/button/index.css +8 -1
  187. package/src/web/components/button/index.tsx +10 -9
  188. package/src/web/components/calendar/index.jsx +1 -1
  189. package/src/web/components/carousel/index.tsx +8 -8
  190. package/src/web/components/chart/bar/index.tsx +40 -39
  191. package/src/web/components/chart/common/config/line.js +1 -1
  192. package/src/web/components/chart/common/core/eChartBar.js +7 -6
  193. package/src/web/components/chart/common/core/eChartBase.ts +20 -16
  194. package/src/web/components/chart/common/core/eChartLine.js +8 -6
  195. package/src/web/components/chart/line/index.tsx +40 -39
  196. package/src/web/components/chart/statisticsCard/index.tsx +29 -8
  197. package/src/web/components/form/checkbox/index.tsx +61 -23
  198. package/src/web/components/form/form/index.css +5 -1
  199. package/src/web/components/form/form/index.tsx +3 -1
  200. package/src/web/components/form/formcell/index.css +22 -1
  201. package/src/web/components/form/formcell/index.tsx +11 -6
  202. package/src/web/components/form/input/index.css +7 -12
  203. package/src/web/components/form/location/components/LocationH5/index.css +4 -7
  204. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +1 -1
  205. package/src/web/components/form/radio/index.tsx +90 -53
  206. package/src/web/components/form/select/h5.tsx +370 -73
  207. package/src/web/components/form/select/index.css +15 -0
  208. package/src/web/components/form/select/index.tsx +392 -145
  209. package/src/web/components/form/select/region/index.ts +122 -31
  210. package/src/web/components/form/select/time.jsx +89 -0
  211. package/src/web/components/form/select/year.tsx +170 -0
  212. package/src/web/components/form/textarea/index.css +4 -0
  213. package/src/web/components/form/textarea/index.tsx +2 -2
  214. package/src/web/components/form/tips/index.css +4 -0
  215. package/src/web/components/form/tips/index.tsx +4 -3
  216. package/src/web/components/form/uploader/index.css +26 -2
  217. package/src/web/components/form/uploader/uploader.h5.tsx +89 -57
  218. package/src/web/components/form/uploader/uploader.pc.tsx +4 -4
  219. package/src/web/components/form/uploaderFile/index.css +2 -4
  220. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +13 -7
  221. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +13 -5
  222. package/src/web/components/image/image.tsx +1 -1
  223. package/src/web/components/image/index.css +3 -3
  224. package/src/web/components/image/index.tsx +6 -7
  225. package/src/web/components/index.js +8 -0
  226. package/src/web/components/link/index.tsx +7 -4
  227. package/src/web/components/listView/index.css +4 -0
  228. package/src/web/components/listView/index.tsx +12 -20
  229. package/src/web/components/lottery/index.css +327 -0
  230. package/src/web/components/lottery/index.tsx +567 -0
  231. package/src/web/components/lottery/lotteryUtil.ts +130 -0
  232. package/src/web/components/modal/index.tsx +3 -1
  233. package/src/web/components/navLayout/index.tsx +2 -2
  234. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  235. package/src/web/components/navigationBar/common.tsx +198 -0
  236. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  237. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  238. package/src/web/components/navigationBar/index.css +762 -0
  239. package/src/web/components/navigationBar/index.tsx +230 -0
  240. package/src/web/components/navigationBar/type.d.ts +111 -0
  241. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  242. package/src/web/components/phone/index.css +0 -0
  243. package/src/web/components/phone/index.tsx +22 -0
  244. package/src/web/components/phoneCode/index.css +0 -0
  245. package/src/web/components/phoneCode/index.tsx +22 -0
  246. package/src/web/components/picker/timePicker.tsx +2 -2
  247. package/src/web/components/richTextView/index.tsx +3 -5
  248. package/src/web/components/share/index.css +0 -0
  249. package/src/web/components/share/index.tsx +38 -0
  250. package/src/web/components/slot/index.tsx +1 -1
  251. package/src/web/components/tabs/index.tsx +2 -0
  252. package/src/web/components/tabs/tabs.h5.tsx +43 -33
  253. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  254. package/src/web/components/text/index.tsx +12 -20
  255. package/src/web/components/userInfo/index.css +0 -0
  256. package/src/web/components/userInfo/index.tsx +30 -0
  257. package/src/web/utils/{constant.js → constant.ts} +17 -2
  258. package/src/web/utils/lodash.ts +2 -0
  259. package/src/web/utils/platform.js +9 -0
  260. package/src/web/utils/tcb.js +26 -0
  261. package/src/web/weda-ui.css +7 -1
  262. package/src/mp/components/internals/listView/arrow-right-line.svg +0 -3
  263. package/src/mp/components/internals/listView/index.js +0 -286
  264. package/src/mp/components/internals/listView/index.wxml +0 -40
  265. package/src/mp/components/internals/listView/index.wxss +0 -150
  266. package/src/mp/components/internals/listView/more-line.svg +0 -3
  267. package/src/web/components/form/select/region/cities.ts +0 -2410
  268. package/src/web/components/form/select/region/provinces.ts +0 -240
  269. 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
+ }