vue完成大乐透界面和算法

2023-12-12 06:20

本文主要是介绍vue完成大乐透界面和算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

参考大乐透玩法分为手选和机选两种,手选可以选择多倍多期多注方式。

引用了uview框架进行开发需要提前引入使用,自行去uview官网下载资源包,引入代码如下

import Vue from 'vue'
import App from './App'
import uView from "uview-ui";
Vue.use(uView);

大乐透注数算法:

//大乐透注数算法factorial(num){if(num <= 1) {return 1;      }else{return num * this.factorial(num-1);   }},combination(n,m){var divisor = this.factorial(n-m) * this.factorial(m);return this.factorial(n)/divisor;},count_zhu_superlottery(r,b){return this.combination(r,5) * this.combination(b,2);},

完整代码如下

<template><div class="container"><view class="u-config-wrap"><view class="u-config-item"><view class="u-item-title">模式选择</view><u-subsection :current="current" :list="['手选', '机选']" @change="modeChange"></u-subsection></view></view><view class="lotto_all"><!-- 手选 --><view class="lotto_manual" v-if="current==0"><view class="u-item-title">选择前区</view><div><ul class="lotto_front" ><li :id= "item" @click="lotto_front(item)" v-for="(item, index) in arrfront" :key="index">{{ item }}</li></ul></div><view class="u-item-title">选择后区</view><div><ul class="back_front"  ><li :id= "item1" @click="lotto_back(item1)" v-for="(item1, index1) in arrback" :key="index1">{{ index1+1 }}</li></ul></div><div id="s_lotto" class=select_area>您选了{{num}}注,共{{2*num}}.00元</div><u-button type="success" @click="confirm_lotto" >确认选号</u-button><u-popup v-model="show" mode="center" border-radius="14"><view>{{description}}</view><view class="confrim-btn"><u-button @click="show = false;">知道了</u-button></view></u-popup><view class="u-item-title">已选号码</view><u-table><u-tr><u-th>类型</u-th><u-th>红球</u-th><u-th>篮球</u-th><u-th>注数</u-th></u-tr><u-tr v-for="(item2,index2) in confirm_lottos" :key="index2"><u-td>{{item2.ltype}}</u-td><u-td>{{item2.larrfront}}</u-td><u-td>{{item2.larrback}}</u-td><u-td>{{item2.nums}}</u-td></u-tr></u-table></view><!-- 机选 --><view class="lotto_machine" v-if="current==1"><ul class="ssq_wrap" ></ul></view></view><view>您选了{{nums}}注</view><view class="beitou_area">倍投:<u-number-box v-model="multiple" :min="1" :max="150" @change="Multiple"></u-number-box></view><view >期数:<u-number-box v-model="periods" :min="1" :max="15" @change="valChange"></u-number-box></view><view  class="append"><u-checkbox-group ><u-checkbox name="append"  v-model="checked" @change="checkboxChange" >追加投注 <span>单注+1元,奖金最高可到1600万元</span></u-checkbox ></u-checkbox-group></view><view>共 {{money}} 元 + 代买服务费:{{service_money}} 元 = {{moneys}} 元</view><u-button type="success">提交订单</u-button></div></template><script>
const NET = require('../../utils/request');
const API = require('../../config/api');
export default {components: {},data() {return {title: '',description: '',show:false,arr: [],control: true,current:0,//模式选择flag:true,//是否选中num:0,//注数nums:0,//总注数multiple:1,//倍数periods:1,//期数append:'',//追加checked:false,arrfront:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],arrback:[101,102,103,104,105,106,107,108,109,110,111,112],arrfront_confirm:[],//选择的红球arrback_confirm:[],//选择的篮球confirm_lottos :[],//选中的号money:'',//下注钱service_money:'',//服务费moneys:'',//总价};},mounted() {var that = this;setTimeout(() => {that.arr = [];function arrFun() {const numArr = [];const time = setInterval(() => {// 生成红球const redNum = Math.floor(Math.random() * (1 - 34) + 34);// 蓝球const blueNum = Math.floor(Math.random() * (1 - 17) + 17);numArr.push(redNum);// 红球去重const n = arrRemoval(numArr);for (let i = 1; i < n.length; i++) {// 获取当前遍历数字。const currentNum = n[i];// 拿到上一个索引值进行比较let prevIndex = i - 1;// 对红球进行排序while (prevIndex >= 0 && n[prevIndex] > currentNum) {n[prevIndex + 1] = n[prevIndex];prevIndex--;}n[prevIndex + 1] = currentNum;}if (n.length === 6) {n.push(blueNum);that.arr.push(n);clearInterval(time);// return n}}, 10);function arrRemoval(array) {const set = [...new Set(array)];return set;}}const intervalFun = setInterval(() => {arrFun();// 机选多组, n+1if (that.arr.length === 4) {clearInterval(intervalFun);}}, 100);}, 2000);},methods: {//模式选择modeChange(index) {this.control = true;if(index == 0) {this.current=0this.control = true;} else {this.current=1this.control = false;}},//获取点击的值lotto_front(item){this.flag=this.arrfront_confirm.includes(item);if(this.flag==true){document.getElementById(item).className="is-boll";this.arrfront_confirm.splice(this.arrfront_confirm.indexOf(item),1);let m=this.arrfront_confirm.length;let n=this.arrback_confirm.length;if(m>4&&n>1){document.getElementById("s_lotto").className="select_areas";console.log("sa",this.num)this.num= this.count_zhu_superlottery(m,n)//alert("sa",this.num)}if(m<5||n<2){document.getElementById("s_lotto").className="select_area";}console.log(document.getElementById(item).innerHTML);}else{document.getElementById(item).className="red-boll-active";let frontval=parseInt(document.getElementById(item).innerHTML);this.arrfront_confirm.push(frontval);let m=this.arrfront_confirm.length;let n=this.arrback_confirm.length;if(m>4&&n>1){document.getElementById("s_lotto").className="select_areas";console.log("sa",this.num)this.num= this.count_zhu_superlottery(m,n)//alert("sa",this.num)}console.log(this.arrfront_confirm);}},lotto_back(item1){this.flag=this.arrback_confirm.includes(item1-100);if(this.flag==true){document.getElementById(item1).className="is-boll";this.arrback_confirm.splice(this.arrback_confirm.indexOf(item1-100),1);let m=this.arrfront_confirm.length;let n=this.arrback_confirm.length;if(m>4&&n>1){document.getElementById("s_lotto").className="select_areas";console.log("sa",this.num)this.num= this.count_zhu_superlottery(m,n)//alert("sa",this.num)}if(m<5||n<2){document.getElementById("s_lotto").className="select_area";}console.log(this.arrback_confirm);}else{document.getElementById(item1).className="blue-boll-active";let frontval=parseInt(document.getElementById(item1).innerHTML);this.arrback_confirm.push(frontval);let m=this.arrfront_confirm.length;let n=this.arrback_confirm.length;if(m>4&&n>1){document.getElementById("s_lotto").className="select_areas";console.log("sa",this.num)this.num= this.count_zhu_superlottery(m,n)//alert("sa",this.num)}console.log(this.arrback_confirm);}},confirm_lotto(){if(this.arrfront_confirm.length<5){this.show=true;this.description="请至少选择5个红球"}else if(this.arrback_confirm.length<2){this.show=true;this.description="请至少选择2个蓝球"}else if(this.arrfront_confirm.length>5 ||this.arrback_confirm.length>2){this.confirm_lottos.push({ltype: "复式",larrfront: this.arrfront_confirm.toString(),larrback: this.arrback_confirm.toString(),nums: this.num,})this.nums+=this.num;this.money=this.nums*this.periods*this.multiple*2;this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;}else{this.confirm_lottos.push({ltype: "单式",larrfront: this.arrfront_confirm.toString(),larrback: this.arrback_confirm.toString(),nums: this.num,})this.nums+=this.num;this.money=this.nums*this.periods*this.multiple*2;this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;}},factorial(num){if(num <= 1) {return 1;      }else{return num * this.factorial(num-1);   }},combination(n,m){var divisor = this.factorial(n-m) * this.factorial(m);return this.factorial(n)/divisor;},count_zhu_superlottery(r,b){return this.combination(r,5) * this.combination(b,2);},//是否多倍Multiple(e) {this.multiple=e.valueconsole.log('当前值为: ' + e.value)this.money=this.nums*this.periods*this.multiple*2;this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;},//是否多期valChange(e) {this.periods=e.valueconsole.log('当前值为: ' + e.value)this.money=this.nums*this.periods*this.multiple*2this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;},//是否追加checkboxChange(e) {//console.log(e);if(e.value==true){this.money=this.nums*this.periods*this.multiple*3this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;}else{this.money=this.nums*this.periods*this.multiple*2this.service_money=Math.round(this.money * 100*0.02) / 100;this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;}},},};
</script><style lang="scss" scoped>
page {background: #cccccc;
}
.container {margin: 0 auto;
}
.lotto_all{.lotto_manual{ul{display: flex;flex-wrap: wrap;align-items: center;flex-direction: row;list-style: none;}ul li{width: 68rpx;height: 68rpx;border-radius: 68rpx;line-height: 68rpx;text-align: center;margin: 6rpx;background-color: #ffffff;}.is-boll{color: #000;background: white;}.red-boll-active{color: #fff;background: red;}.blue-boll-active{color: #fff;background: blue;}}.select_area{display: none;}.select_areas{height: 80rpx;line-height: 80rpx;text-align: center;display: block;}.confirm_area{border: #ccc 1px solid;min-height: 120px;padding: 6px;background: #fff;}}
.beitou_area{background: #ffffff;display: flex;flex-direction: row;}
.append{//height: 40rpx;padding:10rpx 10rpx ;background: #ffffff;span{font-size: 24rpx;color: red;}}</style>

最终效果展示图如下,后续不断优化代码和界面样式

 

 

这篇关于vue完成大乐透界面和算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,