Commit 20b4559f by 梁建民

GET

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