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

相关文章

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

HTML5表格语法格式详解

《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

前端下载文件时如何后端返回的文件流一些常见方法

《前端下载文件时如何后端返回的文件流一些常见方法》:本文主要介绍前端下载文件时如何后端返回的文件流一些常见方法,包括使用Blob和URL.createObjectURL创建下载链接,以及处理带有C... 目录1. 使用 Blob 和 URL.createObjectURL 创建下载链接例子:使用 Blob

Vuex Actions多参数传递的解决方案

《VuexActions多参数传递的解决方案》在Vuex中,actions的设计默认只支持单个参数传递,这有时会限制我们的使用场景,下面我将详细介绍几种处理多参数传递的解决方案,从基础到高级,... 目录一、对象封装法(推荐)二、参数解构法三、柯里化函数法四、Payload 工厂函数五、TypeScript

openCV中KNN算法的实现

《openCV中KNN算法的实现》KNN算法是一种简单且常用的分类算法,本文主要介绍了openCV中KNN算法的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录KNN算法流程使用OpenCV实现KNNOpenCV 是一个开源的跨平台计算机视觉库,它提供了各

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo