7.10 增加登录页面,事件详情接口对接,我的点赞,关注收藏页面搭建,接口对接
This commit is contained in:
122
request/http.js
122
request/http.js
@@ -2,11 +2,11 @@
|
||||
let baseURL = ''
|
||||
|
||||
if (process.env.NODE_ENV==='development') {
|
||||
// baseURL = 'https://admin.zleniao.com'
|
||||
baseURL = 'https://app.valuefrontier.cn'
|
||||
// baseURL = 'https://app.valuefrontier.cn'
|
||||
baseURL = 'http://43.143.189.195:5001'
|
||||
} else{
|
||||
// baseURL = 'https://admin.zleniao.com'
|
||||
baseURL = 'https://app.valuefrontier.cn'
|
||||
// baseURL = 'https://app.valuefrontier.cn'
|
||||
baseURL = 'http://43.143.189.195:5001'
|
||||
}
|
||||
|
||||
export function getBaseURL() {
|
||||
@@ -21,18 +21,23 @@ export function getBaseURL() {
|
||||
export function get(url, params){
|
||||
return new Promise((resolve, reject) =>{
|
||||
let token = uni.getStorageSync('token')
|
||||
uni.showLoading({
|
||||
title:'加载中'
|
||||
})
|
||||
uni.request({
|
||||
url:baseURL+url,
|
||||
data:params,
|
||||
header:{
|
||||
'Accept':'application/json',
|
||||
'Content-Type':'application/x-www-form-urlencoded',
|
||||
'token':token?token:''
|
||||
'Authorization':token?('Bearer '+token):''
|
||||
},
|
||||
method:"GET",
|
||||
success:(response) =>{
|
||||
console.log(response)
|
||||
if (response.data.code==-200) {
|
||||
uni.hideLoading()
|
||||
if (response.data.code==401) {
|
||||
uni.removeStorageSync('token')
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login',
|
||||
})
|
||||
@@ -41,6 +46,11 @@ export function get(url, params){
|
||||
}
|
||||
},
|
||||
fail:(error) =>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:'请求失败',
|
||||
icon:'error'
|
||||
})
|
||||
reject(error.response)
|
||||
}
|
||||
})
|
||||
@@ -56,30 +66,33 @@ export function post(url, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let token = uni.getStorageSync('token')
|
||||
let isJson = 0
|
||||
let isFile = 0
|
||||
if(params)
|
||||
{
|
||||
isJson = params.isJson
|
||||
}
|
||||
uni.request({
|
||||
url:baseURL+url,
|
||||
data:params,
|
||||
header:{
|
||||
'Accept':'application/json',
|
||||
'Content-Type':isJson?'application/json':'application/x-www-form-urlencoded',
|
||||
'token':token?token:''
|
||||
},
|
||||
method:"POST",
|
||||
success:(response) =>{
|
||||
console.log(JSON.parse(JSON.stringify(response)))
|
||||
if(response.header.token&&!params.isNotSaveToken)
|
||||
{
|
||||
uni.setStorageSync('token',response.header.token)
|
||||
}
|
||||
if (params&¶ms.isNotNeedLogin) {
|
||||
|
||||
}else
|
||||
{
|
||||
if (response.data.code==-200) {
|
||||
if(params)
|
||||
{
|
||||
isFile = params.isFile
|
||||
}
|
||||
uni.showLoading({
|
||||
title:'加载中'
|
||||
})
|
||||
if(isFile)
|
||||
{
|
||||
let token = uni.getStorageSync('token')
|
||||
uni.uploadFile({
|
||||
url: baseURL+url,
|
||||
filePath: params.avatar,
|
||||
name: 'avatar',
|
||||
header:{
|
||||
'Authorization':token?('Bearer '+token):''
|
||||
},
|
||||
formData:params,
|
||||
success: (response) => {
|
||||
console.log(response)
|
||||
uni.hideLoading()
|
||||
if (response.data.code==401) {
|
||||
uni.removeStorageSync('token')
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
@@ -88,16 +101,55 @@ export function post(url, params) {
|
||||
} else{
|
||||
resolve(response.data)
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.log('上传失败'+error.errMsg)
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:'请求失败',
|
||||
icon:'error'
|
||||
})
|
||||
reject()
|
||||
}
|
||||
},
|
||||
fail:(error) =>{
|
||||
uni.showToast({
|
||||
title:'网络请求失败',
|
||||
icon:'none'
|
||||
})
|
||||
reject(error.response)
|
||||
}
|
||||
})
|
||||
});
|
||||
}else
|
||||
uni.request({
|
||||
url:baseURL+url,
|
||||
data:params,
|
||||
header:{
|
||||
'Accept':'application/json',
|
||||
'Content-Type':isJson?'application/json':(isFile?'multipart/form-data':'application/x-www-form-urlencoded'),
|
||||
'Authorization':token?('Bearer '+token):''
|
||||
},
|
||||
method:"POST",
|
||||
success:(response) =>{
|
||||
console.log(JSON.parse(JSON.stringify(response)))
|
||||
uni.hideLoading()
|
||||
if (params&¶ms.isNotNeedLogin) {
|
||||
|
||||
}else
|
||||
{
|
||||
console.log(response.data)
|
||||
if (response.data.code==401) {
|
||||
uni.removeStorageSync('token')
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
reject(response.data)
|
||||
} else{
|
||||
resolve(response.data)
|
||||
}
|
||||
}
|
||||
},
|
||||
fail:(error) =>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:'请求失败',
|
||||
icon:'error'
|
||||
})
|
||||
reject(error.response)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user