dailyDrawCarousel.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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/2024/09/27/gju2h9j4ttpjwscw9119.jpg') no-repeat;
  42. background-size: 100% 100%;
  43. width: 640px;
  44. height: 680px;
  45. margin: 0 auto;
  46. margin-top: 20px;
  47. }
  48. .el-dialog__body {
  49. padding-top: 0px !important;
  50. }
  51. [v-cloak] {
  52. display: none;
  53. }
  54. .rules {
  55. cursor: pointer;
  56. position: absolute;
  57. width: 50px;
  58. height: 50px;
  59. background: #fff;
  60. border-radius: 50%;
  61. display: flex;
  62. justify-content: center;
  63. align-items: center;
  64. font-size: 14px;
  65. font-weight: 600;
  66. left: 8%;
  67. top: 22%;
  68. }
  69. .recordBtn {
  70. cursor: pointer;
  71. position: absolute;
  72. width: 50px;
  73. height: 50px;
  74. background: #fff;
  75. border-radius: 50%;
  76. display: flex;
  77. justify-content: center;
  78. align-items: center;
  79. font-size: 14px;
  80. font-weight: 600;
  81. right: 10%;
  82. bottom: 7%;
  83. }
  84. .recordBtn>img {
  85. width: 75px;
  86. height: auto;
  87. }
  88. .container {
  89. overflow: hidden;
  90. width: 500px;
  91. height: 500px;
  92. margin: 0 auto;
  93. position: relative;
  94. top: 24%;
  95. }
  96. .prize-list {
  97. width: 100%;
  98. height: 100%;
  99. border-radius: 50%;
  100. border: 10px solid #ffc227;
  101. overflow: hidden;
  102. }
  103. .prize-item {
  104. /*border: 2px solid red;*/
  105. position: absolute;
  106. left: 0;
  107. right: 0;
  108. top: -10px;
  109. margin: auto;
  110. }
  111. .prize-item img {
  112. width: 35%;
  113. /* height: 25%; */
  114. margin: 35px auto 10px;
  115. display: block;
  116. }
  117. .prize-item p {
  118. color: #fff;
  119. font-size: 12px;
  120. text-align: center;
  121. line-height: 20px;
  122. }
  123. .btn {
  124. width: 80px;
  125. height: 110px;
  126. background: url('https://xiaoyou.dgtis.com/images/image/2023/09/12/xvtwunkntyc65fngc9pb.png') no-repeat center / 100% 100%;
  127. position: absolute;
  128. left: 0;
  129. right: 0;
  130. top: -5%;
  131. bottom: 0;
  132. margin: auto;
  133. cursor: pointer;
  134. }
  135. /* .btn::before {
  136. content: "";
  137. width: 41px;
  138. height: 39px;
  139. background: url('https://xiaoyou.dgtis.com/images/image/2023/08/15/2vac6uuqd3gpbl35l8e1.png') no-repeat center / 100% 100%;
  140. position: absolute;
  141. left: 0;
  142. right: 0;
  143. top: -30px;
  144. margin: auto;
  145. -webkit-transform: rotate(-5deg);
  146. transform: rotate(-5deg);
  147. } */
  148. .recordListBox {
  149. max-height: 200px;
  150. overflow: auto;
  151. }
  152. .title {
  153. font-size: 15px;
  154. font-weight: 600;
  155. }
  156. .recordItem {
  157. display: flex;
  158. justify-content: space-around;
  159. align-items: center;
  160. margin: 10px 0;
  161. }
  162. </style>
  163. </head>
  164. <body>
  165. <div id="app" v-cloak class="app">
  166. <div class="rules" @click="showRules">
  167. 抽奖<br>规则
  168. </div>
  169. <div class="recordBtn" @click="showRecordList">
  170. <!-- <img src="https://xiaoyou.dgtis.com/images/image/2023/09/06/lt1vbg426idwq725ysdm.png" alt="抽奖记录"> -->
  171. <img src="https://xiaoyou.dgtis.com/images/image/2024/11/28/9p4ts0l94ngnz9rac48b.png" alt="十连抽奖">
  172. </div>
  173. <div class="container">
  174. <div class="prize-list" ref="prizeWrap" :style="bgColor">
  175. <div class="prize-item" v-for="(item, index) in prizeList" :style="prizeStyle(index)">
  176. <img :src="item.imgUrl" alt="">
  177. <p>{{ item.prizeName }}</p>
  178. </div>
  179. </div>
  180. <div class="btn" @click="start"></div>
  181. </div>
  182. <el-dialog v-model="dialogVisible" title="抽奖规则" width="70%" center>
  183. <div style="max-height: 400px;overflow: auto;" v-html="rule"></div>
  184. </el-dialog>
  185. <el-dialog v-model="dialogRecordList" title="中奖记录" width="40%" center>
  186. <div class="recordListBox">
  187. <!-- <div class="recordItem title">
  188. <div style="width: 30%;text-align: center;">姓名</div>
  189. <div style="width: 30%;text-align: center;">奖品</div>
  190. <div style="width: 40%;text-align: center;">获奖时间</div>
  191. </div> -->
  192. <!-- <el-empty description="暂无数据" v-if="recordList.length==0" :image-size="20"></el-empty> -->
  193. <div class="recordItem">
  194. <div style="width: 100%;text-align: center;">恭喜,你中了10积分</div>
  195. </div>
  196. <!-- <div class="recordItem" v-for="(item, index) in recordList">
  197. <div style="width: 100%;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 = ['#e32c1a', '#ff5544']
  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. window.addEventListener('message', function (e) {
  274. // console.log("接收值:", e.data)
  275. state.token = e.data.token;
  276. state.actId = e.data.actId;
  277. ElementPlus.ElLoading.service();
  278. getTurntableInfo();
  279. ElementPlus.ElLoading.service().close();
  280. })
  281. })
  282. onMounted(() => {
  283. prizeWrap.value.style = `${bgColor.value} transform: rotate(-${rotateAngle.value / 2}deg)`;
  284. })
  285. onUnmounted(() => {
  286. prizeWrap.value.removeEventListener('transitionend', stopRun)
  287. })
  288. // 获取大转盘信息
  289. async function getTurntableInfo() {
  290. const postData = {
  291. actId: state.actId,
  292. };
  293. let res = await httpAjax('get', '/mall-prize/prize/info', postData)
  294. if (res.errno === 0) {
  295. // console.log('获取大转盘信息',res.data);
  296. state.prizeList = res.data.pool;
  297. state.rule = res.data.content;
  298. } else {
  299. ElementPlus.ElMessage({
  300. showClose: true,
  301. message: res.errmsg,
  302. type: 'error',
  303. });
  304. }
  305. };
  306. function encryptECB(word) {
  307. var keyHex = CryptoJS.enc.Utf8.parse(state.keyStr)
  308. var plaintText = word
  309. var encryptedData = CryptoJS.AES.encrypt(
  310. plaintText,
  311. keyHex,
  312. {
  313. mode: CryptoJS.mode.ECB,
  314. padding: CryptoJS.pad.Pkcs7
  315. })
  316. return encryptedData.toString();
  317. };
  318. // 大转盘抽奖按钮
  319. async function starDraw() {
  320. let postData = {
  321. actId: state.actId,
  322. };
  323. postData = JSON.stringify(postData)
  324. postData = encryptECB(postData)
  325. postData = postData.replace(/[\t\r\f\n\s]*/g, '');
  326. // let res = await httpAjax('post', '/mall-prize/prize', getFormData(postData));
  327. let res = await httpAjax('post', '/mall-prize/prize', postData);
  328. if (res.errno === 0) {
  329. // console.log('抽奖',res.data);
  330. state.prizeId = res.data.index;
  331. startRun();
  332. } else {
  333. state.isRunning = false;
  334. ElementPlus.ElMessage({
  335. showClose: true,
  336. message: res.errmsg,
  337. type: 'error',
  338. });
  339. }
  340. };
  341. //抽奖记录
  342. // async function getRecordList() {
  343. // const postData = {
  344. // actId: state.actId,
  345. // };
  346. // let res = await httpAjax('get', '/mall-prize/prize/user/list', postData);
  347. // if (res.errno === 0) {
  348. // console.log('抽奖记录',res.data);
  349. // state.recordList = res.data;
  350. // } else {
  351. // state.isRunning = false;
  352. // ElementPlus.ElMessage({
  353. // showClose: true,
  354. // message: res.errmsg,
  355. // type: 'error',
  356. // });
  357. // }
  358. // };
  359. //获奖名单
  360. async function getRecordList() {
  361. const postData = {
  362. actId: state.actId,
  363. };
  364. let res = await httpAjax('get', '/mall-prize/prize/winners', postData);
  365. if (res.errno === 0) {
  366. state.recordList = res.data;
  367. } else {
  368. state.isRunning = false;
  369. ElementPlus.ElMessage({
  370. showClose: true,
  371. message: res.errmsg,
  372. type: 'error',
  373. });
  374. }
  375. };
  376. // 简单封装ajax
  377. const httpAjax = (type, url, data) => {
  378. ajaxHeaders = {
  379. "Authorization": state.token,
  380. 'Content-Type':'application/json'
  381. }
  382. return new Promise((resolve, reject) => {
  383. $.ajax({
  384. type: type,
  385. // url: 'http://192.168.100.208:9083/admin' + url, //本地
  386. url: "http://47.103.79.143:9085/admin" + url,//测试环境
  387. // url:"https://xiaoyou.dgtis.com/admin"+ url,//正式环境
  388. data: data,
  389. contentType: type === 'post' ? false : true,
  390. processData: type === 'post' ? false : true,
  391. headers: ajaxHeaders,
  392. success: function (res) {
  393. if (res.errno == 503) {
  394. window.location.href = 'https://dgt.dgtis.com/oneportal/login'
  395. } else {
  396. resolve(res);
  397. }
  398. },
  399. error: function (error) {
  400. reject(error);
  401. ElementPlus.ElMessage({
  402. showClose: true,
  403. message: '网络错误,请稍后再试!',
  404. type: 'error',
  405. });
  406. }
  407. })
  408. })
  409. }
  410. // 处理formData数据格式
  411. const getFormData = (datas) => {
  412. let formData = new FormData();
  413. for (let key in datas) {
  414. formData.append(key, datas[key]);
  415. }
  416. return formData;
  417. }
  418. // 获取随机数
  419. const getRandomNum = () => {
  420. const num = Math.floor(Math.random() * state.prizeList.length)
  421. return num
  422. }
  423. const showRules = () => {
  424. state.dialogVisible = true;
  425. }
  426. const showRecordList = () => {
  427. getRecordList();
  428. state.dialogRecordList = true;
  429. }
  430. const start = () => {
  431. // ElementPlus.ElMessage({
  432. // showClose: true,
  433. // message: '已无抽奖次数!',
  434. // type: 'warning',
  435. // })
  436. // return
  437. if (!state.isRunning) {
  438. state.isRunning = true;
  439. starDraw();
  440. // console.log('开始抽奖,后台请求中奖奖品')
  441. // // 请求返回的奖品编号 这里使用随机数
  442. // const prizeId = getRandomNum()
  443. // console.log('中奖ID>>>', prizeId, state.prizeList[prizeId])
  444. // state.prizeId = prizeId
  445. }
  446. }
  447. const startRun = () => {
  448. // console.log(state.isRunning, totalRunAngle.value)
  449. // 设置动效
  450. prizeWrap.value.style = `
  451. ${bgColor.value}
  452. transform: rotate(${totalRunAngle.value}deg);
  453. transition: all 4s ease;
  454. `
  455. // 监听transition动效停止事件
  456. prizeWrap.value.addEventListener('transitionend', stopRun)
  457. }
  458. const stopRun = (e) => {
  459. // console.log(e)
  460. state.isRunning = false
  461. prizeWrap.value.style = `
  462. ${bgColor.value}
  463. transform: rotate(${totalRunAngle.value - state.baseRunAngle}deg);
  464. `
  465. if (state.prizeList[state.prizeId].prizeType == '10') {
  466. ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换相应物品。", {
  467. showClose: false,
  468. center: true,
  469. confirmButtonText: '确定',
  470. })
  471. window.parent.getUserInfo();
  472. } else if (state.prizeList[state.prizeId].prizeType == '20') {
  473. ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "!", {
  474. showClose: false,
  475. center: true,
  476. confirmButtonText: '确定',
  477. })
  478. window.parent.getUserInfo();
  479. } else {
  480. ElementPlus.ElMessageBox.alert("很遗憾,您未中奖。", {
  481. showClose: false,
  482. center: true,
  483. confirmButtonText: '确认',
  484. })
  485. window.parent.getUserInfo();
  486. }
  487. }
  488. return {
  489. ...toRefs(state),
  490. bgColor,
  491. prizeStyle,
  492. prizeWrap,
  493. start,
  494. showRules,
  495. showRecordList
  496. }
  497. }
  498. }).use(ElementPlus).mount('#app')
  499. </script>
  500. </html>