微信php喝酒转盘小程序,微信小程序 转盘

2023-10-10 00:30
文章标签 程序 微信 php 转盘 喝酒

本文主要是介绍微信php喝酒转盘小程序,微信小程序 转盘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

c59da2b9553d

1.html

{{item.award}}

抽奖

2.css

/* 转盘 */

.canvas-container ul,

.canvas-container li{

margin: 0 ;

padding: 0;

list-style: none;

}

.canvas-container{

margin: 0 auto;

position: relative;

width: 300px;

height: 300px;

border-radius: 50%;

border: 2px solid #E44025;

box-shadow: 0 2px 3px #333,0 0 2px #000;

}

.canvas-content{

position: absolute;

left: 0;

top: 0;

z-index: 1;

display: block;

width: inherit;

height: inherit;

border-radius: inherit;

background-clip: padding-box;

background-color: #ffcb3f;

}

.canvas-element{

width: inherit;

height: inherit;

border-radius: 50%;

}

.canvas-list{

position: absolute;

left: 0;

top: 0;

width: inherit;

height: inherit;

z-index: 2;

}

.canvas-item{

position: absolute;

left: 0;

top: 0;

width: 100%;

height: 100%;

color: #e4370e;

font-weight: bold;

text-shadow: 0 1px 1px rgba(255,255,255,.6);

}

.canvas-item-text{

position: relative;

display: block;

padding-top: 20px;

/* width: 50px; */

margin: 0 auto;

text-align: center;

-webkit-transform-origin: 50% 150px;

transform-origin: 50% 150px;

}

.canvas-btn{

position: absolute;

left: 110px;

top: 110px;

z-index: 3;

width: 80px;

height: 80px;

border-radius: 50%;

color: #F4E9CC;

background-color: #E44025;

line-height: 80px;

text-align: center;

font-size: 20px;

text-shadow: 0 -1px 1px rgba(0,0,0,.6);

box-shadow: 0 3px 5px rgba(0,0,0,.6);

text-decoration: none;

}

.canvas-btn::after{

position: absolute;

display: block;

content: ' ';

left: 10px;

top: -46px;

width: 0;

height: 0;

overflow: hidden;

border-width: 30px;

border-style: solid;

border-color: transparent;

border-bottom-color: #E44025;

}

.canvas-btn.disabled{

pointer-events: none;

background: #B07A7B;

color: #ccc;

}

.canvas-btn.disabled::after{

border-bottom-color: #B07A7B;

}

.gb-run{

-webkit-transition: all 6s ease;

transition: all 6s ease;

}

/* 查看中奖 */

.main-container{

margin: 1rem 2rem;

}

.main-container-rule{

padding: 1rem 0;

}

.main-rule-title{

display: block;

padding: 4px 0;

font-size: 16px;

font-weight: bold;

}

.main-rule-item{

display: block;

padding: 2px 0;

}

.main-container-btn{

display: flex;

justify-content: center;

}

3.js

data: {

awardsList: {},

animationData: {},

btnDisabled: '',

awards:[],

prob:[],

}

c59da2b9553d

图1

c59da2b9553d

图2

onReady: function (e) {

var that = this;

// 获取数据,如图1,

app.util.request({

url: xxxxxxxxxx",

cachetime: "0",

data: {},

success: function(n) {

// 把获取出来的概率数据循环复制一份到prob,概率数据保持整数,如图2

let prob=[];

for(let i=0;i

if (n.data.data[i].prob!=0) {

for(let k=0;k

prob.push(n.data.data[i].prob)

}

}

};

// 打乱prob数组,

prob.sort(function() {

return (0.5-Math.random());

});

that.setData({

awards:n.data.data,

prob:prob,

});

// 绘制转盘

var awardsConfig = that.data.awards,len = awardsConfig.length,rotateDeg = 360 / len / 2 + 90,html = [],turnNum = 1 / len  // 文字旋转 turn 值

that.setData({

btnDisabled: that.data.chance ? '' : 'disabled'

})

var ctx = wx.createContext()

for (var i = 0; i 

// 保存当前状态

ctx.save();

// 开始一条新路径

ctx.beginPath();

// 位移到圆心,下面需要围绕圆心旋转

ctx.translate(150, 150);

// 从(0, 0)坐标开始定义一条新的子路径

ctx.moveTo(0, 0);

// 旋转弧度,需将角度转换为弧度,使用 degrees * Math.PI/180 公式进行计算。

ctx.rotate((360 / len * i - rotateDeg) * Math.PI/180);

// 绘制圆弧

ctx.arc(0, 0, 150, 0,  2 * Math.PI / len, false);

// 颜色间隔

if (i % 2 == 0) {

ctx.setFillStyle('#ffb820');

}else{

ctx.setFillStyle('#ffcb3f');

}

// 填充扇形

ctx.fill();

// 绘制边框

ctx.setLineWidth(0.5);

ctx.setStrokeStyle('#e4370e');

ctx.stroke();

// 恢复前一个状态

ctx.restore();

// 奖项列表

html.push({turn: i * turnNum + 'turn', award: awardsConfig[i].name});

}

that.setData({

awardsList: html

});

wx.drawCanvas({

canvasId: 'lotteryCanvas',

actions: ctx.getActions()

})

}

});

},

