Browse Source

1、登录页login完成

2、请求方法完成
master
chenxuhui 7 years ago
parent
commit
5b586660a7
12 changed files with 386 additions and 141 deletions
  1. +2
    -30
      app.js
  2. +2
    -1
      app.json
  3. BIN
      imgs/blueBtn.png
  4. +196
    -0
      pages/login/login.js
  5. +5
    -0
      pages/login/login.json
  6. +32
    -0
      pages/login/login.wxml
  7. +72
    -0
      pages/login/login.wxss
  8. +0
    -15
      pages/logs/logs.js
  9. +0
    -3
      pages/logs/logs.json
  10. +0
    -6
      pages/logs/logs.wxml
  11. +0
    -8
      pages/logs/logs.wxss
  12. +77
    -78
      utils/net.js

+ 2
- 30
app.js View File

@ -1,37 +1,9 @@
//app.js
App({
onLaunch: function() {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.UserInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
PhoneNum: "",
OpenId: "",


+ 2
- 1
app.json View File

@ -1,9 +1,9 @@
{
"pages": [
"pages/login/login",
"pages/navigation/navigation",
"pages/selectCustomer/selctCustomer",
"pages/index/index",
"pages/logs/logs",
"pages/main/main",
"pages/my/my",
"pages/saleForecastList/saleForecastList",
@ -19,6 +19,7 @@
"pages/guarantee/newbill/newbill",
"pages/guarantee/selectbill/selectbill",
"pages/guarantee/detailshow/detailshow"
],
"window": {
"backgroundTextStyle": "light",


BIN
imgs/blueBtn.png View File

Before After
Width: 577  |  Height: 258  |  Size: 7.9 KiB

+ 196
- 0
pages/login/login.js View File

@ -0,0 +1,196 @@
// pages/login/login.js
var network = require("../../utils/net.js");
var app = getApp();
var openID;
/**
* 获取绑定客户ID及用户电话 参数1appID 2openID
* 返回值globalCustomerIDWeixinUser_Phone
* 成功调用获取cookie方法及判断是否绑定成功方法
*/
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;
WeixinLogin(function (res) {
IsBinded(app.globalData.openID);
});
}
})
}
/**
* 判断是否绑定成功 参数openid
* 返回值phoneNum
* 成功调用是否关注公众号方法
*/
function IsBinded(openid) {
let method = '/MainSystem/B3MiniProgramRpc/Rpcs/ManagerRpc/AccountRpc/IsBinded';
let params = [openid];
network.newRequestLoading(method, params, function (res) {
if (res.result != "") {
app.globalData.phoneNum = res.result;
IsBindWeixinMP(app.globalData.phoneNum)
}
})
}
// 判断是否关注公众号 参数phone 返回值bool 成功进入首页
function IsBindWeixinMP(phone) {
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP';
let params = [phone];
network.requestLoading(method, params, function (res) {
// res.result = false;
if (res.result == true) {
wx.switchTab({
url: '/pages/indexL/indexL',
})
} else {
wx.showModal({
title: '提示',
content: '请关注公众号',
showCancel: false,
})
}
})
}
// 获取cookie值 参数1、appID 2、openID
function WeixinLogin(successtion) {
let method = '/MainSystem/MainSystem/Auth/WeixinLogin';
let params = [app.globalData.appID, app.globalData.openID];
network.newRequestLoading(method, params, function (res) {
app.globalData.cookie = res.result;
successtion();
})
}
//绑定中转服务器客户对应信息 成功判断是否关注公众号
function Bind(that) {
let userInfos = app.globalData.userInfo
let method2 = "/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind";
let params2 = [{
"AppId": app.globalData.appID,
"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": "",
"CustomerId": app.globalData.globalCustomerID
}];
network.requestLoading(method2, params2, function (res) {
if (res.result == true) {
IsBindWeixinMP(app.globalData.phoneNum)
}
})
}
Page({
data: {
phoneNum: "",
index: 0,
customerArray: [{
ID: 0,
Name: "请选择所属客户"
}],
},
// 客户列表变更选项信息
listenerPickerSelected: function (e) {
this.setData({
index: e.detail.value,
});
app.globalData.globalCustomerID = this.data.customerArray[this.data.index].ID;
},
// 页面生命周期函数
onShow: function () {
//由登录页面进入详情页变更值为0;分享直接进入为1
app.globalData.shareInState = 0;
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];
network.requestLoading(method, params, function (res) {
app.globalData.openID = res.result;
GetBindCustomer(that)
})
}
});
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList';
let params = [];
network.requestLoading(method, params, function (res) {
if (res.result.length > 0) {
var lastArr = that.data.customerArray.concat(res.result)
that.setData({
customerArray: lastArr,
})
}
})
},
// 电话输入框
getPhone: function (e) {
let val = e.detail.value;
this.data.phoneNum = val;
},
// 获取授权 成功 绑定信息到客户服务器 回调函数绑定中转服务器
getUserInfo: function (e) {
var that = this;
if (e.detail.userInfo != null) {
app.globalData.userInfo = e.detail.userInfo
if (that.data.array[that.data.index].ID == 0) {
wx.showToast({
title: '请选择所属客户',
})
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/B3MiniProgramRpc/Rpcs/ManagerRpc/AccountRpc/QinBindByPhone';
let params = [{
"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.newRequestLoading(method, params, function (res) {
if (res.result != null) {
app.globalData.phoneNum = that.data.phoneNum;
Bind(that)
}
})
} else {
wx.showModal({
title: '授权提示',
content: '请给予权限,不涉及个人隐私',
showCancel: false
})
}
}
})

