Kaynağa Gözat

注册

master
ljc 5 yıl önce
ebeveyn
işleme
6d0e9fed05
4 değiştirilmiş dosya ile 235 ekleme ve 78 silme
  1. +171
    -64
      laomenkuang_project/app.js
  2. +8
    -0
      laomenkuang_project/pages/index/index.js
  3. +54
    -12
      laomenkuang_project/pages/register/register.js
  4. +2
    -2
      laomenkuang_project/pages/register/register.wxml

+ 171
- 64
laomenkuang_project/app.js Dosyayı Görüntüle

// var logs = wx.getStorageSync('logs') || [] // var logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now()) // logs.unshift(Date.now())
// wx.setStorageSync('logs', logs) // wx.setStorageSync('logs', logs)
var openid = wx.getStorageSync('openid') || "";


// 登录 // 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log(res)
if (res.code){
wx.request({
url: 'https://laomenkuang.jiyou-tech.com/apiWx/openid',
header: {
code: res.code
},
success: e => {
console.log(e)
if (e.data.code == 200) {
this.globalData.openId = e.data.data.openid;
this.globalData.session_key = e.data.data.session_key;
this.globalData.token = e.data.data.token;
wx.setStorageSync('openid', e.data.data.openid)
wx.setStorageSync('session_key', e.data.data.session_key)
wx.setStorageSync('token', e.data.data.token)
if (!openid){
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log(res)
if (res.code){
wx.request({
url: this.globalData.httpUrl+'openid',
header: {
code: res.code
},
success: e => {
console.log(e)
if (e.data.code == 200) {
this.globalData.openId = e.data.data.openid;
this.globalData.session_key = e.data.data.session_key;
this.globalData.token = e.data.data.token;
wx.setStorageSync('openid', e.data.data.openid)
wx.setStorageSync('session_key', e.data.data.session_key)
wx.setStorageSync('token', e.data.data.token)

}
} }
}
})
} else {
console.log("登陆失败" + res.errMsg)
})
} else {
console.log("登陆失败" + res.errMsg)
}
} }
}
})
})
}else{
this.globalData.openid = openid;
}
this.getUserType();
// 获取用户信息 // 获取用户信息
wx.getSetting({
success: res => {
console.log(res)
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: e => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = e.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}else{
wx.authorize({
scope: 'scope.record',
success() {
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
wx.startRecord()
}
})
}
// wx.getSetting({
// success: res => {
// console.log(res)
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// wx.getUserInfo({
// success: e => {
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = e.userInfo
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// if (this.userInfoReadyCallback) {
// this.userInfoReadyCallback(res)
// }
// }
// })
// }else{
// wx.authorize({
// scope: 'scope.record',
// success() {
// wx.getUserInfo({
// success: e => {
// console.log(e)
// }
// })
// }
// })
// }
// }
// })
},
getUserType:function(){//获取用户注册状态

this.wxRequest(this.globalData.httpUrl + 'getinfo',{},e=>{
console.log(e)
if(e.code==201){//未注册跳到注册页面
wx.reLaunch({
url: '/pages/register/register'
})
} else if (e.code == 202){//已注册跳到首页购券大厅
wx.switchTab({
url: '/pages/index/index'
})
} }
})
},this)
}, },
globalData: { globalData: {
userInfo: null, userInfo: null,
session_key:"", session_key:"",
token:"", token:"",
userInfo:"", userInfo:"",
httpUrl:"https://laomenkuang.jiyou-tech.com/apiWx/"
}, },
wxRequest:function(url,data){//接口调用
wx.request({
url: url,
data: data,
header: {
openid: this.globalData.openId
},
success(res) {
console.log(res.data)
wxRequest: function (url, params, callback, thisArg, methods, openid) {
let that = this;
console.log(this.globalData.openid)
var httpUrl = url;
var str = "";
var count = 0;
for (let key in params) {
if (count) {
str += "&" + key + "=" + params[key];
} else {
str += key + "=" + params[key];
} }
})
}
count++;
}
if (str) {
httpUrl += "?" + str;
}
if (!methods) {
methods = "GET";
}
if (methods == "POST") {
wx.request({
url: url,
data: params,
method: methods,
header: {
"content-type": "application/x-www-form-urlencoded",
"openid": this.globalData.openid
},
success: function (re) {
// if (re.data.code == -1002) {
// wx.removeStorageSync('openid');
// that.wxLogin();
// // that.wxRequest(url, params, callback, thisArg, methods, openid);
// }
if (callback && thisArg) {
callback.call(thisArg, re.data);
}
},
fail: function (re) {
wx.hideLoading();
}
})
} else {
wx.request({
url: httpUrl,
method: methods,
header: {
"openid": this.globalData.openid,
},
success: function (re) {
// if (re.data.code == -1002) {
// wx.removeStorageSync('openid');
// that.wxLogin();
// // that.wxRequest(url, params, callback, thisArg, methods, openid);
// }
if (callback && thisArg) {
callback.call(thisArg, re.data);
}
},
fail: function (res) {
wx.hideLoading();
}
})
}
},
// requestGet:function(url,data,callback){//get接口调用
// wx.request({
// url: url,
// header: {
// "openid": this.globalData.openId
// },
// data: data,
// success:res=>{
// if (callback) {
// }
// }
// })
// },
// requestPost: function (url, data) {//post接口调用
// wx.request({
// url: url,
// header: {
// "Content-Type":"application/x-www-form-urlencoded",
// openid: this.globalData.openId
// },
// data: data,
// success(res) {
// console.log(res.data)
// }
// })
// }
}) })

