uniapp中制作战力计算器
<template>
<view class="calculate-wrap">
<!-- 计时器-start -->
<view class="calculate-screen">
<view class="calculate-screen-title">
<image class="calculate-screen-small" mode="aspectFill" src="@/pagesB/static/calculate/small.png"></image>
<view class="calculate-screen-title-content">
<template v-if="isPause">
<image mode="aspectFill" @click="isPauseHandle(false)" class="calculate-screen-title-content-icon" src="@/pagesB/static/calculate/end.png"></image>
</template>
<template v-else>
<image mode="aspectFill" @click="isPauseHandle(true)" class="calculate-screen-title-content-icon" src="@/pagesB/static/calculate/start.png"></image>
</template>
<text class="calculate-screen-title-content-text">{{countdown}}</text>
</view>
</view>
<image class="calculate-screen-big" mode="aspectFill" src="@/pagesB/static/calculate/big.png"></image>
<view class="calculate-screen-content">
<view class="calculate-screen-content-box">
<view class="calculate-screen-content-box-lf">
<template v-if="powerValueCurrentIndex=='A'">
<view class="calculate-screen-people" @click="changeClashRoleHandle(powerValueA,'A')">
<view class="calculate-screen-people-title">DUEL 01</view>
<view class="calculate-screen-people-number">{{powerValueA}}</view>
</view>
</template>
<template v-else>
<view class="calculate-screen-people" @click="changeClashRoleHandle(powerValueA,'A')" style="opacity: 0.5;">
<view class="calculate-screen-people-title">DUEL 01</view>
<view class="calculate-screen-people-number">{{powerValueA}}</view>
</view>
</template>
</view>
<image class="calculate-screen-content-box-clash" mode="aspectFill" src="@/pagesB/static/calculate/clash.png"></image>
<view class="calculate-screen-content-box-rg">
<template v-if="powerValueCurrentIndex=='B'">
<view class="calculate-screen-people" @click="changeClashRoleHandle(powerValueB,'B')">
<view class="calculate-screen-people-title">DUEL 02</view>
<view class="calculate-screen-people-number">{{powerValueB}}</view>
</view>
</template>
<template v-else>
<view class="calculate-screen-people" @click="changeClashRoleHandle(powerValueB,'B')" style="opacity: 0.5;">
<view class="calculate-screen-people-title">DUEL 02</view>
<view class="calculate-screen-people-number">{{powerValueB}}</view>
</view>
</template>
</view>
</view>
</view>
</view>
<!-- 计时器-end -->
<!-- footer-start -->
<view class="calculate-footer">
<!-- 计算屏幕区域 -->
<view class="calculate-footer-screen">
<text class="calculate-footer-screen-num">{{calculateTotal}}</text>
<text class="calculate-footer-screen-operate" style="margin-left: 5px;margin-right: 5px;">{{calculateOperate}}</text>
<text class="calculate-footer-screen-num">{{calculateVariable}}</text>
</view>
<!-- 计算操作按钮区域 -->
<view class="calculate-footer-operate">
<view class="calculate-footer-operate-item" @click="calculateCLRHandle()" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">CLR</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('7')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">7</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('8')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">8</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('9')" style="border-top: 1px solid #29304A;">9</view>
<view class="calculate-footer-operate-item" @click="calculateOperateHandle('+')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">+</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('4')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">4</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('5')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">5</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('6')" style="border-top: 1px solid #29304A;">6</view>
<view class="calculate-footer-operate-item" @click="calculateOperateHandle('-')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">-</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('1')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">1</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('2')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">2</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('3')" style="border-top: 1px solid #29304A;">3</view>
<view class="calculate-footer-operate-item" @click="calculateOperateHandle('/')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">÷2</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('0')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">0</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('00')" style="border-top: 1px solid #29304A;border-right: 1px solid #29304A;">00</view>
<view class="calculate-footer-operate-item" @click="calculateNumberHandle('000')" style="border-top: 1px solid #29304A;">000</view>
</view>
<!-- 计算确认按钮 -->
<view class="calculate-footer-operate-btn" @click="calculateTotalHandle">=</view>
<!-- 底部按钮 -->
<view class="calculate-footer-box">
<view class="calculate-footer-item">
<image src="@/pagesB/static/calculate/jilu.png" class="calculate-footer-item-icon"></image>
<text class="calculate-footer-item-name">记录</text>
</view>
<view class="calculate-footer-item">
<image src="@/pagesB/static/calculate/shaizi.png" class="calculate-footer-item-icon"></image>
<text class="calculate-footer-item-name">筛子</text>
</view>
<view class="calculate-footer-item">
<image src="@/pagesB/static/calculate/yingbi.png" class="calculate-footer-item-icon"></image>
<text class="calculate-footer-item-name">硬币</text>
</view>
<view class="calculate-footer-item">
<image src="@/pagesB/static/calculate/shezhi.png" class="calculate-footer-item-icon"></image>
<text class="calculate-footer-item-name">设置</text>
</view>
</view>
</view>
<!-- footer-end -->
</view>
</template>
<script>
let timer=null;
export default {
data() {
return {
isPause:false,//是否暂停,true:暂停;false:继续
limitTime:356400,//限制最大时间
time:0,//计时开始值
countdown:"00:00:00",//计时
calculateTotal:"",//计算的开始值
calculateOperate:"",//操作符
calculateVariable:"",//计算的变量
powerValueA:"8000",//战力值
powerValueB:"80000",//战力值
powerValueCurrentIndex:'A',//
};
},
onLoad() {
this.calculateOperate="";
this.calculateVariable="";
if(this.powerValueCurrentIndex=='A'){
this.calculateTotal=this.powerValueA;
}else{
this.calculateTotal=this.powerValueB;
}
},
onShow() {
this.timingFun();
},
onHide() {
console.log("[关闭页面onHide]")
clearInterval(timer)
},
onUnload() {
console.log("[关闭页面onUnload]")
clearInterval(timer)
},
methods:{
//是否开始计时器
isPauseHandle(state){
this.isPause=state;
if(state){
clearInterval(timer)
}else{
this.timingFun();
}
},
timingFun(){
let time=this.time;
let limitTime=this.limitTime;
timer=setInterval(()=>{
time+=1;
this.time=time
if(time>limitTime){
clearInterval(timer);
return false
}
this.countdown=this.countdownFun(time)
},1000)
},
countdownFun(result){
var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) : Math.floor(result / 3600);
var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
result = h+':'+m + ":" + s;
console.log(result)
return result;
},
//点击战力值
changeClashRoleHandle(powerValue,currentIndex){
console.log(powerValue)
this.calculateTotal=powerValue;
this.powerValueCurrentIndex=currentIndex;
},
//计算结果
calculateTotalHandle(){
const calculateTotal=Number(this.calculateTotal);//计算总值
const calculateVariable=Number(this.calculateVariable);//操作值
const calculateOperate=this.calculateOperate;//操作符
const powerValueCurrentIndex=this.powerValueCurrentIndex;
let tempTotal=0;
if(calculateVariable>0){
if(calculateOperate=='+'){
tempTotal=calculateTotal+calculateVariable;
}else{
tempTotal=calculateTotal-calculateVariable;
}
if(tempTotal<=0){
tempTotal=0;
}
if(tempTotal>999999){
tempTotal=999999;
}
this.calculateTotal=tempTotal;
if(powerValueCurrentIndex=='A'){
this.powerValueA=tempTotal;//战力值
}else{
this.powerValueB=tempTotal;//战力值
}
console.log("ok=")
//清除输入值
this.calculateOperate="";
this.calculateVariable="";
}
},
//操作值
calculateNumberHandle(number){
const calculateTotal=Number(this.calculateTotal);//计算总值
const calculateOperate=this.calculateOperate;//操作符
const calculateVariable=Number(this.calculateVariable);//操作值
if(Number(number)==0){
if(calculateVariable!=0){
if(calculateOperate==""){
this.calculateOperate='-'
}
this.calculateVariable+=number
}
}else{
if(calculateOperate==""){
this.calculateOperate='-'
}
this.calculateVariable+=number
}
if(Number(this.calculateVariable)>calculateTotal){
this.calculateVariable=calculateTotal
}
},
//操作符
calculateOperateHandle(operate){
this.calculateVariable="";
if(operate=='+'){
this.calculateOperate='+'
}else if(operate=='-'){
this.calculateOperate='-'
}else{
this.calculateOperate='-'
this.calculateVariable=Math.floor(this.calculateTotal/2)
}
},
//清空
calculateCLRHandle(){
this.calculateOperate="";
this.calculateVariable="";
}
}
}
</script>
<style lang="scss" scoped>
.calculate-wrap{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #131728;
.calculate-screen{
width: 348px;
height: 152px;
margin: auto;
margin-top: 24.5px;
position: relative;
.calculate-screen-big{
width: 100%;
height: 100%;
}
.calculate-screen-title{
width: 248px;
height: 49px;
position: absolute;
top:-24.5px;
left: 50%;
transform: translateX(-50%);
.calculate-screen-small{
width: 100%;
height: 100%;
}
.calculate-screen-title-content{
width: 100%;
height: 49px;
position: absolute;
top: 0;
display: flex;
justify-content: center;
align-items: center;
.calculate-screen-title-content-icon{
width: 20.4px;
height: 20.4px;
}
.calculate-screen-title-content-text{
font-size: 23px;
font-family: Arial;
font-weight: 400;
color: #B8C7FF;
margin-left: 11px;
padding-top: 2px;
}
}
}
.calculate-screen-content{
width: 348px;
height: 152px;
position: absolute;
top: 0;
left: 0;
.calculate-screen-content-box{
width: 100%;
position: relative;
height:127.5px;
margin-top: 24.5px;
.calculate-screen-content-box-clash{
position: absolute;
width: 59px;
height: 78.5px;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.calculate-screen-content-box-lf{
position: absolute;
top: 15px;
left: 10px;
width: 125px;
}
.calculate-screen-content-box-rg{
position: absolute;
top: 15px;
right: 10px;
width: 123px;
}
.calculate-screen-people{
display: flex;
flex-direction: column;
text-align: center;
.calculate-screen-people-title{
font-size: 16px;
font-family: Arial;
font-weight: bold;
color: #FFFFFF;
}
.calculate-screen-people-number{
border-bottom: 1px solid #FFFFFF;
width: 100px;
padding: 10px 0px 6px 0px;
font-size: 25px;
font-family: Arial;
font-weight: 400;
color: #FFFFFF;
text-align: center;
margin: auto;
}
}
}
}
}
.calculate-footer{
position: fixed;
min-height: 408px;
bottom: 0;
right: 0;
left: 0;
z-index: 1;
background: #0A0E1D;
border-radius: 20px 20px 0px 0px;
display: flex;
flex-direction: column;
//计算屏幕
.calculate-footer-screen{
border-radius: 20px 20px 0px 0px;
height: 60px;
line-height: 60px;
font-size: 25px;
font-family: Arial;
font-weight: 400;
color: #FFFFFF;
padding-left: 22px;
}
//计算操作按钮区域
.calculate-footer-operate{
display: flex;
flex-wrap: wrap;
.calculate-footer-operate-item{
width: 24.75%;
height: 60px;
font-size: 22px;
font-family: Arial;
font-weight: 400;
color: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
}
}
//计算操作确认按钮
.calculate-footer-operate-btn{
border-top: 1px solid #29304A;
height: 60px;
line-height: 60px;
font-size:25px;
font-family: Arial;
font-weight: 400;
color: #FFFFFF;
text-align: center;
}
//底部按钮
.calculate-footer-box{
height: 49px;
position: fixed;
bottom: 0;
right: 0;
left: 0;
display: flex;
flex-direction: row;
box-shadow: 0px 0px 5px 1.5px rgba(127, 140, 189, 0.16);
.calculate-footer-item{
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
.calculate-footer-item-icon{
width: 25px;
height: 25px;
margin-top: 5px;
}
.calculate-footer-item-name{
font-size: 14px;
font-family: PingFang SC;
font-weight: 400;
color: #999999;
opacity: 0.97;
}
}
}
}
}
</style>