+ 5
- 0
pages/login/login.json View File

@ -0,0 +1,5 @@
{
"navigationBarBackgroundColor": "white",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "业务员登录"
}

+ 32
- 0
pages/login/login.wxml View File

@ -0,0 +1,32 @@
<!--pages/login/login.wxml-->
<view class='containerView'>
<view class='customerChooseView'>
<view class='keyView'>绑定客户</view>
<view class='valueView'>
<picker class="{{index==0 ? 'pickerPlaceHolder' : 'pickerSelected'}}" mode="selector" range="{{customerArray}}" value="{{customerArray[index].Name}}" range-key="Name" bindchange="listenerPickerSelected">
<text>{{customerArray[index].Name}}</text>
</picker>
</view>
</view>
<view class='lineView'></view>
<view class='customerChooseView'>
<view class='keyView'>手机号码</view>
<view class='valueView'>
<input class='imput_phone' bindinput='getPhone' type='number' maxlength='11' placeholder='请输入手机号' placeholder-style='color:rgb(202, 202, 202)'></input>
</view>
</view>
<view class='lineView'></view>
</view>
<view class='imageView' catchtap='saveCarsChange'>
<image class='currentImage' src="/imgs/blueBtn.png">
<view class='btnTextView'>
<text class='btnText'>确认绑定</text>
</view>
</image>
</view>
<official-account class="wxmp"></official-account>

+ 72
- 0
pages/login/login.wxss View File

@ -0,0 +1,72 @@
/* pages/login/login.wxss */
.containerView{
margin-left: 30rpx;
margin-right: 30rpx;
height: 240rpx;
margin-top: 40%;
display: flex;
flex-direction: column;
}
.customerChooseView{
height: 120rpx;
width: 100%;
display: flex;
flex-direction: row;
font-size: 20px;
color: black;
}
.keyView{
padding-top: 60rpx;
width: 40%;
height: 100%;
}
.valueView{
padding-top: 60rpx;
width: 60%;
height: 100%;
}
.pickerPlaceHolder{
color:rgb(202, 202, 202);
}
.pickerSelected{
color: black;
}
.lineView {
height: 1rpx;
background-color: #dbdbdb;
}
.imageView {
height: 80px;
width: 100%;
margin-top: 30px;
position: relative;
align-items: center;
justify-content: center;
box-sizing: content-box;
}
.currentImage {
width: 100%;
height: 100%;
}
.btnTextView {
position: absolute;
width: 100%;
top:0;
line-height: 65px;
text-align: center;
}
.btnText {
color: white;
font-size: 34rpx;
}

+ 0
- 15
pages/logs/logs.js View File

@ -1,15 +0,0 @@
//logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})

+ 0
- 3
pages/logs/logs.json View File

@ -1,3 +0,0 @@
{
"navigationBarTitleText": "查看启动日志"
}

+ 0
- 6
pages/logs/logs.wxml View File

@ -1,6 +0,0 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>

+ 0
- 8
pages/logs/logs.wxss View File

@ -1,8 +0,0 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}

+ 77
- 78
utils/net.js View File

