Browse Source

改变小程序登录的交互逻辑

master
chenxuhui 6 years ago
parent
commit
21a129d458
7 changed files with 152 additions and 283 deletions
  1. +7
    -7
      app.js
  2. +1
    -1
      app.json
  3. +129
    -258
      pages/login/login.js
  4. +9
    -11
      pages/login/login.wxml
  5. +1
    -1
      pages/login/login.wxss
  6. +1
    -1
      project.config.json
  7. +4
    -4
      utils/net.js

+ 7
- 7
app.js View File

@ -41,14 +41,14 @@ App({
userInfo:null, userInfo:null,
UserName:"", UserName:"",
shareOrderID: 0, shareOrderID: 0,
OpenId: "",
AppId: "wx246fd8f3a0273f2f",
Phone: "",
openID: "",
appID: "wx246fd8f3a0273f2f",
phoneNum: "",
From: "", From: "",
baseUrl: "https://miniprogram.food988.com/Rest.aspx",
TransferBaseUrl: "https://miniprogram.food988.com/RequestTransfer.aspx",
CustomerId: "",
baseUrl: "https://miniprotest.food988.com/Rest.aspx",
tranferBaseUrl: "https://miniprotest.food988.com/RequestTransfer.aspx",
globalCustomerID: "",
cookie: "",
} }
}) })


+ 1
- 1
app.json View File

