diff --git a/app.js b/app.js index aeefd6a..1659c3f 100644 --- a/app.js +++ b/app.js @@ -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: "", diff --git a/app.json b/app.json index 4760eee..584d3dc 100644 --- a/app.json +++ b/app.json @@ -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", diff --git a/imgs/blueBtn.png b/imgs/blueBtn.png new file mode 100644 index 0000000..7c2da0b Binary files /dev/null and b/imgs/blueBtn.png differ diff --git a/pages/login/login.js b/pages/login/login.js new file mode 100644 index 0000000..f08bc99 --- /dev/null +++ b/pages/login/login.js @@ -0,0 +1,196 @@ +// pages/login/login.js + +var network = require("../../utils/net.js"); +var app = getApp(); +var openID; + +/** + * 获取绑定客户ID及用户电话 参数1、appID 2、openID + * 返回值globalCustomerID,WeixinUser_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 + }) + } + } + +}) + diff --git a/pages/login/login.json b/pages/login/login.json new file mode 100644 index 0000000..fc754d6 --- /dev/null +++ b/pages/login/login.json @@ -0,0 +1,5 @@ +{ + "navigationBarBackgroundColor": "white", + "navigationBarTextStyle": "black", + "navigationBarTitleText": "业务员登录" +} \ No newline at end of file diff --git a/pages/login/login.wxml b/pages/login/login.wxml new file mode 100644 index 0000000..e6c1e2d --- /dev/null +++ b/pages/login/login.wxml @@ -0,0 +1,32 @@ + + + + + 绑定客户 + + + {{customerArray[index].Name}} + + + + + + + 手机号码 + + + + + + + + + + + + 确认绑定 + + + + + \ No newline at end of file diff --git a/pages/login/login.wxss b/pages/login/login.wxss new file mode 100644 index 0000000..f16f7dd --- /dev/null +++ b/pages/login/login.wxss @@ -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; +} \ No newline at end of file diff --git a/pages/logs/logs.js b/pages/logs/logs.js deleted file mode 100644 index b2b967d..0000000 --- a/pages/logs/logs.js +++ /dev/null @@ -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)) - }) - }) - } -}) diff --git a/pages/logs/logs.json b/pages/logs/logs.json deleted file mode 100644 index 28379bc..0000000 --- a/pages/logs/logs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "navigationBarTitleText": "查看启动日志" -} \ No newline at end of file diff --git a/pages/logs/logs.wxml b/pages/logs/logs.wxml deleted file mode 100644 index b5a85ac..0000000 --- a/pages/logs/logs.wxml +++ /dev/null @@ -1,6 +0,0 @@ - - - - {{index + 1}}. {{log}} - - diff --git a/pages/logs/logs.wxss b/pages/logs/logs.wxss deleted file mode 100644 index 94d4b88..0000000 --- a/pages/logs/logs.wxss +++ /dev/null @@ -1,8 +0,0 @@ -.log-list { - display: flex; - flex-direction: column; - padding: 40rpx; -} -.log-item { - margin: 10rpx; -} diff --git a/utils/net.js b/utils/net.js index 1da5e63..1abacff 100644 --- a/utils/net.js +++ b/utils/net.js @@ -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 -} \ No newline at end of file +}