@ -1,57 +1,70 @@
//不显示对话框的请求
const app = getApp()
function request(url, params, success, fail) {
this.requestLoading(url, params, "", success, fail)
}
var app = getApp();
var reconnectMethod = '';
var reconnectParams = [];
var newReconnectMethod = '';
var newReconnectParams = [];
// 展示进度条的网络请求
// url:网络请求的url
// params:请求参数
// message:进度条的提示信息
// success:成功的回调函数
// fail:失败的回调
function requestLoading(method, params, successaction, erroraction) {
/**
* method:接口str
* params:参数[]
* successaction:成功回调
*/
function requestLoading(method, params, successaction) {
reconnectMethod = method;
reconnectParams = params;
wx.showLoading({
title: "加载中",
})
var data = {
'id': 1,
'method': method,
'params': params
};
var baseUrl = app.globalData.BaseUrl
console.log(baseUrl)
console.log(data)
wx.request({
url: baseUrl,
url: app.globalData.BaseUrl,
data: data,
header: {
'content-type': 'application/json',
'cookie': app.globalData.Cookie
'cookie': app.globalData.cookie
},
method: 'POST',
success: function(res) {
success: function (res) {
// console.log(res)
if (res.data.error != null) {
if (erroraction != null) {
erroraction(res.data.error)
if (res.data.error.code == 401) {
wx.request({
url: app.globalData.BaseUrl,
data: {
'id': 1,
'method': "/MainSystem/MainSystem/Auth/WeixinLogin",
'params': [app.globalData.appID, app.globalData.openID]
},
header: {
'content-type': 'application/json',
'cookie': app.globalData.cookie
},
method: 'POST',
success: function (res) {
app.globalData.cookie = res.data.result;
requestLoading(reconnectMethod, reconnectParams, successaction);
}
})
} else {
wx.showModal({
showCancel: false,
title: '执行出错:',
title: '执行出错',
content: res.data.error.message,
})
}
}
} else {
successaction(res.data)
}
},
fail: function(res) {
fail: function (res) {
console.log(res)
wx.showModal({
title: '执行出错',
@ -59,41 +72,58 @@ function requestLoading(method, params, successaction, erroraction) {
})
},
complete: function(res) {
complete: function (res) {
wx.hideLoading()
},
})
}
function transfer_request(method, params, successaction) {
newReconnectMethod = method;
newReconnectParams = params;
wx.showLoading({
title: "加载中",
})
var data = {
'DecryptCookie': app.globalData.DecryptCookie,
'AppendUrlString': '',
'Method': method,
'CustomerId': app.globalData.CustomerId,
'Data': params
var newData = {
"DecryptCookie": app.globalData.cookie,
"CustomerId": app.globalData.globalCustomerID,
"Method": method,
"Data": params
};
var baseUrl = app.globalData.TransferUrl
console.log(baseUrl)
console.log(data)
var baseUrl = app.globalData.TranferBaseUrl;
wx.request({
url: baseUrl,
data: data,
data: newData,
header: {
'content-type': 'application/json'
'content-type': 'application/json',
'cookie': app.globalData.cookie
},
method: 'POST',
success: function(res) {
// console.log(res)
success: function (res) {
// console.log(res)
if (res.data.error != null) {
if (res.data.error.code == '401' && res.data.error.message == "Unauthorized") {
console.log('重连系统-------------');
transfer_login()
if (res.data.error.code == 401) {
wx.request({
url: app.globalData.TransferUrl,
data: {
"DecryptCookie": app.globalData.cookie,
"CustomerId": app.globalData.globalCustomerID,
"Method": "/MainSystem/MainSystem/Auth/WeixinLogin",
"Data": [app.globalData.appID, app.globalData.openID]
},
header: {
'content-type': 'application/json',
'cookie': app.globalData.cookie
},
method: 'POST',
success: function (res) {
app.globalData.cookie = res.data.result;
transfer_request(newReconnectMethod, newReconnectParams, successaction);
}
})
} else {
wx.showModal({
showCancel: false,
@ -104,52 +134,21 @@ function transfer_request(method, params, successaction) {
} else {
successaction(res.data)
}
},
fail: function(res) {
fail: function (res) {
console.log(res)
wx.showModal({
title: '执行出错',
content: res,
})
});
},
complete: function(res) {
complete: function (res) {
wx.hideLoading()
},
})
}
function transfer_login() {
wx.request({
url: app.globalData.TransferUrl,
data: {
'CustomerId': 1,
'Method': app.globalData.LoginPath,
'Data': [app.globalData.AppId, app.globalData.OpenId]
},
header: {
'content-type': 'application/json'
},
method: 'POST',
success: function(res) {
app.globalData.DecryptCookie = res.data.result;
console.log(app.globalData.DecryptCookie)
wx.showModal({
showCancel: false,
title: '提示',
content: '由于长时间未操作,需要重新连接!',
})
wx.switchTab({
url: '/pages/main/main',
})
}
})
}
module.exports = {
request: request,
requestLoading: requestLoading,
transfer_request: transfer_request
}
}

Loading…
Cancel
Save