操作说明,产品说明,接口联调对接
This commit is contained in:
@ -1,44 +1,47 @@
|
||||
const BASE_URL = 'http://192.168.2.34:8001';
|
||||
|
||||
const BASE_URL = 'http://192.168.2.34:8000';
|
||||
const request = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 处理GET请求参数
|
||||
let url = BASE_URL + options.url;
|
||||
if (options.method === 'GET' && options.data) {
|
||||
// 使用qs序列化参数
|
||||
const params = Object.keys(options.data)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options.data[key])}`)
|
||||
.join('&');
|
||||
url += `?${params}`;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
// 处理GET请求参数
|
||||
let url = BASE_URL + options.url;
|
||||
if (options.method === 'GET' && options.data) {
|
||||
// 使用qs序列化参数
|
||||
const params = Object.keys(options.data)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options.data[key])}`)
|
||||
.join('&');
|
||||
url += `?${params}`;
|
||||
}
|
||||
|
||||
const config = {
|
||||
url: url,
|
||||
method: options.method || 'GET',
|
||||
data: options.method !== 'GET' ? options.data : {},
|
||||
header: options.header || {},
|
||||
timeout: 10000,
|
||||
success: (res) => {
|
||||
resolve(res.data);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
const config = {
|
||||
url: url,
|
||||
method: options.method || 'GET',
|
||||
data: options.method !== 'GET' ? options.data : {},
|
||||
header: options.header || {},
|
||||
timeout: 10000,
|
||||
success: (res) => {
|
||||
resolve(res.data);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
if (!options.url.includes('/login')) {
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
if (token) {
|
||||
config.header['Authorization'] = 'Bearer ' + token;
|
||||
config.header['clientid'] = clientid;
|
||||
}
|
||||
}
|
||||
if (!config.header['Content-Type']) {
|
||||
config.header['Content-Type'] = 'application/json';
|
||||
}
|
||||
uni.request(config);
|
||||
});
|
||||
if (!options.url.includes('/login')) {
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
if (token) {
|
||||
config.header['Authorization'] = 'Bearer ' + token;
|
||||
config.header['clientid'] = clientid;
|
||||
}
|
||||
}
|
||||
if (!config.header['Content-Type']) {
|
||||
config.header['Content-Type'] = 'application/json';
|
||||
}
|
||||
uni.request(config);
|
||||
});
|
||||
};
|
||||
|
||||
export default request;
|
||||
export default request;
|
||||
// 导出基础URL以便其他地方使用
|
||||
export const baseURL = BASE_URL
|
||||
export const getToken = () => uni.getStorageSync('token') // 获取token的方法
|
||||
export const clientid =() => uni.getStorageSync('clientID');
|
Reference in New Issue
Block a user