小回合记分 大比分记分 随时查看比赛记录css
小回合记分 大比分记分 记分时不息屏 随时查看比赛记录小程序
队名输入 分数上下区域点击、按钮均可增减比分 记分时不息屏bash
计时功能 一局比赛结束换位功能 比赛类型 随机先手app
1.页面布局:css布局 基本使用display: flex; flex-direction: row/column; position: absolute;等 2.数据存储:小程序本地存储功能setStorageSync(存,使用同步操做)、getStorage(取,使用异步操做) 3.模板使用(模板只有.wxml和.wxss两个文件,其余文件目前不生效,不是完整的封装,事件在引入的.js中写) 4.this指代 5.欢迎引导页dom
1,2与iOS版比赛记分器相似,这里不在详细说明 3.封装比分模板,与RBScoreView相似,封装分数和按钮操做异步
<template name="scoreTemplate">
<view class='scoreview'>
<text class='scoretext'>{{score}}
</text>
<view class='cover-view'>
<text class='cover-up' hidden='{{false}}' catchtap='addButtonClick' data-type='{{isLeft}}'></text>
<text class='cover-down' hidden='{{false}}' bindtap='reduceButtonClick' data-text='{{score}}' data-type='{{isLeft}}'></text>
</view>
<view class='scoreAddAndReduce'>
<button class='add' bindtap='addButtonClick' data-text='{{score}}' data-type='{{isLeft}}'>+</button>
<button class='reduce' bindtap='reduceButtonClick' data-text='{{score}}' data-type='{{isLeft}}'>-</button>
</view>
<button class='reset' bindtap='resetButtonClick' data-type='{{isLeft}}'>重置</button>
</view>
</template>
复制代码
.scoreview {
flex-direction: column;
display: flex;
text-align: center;
padding: 0 0 0 0;
width: 280rpx;
}
.scoretext {
font-size: 100px;
background-color: black;
color: white;
height: 280rpx;
/* width: 100%;
height: width; */
text-align: center;
line-height: 280rpx;
}
.cover-view {
display: flex;
flex-direction: column;
position: absolute;
width: 280rpx;
height: 280rpx;
}
.cover-up {
height: 140rpx;
}
.cover-down {
height: 140rpx;
}
.scoreAddAndReduce {
flex-direction: row;
display: flex;
/* width: 300rpx; */
height: 90rpx;
margin-top: 20rpx;
}
.add {
background-color: black;
color: white;
padding: 0;
width: 130rpx;
height: 90rpx;
line-height: 90rpx;
border-radius: 0;
margin-left: 0rpx;
font-size: 30px;
}
.reduce {
background-color: black;
color: white;
width: 130rpx;
height: 90rpx;
line-height: 90rpx;
font-size: 30px;
margin-left: 40rpx;
margin-right: 0rpx;
border-radius: 0;
}
.reset {
background-color: black;
color: white;
margin-left: 0rpx;
margin-right: 0rpx;
border-radius: 0; /* 去除边框 */
}
/* 去除按钮边框 */
.add::after {
border: none;
}
.reduce::after {
border: none;
}
.reset::after {
border: none;
}
复制代码
<import src="template/littlescore.wxml" />
复制代码
@import "template/littlescore.wxss";
复制代码
<button class='reduce' bindtap='reduceButtonClick' data-text='{{score}}' data-type='{{isLeft}}'>-</button>
reduceButtonClick: function(event) {
// 经过获取组件绑定的变量累加
var score = event.target.dataset.text;
var isLeft = event.target.dataset.type;
if (score > 0) {
score--;
if (isLeft) {
this.setData({
leftScore: score
});
} else {
this.setData({
rightScore: score
});
}
}
},
复制代码
4.this指代 此时定义that变量保存this,由于在success函数中,this指代的不是上文的this了。xss
var that = this;
wx.showModal({
title: '比赛结束',
content: '比分:' + leftBigScore + ":" + rightBigScore + " " + winner + "胜",
success: function(res) {
if (res.confirm) {
that.storagerecordListData();
that.resetAllData();
that.recordTap();
}
else if (res.cancel) {
}
}
});
复制代码
5.欢迎引导页:经过本地存储一个变量,第一次进入小程序默认值为false,在app.js->onLaunch/onShow方法中判断是不是false,进入欢迎引导页,而后本地存入true,下次进来直接进入首页。这里使用wx.reLaunch方法,看到网上说使用过redirectTo好像不是每次都能成功。函数
// 引导欢迎页
var isFirst = wx.getStorageSync("isFirstLaunch");
if (isFirst == false) {
wx.setStorageSync("isFirstLaunch", true);
// redirectTo
wx.reLaunch({
url: 'pages/index/index',
});
}
else {
wx.reLaunch({
url: 'pages/home/home',
});
}
复制代码
可选比赛为普通比赛 标准比赛(标准比赛比普通比赛更严格,必须根据比赛规则结束比赛) 页面使用小程序radio-group组件,仿iOS的UISegmentControl控件。布局
home.wxml测试
<view class='segment'>
<radio-group class="radio-group" bindchange="radioChange">
<label class="radio" wx:for="{{items}}" wx:key="" class="{{gameType == item.value ? 'bc_green white': 'green'}}">
<radio value="{{item.value}}" checked="{{item.checked}}" /> {{item.name}}
</label>
</radio-group>
</view>
复制代码
home.wxss
.segment {
position: fixed;
right: 30rpx;
top: 30rpx;
height: 60rpx;
}
.radio-group {
background-color:blue;
display: flex;
/* margin: 25px; */
border: 1px solid white;
border-radius: 5px;
/* border-right: 0; */
}
.radio-group radio {
display: none;
}
.green{
color: white;
}
.bc_green{
background-color: white;
}
.white {
color: black;
}
/* label均匀分布,文字居中 */
label {
font-size: 26rpx;
text-align: center;
padding: 3px 5px;
/* line-height: 50rpx;
height: 50rpx; */
flex: 1;
border-right: 1px solid white;
}
label:last-child {
border-right: 0;
}
复制代码
乒乓球比赛看哪一方先发球,另外一方可选择场地。使用js定时器: js 定时器有如下两个方法:
initativeTap:function(event) {
// var isStart = currentTarget.dataset.isstart;
if(this.data.isStart) {
clearTimeout(timer);
this.setData({
isStart: false
});
}
else {
this.random();
this.setData({
isStart: true
});
}
},
random:function() {
var that = this;
timer = setTimeout(function () {
that.random();
that.setData({
firstTeam: that.data.randomArray[i]
});
i++;
// 防止屡次使用计时器无限累加
if(i >= 2) {
i = 0;
}
console.log(i);
}, 100);
},
复制代码