作者 乔蒙蒙

对接接口

... ... @@ -103,6 +103,7 @@ App({
return dateObj;
},
globalData: {
userInfo: null
userInfo: null,
imgUrl: 'http://qiniu.conyou-zj.com/'
}
})
\ No newline at end of file
... ...
//index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
rankstate:0//0综合,1距离,2销量,3筛选
imgUrl: app.globalData.imgUrl,
rankstate: 0, //0综合,1距离,2销量,3筛选
},
setrankstate(e){
setrankstate(e) {
this.setData({
rankstate: e.currentTarget.dataset.rankstate
... ... @@ -17,56 +19,56 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function() {
}
})
\ No newline at end of file
... ...
<!--index.wxml-->
<navigator class='index_img' hover-class='navigator_hover' url='/pages/tuangou/tuanguo'>
<image src='../../../imgs/dianoufengmian@3x.png'></image>
</navigator >
<image src='{{imgUrl}}dianoufengmian@3x.png'></image>
</navigator>
<view class='index_class'>
<navigator class='index_classcell' hover-class='navigator_hover' url='/pages/tuangou/tuanguo'>
<view>品质团购</view>
... ... @@ -18,7 +18,7 @@
</view>
<view class='index_title'>热门酒吧</view>
<view class='plaza_nav'>
<view class="plaza_navitem {{rankstate==0?'navitem_active':''}}" data-rankstate='0' bindtap='setrankstate' >
<view class="plaza_navitem {{rankstate==0?'navitem_active':''}}" data-rankstate='0' bindtap='setrankstate'>
<view class=' plaza_navitemimg iconfont icon-fenlei-'></view>
<view>综合排序</view>
</view>
... ... @@ -42,11 +42,12 @@
<view class='order_imgtxtsubtitle'>[主题酒吧]</view>
</view>
<view class='order_imgtime'>月售120单</view>
<image src='../../../imgs/dianoufengmian@3x.png'></image>
<image src='{{imgUrl}}dianoufengmian@3x.png'></image>
</navigator>
<view class='formitem'>
<view class='formitem_rigth form_nimi'>
<view class='formitem_rigth_jian'> <text class='jian_txt'> 减</text>
<view class='formitem_rigth_jian'>
<text class='jian_txt'> 减</text>
</view>
满1000减300 满1500减500 满2000减800
</view>
... ...
... ... @@ -7,9 +7,9 @@ Page({
*/
data: {
imgUrls: [
'../../imgs/lunbo1@3x.png',
'../../imgs/lunbo2@3x.png',
'../../imgs/lunbo3@3x.png'
app.globalData.imgUrl + 'lunbo1@3x.png',
app.globalData.imgUrl + 'lunbo2@3x.png',
app.globalData.imgUrl + 'lunbo3@3x.png'
],
indexs: 0,
color: '#cccccc',
... ... @@ -17,7 +17,8 @@ Page({
autoplay: true,
activecolor: '#ffffff',
interval: 5000,
duration: 1000
duration: 1000,
imgUrl: app.globalData.imgUrl
},
start(e) {
... ... @@ -32,9 +33,9 @@ Page({
code: s.code
}
app.post(url, param).then((res) => {
console.log(res);
console.log(e);
that.login(res.data.openid, res.data.session_key, e.detail.encryptedData, e.detail.iv, e.detail.rawData, e.detail.signature);
// console.log(res);
// console.log(e);
that.login(res.data.openid, res.data.session_key, e.detail.encryptedData, e.detail.iv);
}).catch((errMsg) => {
console.log(errMsg);
})
... ... @@ -42,25 +43,22 @@ Page({
}
});
},
login(openid, session_key, encrypted_data, iv,r,s) {
login(openid, session_key, encrypted_data, iv) {
let that = this;
wx.checkSession({
success: function () {
console.log('未过期');
//session_key 未过期,并且在本生命周期一直有效
let param = {
openid: openid,
session_key: session_key,
encrypted_data: encrypted_data,
iv: iv,
rawData: r,
signature: s
}
let url = 'wxapp/public/login';
// wx.navigateTo({
// url: '/pages/login/login',
// success: function (res) { },
// fail: function (res) { },
// complete: function (res) { },
// })
app.post(url, param).then((res) => {
console.log(res)
// console.log(res)
wx.setStorageSync('token', res.data.token);
let u = "wxapp/public/isMobile";
let header = {
... ... @@ -70,7 +68,22 @@ Page({
type: 1
}
app.post(u, data, header).then((r) => {
console.log(r)
console.log(r);
if (r.data.is_mobile == 2) {
wx.redirectTo({
url: '/pages/login/login',
success: function (res) { },
fail: function (res) { },
complete: function (res) { },
})
} else if (r.data.is_mobile == 1) {
wx.redirectTo({
url: '/pages/index/index',
success: function (res) { },
fail: function (res) { },
complete: function (res) { },
})
}
}).catch((err) => {
})
... ... @@ -84,6 +97,14 @@ Page({
console.log(errMsg);
})
},
fail: function () {
console.log('session_key 已经失效');
// session_key 已经失效,需要重新执行登录流程
that.start() //重新登录
}
})
},
changeindexs(e) {
this.setData({
indexs: e.detail.current
... ...
... ... @@ -8,14 +8,14 @@
</block>
<swiper-item>
<view class='start_main'>
<image src='../../imgs/yonghushouyedenglubiejing@3x.png'></image>
<image src='{{imgUrl}}yonghushouyedenglubiejing@3x.png'></image>
<view class='head_txt'>
<view class='head_title'>从友</view>
<view>From·Friends</view>
<view class='head_subtitle'>让娱乐更简单</view>
</view>
<view class='logo'>
<image src='../../imgs/qdongtupian@3x.png'></image>
<image src='{{imgUrl}}qdongtupian@3x.png'></image>
</view>
</view>
<view class='start_btnbox'>
... ...
// pages/login/login.js
const app = getApp();
Page({
/**
... ... @@ -6,14 +7,50 @@ Page({
*/
data: {
timer: '', //定时器名字
codetxt:'输入验证码',
downsec: '60', //倒计时初始值
codetxt: '获取验证码',
downsec: 60, //倒计时初始值
mobile: "",
code: "",
imgUrl: app.globalData.imgUrl
},
//倒计时
downsec() {
let that=this;
let that = this;
let downsec = that.data.downsec;
if (downsec == '60')
if(that.data.mobile == "") {
wx.showToast({
title: '请输入手机号!',
icon: 'none',
duration: 1300
})
return false;
}
if(that.data.mobile.length != 11) {
wx.showToast({
title: '手机号长度有误!',
icon: 'none',
duration: 1300
})
return false;
}
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
if (!myreg.test(that.data.mobile)) {
wx.showToast({
title: '请输入正确的手机号!',
icon: 'none',
duration: 1300
})
return false;
}
let u = "wxapp/public/getCode";
let data = {
mobile: that.data.mobile
}
app.post(u,data).then((r) => {
console.log(r);
if (r.code == 20000) {
if (downsec == 60)
that.setData({
timer: setInterval(function () { //这里把setInterval赋值给变量名为timer的变量
//每隔一秒countDownNum就减一,实现同步
... ... @@ -36,64 +73,103 @@ Page({
}
}, 1000)
})
}
}).catch((err) => {
})
},
// 手机号同步到data
bindMobile(e) {
this.setData({
mobile: e.detail.value.replace(/\s+/g, '')
})
},
// 验证码同步到data
codeFun(e) {
this.setData({
code: e.detail.value.replace(/\s+/g, '')
})
},
goindex(){
wx.switchTab({url: '/pages/index/index',})
// 进入首页
goindex() {
let t = this;
let data = {
mobile: t.data.mobile,
code: t.data.code,
type: 1
}
let u = "wxapp/public/lineMobile";
let header = {
"XX-Token": wx.getStorageSync("token")
}
app.post(u, data,header).then((r) => {
console.log(r);
// wx.switchTab({
// url: '/pages/index/index',
// })
}).catch((err) => {
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function() {
}
})
\ No newline at end of file
... ...
<!--pages/login/login.wxml-->
<view class='my_content'>
<image src='../../../imgs/denglubviejing@3x.png'></image>
<image src='{{imgUrl}}denglubviejing@3x.png'></image>
<view class='login_box'>
<view class='input_item'>
<input placeholder='绑定手机' placeholder-class='input_place'></input>
绑定手机
<!-- <input placeholder='绑定手机' placeholder-class='input_place'></input> -->
</view>
<view class='input_item'>
<input placeholder='输入手机号' placeholder-class='input_place'></input>
<input placeholder='输入手机号' type='number' maxlength='11' bindinput='bindMobile' placeholder-class='input_place'></input>
</view>
<view class='input_item code'>
<input placeholder='绑定手机' placeholder-class='input_place'></input>
<input placeholder='输入验证码' type='number' bindinput='codeFun' placeholder-class='input_place'></input>
<view class='code_txt' bindtap='downsec'>{{codetxt}}</view>
</view>
<view class='agree'>
<text class='iconfont icon-duigou'></text> 已阅读
<navigator class='agree_txt'url='/pages/img_txt/img_txt' hover-class="none">《用户注册协议》</navigator>
<navigator class='agree_txt' url='/pages/img_txt/img_txt' hover-class="none">《用户注册协议》</navigator>
</view>
<view class='goindex' bindtap='goindex'>
<view class='goindex_txt' >进入首页</view>
<view class='goindex_txt'>进入首页</view>
</view>
</view>
... ...
... ... @@ -3,7 +3,7 @@
<image src='../../../imgs/shenaghudenglubeijing@3x.png'></image>
<view class='login_box'>
<view class='input_item'>
<input placeholder='绑定手机' placeholder-class='input_place'></input>
<input placeholder='绑定手机' readonly="readonly" placeholder-class='input_place'></input>
</view>
<view class='input_item'>
<input placeholder='输入手机号' placeholder-class='input_place'></input>
... ...
/* pages/login/login.wxss */
page{
page {
background: #010938;
}
.login_box{
.login_box {
position: absolute;
top:0;
left:50%;
top: 0;
left: 50%;
transform: translateX(-50%);
overflow-y: scroll;
/* overflow-y: scroll; */
height: 100%;
width:530rpx;
margin: 170rpx auto 0 auto;
color:#fff;
font-size:28rpx;
width: 530rpx;
margin: 170rpx auto 0 auto;
color: #fff;
font-size: 28rpx;
}
.input_item{
padding:16rpx 0;
border-bottom:1rpx solid #fff;
.input_item {
padding: 16rpx 0;
border-bottom: 1rpx solid #fff;
margin: 0 0 26rpx 0;
}
.input_place{
color:#fff;
.input_place {
color: #fff;
font-size: 28rpx;
}
.code{
.code {
display: flex;
justify-content: space-between;
align-items: center;
}
.code input{
width:60%;
.code input {
width: 60%;
}
.code_txt{
.code_txt {
display: flex;
align-items: center;
justify-content: center;
padding:2rpx 10rpx;
padding: 5rpx 10rpx 7rpx;
box-sizing: border-box;
width:178rpx;
width: 178rpx;
height: 44rpx;
border:1rpx solid #fff;
border: 1rpx solid #fff;
border-radius: 10rpx;
}
.agree{
.agree {
display: flex;
justify-content: center;
align-items: center;
}
.agree_txt{
color:#009FE8;
.agree_txt {
color: #009fe8;
}
.agree .iconfont{
.agree .iconfont {
display: inline-block;
border:1rpx solid rgba(255,255,255,0.7);
color:rgba(255,255,255,0.7);
border: 1rpx solid rgba(255, 255, 255, 0.7);
color: rgba(255, 255, 255, 0.7);
margin: 0 13rpx 0 0;
font-size:20rpx;
font-size: 20rpx;
border-radius: 33%;
}
.goindex{
.goindex {
position: fixed;
padding:27rpx 0;
bottom:300rpx;
left:50%;
padding: 27rpx 0;
bottom: 300rpx;
left: 50%;
transform: translateX(-50%);
width: 530rpx;
display: flex;
justify-items: center;
justify-content: center;
border-top:1rpx solid #fff;
border-bottom:1rpx solid #fff;
border-top: 1rpx solid #fff;
border-bottom: 1rpx solid #fff;
}
.goindex_txt{
padding:4rpx 20rpx;
background: rgba(255,255,255,0.7);
border-radius: 10rpx;
color:rgba(255,255,255,0.7);
.goindex_txt {
padding: 4rpx 20rpx;
background: rgba(255, 255, 255, 0.7);
border-radius: 10rpx;
color: rgba(255, 255, 255, 0.7);
}
.goindex_txt::active{
opacity: 0.7;
.goindex_txt::active {
opacity: 0.7;
}
... ...