请求
This commit is contained in:
parent
42ef4d312e
commit
cc0ddd0bc9
@ -678,6 +678,8 @@
|
||||
const getHomeData = async () => {
|
||||
try {
|
||||
uni.showLoading({ title: '加载中...' });
|
||||
|
||||
|
||||
const res = await api.getHomeData();
|
||||
console.log('首页数据:', res);
|
||||
|
||||
@ -776,7 +778,6 @@
|
||||
defineExpose({
|
||||
testTabbar,
|
||||
getTabbarStatus,
|
||||
updateTabbarData,
|
||||
goToCourseHome
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -190,8 +190,8 @@
|
||||
const result = await api.getCode(postData,{
|
||||
sign:sign
|
||||
});
|
||||
|
||||
if (result.data.code === 200) {
|
||||
console.log(result);
|
||||
if (result.code === 200) {
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@ -313,16 +313,41 @@
|
||||
});
|
||||
|
||||
uni.hideLoading();
|
||||
|
||||
if (result.data.code == 1) {
|
||||
console.log(result)
|
||||
if (result.code == 1) {
|
||||
// 保存用户信息到本地存储
|
||||
if (result.data.data && result.data.data.token) {
|
||||
uni.setStorageSync('AUTH_TOKEN_App', result.data.data.token);
|
||||
if (result.data.data) {
|
||||
uni.setStorageSync('USER_INFO', result.data.data);
|
||||
if (process.env.UNI_PLATFORM == "h5") {
|
||||
if (window.location.href.indexOf('dev') > -1) {
|
||||
uni.setStorageSync('AUTH_TOKEN_App',result.access_token);
|
||||
uni.setStorageSync('AUTH_YX_ACCID_App', result.YX_accid);
|
||||
uni.setStorageSync('AUTH_YX_TOKEN_App', result.YX_token);
|
||||
uni.setStorageSync('userInfo', result.data);
|
||||
|
||||
} else {
|
||||
uni.setStorageSync('DEV_AUTH_TOKEN_App', result.access_token);
|
||||
uni.setStorageSync('DEV_AUTH_YX_ACCID_App', result.YX_accid);
|
||||
uni.setStorageSync('DEV_AUTH_YX_TOKEN_App', result.YX_token);
|
||||
uni.setStorageSync('userInfo', result.data);
|
||||
}
|
||||
} else if(process.env.UNI_PLATFORM == "mp-weixin") {
|
||||
const {
|
||||
envVersion
|
||||
} = uni.getAccountInfoSync().miniProgram;
|
||||
if (envVersion == "release") {
|
||||
uni.setStorageSync('AUTH_TOKEN_App',result.access_token);
|
||||
uni.setStorageSync('AUTH_YX_ACCID_App', result.YX_accid);
|
||||
uni.setStorageSync('AUTH_YX_TOKEN_App', result.YX_token);
|
||||
uni.setStorageSync('userInfo', result.data);
|
||||
} else {
|
||||
uni.setStorageSync('DEV_AUTH_TOKEN_App', result.access_token);
|
||||
uni.setStorageSync('DEV_AUTH_YX_ACCID_App', result.YX_accid);
|
||||
uni.setStorageSync('DEV_AUTH_YX_TOKEN_App', result.YX_token);
|
||||
uni.setStorageSync('userInfo', result.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
@ -330,7 +355,7 @@
|
||||
|
||||
// 跳转到首页
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
uni.redirectTo({
|
||||
url: '/pages/index/index'
|
||||
});
|
||||
},0);
|
||||
|
||||
@ -19,7 +19,7 @@ export const request = (url, data = {}, method = 'post', loading = false, conten
|
||||
};
|
||||
let token = '';
|
||||
if (process.env.UNI_PLATFORM == "h5") {
|
||||
if (window.location.href.indexOf('//App.igandan.com') > -1) {
|
||||
if (window.location.href.indexOf('//.igandan.com') > -1) {
|
||||
token = uni.getStorageSync('AUTH_TOKEN_App');
|
||||
} else {
|
||||
token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
|
||||
@ -38,20 +38,33 @@ export const request = (url, data = {}, method = 'post', loading = false, conten
|
||||
'content-type': contentType,
|
||||
}
|
||||
let defaultData={}
|
||||
if(token){
|
||||
header['Authorization']='Bearer ' + token
|
||||
|
||||
}
|
||||
defaultData = {
|
||||
version: '4.0.0',
|
||||
user_uuid: 'Rj3zuTY6zP6YTjHsYEz',
|
||||
client_type: 'A', //client_type,
|
||||
let freeList=['/manager/getSystemTimeStamp','/expertAPI/smsLogin','/login/mobile','/expertAPI/login','/expertAPI/index']
|
||||
|
||||
if(freeList.indexOf(url)!=-1){
|
||||
if(freeList[4].indexOf(url)!=-1){
|
||||
if(!token){
|
||||
header['Authorization']='Bearer ' + ''
|
||||
}else{
|
||||
header['Authorization']='Bearer ' + token
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(token){
|
||||
header['Authorization']='Bearer ' +token
|
||||
}
|
||||
}
|
||||
|
||||
// defaultData = {
|
||||
// version: '4.0.0',
|
||||
// user_uuid: 'Rj3zuTY6zP6YTjHsYEz',
|
||||
// client_type: 'A', //client_type,
|
||||
// }
|
||||
|
||||
return new Promise(function(e, n) {
|
||||
let timestamp = Date.now();
|
||||
uni.request({
|
||||
data: {...data,...defaultData,timestamp:new Date().getTime().toString()},
|
||||
data: {...data},
|
||||
url: url.indexOf('http') != -1 ? url : encodeURI(BASE_URL + url),
|
||||
method: method,
|
||||
sslVerify: false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user