@ -17,7 +17,7 @@
"backgroundTextStyle": "light", "backgroundTextStyle": "light",
"navigationBarTitleText": "畜司机易", "navigationBarTitleText": "畜司机易",
"navigationBarBackgroundColor": "#2689f8", "navigationBarBackgroundColor": "#2689f8",
"navigationBarTextStyle": "#FFFFFF"
"navigationBarTextStyle": "white"
}, },
"tabBar": { "tabBar": {
"borderStyle": "white", "borderStyle": "white",


+ 129
- 258
pages/login/login.js View File

@ -1,303 +1,174 @@
// pages/login/login.js // pages/login/login.js
var ID;
var Idcard = "";
var openid;
var Phone;
var nickName;
var gender;
var province;
var city;
var country;
var avatarUrl;
var UnionId;
const app = getApp()
var network = require("../../utils/net.js")
var getOpenIdByCode = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode';
var getCustomerList = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList';
var getBindCustomer = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer';
var isBindWeixinPath = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP';
// 直接请求青花瓷服务器获取绑定信息的返回
var bindPath = "/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind";
// var XuBindDriver = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/XuBindDriver'
var bindByPhone = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/XuBindByPhone';
var GetDriverByIdCard = "/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByIdCard"
var GetDriverByOpenId = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByOpenId'
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/IsBinded';
//获取openID 参数1、app.globalData.AppId 2、code
function getOpenId(successaction) {
wx.login({
success: function(res) {
var code = res.code;
var method = getOpenIdByCode;
var params = [app.globalData.AppId, code];
network.requestLoading(method, params, function(res) {
app.globalData.OpenId = res.result;
successaction(app.globalData.OpenId)
})
}
})
}
//获取绑定的客户ID 参数1:appid, 参数2:openid 返回用户电话 客户ID 客户Name
function IsBind(openid, successaction) {
var method = getBindCustomer;
var params = [app.globalData.AppId, openid];
network.requestLoading(method, params, function(res) {
app.globalData.CustomerId = res.result.ID;
successaction(res.result.WeixinUser_Phone)
})
}
var network = require("../../utils/net.js");
var app = getApp();
var openID;
/** /**
* 客户服务器判断是否绑定成功 参数openid
* 返回值phoneNum
* 成功调用是否关注公众号方法
* 获取绑定客户ID及用户电话 参数1appID 2openID
* 返回值globalCustomerIDWeixinUser_Phone
* 成功调用获取cookie方法及判断是否绑定成功方法
*/ */
function IsBinded(openid) {
let method = isBindedPath;
let params = [openid];
network.transfer_request(method, params, function (res) {
if (res.result != "") {
app.globalData.Phone = res.result;
// 判断是否关注公众号
IsBindWeixinMP(app.globalData.Phone)
function GetBindCustomer(that) {
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer';
let params = [app.globalData.appID, app.globalData.openID];
network.requestLoading(method, params, function (res) {
if (res.result != null) {
app.globalData.globalCustomerID = res.result.ID;
app.globalData.phoneNum = res.result.WeixinUser_Phone;
// 获取cookie值
// WeixinLogin(function (res) {
wx.switchTab({
url: '/pages/homePage/homePage',
})
// });
} }
}) })
} }
//绑定公众号 参数用户电话 返回true已关注 false未关注
function IsBindWeixinMP(phone) {
let method = isBindWeixinPath;
let params = [phone];
network.requestLoading(method, params, function(res) {
//添加假数据。方便登录测试,提交版本需更正注释
// res.result = false;
if (res.result == true) {
wx.switchTab({
url: '/pages/homePage/homePage',
})
} else {
wx.showModal({
title: '提示',
content: '请关注公众号',
showCancel: false,
})
// 获取cookie值 参数1、appID 2、openID
// function WeixinLogin(successtion) {
// let method = '/MainSystem/B3MiniProgramRpc/Rpcs/CommonRpc/WeixinLogin';
// let params = [app.globalData.appID, app.globalData.openID];
// network.transfer_request(method, params, function (res) {
// app.globalData.cookie = res.result;
// successtion();
// })
// }
//2次绑定第二次 绑定客户 要有先后
function XuBindByPhone(that) {
let userInfos = app.globalData.userInfo
let method2 = "/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/XuBindByPhone";
let params2 = [{
"UserName": that.data.userName,
"Password": that.data.psw,
"OpenId": app.globalData.openID,
"Phone": that.data.phoneNum,
"NickName": userInfos.nickName,
"Sex": userInfos.gender,
"Province": userInfos.province,
"City": userInfos.city,
"Country": userInfos.country,
"HeadImgUrl": userInfos.avatarUrl,
"UnionId": "",
}];
network.transfer_request(method2, params2, function (res) {
if (res.result != null) {
// WeixinLogin(function () {
wx.switchTab({
url: '/pages/homePage/homePage',
})
// })
} }
}) })
} }
Page({ Page({
data: { data: {
idCard: "",
customerList: [{
ID: 0,
Name: "请选择所属客户"
}],
customerIndex: 0,
code: "",
userName: "",
psw: "",
phoneNum: "",
}, },
// 绑定客户
listenerPickerSelected: function(e) {
this.setData({
customerIndex: e.detail.value,
// 页面生命周期函数
onShow: function () {
var that = this;
wx.login({
success: function (res) {
let code = res.code;
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode';
let params = [app.globalData.appID, code];
// 获取openID
network.requestLoading(method, params, function (res) {
app.globalData.openID = res.result;
// 获取绑定客户ID及用户电话
GetBindCustomer(that)
})
}
}); });
app.globalData.CustomerId = this.data.customerList[this.data.customerIndex].ID;
}, },
// // 姓名
// getDriverName: function(e) {
// app.globalData.UserName = e.detail.value
// },
// 手机号码
getPhone: function(e) {
Phone = e.detail.value;
app.globalData.Phone = Phone;
//获取企业编号
getCode: function (e) {
this.data.code = e.detail.value;
}, },
// 身份证
// getIDCardNum: function(e) {
// if (!app.globalData.CustomerId) {
// wx: wx.showModal({
// title: '提示',
// content: '请先绑定客户',
// });
// return;
// }
// var that = this;
// if (e.detail.value.length == 18) {
// Idcard = e.detail.value;
// var method = GetDriverByIdCard;
// var params = [1, Idcard];
// network.transfer_request(method, params, function(res) {
// //res就是我们请求接口返回的数据
// if (res.result != null) {
// app.globalData.UserName = res.result.Name,
// app.globalData.Phone = res.result.Telephone;
// that.setData({
// name: res.result.Name,
// phoneNum: res.result.Telephone,
// })
// }
// })
// }
// },
// 获取所有客户列表
choiceCustomer: function() {
var that = this;
var method = getCustomerList;
var params = [];
network.requestLoading(method, params, function(res) {
if (res.result.length > 0) {
var lastArr = that.data.customerList.concat(res.result)
that.setData({
customerList: lastArr,
})
}
})
//获取用户名
getUserName: function (e) {
this.data.userName = e.detail.value;
},
//获取密码
getPSW: function (e) {
this.data.psw = e.detail.value;
},
// 电话输入框
getPhone: function (e) {
let val = e.detail.value;
this.data.phoneNum = val;
}, },
getUserInfo: function(e) {
// 获取授权 成功 绑定信息到客户服务器 回调函数绑定中转服务器
getUserInfo: function (e) {
var that = this; var that = this;
if (e.detail.userInfo != null) { if (e.detail.userInfo != null) {
app.globalData.userInfo = e.detail.userInfo;
nickName = app.globalData.userInfo.nickName;
gender = app.globalData.userInfo.gender;
province = app.globalData.userInfo.province;
city = app.globalData.userInfo.city;
country = app.globalData.userInfo.country;
avatarUrl = app.globalData.userInfo.avatarUrl;
// 判断是否绑定所属客户
if (that.data.customerList[that.data.customerIndex].ID == 0) {
wx.showToast({
image: '/imgs/ddpc.png',
title: '请选择所属客户',
})
return false;
}
// 判断电话号码信息
if (app.globalData.Phone == "") {
app.globalData.userInfo = e.detail.userInfo
if (this.data.code == "") {
wx.showToast({ wx.showToast({
image: '/imgs/ddpc.png',
title: '手机号码不能为空',
title: '请输入企业编码',
}) })
return false; return false;
} }
if (!(/^1[34578]\d{9}$/.test(app.globalData.Phone))) {
wx.showToast({
image: '/imgs/ddpc.png',
title: '号码不正确',
})
return false;
}
// 判断用户姓名
// if (app.globalData.UserName == "") {
// if (this.data.userName == "") {
// wx.showToast({ // wx.showToast({
// image: '/imgs/ddpc.png',
// title: '用户姓名不能为空',
// title: '请输入用户名',
// }) // })
// return false; // return false;
// } // }
// 判断身份证信息
// if ((Idcard.length < 18) || (Idcard.length > 18)) {
// if (this.data.psw == "") {
// wx.showToast({ // wx.showToast({
// image: '/imgs/ddpc.png',
// title: '身份证号不正确',
// title: '请输入密码',
// }) // })
// return false; // return false;
// } // }
if (this.data.phoneNum == "") {
wx.showToast({
title: '请输入手机号码',
})
return false;
} else if (!(/^1[34578]\d{9}$/.test(this.data.phoneNum))) {
wx.showToast({
title: '号码不正确',
})
return false;
}
let userInfos = app.globalData.userInfo
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/BindCustomerCode';
let params = [{
"AppId": app.globalData.appID,
"CustomerCode": this.data.code,
"OpenId": app.globalData.openID,
"Phone": this.data.phoneNum,
"NickName": userInfos.nickName,
"Sex": userInfos.gender,
"Province": userInfos.province,
"City": userInfos.city,
"Country": userInfos.country,
"HeadImgUrl": userInfos.avatarUrl,
"UnionId": ""
}];
network.requestLoading(method, params, function (res) {
if (res.result != null) {
app.globalData.globalCustomerID = res.result;
XuBindByPhone(that);
}
})
} else { } else {
wx.showModal({ wx.showModal({
title: '授权提示', title: '授权提示',
content: '请给予权限,不涉及个人隐私', content: '请给予权限,不涉及个人隐私',
showCancel: false,
showCancel: false
}) })
return false;
} }
var method = bindByPhone;
let params = [{
"OpenId": app.globalData.OpenId,
"Phone": app.globalData.Phone,
"NickName": nickName,
"Sex": gender,
"Province": province,
"City": city,
"Country": country,
"HeadImgUrl": avatarUrl,
"UnionId": ""
}];
// var params = [{
// // "Domain_ID": that.data.array[that.data.index].ID,
// "Driver_Name": app.globalData.UserName,
// "Phone": app.globalData.Phone,
// "IdCard": Idcard,
// "OpenId": app.globalData.OpenId,
// "NickName": nickName,
// "Sex": gender,
// "Province": province,
// "City": city,
// "Country": country,
// "HeadImgUrl": avatarUrl,
// "UnionId": " "
// }];
var transferParams = [{
"OpenId": app.globalData.OpenId,
"Phone": app.globalData.Phone,
"NickName": nickName,
"Sex": gender,
"Province": province,
"City": city,
"Country": country,
"HeadImgUrl": avatarUrl,
"UnionId": " ",
//请求新增参数
"AppId": app.globalData.AppId,
"CustomerId": that.data.customerList[that.data.customerIndex].ID,
}];
network.transfer_request(method, params, function(res) {
app.globalData.Phone = that.data.phoneNum;
//绑定中转服务器客户对应信息 成功判断是否关注公众号
that.bingDriverInTransferServer(transferParams, function(res) {
IsBindWeixinMP(app.globalData.Phone)
});
})
},
bingDriverInTransferServer: function(params, successaction) {
var that = this;
var method = bindPath;
network.requestLoading(method, params, function(res) {
if (res.result == true) {
successaction();
}
});
}, },
onShow: function() {
var that = this;
that.choiceCustomer();
getOpenId(function(res) {
openid = res;
IsBind(openid, function(res) {
app.globalData.Phone = res;
if (res == "") {
} else {
// 判断是否绑定成功 参数openid 返回值phoneNum
IsBinded(openid);
}
})
})
},
}) })

+ 9
- 11
pages/login/login.wxml View File

@ -2,27 +2,25 @@
<view class='containerView'> <view class='containerView'>
<view class='customerChooseView'> <view class='customerChooseView'>
<view class='keyView'>绑定客户</view>
<view class='keyView'>企业编码</view>
<view class='valueView'> <view class='valueView'>
<picker class="{{customerIndex==0 ? 'pickerPlaceHolder' : 'pickerSelected'}}" mode="selector" range="{{customerList}}" value="{{customerList[customerIndex].Name}}" range-key="Name" bindchange="listenerPickerSelected">
<text>{{customerList[customerIndex].Name}}</text>
</picker>
<input class='imput_phone' bindinput='getCode' placeholder='请输入企业编码' placeholder-style='color:rgb(202, 202, 202)'></input>
</view> </view>
</view> </view>
<view class='lineView'></view> <view class='lineView'></view>
<!-- <view class='customerChooseView'>
<view class='keyView'>身份证号码</view>
<!-- <view class='customerChooseView'>
<view class='keyView'>用户名</view>
<view class='valueView'> <view class='valueView'>
<input class='imput_phone' bindinput='getIDCardNum' type='number' maxlength='18' placeholder='请输入身份证号码' placeholder-style='color:rgb(202, 202, 202)'></input>
<input class='imput_phone' bindinput='getUserName' placeholder='请输入用户名' placeholder-style='color:rgb(202, 202, 202)'></input>
</view> </view>
</view> </view>
<view class='lineView'></view> -->
<view class='lineView'></view>
<!-- <view class='customerChooseView'>
<view class='keyView'>姓 名</view>
<view class='customerChooseView'>
<view class='keyView'>密码</view>
<view class='valueView'> <view class='valueView'>
<input class='imput_phone' bindinput='getDriverName' type='text' placeholder='请输入姓名' placeholder-style='color:rgb(202, 202, 202)'></input>
<input class='imput_phone' bindinput='getPSW' placeholder='请输入密码' placeholder-style='color:rgb(202, 202, 202)'></input>
</view> </view>
</view> </view>
<view class='lineView'></view> --> <view class='lineView'></view> -->


+ 1
- 1
pages/login/login.wxss View File

@ -5,7 +5,7 @@
/* height: 480rpx; /* height: 480rpx;
margin-top: 25%; */ margin-top: 25%; */
height: 240rpx; height: 240rpx;
margin-top: 40%;
margin-top: 50%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;


+ 1
- 1
project.config.json View File

@ -42,7 +42,7 @@
"query": "", "query": "",
"scene": "1038", "scene": "1038",
"referrerInfo": { "referrerInfo": {
"appId": "wx862a803bfc8b0af0",
"appId": "wx246fd8f3a0273f2f",
"extraData": "{\"orderID\":32}" "extraData": "{\"orderID\":32}"
} }
}, },


