1
0
forked from dyf/APP

设备列表,设备绑定,删除,修改设备名

This commit is contained in:
fengerli
2025-07-09 13:41:42 +08:00
parent e69ff064d5
commit 82fd1574c8
23 changed files with 6892 additions and 2974 deletions

View File

@ -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;