dailyDrawCarousel-H5.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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/2025/01/16/h1xp8b04dwbqs4m6qzrd.jpg') no-repeat;
  42. background-size: 100% 100%;
  43. width: 375px;
  44. height: 680px;
  45. margin: 0 auto;
  46. margin-top: 20px;
  47. position: relative;
  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: 5%;
  68. top: 24%;
  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: 10%;
  83. bottom: 7%;
  84. }
  85. .recordBtn>img {
  86. width: 75px;
  87. height: auto;
  88. }
  89. .container {
  90. overflow: hidden;
  91. width: 350px;
  92. height: 350px;
  93. margin: 0 auto;
  94. position: relative;
  95. top: 30%;
  96. }
  97. .prize-list {
  98. width: 100%;
  99. height: 100%;
  100. border-radius: 50%;
  101. border: 10px solid #ffc227;
  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: 25%;
  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: 300px;
  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. <!-- <img src="https://xiaoyou.dgtis.com/images/image/2023/09/06/lt1vbg426idwq725ysdm.png" alt="抽奖记录"> -->
  172. <img src="https://xiaoyou.dgtis.com/images/image/2024/11/28/9p4ts0l94ngnz9rac48b.png" alt="十连抽奖">
  173. </div>
  174. <div class="container">
  175. <div class="prize-list" ref="prizeWrap" :style="bgColor">
  176. <div class="prize-item" v-for="(item, index) in prizeList" :style="prizeStyle(index)">
  177. <img :src="item.imgUrl" alt="">
  178. <p>{{ item.prizeName }}</p>
  179. </div>
  180. </div>
  181. <div class="btn" @click="start"></div>
  182. </div>
  183. <el-dialog v-model="dialogVisible" title="抽奖规则" width="90%" center>
  184. <div style="max-height: 400px;overflow: auto;" v-html="rule"></div>
  185. </el-dialog>
  186. <el-dialog v-model="dialogRecordList" title="中奖记录" width="90%" center>
  187. <div class="recordListBox">
  188. <div class="recordItem" v-for="item in recordList">
  189. <div style="width: 100%;text-align: center;">{{item}}</div>
  190. </div>
  191. </div>
  192. </el-dialog>
  193. </div>
  194. </body>
  195. <script src="./js/crypto-js.min.js"></script>
  196. <script src="./js/vue.global.js"></script>
  197. <link href="./css/index.css" rel="stylesheet">
  198. <script src="./js/index.full.min.js"></script>
  199. <script src="./js/jquery.js"></script>
  200. <script>
  201. const {
  202. createApp,
  203. onBeforeMount,
  204. onMounted,
  205. onUnmounted,
  206. ref,
  207. reactive,
  208. toRefs,
  209. computed,
  210. nextTick
  211. } = Vue
  212. createApp({
  213. setup() {
  214. const state = reactive({
  215. recordList: [],
  216. dialogRecordList: false,
  217. dialogVisible: false,
  218. rule: '',
  219. token: '',
  220. actId: '',
  221. keyStr: 'qwerasdfzxcvtyui',
  222. prizeList: [
  223. ], // 后台配置的奖品数据
  224. isRunning: false, // 是否正在抽奖
  225. baseRunAngle: 360 * 5, // 总共转动角度 至少5圈
  226. prizeId: 0, // 中奖id
  227. })
  228. const prizeWrap = ref(null)
  229. // 平均每个奖品角度
  230. const rotateAngle = computed(() => {
  231. const _degree = 360 / state.prizeList.length
  232. return _degree
  233. })
  234. // 要执行总角度数
  235. const totalRunAngle = computed(() => {
  236. return state.baseRunAngle + 360 - state.prizeId * rotateAngle.value - rotateAngle.value / 2
  237. })
  238. // 计算绘制转盘背景
  239. const bgColor = computed(() => {
  240. const _len = state.prizeList.length
  241. const colorList = ['#e32c1a', '#ff5544']
  242. let colorVal = ''
  243. for (let i = 0; i < _len; i++) {
  244. colorVal += `${colorList[i % 2]} ${rotateAngle.value * i}deg ${rotateAngle.value * (i + 1)}deg,`
  245. }
  246. return `
  247. background: conic-gradient(${colorVal.slice(0, -1)});
  248. `
  249. })
  250. // 每个奖品布局
  251. const prizeStyle = computed(() => {
  252. const _degree = rotateAngle.value
  253. return (i) => {
  254. return `
  255. width: ${2 * 185 * Math.sin(_degree / 2 * Math.PI / 180)}px;
  256. height: 185px;
  257. transform: rotate(${_degree * i + _degree / 2}deg);
  258. transform-origin: 50% 100%;
  259. `
  260. }
  261. })
  262. onBeforeMount(() => {
  263. // 创建URL对象
  264. const url = new URL(window.location.href);
  265. // 获取查询参数
  266. const actId = url.searchParams.get('actId');
  267. const token = url.searchParams.get('token');
  268. state.token = token;
  269. state.actId = actId;
  270. ElementPlus.ElLoading.service();
  271. getTurntableInfo();
  272. ElementPlus.ElLoading.service().close();
  273. })
  274. onMounted(() => {
  275. prizeWrap.value.style = `${bgColor.value} transform: rotate(-${rotateAngle.value / 2}deg)`;
  276. })
  277. onUnmounted(() => {
  278. prizeWrap.value.removeEventListener('transitionend', stopRun)
  279. })
  280. // 获取大转盘信息
  281. async function getTurntableInfo() {
  282. const postData = {
  283. actId: state.actId,
  284. };
  285. let res = await httpAjax('get', '/mall-prize/prize/info', postData)
  286. if (res.errno === 0) {
  287. // console.log('获取大转盘信息',res.data);
  288. state.prizeList = res.data.pool;
  289. state.rule = res.data.content;
  290. } else {
  291. ElementPlus.ElMessage({
  292. showClose: true,
  293. message: res.errmsg,
  294. type: 'error',
  295. });
  296. }
  297. };
  298. function encryptECB(word) {
  299. var keyHex = CryptoJS.enc.Utf8.parse(state.keyStr)
  300. var plaintText = word
  301. var encryptedData = CryptoJS.AES.encrypt(
  302. plaintText,
  303. keyHex,
  304. {
  305. mode: CryptoJS.mode.ECB,
  306. padding: CryptoJS.pad.Pkcs7
  307. })
  308. return encryptedData.toString();
  309. };
  310. // 大转盘抽奖按钮
  311. async function starDraw() {
  312. let postData = {
  313. actId: state.actId,
  314. };
  315. postData = JSON.stringify(postData)
  316. postData = encryptECB(postData)
  317. postData = postData.replace(/[\t\r\f\n\s]*/g, '');
  318. // let res = await httpAjax('post', '/mall-prize/prize', getFormData(postData));
  319. let res = await httpAjax('post', '/mall-prize/prize', postData);
  320. if (res.errno === 0) {
  321. // console.log('抽奖',res.data);
  322. state.prizeId = res.data.index;
  323. startRun();
  324. } else {
  325. state.isRunning = false;
  326. ElementPlus.ElMessage({
  327. showClose: true,
  328. message: res.errmsg,
  329. type: 'error',
  330. });
  331. }
  332. };
  333. //中奖记录
  334. async function getRecordList() {
  335. let postData = {
  336. actId: state.actId,
  337. };
  338. postData = JSON.stringify(postData)
  339. postData = encryptECB(postData)
  340. postData = postData.replace(/[\t\r\f\n\s]*/g, '');
  341. ElementPlus.ElLoading.service();
  342. let res = await httpAjax('post', '/mall-prize/continuousClicks', postData);
  343. ElementPlus.ElLoading.service().close();
  344. if (res.errno === 0) {
  345. state.recordList = res.data;
  346. state.dialogRecordList = true;
  347. } else {
  348. ElementPlus.ElMessage({
  349. showClose: true,
  350. message: res.errmsg,
  351. type: 'error',
  352. });
  353. }
  354. };
  355. // 简单封装ajax
  356. const httpAjax = (type, url, data) => {
  357. ajaxHeaders = {
  358. "Authorization": state.token,
  359. 'Content-Type':'application/json'
  360. }
  361. return new Promise((resolve, reject) => {
  362. $.ajax({
  363. type: type,
  364. // url: 'http://192.168.100.208:9083/admin' + url, //本地
  365. // url: "http://47.103.79.143:9085/admin" + url,//测试环境
  366. url:"https://xiaoyou.dgtis.com/admin"+ url,//正式环境
  367. data: data,
  368. contentType: type === 'post' ? false : true,
  369. processData: type === 'post' ? false : true,
  370. headers: ajaxHeaders,
  371. success: function (res) {
  372. if (res.errno == 503) {
  373. //window.location.href = 'https://dgt.dgtis.com/oneportal/login'
  374. } else {
  375. resolve(res);
  376. }
  377. },
  378. error: function (error) {
  379. reject(error);
  380. ElementPlus.ElMessage({
  381. showClose: true,
  382. message: '网络错误,请稍后再试!',
  383. type: 'error',
  384. });
  385. }
  386. })
  387. })
  388. }
  389. // 处理formData数据格式
  390. const getFormData = (datas) => {
  391. let formData = new FormData();
  392. for (let key in datas) {
  393. formData.append(key, datas[key]);
  394. }
  395. return formData;
  396. }
  397. // 获取随机数
  398. const getRandomNum = () => {
  399. const num = Math.floor(Math.random() * state.prizeList.length)
  400. return num
  401. }
  402. const showRules = () => {
  403. state.dialogVisible = true;
  404. }
  405. const showRecordList = () => {
  406. getRecordList();
  407. }
  408. const start = () => {
  409. // ElementPlus.ElMessage({
  410. // showClose: true,
  411. // message: '已无抽奖次数!',
  412. // type: 'warning',
  413. // })
  414. // return
  415. if (!state.isRunning) {
  416. state.isRunning = true;
  417. starDraw();
  418. // console.log('开始抽奖,后台请求中奖奖品')
  419. // // 请求返回的奖品编号 这里使用随机数
  420. // const prizeId = getRandomNum()
  421. // console.log('中奖ID>>>', prizeId, state.prizeList[prizeId])
  422. // state.prizeId = prizeId
  423. }
  424. }
  425. const startRun = () => {
  426. // console.log(state.isRunning, totalRunAngle.value)
  427. // 设置动效
  428. prizeWrap.value.style = `
  429. ${bgColor.value}
  430. transform: rotate(${totalRunAngle.value}deg);
  431. transition: all 4s ease;
  432. `
  433. // 监听transition动效停止事件
  434. prizeWrap.value.addEventListener('transitionend', stopRun)
  435. }
  436. const stopRun = (e) => {
  437. // console.log(e)
  438. state.isRunning = false
  439. prizeWrap.value.style = `
  440. ${bgColor.value}
  441. transform: rotate(${totalRunAngle.value - state.baseRunAngle}deg);
  442. `
  443. if (state.prizeList[state.prizeId].prizeType == '10') {
  444. ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换相应物品。", {
  445. showClose: false,
  446. center: true,
  447. confirmButtonText: '确定',
  448. })
  449. window.parent.getUserInfo();
  450. } else if (state.prizeList[state.prizeId].prizeType == '20') {
  451. ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "!", {
  452. showClose: false,
  453. center: true,
  454. confirmButtonText: '确定',
  455. })
  456. window.parent.getUserInfo();
  457. } else {
  458. ElementPlus.ElMessageBox.alert("很遗憾,您未中奖。", {
  459. showClose: false,
  460. center: true,
  461. confirmButtonText: '确认',
  462. })
  463. window.parent.getUserInfo();
  464. }
  465. }
  466. return {
  467. ...toRefs(state),
  468. bgColor,
  469. prizeStyle,
  470. prizeWrap,
  471. start,
  472. showRules,
  473. showRecordList
  474. }
  475. }
  476. }).use(ElementPlus).mount('#app')
  477. </script>
  478. </html>