vue2插件之@lucky-canvas/vue,大转盘、抽奖、老虎机

本文主要是介绍vue2插件之@lucky-canvas/vue,大转盘、抽奖、老虎机,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

提示:vue2插件

文章目录

    • @[TOC](文章目录)
  • 前言
  • 一、查看nodejs版本
  • 二、创建项目
  • 三、大转盘
  • 四、抽奖
  • 五、老虎机
  • 六、官网
  • 总结

前言

@lucky-canvas/vue

一、查看nodejs版本

node -v

在这里插入图片描述

二、创建项目

1、安装插建

npm install @lucky-canvas/vue --save

在这里插入图片描述
在这里插入图片描述
2、目录结构
在这里插入图片描述
3、引用main.js

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import VueLuckyCanvas from '@lucky-canvas/vue';
Vue.use(VueLuckyCanvas);
Vue.config.productionTip = false
new Vue({render: h => h(App),router
}).$mount('#app')

4、配置路由src/router/index.js

import Vue from 'vue';
import Router from 'vue-router';
import LuckyWheel  from '@/components/LuckyWheel.vue';
import LuckyGrid  from '@/components/LuckyGrid.vue';
import SlotMachine   from '@/components/SlotMachine .vue';
Vue.use(Router);
const routes = [{ path: '/', component: LuckyWheel  },{ path: '/lucky-wheel', component: LuckyWheel  },{ path: '/lucky-grid', component: LuckyGrid  },{ path: '/slot-machine', component: SlotMachine },]
export default new Router({ routes })

三、大转盘

1、src/components/LuckyWheel.vue

