Files
JiaZhiQianYan/request/http.js
renzhijun 44d8ecf318 饼图
2026-01-31 11:40:28 +08:00

172 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let baseURL = ''
if (process.env.NODE_ENV==='development') {
// baseURL = 'https://app.valuefrontier.cn:5002'
baseURL = 'https://api.valuefrontier.cn:5002'
// baseURL = 'http://43.143.189.195:5002'
} else{
// baseURL = 'https://app.valuefrontier.cn:5002'
baseURL = 'https://api.valuefrontier.cn:5002'
// baseURL = 'http://43.143.189.195:5002'
}
export function getBaseURL() {
return baseURL
}
export function getBaseURL1() {
return "https://valuefrontier.cn"
}
/**
* get方法对应get请求
* @param {String} url [请求的url地址]
* @param {Object} params [请求时携带的参数]
*/
export function get(url, params, isNotPort){
return new Promise((resolve, reject) =>{
let token = uni.getStorageSync('token')
uni.showLoading({
title:'加载中'
})
let baseUrl = baseURL
if (isNotPort) {
//如果不需要端口号
baseUrl = 'https://api.valuefrontier.cn'
}
uni.request({
url:baseUrl+url,
data:params,
header:{
'Accept':'application/json',
'Content-Type':'application/x-www-form-urlencoded',
'Authorization':token?('Bearer '+token):''
},
method:"GET",
success:(response) =>{
console.log(response)
uni.hideLoading()
if (response.data.code==401) {
uni.removeStorageSync('token')
uni.navigateTo({
url:'/pages/login/login',
})
} else{
resolve(response.data)
}
},
fail:(error) =>{
uni.hideLoading()
uni.showToast({
title:'请求失败',
icon:'error'
})
reject(error.response)
}
})
});
}
/**
* post方法对应post请求
* @param {String} url [请求的url地址]
* @param {Object} params [请求时携带的参数]
*/
export function post(url, params, isNotPort) {
return new Promise((resolve, reject) => {
let token = uni.getStorageSync('token')
let isJson = 0
let isFile = 0
if(params)
{
isJson = params.isJson
}
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'
})
reject(response.data)
} else{
resolve(response.data)
}
},
fail: (error) => {
console.log('上传失败'+error.errMsg)
uni.hideLoading()
uni.showToast({
title:'请求失败',
icon:'error'
})
reject()
}
});
}else
{
let baseUrl = baseURL
if(url.indexOf('concept-api')>-1||url.indexOf('api/market/trade/batch')>-1)
{
baseUrl = 'https://api.valuefrontier.cn'
}
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) =>{
uni.hideLoading()
if (params&&params.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)
}
})
}
});
}