小回合記分 大比分記分 隨時查看比賽記錄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);
},
複製代碼