<template><div class="lucky_wheel"><h1>LuckyWheel页面</h1><template><LuckyWheelref="myLucky"width="400px"height="400px":prizes="prizes":blocks="blocks":buttons="buttons"@start="startCallback"@end="endCallback"/>
</template>
</div>
</template><script>
export default {name: 'LuckyWheel1',data () {return {//转盘背景blocks: [{ padding: '40px',     //可旋转区域与转盘边缘的距离background: '#eee',  //转盘背景色//转盘背景图imgs:[{src:require('@/assets/LuckyWheel.png'),   //图片urltop:'0',     //图片距顶部距离width:'400px',  //图片宽height:'400px', //图片高}],}],// 扇形数组prizes: [//单个扇形{ //奖品文字fonts: [{ text: '苹果',        //文字top: '10%',          //文字距顶部距离fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高wordWrap:true,       //换行lineClamp:2,         //2行,剩下的...wordWrap:true,       //换行}], //奖品图imgs:[{src:'https://img95.699pic.com/xsj/1s/5e/0g.jpg%21/fh/300',   //图片urltop:'30%',     //图片距顶部距离width:'60px',  //图片宽height:'60px', //图片高}],background: '#FFF402',  //扇形背景色range:10,  //当前prize.range/所有prize中range总和},{ fonts: [{ text: '橘子', top: '10%' }], background: '#76C5F0' },{ fonts: [{ text: '香蕉', top: '10%' }], background: '#2A1570' },{ fonts: [{ text: '葡萄', top: '10%' }], background: '#009241' },{ fonts: [{ text: '芒果', top: '10%' }], background: '#DD167B' },{ fonts: [{ text: '西瓜', top: '10%' }], background: '#F8C301' },{ fonts: [{ text: '柠檬', top: '10%' }], background: '#E77841' },{ fonts: [{ text: '柚子', top: '10%' }], background: '#42929D' },{ fonts: [{ text: '山竹', top: '10%' }], background: '#E3556B' },],buttons: [{radius: '35%',// background: '#333',pointer: true,fonts: [{ text: '点击抽奖',        //文字top: '-15%',          //文字距顶部距离fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高}],//抽奖按钮图imgs:[{src:require('@/assets/btn_cj.png'),   //图片urltop:'-130%',     //图片距顶部距离width:'100%',  //图片宽// height:'100%', //图片高}],}],}},methods: {// 点击抽奖按钮会触发star回调startCallback () {// 调用抽奖组件的play方法开始游戏this.$refs.myLucky.play()// 模拟调用接口异步抽奖setTimeout(() => {// 假设后端返回的中奖索引是0const index = 0// 调用stop停止旋转并传递中奖索引this.$refs.myLucky.stop(index)}, 3000)},// 抽奖结束会触发end回调endCallback (prize) {console.log(prize)},}
}
</script>
<style scoped></style>

2、预览

请添加图片描述

四、抽奖

1、src/components/LuckyGrid.vue

<template><div class="lucky_grid"><h1>LuckyGrid页面</h1><template><LuckyGridref="myLucky"width="400px"height="400px":blocks="blocks":prizes="prizes":buttons="buttons":activeStyle="activeStyle":defaultConfig="defaultConfig":defaultStyle="defaultStyle"@start="start"@end="end"/>
</template>
</div>
</template><script>
export default {name: 'LuckyGrid1',data () {return {defaultStyle: {background: '#f00',borderRadius:'60px',shadow: '2px 2px 3px #f00',fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高wordWrap:true,       //换行lineClamp:2,         //2行,剩下的...lengthLimit:'90%',},defaultConfig:{gutter:'12px',speed:10,accelerationTime:1500,decelerationTime:1500,},activeStyle:{fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗background:'#FFF402',       //换行shadow: '2px 2px 3px #f00',},blocks: [{ padding: '40px',     //可旋转区域与转盘边缘的距离background: '#f00',  //转盘背景色borderRadius: '80px',//转盘背景图imgs:[{src:require('@/assets/LuckyGrid.png'),   //图片urltop:'0',     //图片距顶部距离width:'400px',  //图片宽height:'400px', //图片高}],}],prizes: [{ x: 0, y: 0, //奖品文字fonts: [{ text: '苹果',        //文字top: '10%',          //文字距顶部距离fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高wordWrap:true,       //换行lineClamp:2,         //2行,剩下的...}], //奖品图imgs:[{src:'https://img95.699pic.com/xsj/1s/5e/0g.jpg%21/fh/300',   //图片urltop:'30%',     //图片距顶部距离width:'60px',  //图片宽height:'60px', //图片高}],background: '#eee',  //扇形背景色range:10,  //当前prize.range/所有prize中range总和borderRadius: '10px',shadow: '2px 2px 3px #f00',},{ x: 1, y: 0, fonts: [{ text: '1', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 2, y: 0, fonts: [{ text: '2', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 2, y: 1, fonts: [{ text: '3', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 2, y: 2, fonts: [{ text: '4', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 1, y: 2, fonts: [{ text: '5', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 0, y: 2, fonts: [{ text: '6', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },{ x: 0, y: 1, fonts: [{ text: '7', top: '25%' }],background: '#eee',borderRadius: '10px',shadow: '2px 2px 3px #f00', },],buttons: [{x: 1, y: 1,borderRadius: '80px',background: '#FFF402',shadow: '2px 2px 3px #f00',fonts: [{ text: '点击抽奖',        //文字top: '40%',          //文字距顶部距离fontColor:'#f00',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高}],// 抽奖按钮图imgs:[{src:require('@/assets/btn_grid.png'),   //图片urltop:'15%',     //图片距顶部距离width:'70%',  //图片宽height:'70%', //图片高borderRadius: '80px',}],}],}},methods: {start () {// 开始游戏this.$refs.myLucky.play()// 使用定时器模拟接口setTimeout(() => {// 结束游戏, 并抽第0号奖品this.$refs.myLucky.stop(0)}, 3000)},end(prize){ // 游戏结束触发 end 回调alert('恭喜中奖: ' + prize.fonts[0].text);}}
}
</script>
<style scoped></style>

2、预览
请添加图片描述

五、老虎机

1、src/components/SlotMachine.vue

<template><div class="slot_machine"><h1>SlotMachine页面</h1><template><SlotMachineref="myLucky"width="400px"height="300px":blocks="blocks":prizes="prizes":slots="slots":defaultConfig="defaultConfig"/><div class="start_slot_machine" @click="start"><div class="slot_machine_btn" @click="start">启动</div></div>
</template>
</div>
</template><script>
export default {name: 'SlotMachine1',data () {return {blocks: [{ padding: '10px', background: '#617df2',imgs:[{src:require('@/assets/SlotMachine .png'),   //图片urltop:'0',     //图片距顶部距离width:'400px',  //图片宽height:'300px', //图片高}],},{ padding: '10px', background: '#869cfa' },{ padding: '10px', background: '#afc8ff' },{ padding: '10px', background: '#e9e8fe' },],slots: [{ speed: 30 },{ speed: 15 },{ speed: 20 },],prizes: [{fonts: [{ text: '苹果',        //文字top: '15%',          //文字距顶部距离fontColor:'#900',    //文字颜色fontSize:'16px',     //文字大小fontStyle:'微软雅黑', //字体fontWeight:'500',    //加粗lineHeight:'16px',   //行高wordWrap:true,       //换行lineClamp:2,         //2行,剩下的...}], background: '#bac5ee',borderRadius: '10px',padding: '10px',imgs: [{top:'10%',width: '80%',height: '80%',src: require('@/assets/face_1.png')},// {//   top:'10%',//   width: '80%',//   height: '80%',//   src: require('@/assets/face_1a.png')// }]},{background: '#bac5ee',borderRadius: '10px',padding: '10px',imgs: [{top:'10%',width: '80%',height: '80%',src: require('@/assets/face_2.png')},// {//   top:'10%',//   width: '80%',//   height: '80%',//   src: require('@/assets/face_2a.png')// }]},{background: '#bac5ee',borderRadius: '10px',padding: '10px',imgs: [{top:'10%',width: '80%',height: '80%',src: require('@/assets/face_3.png')},]}],defaultConfig: {rowSpacing: '20px',colSpacing: '20px',}}},methods: {start () {// 开始游戏this.$refs.myLucky.play()// 使用定时器模拟接口setTimeout(() => {// 假设 4 种结果const res = [[0, 1, 2],[1, 2, 1],[1, 2, 2],[2, 2, 2]]// 随机取一组数据const index = res[Math.random() * 4 >> 0]// 调用 stop 方法停止游戏this.$refs.myLucky.stop(index)}, 500);},end(prize){ // 游戏结束触发 end 回调alert('恭喜中奖: ' + prize.fonts[0].text);requestServices.queryCoursewareSource({ lessonNumberId: this.lessonInfo.id }).then((res) => {if(res&&res.success)localStorage.setItem('KJPathData',res.object);});}}
}
</script>
<style scoped>
.start_slot_machine {width: 400px;height: 40px;line-height: 40px;margin-top: 20px;
}.slot_machine_btn {width: 80px;height: 40px;line-height: 40px;border-radius: 4px;border: 1px solid #eee;text-align: center;margin: 0 auto;cursor: pointer;
}
</style>

2、预览
请添加图片描述

六、官网

lucky-canvas官网

总结

踩坑路漫漫长@~@

这篇关于vue2插件之@lucky-canvas/vue,大转盘、抽奖、老虎机的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

vue, 左右布局宽,可拖动改变

1:建立一个draggableMixin.js  混入的方式使用 2:代码如下draggableMixin.js  export default {data() {return {leftWidth: 330,isDragging: false,startX: 0,startWidth: 0,};},methods: {startDragging(e) {this.isDragging = tr

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

js+css二级导航

效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con

基于Springboot + vue 的抗疫物质管理系统的设计与实现

目录 📚 前言 📑摘要 📑系统流程 📚 系统架构设计 📚 数据库设计 📚 系统功能的具体实现    💬 系统登录注册 系统登录 登录界面   用户添加  💬 抗疫列表展示模块     区域信息管理 添加物资详情 抗疫物资列表展示 抗疫物资申请 抗疫物资审核 ✒️ 源码实现 💖 源码获取 😁 联系方式 📚 前言 📑博客主页:

vue+el国际化-东抄西鉴组合拳

vue-i18n 国际化参考 https://blog.csdn.net/zuorishu/article/details/81708585 说得比较详细。 另外做点补充,比如这里cn下的可以以项目模块加公共模块来细分。 import zhLocale from 'element-ui/lib/locale/lang/zh-CN' //引入element语言包const cn = {mess

以canvas方式绘制粒子背景效果,感觉还可以

这个是看到项目中别人写好的,感觉这种写法效果还可以,就存留记录下 就是这种的背景效果。如果想改背景颜色可以通过canvas.js文件中的fillStyle值改。 附上demo下载地址。 https://download.csdn.net/download/u012138137/11249872

vue同页面多路由懒加载-及可能存在问题的解决方式

先上图,再解释 图一是多路由页面,图二是路由文件。从图一可以看出每个router-view对应的name都不一样。从图二可以看出层路由对应的组件加载方式要跟图一中的name相对应,并且图二的路由层在跟图一对应的页面中要加上components层,多一个s结尾,里面的的方法名就是图一路由的name值,里面还可以照样用懒加载的方式。 页面上其他的路由在路由文件中也跟图二是一样的写法。 附送可能存在

vue+elementUI下拉框联动显示

<el-row><el-col :span="12"><el-form-item label="主账号:" prop="partyAccountId" :rules="[ { required: true, message: '主账号不能为空'}]"><el-select v-model="detailForm.partyAccountId" filterable placeholder="

vue+elementui分页输入框回车与页面中@keyup.enter事件冲突解决

解决这个问题的思路只要判断事件源是哪个就好。el分页的回车触发事件是在按下时,抬起并不会再触发。而keyup.enter事件是在抬起时触发。 so,找不到分页的回车事件那就拿keyup.enter事件搞事情。只要判断这个抬起事件的$event中的锚点样式判断不等于分页特有的样式就可以了 @keyup.enter="allKeyup($event)" //页面上的//js中allKeyup(e