2017/12/20 0:00:00
泉源:不详
作者:未知
上一节我们实现首页地图,,,也响应了控件点击和用户拖动地图事务。。。。。。这一节我们实现一下点击连忙用车扫码乐成之后的页面逻辑。。。。。。
这里我用了我自己微信号的二维码,,,你们可以用你们自己的,,,扫码乐成后的页面是酱的:
页面剖析
-
后台需要拿到开锁密码,,,然后显示在页面上
-
我们需要一个准时器,,,划定多长时间用来检查单车是否损坏,,,这时代若是单车故障,,,可以点击回首页去车辆报障,,,虽然也就作废了本次扫码。。。。。。
-
若是单车没有问题,,,检查时长完成后,,,自动跳转到计费页面
页面结构
-
<!--pages/scanresult/index.wxml-->
-
<view class="container">
-
<view class="password-title">
-
<text>开锁密码</text>
-
</view>
-
<view class="password-content">
-
<text>{{password}}</text>
-
</view>
-
<view class="tips">
-
<text>请使用密码解锁,,,{{time}}s后最先计费</text>
-
<view class="tips-action" bindtap="moveToWarn">
-
车辆有问题?
-
<text class="tips-href">回首页去车辆报障</text>
-
</view>
-
</view>
-
</view>
复制代码
微信小程序的页面元素有自己的一套名字,,,用的是weui设计气概,,,可是元素种类较量少,,,好比说<view>就代表着<div>,,,<text>是行内元素,,,<image>是图片标签等,,,以是页面标签这一块只要有html基础就很容易明确
页面样式
-
.container{
-
width: 100%;
-
display: flex;
-
flex-direction: column;
-
align-items: center;
-
justify-content: space-between;
-
background-color: #fff;
-
}
-
.password-title,.tips{
-
width: 100%;
-
flex: 1;
-
text-align: center;
-
padding: 60rpx 0;
-
}
-
.password-content{
-
width: 100%;
-
flex: 8;
-
text-align: center;
-
font-size: 240rpx;
-
font-weight: 900;
-
}
-
.tips{
-
font-size: 32rpx;
-
}
-
.tips .tips-action{
-
margin-top: 20rpx;
-
}
-
.tips .tips-href{
-
color: #b9dd08
-
}
复制代码
样式方面完全是css,,,注重这里的单位是rpx,,,是小程序为了自顺应所有装备而设定的单位,,,按宽度为750px的装备盘算,,,1rpx = 0.5px。。。。。。其他比例换算可以看官方文档。。。。。。
先来相识两个知识点:
-
数据渲染页面:前面我们在地图组件中设置了数据模板,,,然后在js里通过服务器获取数据动态给模板数据赋值,,,每当js数据改变,,,页面就会重新渲染数据。。。。。。以是焦点头脑是数据驱动页面。。。。。。我们在结构里设置了数据模板{{time}},,,说明这个数据是需要我们去改变的,,,以是先在data工具里赋予初始值9(为了调试利便,,,特意把时间调的很短)
-
为元素绑定事务:和古板html里差别,,,小程序页面为元素绑定事务不可操作元素,,,否则就违反了数据驱动页面的初志,,,以是小程序在元素内声明一个变量如 bindtap="moveToWarn"来为指定元素绑定点击事务,,,然后在js里实现这个事务的功效。。。。。;;;;;;箍梢园蠖ㄐ矶嗍挛窭嘈,,,更多可以查阅事务文档
先来转头看一下首页地图连忙用车事务代码,,,若是目今没有在计费,,,将可以扫码,,,扫码乐成后将会转达参数(密码和车牌号)并跳转到../scanresult/index,,,也就是本页面。。。。。。
-
// 地图控件点击事务
-
bindcontroltap: function(e){
-
// 判断点击的是哪个控件 e.controlId代表控件的id,,,在页面加载时的第3步设置的id
-
switch(e.controlId){
-
// 点击定位控件
-
case 1: this.movetoPosition();
-
break;
-
// 点击连忙用车,,,判断目今是否正在计费
-
case 2: if(this.timer === "" || this.timer === undefined){
-
// 没有在计费就扫码
-
wx.scanCode({
-
success: (res) => {
-
// 正在获取密码通知
-
wx.showLoading({
-
title: '正在获取密码',
-
mask: true
-
})
-
// 请求服务器获取密码和车号
-
wx.request({
-
url: 'https://www.easy-mock.com/mock/59098d007a878d73716e966f/ofodata/password',
-
data: {},
-
method: 'GET',
-
success: function(res){
-
// 请求密码乐成隐藏期待框
-
wx.hideLoading();
-
// 携带密码和车号跳转到密码页
-
wx.redirectTo({
-
url: '../scanresult/index?password=' + res.data.data.password + '&number=' + res.data.data.number,
-
success: function(res){
-
wx.showToast({
-
title: '获取密码乐成',
-
duration: 1000
-
})
-
}
-
})
-
}
-
})
-
}
-
})
-
// 目今已经在计费就回退到计费页
-
}else{
-
wx.navigateBack({
-
delta: 1
-
})
-
}
-
break;
-
// 点击包管控件,,,跳转到报障页
-
case 3: wx.navigateTo({
-
url: '../warn/index'
-
});
-
break;
-
// 点击头像控件,,,跳转到个人中心
-
case 5: wx.navigateTo({
-
url: '../my/index'
-
});
-
break;
-
default: break;
-
}
-
},
复制代码
我们在js内里写下如下代码,,,本页面的options就是上面转达过来的参数。。。。。。试试打印出来是什么!
-
// pages/scanresult/index.js
-
Page({
-
data:{
-
time: 9 // 默认计时时长,,,这里设短一点,,,用于调试,,,ofo app是90s
-
},
-
// 页面加载
-
onLoad:function(options){
-
// 获取密码
-
this.setData({
-
password: options.password
-
})
-
// 设置初始计时秒数
-
let time = 9;
-
// 最先准时器
-
this.timer = setInterval(() => {
-
this.setData({
-
time: -- time // 倒计时
-
});
-
// 读完秒后携带单车号码跳转到计费页
-
if(time = 0){
-
clearInterval(this.timer)
-
wx.redirectTo({
-
url: '../billing/index?number=' + options.number
-
})
-
}
-
},1000)
-
},
-
// 点击去首页报障
-
moveToWarn: function(){
-
// 扫除准时器
-
clearInterval(this.timer)
-
wx.redirectTo({
-
url: '../index/index'
-
})
-
}
-
})
复制代码
当倒计时完成之后,,,就应该自动跳转到计费页:
Screenshot_2017-05-07-10-16-52-776_com.tencent.mm.png (81.65 KB, 下载次数: 19)
下载附件 生涯到相册
2017-6-5 14:30 上传
页面剖析
-
后台需要拿到单车编号,,,并显示在页面上
-
我们需要一个计时器累加骑行事务用来计费,,,并且可以显示最大单位是小时
-
两个按钮:竣事骑行,,,回到地图 。。。。。。其中,,,点击竣事骑行,,,关闭计时器,,,凭证累计时长计费;;;;;;点击回到地图,,,若是计时器已经关闭了,,,就关闭计费页,,,跳转到地图。。。。。。若是计时器仍然在计时,,,保存目今页面,,,跳转到地图。。。。。。
-
点击回到地图需要把计时器状态带给首页,,,首页做出判断,,,判断再次点击连忙用车响应合理逻辑(已经在计费,,,不可重复扫码。。。。。。已经阻止计费了,,,需要重新扫码)
页面结构(看看我们哪些是数据模板??????,,,为元素绑定了什么事务??????)
-
<!--pages/billing/index.wxml-->
-
<view class="container">
-
<view class="number">
-
<text>目今单车编号: {{number}}</text>
-
</view>
-
<view class="time">
-
<view class="time-title">
-
<text>{{billing}}</text>
-
</view>
-
<view class="time-content">
-
<text>{{hours}}:{{minuters}}:{{seconds}}</text>
-
</view>
-
</view>
-
-
<view class="endride">
-
<button type="warn" disabled="{{disabled}}" bindtap="endRide">竣事骑行</button>
-
<button type="primary" bindtap="moveToIndex">回到地图</button>
-
</view>
-
</view>
复制代码
页面样式
-
.container{
-
width: 100%;
-
display: flex;
-
flex-direction: column;
-
align-items: center;
-
justify-content: space-between;
-
background-color: #fff;
-
}
-
.number,.endride{
-
padding: 60rpx 0;
-
flex: 2;
-
width: 100%;
-
text-align: center;
-
}
-
.time{
-
text-align: center;
-
width: 100%;
-
flex: 6;
-
}
-
.time .time-content{
-
font-size: 100rpx;
-
}
-
.endride button{
-
width: 90%;
-
margin-top: 40rpx;
-
}
复制代码
数据逻辑(看注释更好明确哦)
-
// pages/billing/index.js
-
Page({
-
data:{
-
hours: 0,
-
minuters: 0,
-
seconds: 0,
-
billing: "正在计费"
-
},
-
// 页面加载
-
onLoad:function(options){
-
// 获取扫码乐成页传过来的车牌号,,,再界说一个准时器
-
this.setData({
-
number: options.number,
-
timer: this.timer
-
})
-
// 初始化计时器
-
let s = 0;
-
let m = 0;
-
let h = 0;
-
// 计时最先
-
this.timer = setInterval(() => {
-
this.setData({
-
seconds: s++
-
})
-
if(s == 60){
-
s = 0;
-
m++;
-
setTimeout(() => {
-
this.setData({
-
minuters: m
-
});
-
},1000)
-
if(m == 60){
-
m = 0;
-
h++
-
setTimeout(() => {
-
this.setData({
-
hours: h
-
});
-
},1000)
-
}
-
};
-
},1000)
-
},
-
// 竣事骑行,,,扫除准时器
-
endRide: function(){
-
clearInterval(this.timer);
-
this.timer = "";
-
this.setData({
-
billing: "本次骑行耗时",
-
disabled: true
-
})
-
},
-
// 携带准时器状态回到地图
-
moveToIndex: function(){
-
// 若是准时器为空
-
if(this.timer == ""){
-
// 关闭计费页跳到地图
-
wx.redirectTo({
-
url: '../index/index'
-
})
-
// 保存计费页跳到地图,,,带上计时器状态
-
}else{
-
wx.navigateTo({
-
url: '../index/index?timer=' + this.timer
-
})
-
}
-
}
-
})
页面剖析的第4步,,,主要实现在moveToIndex函数里。。。。。。竣事骑行之后,,,设置准时器值为空,,,当点击回到地图时判断计时器的状态(值是否为空)。。。。。。若是为空,,,关闭计费页,,,竣事本次骑行。。。。。。若是不为空,,,携带准时器状态跳转到首页,,,首页连忙用车点击事务就会对传过来的参数(计时器状态)响应合理逻辑。。。。。。再回去上面看一下连忙用车的判断条件,,,当本页面传已往的计时器不知足条件时,,,我们在地图首页点击连忙用车将会回到本页面
其他章节
微信小程序开发之OFO共享单车——扫码
微信小程序开发之OFO共享单车——单车报障页
微信小程序开发之OFO共享单车——个人中心页
微信小程序开发之OFO共享单车——钱包与充值
【本站声明】
1、本站文章中所选用的图片及文字泉源于网络以及用户投稿,,,由于未联系到知识产权人或未发明有关知识产权的挂号,,,若有知识产权人并不肯意我们使用,,,若是有侵权请连忙联系。。。。。。
2、本网站差池文章中所涉及的内容真实性、准确性、可靠性认真,,,仅系客观性形貌,,,如您需要相识该类商品/服务详细的资讯,,,请您直接与该类商品/服务的提供者联系。。。。。。
KESION pp电子软件
KESION pp电子软件是海内领先的在线教育软件及私域社交电商软件服务提供商,,,恒久专注于为企业提供在线教育软件及社交电商SaaS平台解决方案。。。。。。
公司焦点产品云开店SaaS社交电商服务平台、在线教育SaaS服务平台、教育企业数字化SaaS云平台、企微营销助手、私有化自力安排品牌网校和在线教育咨询等。。。。。。KESION 一直通过手艺立异,,,提供产品和服务,,,助力企业向数字化转型,,,通过科技驱动商业刷新,,,让商业变得更智慧!