+ 4
- 4
utils/net.js View File

@ -15,7 +15,7 @@ function requestLoading(method, params, successaction) {
'method': method, 'method': method,
'params': params 'params': params
}; };
var baseUrl = app.globalData.baseUrl ;//+ "?appid=" + app.globalData.AppId + "&phone=" + app.globalData.Phone;
var baseUrl = app.globalData.baseUrl + "?appID=" + app.globalData.appID + "&phone=" + app.globalData.phoneNum;
wx.request({ wx.request({
url: baseUrl, url: baseUrl,
data: data, data: data,
@ -55,13 +55,13 @@ function transfer_request(method, params, successaction) {
}) })
var newData = { var newData = {
"DecryptCookie": "", "DecryptCookie": "",
"CustomerId": app.globalData.CustomerId,
//"AppendUrlString": "?appid=" + app.globalData.AppId + "&phone=" + app.globalData.Phone,
"CustomerId": app.globalData.globalCustomerID,
"AppendUrlString": "?appID=" + app.globalData.appID + "&phone=" + app.globalData.phoneNum,
"Method": method, "Method": method,
"Data": params, "Data": params,
}; };
// 中转服务器地址 // 中转服务器地址
var baseUrl = app.globalData.TransferBaseUrl;
var baseUrl = app.globalData.tranferBaseUrl;
wx.request({ wx.request({
url: baseUrl, url: baseUrl,
data: newData, data: newData,


Loading…
Cancel
Save