// 点击抽奖

getLottery: function () {

var that = this

// 随机prob数组的下标拿到prob的值

let Snum = Math.floor(Math.random()*that.data.prob.length);

that.query(that.data.prob[Snum]);

},

// 获取奖品数据以及下标,

query(snum){

let that=this;

let arr=[];

for(let i=0;i

if (that.data.awards[i].prob==snum) {

arr.push(that.data.awards[i])

}

};

// 判断arr的数组是否含有相同概率的元素,然后根据name来匹配awards奖品数组中的name,返回awards数组的下标,如需判断根据奖品数量是否被抽完,则需要在加一层if,重新执行一边getLottery()方法即可,

if (arr.length==1) {

// console.log(arr[0].name);

for (let i in that.data.awards) {

if (that.data.awards[i].name==arr[0].name) {

this.Statr(i)

}

};

} else {

let Snum = Math.floor(Math.random() * arr.length);

// console.log(arr[Snum].name);

for (let i in that.data.awards) {

if (that.data.awards[i].name==arr[Snum].name) {

this.Statr(i)

}

};

}

},

// 开始抽奖

Statr(Snum){

let that=this;

var awardIndex = Snum;

// var awardIndex = Math.random() * 6 >>> 0;

// 获取奖品配置

var awardsConfig = that.data.awards

if (awardIndex 

// console.log(awardIndex)

// 初始化 rotate

var animationInit = wx.createAnimation({

duration: 1

})

this.animationInit = animationInit;

animationInit.rotate(0).step()

this.setData({

animationData: animationInit.export(),

// btnDisabled: 'disabled'

})

// 旋转抽奖

setTimeout(function() {

var animationRun = wx.createAnimation({

duration: 4000,

timingFunction: 'ease'

})

that.animationRun = animationRun

animationRun.rotate(360 * 8 - awardIndex * (360 / 6)).step()

that.setData({

animationData: animationRun.export()

})

}, 100)

// 中奖提示

setTimeout(function() {

wx.showModal({

title: '恭喜',

content: '获得' + (awardsConfig[awardIndex].name),

showCancel: false

})

if (that.data.chance) {

that.setData({

btnDisabled: ''

})

}

}, 4100);

},

这篇关于微信php喝酒转盘小程序,微信小程序 转盘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/176664

相关文章

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python程序的文件头部声明小结

《Python程序的文件头部声明小结》在Python文件的顶部声明编码通常是必须的,尤其是在处理非ASCII字符时,下面就来介绍一下两种头部文件声明,具有一定的参考价值,感兴趣的可以了解一下... 目录一、# coding=utf-8二、#!/usr/bin/env python三、运行Python程序四、

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

uniapp小程序中实现无缝衔接滚动效果代码示例

《uniapp小程序中实现无缝衔接滚动效果代码示例》:本文主要介绍uniapp小程序中实现无缝衔接滚动效果的相关资料,该方法可以实现滚动内容中字的不同的颜色更改,并且可以根据需要进行艺术化更改和自... 组件滚动通知只能实现简单的滚动效果,不能实现滚动内容中的字进行不同颜色的更改,下面实现一个无缝衔接的滚动