Commit 20b4559f by 梁建民

GET

parent 47113b44
...@@ -79,7 +79,6 @@ App({ ...@@ -79,7 +79,6 @@ App({
// 查看是否授权 // 查看是否授权
wx.getSetting({ wx.getSetting({
success(res) { success(res) {
console.log(res)
if (res.authSetting['scope.userInfo']) { if (res.authSetting['scope.userInfo']) {
// 已经授权 // 已经授权
wx.switchTab({ wx.switchTab({
......
...@@ -84,7 +84,7 @@ Page({ ...@@ -84,7 +84,7 @@ Page({
}); });
//获取openId //获取openId
http.getData(apis.getOpenId, { http.getData(apis.getOpenId, 'GET',{
code: res.code, code: res.code,
'userinfo[avatarUrl]': self.data.userinfo.avatarUrl, 'userinfo[avatarUrl]': self.data.userinfo.avatarUrl,
'userinfo[nickName]': self.data.userinfo.nickName 'userinfo[nickName]': self.data.userinfo.nickName
...@@ -110,16 +110,11 @@ Page({ ...@@ -110,16 +110,11 @@ Page({
} }
}, true); }, true);
} else { } else {
console.log('登录失败!' + res.errMsg); console.log('登录失败!' + res.errMsg);
} }
}, },
fail(res) { fail(res) {
wx.showLoading({
title: '网络不通,请重试'
})
} }
}) })
}else{ }else{
......
const http = require('../../../utils/util.js'); const http = require('../../../utils/util.js');
import { apis } from '../../../utils/api.js'; import {
apis
} from '../../../utils/api.js';
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
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() {
}, },
/** /**
* 一键获取手机号 * 一键获取手机号
*/ */
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok'){ if (e.detail.errMsg == 'getPhoneNumber:ok') {
http.getData(apis.getwxUserInfo, { http.getData(apis.getwxUserInfo, 'GET', {
openid: wx.getStorageSync('openid'), openid: wx.getStorageSync('openid'),
session_key: wx.getStorageSync('session_key'), session_key: wx.getStorageSync('session_key'),
encryptedData: e.detail.encryptedData, encryptedData: e.detail.encryptedData,
iv: e.detail.iv iv: e.detail.iv
}, function (res) { }, (res) => {
if (res.err_code === 0) {
if (res.err_code === 0) { //注入token
wx.setStorage({
//注入token key: "access_token",
wx.setStorage({ data: res.data.access_token
key: "access_token", });
data: res.data.access_token
}); wx.switchTab({
url: '/pages/tab/home/home'
wx.switchTab({ });
url: '/pages/tab/home/home' }
}); }, true);
} else {
} //用户拒绝获取手机
},true); wx.navigateTo({
url: '/pages/person/login/index'
}else{ });
}
//用户拒绝获取手机 }
wx.navigateTo({ })
url: '/pages/person/login/index'
});
}
}
})
\ No newline at end of file
...@@ -210,7 +210,7 @@ Page({ ...@@ -210,7 +210,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authlogin, e.detail.value, function (res) { http.getData(apis.authlogin,'POST', e.detail.value, function (res) {
if (res.err_code === 0) { if (res.err_code === 0) {
......
...@@ -130,7 +130,7 @@ Page({ ...@@ -130,7 +130,7 @@ Page({
//是否填写了验证码 //是否填写了验证码
if (this.data.captcha) { if (this.data.captcha) {
http.getData(apis.getRegistCode, { http.getData(apis.getRegistCode,'GET',{
captchaUuid: this.data.captchaUuid, captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha, captcha: this.data.captcha,
mobile: this.data.formData.mobile, mobile: this.data.formData.mobile,
...@@ -186,7 +186,7 @@ Page({ ...@@ -186,7 +186,7 @@ Page({
vcode: true vcode: true
}); });
http.getData(apis.captchaInfo, null, (res) => { http.getData(apis.captchaInfo,'GET',null, (res) => {
this.setData({ this.setData({
captchaUrl: res.captchaUrl, captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid captchaUuid: res.captchaUuid
...@@ -354,7 +354,7 @@ Page({ ...@@ -354,7 +354,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authRegister, e.detail.value, (res) => { http.getData(apis.authRegister,'POST', e.detail.value, (res) => {
if (res.err_code === 0) { if (res.err_code === 0) {
//注入token //注入token
...@@ -363,10 +363,18 @@ Page({ ...@@ -363,10 +363,18 @@ Page({
data: res.data.access_token data: res.data.access_token
}); });
wx.switchTab({ wx.navigateTo({
url: '/pages/tab/home/home' url: '/pages/person/successfully/index'
}) });
}else if(res.err_code === 500){
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} else { } else {
wx.showToast({ wx.showToast({
title: res.err_msg, title: res.err_msg,
...@@ -374,6 +382,7 @@ Page({ ...@@ -374,6 +382,7 @@ Page({
duration: 2000 duration: 2000
}); });
} }
this.setData({ this.setData({
disabledBtn: false, disabledBtn: false,
loading: false loading: false
......
...@@ -62,5 +62,13 @@ Page({ ...@@ -62,5 +62,13 @@ Page({
*/ */
onShareAppMessage: function () { onShareAppMessage: function () {
},
/**
* 暂不认证
*/
toUrl: function() {
wx.switchTab({
url: '/pages/tab/home/home'
})
} }
}) })
\ No newline at end of file
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
<text class="t2">资质认证</text> <text class="t2">资质认证</text>
<text class="t1">” 否则将影响您的询价和报价业务</text> <text class="t1">” 否则将影响您的询价和报价业务</text>
</view> </view>
<text class="skip-text">暂不认证,跳过</text> <text class="skip-text" bindtap="toUrl">暂不认证,跳过</text>
</view> </view>
...@@ -126,7 +126,7 @@ Page({ ...@@ -126,7 +126,7 @@ Page({
//是否填写了验证码 //是否填写了验证码
if (this.data.captcha) { if (this.data.captcha) {
http.getData(apis.getRegistCode, { http.getData(apis.getRegistCode, 'GET', {
captchaUuid: this.data.captchaUuid, captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha, captcha: this.data.captcha,
mobile: this.data.formData.mobile, mobile: this.data.formData.mobile,
...@@ -182,7 +182,7 @@ Page({ ...@@ -182,7 +182,7 @@ Page({
vcode: true vcode: true
}); });
http.getData(apis.captchaInfo, null, (res) => { http.getData(apis.captchaInfo, 'GET', null, (res) => {
this.setData({ this.setData({
captchaUrl: res.captchaUrl, captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid captchaUuid: res.captchaUuid
...@@ -304,7 +304,7 @@ Page({ ...@@ -304,7 +304,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authMobilelogin, e.detail.value, (res) => { http.getData(apis.authMobilelogin, 'POST', e.detail.value, (res) => {
if (res.err_code === 0) { if (res.err_code === 0) {
//注入token //注入token
...@@ -317,6 +317,14 @@ Page({ ...@@ -317,6 +317,14 @@ Page({
url: '/pages/tab/home/home' url: '/pages/tab/home/home'
}) })
} else if (res.err_code === 500) {
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} else { } else {
wx.showToast({ wx.showToast({
title: res.err_msg, title: res.err_msg,
......
...@@ -11,6 +11,10 @@ const apis = { ...@@ -11,6 +11,10 @@ const apis = {
* 授权接口 * 授权接口
*/ */
getOpenId: auth_url + '/v1/getOpenId', getOpenId: auth_url + '/v1/getOpenId',
/**
* 刷新token
*/
authRefresh: auth_url + '/auth/refresh',
/** /**
* 获取微信用户信息 * 获取微信用户信息
*/ */
......
//数据请求(get) import {
const getData = (url, param, callBack,loading) => { apis
wx.showNavigationBarLoading(); } from './api.js';
var params = Object.assign({}, param, { source: 1 });
//数据请求(get,post)
if(loading){ const getData = (url, type, param, callBack, loading, isheader) => {
wx.showLoading(); wx.showNavigationBarLoading();
}
//获取token
wx.request({ var token, header;
url: url, wx.getStorage({
data: params, key: 'access_token',
header: { success(res) {
"Content-Type": "applciation/json" if (res.data) {
}, token = res.data;
success: (res) => { }
}
typeof callBack == "function" && callBack(res.data, ""); });
wx.hideNavigationBarLoading(); //参数字段追加来源字段
var params = Object.assign({}, param, {
wx.hideLoading(); source: 1
});
},
fail: (err) => { //是否启用loading加载效果
if (loading) {
typeof callBack == "function" && callBack(null, err.errMsg); wx.showLoading();
}
console.log(err);
//是否启用请求头token
wx.hideNavigationBarLoading(); if (isheader) {
header = {
wx.hideLoading(); "Content-Type": "applciation/json",
"Authorization": 'Bearer ' + token
} }
}) } else {
}; header = {
"Content-Type": "applciation/json"
//数据请求(post) }
const postData = (url, param, callBack, loading) => { }
wx.showNavigationBarLoading(); wx.request({
url: url,
var params = Object.assign({}, param, { source: 1 }); data: params,
header: header,
if (loading) { method: type,
wx.showLoading(); success: (res) => {
}
//处理token失效的情况
if (res.data.hasOwnProperty('data')) {
wx.request({ if (res.data.data.err_code === 501 || res.data.data.errcode === 501) {
url: url, wx.navigateTo({
data: params, url: '/pages/person/login/index'
header: { });
"Content-Type": "applciation/json" } else {
}, typeof callBack == "function" && callBack(res.data, "");
method: "POST", }
success: (res) => { } else {
typeof callBack == "function" && callBack(res.data, "");
typeof callBack == "function" && callBack(res.data, ""); }
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
wx.hideLoading(); wx.hideLoading();
},
fail: (err) => { },
fail: (err) => {
typeof callBack == "function" && callBack(null, err.errMsg);
typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err);
console.log(err);
wx.hideNavigationBarLoading();
wx.hideNavigationBarLoading();
wx.hideLoading();
wx.hideLoading();
}
}) }
})
}; };
//上传文件 //上传文件
const uploadFile = (paths, callBack) => { const uploadFile = (paths, callBack) => {
let gUrl = getApp().globalUrl; let gUrl = getApp().globalUrl;
showLoading('正在上传', true) showLoading('正在上传', true)
for (var i = 0; i < paths.length; i++) { for (var i = 0; i < paths.length; i++) {
wx.uploadFile({ wx.uploadFile({
url: gUrl.baseUrl + gUrl.uploadImg, url: gUrl.baseUrl + gUrl.uploadImg,
filePath: paths[i], filePath: paths[i],
name: 'file', name: 'file',
success: (res) => { success: (res) => {
var data = JSON.parse(res.data); var data = JSON.parse(res.data);
if (data.suc == 'y') { if (data.suc == 'y') {
callBack({ callBack({
imgSrc: data.data.file.url, imgSrc: data.data.file.url,
image_id: data.data.file.image_id image_id: data.data.file.image_id
}) })
} else { } else {
showModal(data.msg); showModal(data.msg);
} }
}, },
fail: () => { fail: () => {
showModal("上传图片失败!"); showModal("上传图片失败!");
}, },
complete: () => { complete: () => {
wx.hideLoading(); wx.hideLoading();
} }
}) })
} }
}; };
const chooseImg = (num, callback) => { const chooseImg = (num, callback) => {
wx.chooseImage({ wx.chooseImage({
count: num, count: num,
success: (res) => { success: (res) => {
var arr = []; var arr = [];
uploadFile(res.tempFilePaths, (rtn) => { uploadFile(res.tempFilePaths, (rtn) => {
arr.push(rtn) arr.push(rtn)
if (arr.length === res.tempFilePaths.length) { if (arr.length === res.tempFilePaths.length) {
callback(arr) callback(arr)
} }
}) })
} }
}) })
}; };
module.exports = { module.exports = {
getData: getData, getData: getData,
postData: postData, chooseImg: chooseImg
chooseImg: chooseImg }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment