设备列表,设备绑定,删除,修改设备名
This commit is contained in:
@ -1,35 +1,44 @@
|
||||
import axios from 'axios'
|
||||
const BASE_URL = 'http://192.168.2.23:8001'
|
||||
// 创建 Axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
timeout: 10000
|
||||
})
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
console.log('Full Request URL:', config.baseURL + config.url)
|
||||
const token = uni.getStorageSync('token')
|
||||
if (token) {
|
||||
config.headers['Authorization'] = 'Bearer ' + token
|
||||
}
|
||||
config.headers['Content-Type'] = config.headers['Content-Type'] || 'application/json';
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
console.log('Request Error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
const BASE_URL = 'http://192.168.2.34:8001';
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
return response.data;
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
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}`;
|
||||
}
|
||||
|
||||
export default service
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
||||
export default request;
|
Reference in New Issue
Block a user