+ 8
- 0
laomenkuang_project/pages/index/index.js Dosyayı Görüntüle

onLoad: function () { onLoad: function () {
}, },
getDataList:function(){
app.wxRequest(app.globalData.httpUrl + 'couponsell/list', {}, e => {
console.log(e)
if (e.code == 200) {
}
}, this)
},
skipPage:function(){ skipPage:function(){
var arr = {"name":"小明","age":20}; var arr = {"name":"小明","age":20};
var option = JSON.stringify(arr); var option = JSON.stringify(arr);

+ 54
- 12
laomenkuang_project/pages/register/register.js Dosyayı Görüntüle

yesSend:false,//是否发送验证码 yesSend:false,//是否发送验证码
minter: 60,//发送验证码60秒后才可再次发送 minter: 60,//发送验证码60秒后才可再次发送
num:60, num:60,
phone: "",//手机号
phoneCode: "",//验证码
}, },


/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function () {
}, },


/** /**
}, },


sendTouch:function(){//发送验证码 sendTouch:function(){//发送验证码
if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
wx.showToast({
title: '手机号错误',
icon: 'none',
duration: 500
})
return;
}
this.setData({ this.setData({
yesSend: true, yesSend: true,
}) })
if (this.data.yesSend) { if (this.data.yesSend) {
time = setInterval(this.setIntervalFn,1000) time = setInterval(this.setIntervalFn,1000)
} }
app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone:this.data.phone}, e => {
console.log(e)
if(e.code==200){
wx.showToast({
title: e.message,
icon: 'success',
duration: 500
})
}
}, this)
}, },
setIntervalFn:function(){//定时器 setIntervalFn:function(){//定时器
if (this.data.num > 0) { if (this.data.num > 0) {
}) })
console.log(this.data.minter) console.log(this.data.minter)
}, },
registerFn:function(){
wx.showToast({
title: '成功',
icon: 'success',
duration: 1000
registerFn:function(){//注册
app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
console.log(e)
if (e.code == 200) {
clearInterval(time);
this.setData({
minter: 60,
num: 60
})
wx.showToast({
title: '注册成功',
icon: 'success',
duration: 500
})
setTimeout(function () {
wx.switchTab({
url: '../index/index'
})
}, 1000)
}
}, this,"POST")
},
getPhone: function (e) {//获取手机号
console.log(e.detail.value);
this.setData({
phone: e.detail.value
}) })
setTimeout(function(){
wx.switchTab({
url: '../index/index'
})
},1000)
}
},
getCode: function (e) {//获取验证码
console.log(e.detail.value);
this.setData({
phoneCode: e.detail.value
})
},
}) })

+ 2
- 2
laomenkuang_project/pages/register/register.wxml Dosyayı Görüntüle

<image class="registerBg" src="../images/registerBg.jpg"></image> <image class="registerBg" src="../images/registerBg.jpg"></image>
<view class="import"> <view class="import">
<view class="phoneView"> <view class="phoneView">
<input class="phoneInt" placeholder="电话" placeholder-class="placeholderClass"></input>
<input class="phoneInt" type="number" bindinput="getPhone" placeholder="电话" placeholder-class="placeholderClass"></input>
</view> </view>
<view class="codeView"> <view class="codeView">
<view bindtap="sendTouch" class="sendBtn" wx:if="{{!yesSend}}">发送</view> <view bindtap="sendTouch" class="sendBtn" wx:if="{{!yesSend}}">发送</view>
<view class="sendBtn" wx:if="{{yesSend}}">{{minter}}</view> <view class="sendBtn" wx:if="{{yesSend}}">{{minter}}</view>
<input class="codeInt" placeholder="验证码" placeholder-class="placeholderClass"></input>
<input class="codeInt" type="number" bindinput="getCode" placeholder="验证码" placeholder-class="placeholderClass"></input>
</view> </view>
<image bindtap="registerFn" class="registerBtn" src="../images/registerBtn.png"></image> <image bindtap="registerFn" class="registerBtn" src="../images/registerBtn.png"></image>
</view> </view>

Yükleniyor…
İptal
Kaydet