monthlyDrawCarousel.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>转盘抽奖</title>
  7. <style>
  8. .el-overlay {
  9. background-color: rgba(0, 0, 0, 0.8);
  10. }
  11. ::-webkit-scrollbar {
  12. width: 6px;
  13. height: 6px;
  14. }
  15. ::-webkit-scrollbar-track {
  16. width: 3px;
  17. background: rgba(#101F1C, 0.1);
  18. -webkit-border-radius: 2em;
  19. -moz-border-radius: 2em;
  20. border-radius: 2em;
  21. }
  22. ::-webkit-scrollbar-thumb {
  23. background-color: rgba(144, 147, 153, .5);
  24. background-clip: padding-box;
  25. min-height: 28px;
  26. -webkit-border-radius: 2em;
  27. -moz-border-radius: 2em;
  28. border-radius: 2em;
  29. transition: background-color .3s;
  30. cursor: pointer;
  31. }
  32. ::-webkit-scrollbar-thumb:hover {
  33. background-color: rgba(144, 147, 153, .3);
  34. }
  35. * {
  36. margin: 0;
  37. padding: 0;
  38. box-sizing: border-box;
  39. }
  40. #app {
  41. background: url('https://xiaoyou.dgtis.com/images/image/2023/09/12/5opx47olb1unf4po3vxt.png') no-repeat;
  42. /* background: url('https://xiaoyou.dgtis.com/images/image/2023/09/19/y5epqefrpodtfzyw0qd9.png') no-repeat; */
  43. background-size: 100% 100%;
  44. width: 640px;
  45. height: 680px;
  46. margin: 0 auto;
  47. margin-top: 20px;
  48. }
  49. .el-dialog__body {
  50. padding-top: 0px !important;
  51. }
  52. [v-cloak] {
  53. display: none;
  54. }
  55. .rules {
  56. cursor: pointer;
  57. position: absolute;
  58. width: 50px;
  59. height: 50px;
  60. background: #fff;
  61. border-radius: 50%;
  62. display: flex;
  63. justify-content: center;
  64. align-items: center;
  65. font-size: 14px;
  66. font-weight: 600;
  67. left: 8%;
  68. top: 22%;
  69. }
  70. .recordBtn {
  71. cursor: pointer;
  72. position: absolute;
  73. width: 50px;
  74. height: 50px;
  75. background: #fff;
  76. border-radius: 50%;
  77. display: flex;
  78. justify-content: center;
  79. align-items: center;
  80. font-size: 14px;
  81. font-weight: 600;
  82. right: 8%;
  83. top: 22%;
  84. }
  85. .recordBtn>img {
  86. width: 80px;
  87. height: auto;
  88. }
  89. .container {
  90. overflow: hidden;
  91. width: 500px;
  92. height: 500px;
  93. margin: 0 auto;
  94. position: relative;
  95. top: 22%;
  96. }
  97. .prize-list {
  98. width: 100%;
  99. height: 100%;
  100. border-radius: 50%;
  101. border: 10px solid #98d3fc;
  102. overflow: hidden;
  103. }
  104. .prize-item {
  105. /*border: 2px solid red;*/
  106. position: absolute;
  107. left: 0;
  108. right: 0;
  109. top: -10px;
  110. margin: auto;
  111. }
  112. .prize-item img {
  113. width: 35%;
  114. /* height: 25%; */
  115. margin: 35px auto 10px;
  116. display: block;
  117. }
  118. .prize-item p {
  119. color: #fff;
  120. font-size: 12px;
  121. text-align: center;
  122. line-height: 20px;
  123. }
  124. .btn {
  125. width: 80px;
  126. height: 110px;
  127. background: url('https://xiaoyou.dgtis.com/images/image/2023/09/12/xvtwunkntyc65fngc9pb.png') no-repeat center / 100% 100%;
  128. position: absolute;
  129. left: 0;
  130. right: 0;
  131. top: -5%;
  132. bottom: 0;
  133. margin: auto;
  134. cursor: pointer;
  135. }
  136. /* .btn::before {
  137. content: "";
  138. width: 41px;
  139. height: 39px;
  140. background: url('https://xiaoyou.dgtis.com/images/image/2023/08/15/2vac6uuqd3gpbl35l8e1.png') no-repeat center / 100% 100%;
  141. position: absolute;
  142. left: 0;
  143. right: 0;
  144. top: -30px;
  145. margin: auto;
  146. -webkit-transform: rotate(-5deg);
  147. transform: rotate(-5deg);
  148. } */
  149. .recordListBox {
  150. max-height: 200px;
  151. overflow: auto;
  152. }
  153. .title {
  154. font-size: 15px;
  155. font-weight: 600;
  156. }
  157. .recordItem {
  158. display: flex;
  159. justify-content: space-around;
  160. align-items: center;
  161. margin: 10px 0;
  162. }
  163. </style>
  164. </head>
  165. <body>
  166. <div id="app" v-cloak class="app">
  167. <div class="rules" @click="showRules">
  168. 抽奖<br>规则
  169. </div>
  170. <!-- <div class="recordBtn" @click="showRecordList">
  171. 获奖<br>名单
  172. </div> -->
  173. <!-- <div class="recordBtn" @click="showRecordList">
  174. <img src="https://xiaoyou.dgtis.com/images/image/2023/09/06/lt1vbg426idwq725ysdm.png" alt="抽奖记录">
  175. </div> -->
  176. <div class="container">
  177. <div class="prize-list" ref="prizeWrap" :style="bgColor">
  178. <div class="prize-item" v-for="(item, index) in prizeList" :style="prizeStyle(index)">
  179. <img :src="item.imgUrl" alt="">
  180. <p>{{ item.prizeName }}</p>
  181. </div>
  182. </div>
  183. <div class="btn" @click="start"></div>
  184. </div>
  185. <el-dialog v-model="dialogVisible" title="抽奖规则" width="80%" center>
  186. <div style="max-height: 200px;overflow: auto;" v-html="rule"></div>
  187. </el-dialog>
  188. <el-dialog v-model="dialogRecordList" title="获奖名单" width="80%" center>
  189. <div class="recordListBox">
  190. <div class="recordItem title">
  191. <div style="width: 30%;text-align: center;">姓名</div>
  192. <div style="width: 30%;text-align: center;">奖品</div>
  193. <div style="width: 40%;text-align: center;">获奖时间</div>
  194. </div>
  195. <el-empty description="暂无数据" v-if="recordList.length==0" :image-size="20"></el-empty>
  196. <div class="recordItem" v-for="(item, index) in recordList">
  197. <div style="width: 30%;text-align: center;">{{item.userName}}</div>
  198. <div style="width: 30%;text-align: center;">{{item.prizeName}}</div>
  199. <div style="width: 40%;text-align: center;">{{item.createTime}}</div>
  200. </div>
  201. </div>
  202. </el-dialog>
  203. </div>
  204. </body>
  205. <script src="./js/crypto-js.min.js"></script>
  206. <script src="./js/vue.global.js"></script>
  207. <link href="./css/index.css" rel="stylesheet">
  208. <script src="./js/index.full.min.js"></script>
  209. <script src="./js/jquery.js"></script>
  210. <script>
  211. const {
  212. createApp,
  213. onBeforeMount,
  214. onMounted,
  215. onUnmounted,
  216. ref,
  217. reactive,
  218. toRefs,
  219. computed,
  220. nextTick
  221. } = Vue
  222. createApp({
  223. setup() {
  224. const state = reactive({
  225. recordList: [],
  226. dialogRecordList: false,
  227. dialogVisible: false,
  228. rule: '',
  229. token: '',
  230. actId: '',
  231. keyStr: 'qwerasdfzxcvtyui',
  232. prizeList: [
  233. ], // 后台配置的奖品数据
  234. isRunning: false, // 是否正在抽奖
  235. baseRunAngle: 360 * 5, // 总共转动角度 至少5圈
  236. prizeId: 0, // 中奖id
  237. })
  238. const prizeWrap = ref(null)
  239. // 平均每个奖品角度
  240. const rotateAngle = computed(() => {
  241. const _degree = 360 / state.prizeList.length
  242. return _degree
  243. })
  244. // 要执行总角度数
  245. const totalRunAngle = computed(() => {
  246. return state.baseRunAngle + 360 - state.prizeId * rotateAngle.value - rotateAngle.value / 2
  247. })
  248. // 计算绘制转盘背景
  249. const bgColor = computed(() => {
  250. const _len = state.prizeList.length
  251. const colorList = ['#5352b3', '#363589']
  252. let colorVal = ''
  253. for (let i = 0; i < _len; i++) {
  254. colorVal += `${colorList[i % 2]} ${rotateAngle.value * i}deg ${rotateAngle.value * (i + 1)}deg,`
  255. }
  256. return `
  257. background: conic-gradient(${colorVal.slice(0, -1)});
  258. `
  259. })
  260. // 每个奖品布局
  261. const prizeStyle = computed(() => {
  262. const _degree = rotateAngle.value
  263. return (i) => {
  264. return `
  265. width: ${2 * 250 * Math.sin(_degree / 2 * Math.PI / 180)}px;
  266. height: 250px;
  267. transform: rotate(${_degree * i + _degree / 2}deg);
  268. transform-origin: 50% 100%;
  269. `
  270. }
  271. })
  272. onBeforeMount(() => {
  273. debugger
  274. window.addEventListener('message', function (e) {
  275. // console.log("接收值:", e.data)
  276. state.token = e.data.token;
  277. state.actId = e.data.actId;
  278. ElementPlus.ElLoading.service();
  279. getTurntableInfo();
  280. ElementPlus.ElLoading.service().close();
  281. })
  282. })
  283. onMounted(() => {
  284. prizeWrap.value.style = `${bgColor.value} transform: rotate(-${rotateAngle.value / 2}deg)`;
  285. })
  286. onUnmounted(() => {
  287. prizeWrap.value.removeEventListener('transitionend', stopRun)
  288. })
  289. // 获取大转盘信息
  290. async function getTurntableInfo() {
  291. debugger
  292. const postData = {
  293. actId: state.actId,
  294. };
  295. let res = await httpAjax('get', '/mall-prize/prize/info', postData)
  296. if (res.errno === 0) {
  297. // console.log('获取大转盘信息',res.data);
  298. state.prizeList = res.data.pool;
  299. state.rule = res.data.content;
  300. } else {
  301. ElementPlus.ElMessage({
  302. showClose: true,
  303. message: res.errmsg,
  304. type: 'error',
  305. });
  306. }
  307. };
  308. function encryptECB(word) {
  309. var keyHex = CryptoJS.enc.Utf8.parse(state.keyStr)
  310. var plaintText = word
  311. var encryptedData = CryptoJS.AES.encrypt(
  312. plaintText,
  313. keyHex,
  314. {
  315. mode: CryptoJS.mode.ECB,
  316. padding: CryptoJS.pad.Pkcs7
  317. })
  318. return encryptedData.toString();
  319. };
  320. // 大转盘抽奖按钮
  321. async function starDraw() {
  322. let postData = {
  323. actId: state.actId,
  324. };
  325. postData = JSON.stringify(postData)
  326. postData = encryptECB(postData)
  327. postData = postData.replace(/[\t\r\f\n\s]*/g, '');
  328. // let res = await httpAjax('post', '/mall-prize/prize', getFormData(postData));
  329. let res = await httpAjax('post', '/mall-prize/prize', postData);
  330. if (res.errno === 0) {
  331. // console.log('抽奖',res.data);
  332. state.prizeId = res.data.index;
  333. startRun();
  334. } else {
  335. state.isRunning = false;
  336. ElementPlus.ElMessage({
  337. showClose: true,
  338. message: res.errmsg,
  339. type: 'error',
  340. });
  341. }
  342. };
  343. //抽奖记录
  344. // async function getRecordList() {
  345. // const postData = {
  346. // actId: state.actId,
  347. // };
  348. // let res = await httpAjax('get', '/mall-prize/prize/user/list', postData);
  349. // if (res.errno === 0) {
  350. // console.log('抽奖记录',res.data);
  351. // state.recordList = res.data;
  352. // } else {
  353. // state.isRunning = false;
  354. // ElementPlus.ElMessage({
  355. // showClose: true,
  356. // message: res.errmsg,
  357. // type: 'error',
  358. // });
  359. // }
  360. // };
  361. //获奖名单
  362. async function getRecordList() {
  363. const postData = {
  364. actId: state.actId,
  365. };
  366. let res = await httpAjax('get', '/mall-prize/prize/winners', postData);
  367. if (res.errno === 0) {
  368. state.recordList = res.data;
  369. } else {
  370. state.isRunning = false;
  371. ElementPlus.ElMessage({
  372. showClose: true,
  373. message: res.errmsg,
  374. type: 'error',
  375. });
  376. }
  377. };
  378. // 简单封装ajax
  379. const httpAjax = (type, url, data) => {
  380. ajaxHeaders = {
  381. "Authorization": state.token,
  382. 'Content-Type':'application/json'
  383. }
  384. return new Promise((resolve, reject) => {
  385. $.ajax({
  386. type: type,
  387. // url: 'http://192.168.100.208:9083/admin' + url, //本地
  388. // url: "http://47.103.79.143:9085/admin" + url,//测试环境
  389. url: "https://xiaoyou.dgtis.com/admin" + url,//正式环境
  390. data: data,
  391. contentType: type === 'post' ? false : true,
  392. processData: type === 'post' ? false : true,
  393. headers: ajaxHeaders,
  394. success: function (res) {
  395. if (res.errno == 503) {
  396. window.location.href = 'https://dgt.dgtis.com/oneportal/login'
  397. } else {
  398. resolve(res);
  399. }
  400. },
  401. error: function (error) {
  402. reject(error);
  403. ElementPlus.ElMessage({
  404. showClose: true,
  405. message: '网络错误,请稍后再试!',
  406. type: 'error',
  407. });
  408. }
  409. })
  410. })
  411. }
  412. // 处理formData数据格式
  413. const getFormData = (datas) => {
  414. let formData = new FormData();
  415. for (let key in datas) {
  416. formData.append(key, datas[key]);
  417. }
  418. return formData;
  419. }
  420. // 获取随机数
  421. const getRandomNum = () => {
  422. const num = Math.floor(Math.random() * state.prizeList.length)
  423. return num
  424. }
  425. const showRules = () => {
  426. state.dialogVisible = true;
  427. }
  428. const showRecordList = () => {
  429. getRecordList();
  430. state.dialogRecordList = true;
  431. }
  432. const start = () => {
  433. debugger
  434. // ElementPlus.ElMessage({
  435. // showClose: true,
  436. // message: '已无抽奖次数!',
  437. // type: 'warning',
  438. // })
  439. // return
  440. if (!state.isRunning) {
  441. state.isRunning = true;
  442. starDraw();
  443. // console.log('开始抽奖,后台请求中奖奖品')
  444. // // 请求返回的奖品编号 这里使用随机数
  445. // const prizeId = getRandomNum()
  446. // console.log('中奖ID>>>', prizeId, state.prizeList[prizeId])
  447. // state.prizeId = prizeId
  448. }
  449. }
  450. const startRun = () => {
  451. // console.log(state.isRunning, totalRunAngle.value)
  452. // 设置动效
  453. prizeWrap.value.style = `
  454. ${bgColor.value}
  455. transform: rotate(${totalRunAngle.value}deg);
  456. transition: all 4s ease;
  457. `
  458. // 监听transition动效停止事件
  459. prizeWrap.value.addEventListener('transitionend', stopRun)
  460. }
  461. const stopRun = (e) => {
  462. // console.log(e)
  463. state.isRunning = false
  464. prizeWrap.value.style = `
  465. ${bgColor.value}
  466. transform: rotate(${totalRunAngle.value - state.baseRunAngle}deg);
  467. `
  468. if (state.prizeList[state.prizeId].prizeType != '40') {
  469. ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换相应物品。", {
  470. showClose: false,
  471. center: true,
  472. confirmButtonText: '确定',
  473. })
  474. // ElementPlus.ElMessage({
  475. // offset:window.screen.height / 2,
  476. // duration:3000,
  477. // showClose: true,
  478. // message: "恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换响应物品。",
  479. // type: 'success',
  480. // })
  481. } else {
  482. ElementPlus.ElMessageBox.alert("很遗憾,您未中奖。", {
  483. showClose: false,
  484. center: true,
  485. confirmButtonText: '确认',
  486. })
  487. // ElementPlus.ElMessage({
  488. // offset:window.screen.height / 4,
  489. // duration:10000,
  490. // showClose: true,
  491. // message: "很遗憾,您未中奖。",
  492. // type: 'error',
  493. // })
  494. }
  495. }
  496. return {
  497. ...toRefs(state),
  498. bgColor,
  499. prizeStyle,
  500. prizeWrap,
  501. start,
  502. showRules,
  503. showRecordList
  504. }
  505. }
  506. }).use(ElementPlus).mount('#app')
  507. </script>
  508. </html>