对接小区、故障报修接口,更换图片地址
This commit is contained in:
@@ -17,4 +17,31 @@ export const getLoginBySms = (data) =>{
|
||||
export const getResetPassword = (data) =>{
|
||||
return post('/api/butler/auth/forgetPassword',data)
|
||||
}
|
||||
// ======首页=====
|
||||
// 获取小区列表
|
||||
export const getVillageList = (data) =>{
|
||||
return get('/api/inspection/today/villageList',data)
|
||||
}
|
||||
// 切换小区
|
||||
export const switchVillage = (data) =>{
|
||||
return post('/api/inspection/today/switchVillage',data)
|
||||
}
|
||||
// ======故障上报=====
|
||||
// 获取报修项目
|
||||
export const getRepairOrder = () =>{
|
||||
return get('/manage/repair/order/list')
|
||||
}
|
||||
// 提交维修信息
|
||||
export const addRepairList = (data) =>{
|
||||
return post('/manage/repair/order',data)
|
||||
}
|
||||
// 上传图片
|
||||
export const uploadFile = (filePath) => {
|
||||
return upload(filePath,' /resource/oss/upload');
|
||||
}
|
||||
|
||||
|
||||
// 一键开门
|
||||
export const openDoor = (data) =>{
|
||||
return post('/manage/remote/open',data)
|
||||
}
|
||||
|
||||
@@ -1,81 +1,92 @@
|
||||
|
||||
let baseUrl = '';
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
baseUrl = 'http://192.168.0.239:8080'; // 开发环境
|
||||
} else {
|
||||
baseUrl = 'http://192.168.1.224:8080'; // 生产环境
|
||||
baseUrl = 'http://192.168.0.224:8080'; // 生产环境
|
||||
}
|
||||
|
||||
export default function request(url, data = {}, method = "GET") {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 加载中提示(提升用户体验)
|
||||
uni.showLoading({ title: '请求中...', mask: true });
|
||||
uni.showLoading({
|
||||
title: '请求中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
uni.request({
|
||||
url: baseUrl + url,
|
||||
data: data,
|
||||
method: method,
|
||||
header: {
|
||||
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
|
||||
"clientid": "resident",
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
// header: {
|
||||
// "token": uni.getStorageSync("token") || '',
|
||||
// 'content-type': 'application/json'
|
||||
// },
|
||||
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
|
||||
"clientid": "butler",
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading(); // 关闭加载提示
|
||||
uni.hideLoading();
|
||||
|
||||
// 处理HTTP状态码(网络层面)
|
||||
// HTTP 失败
|
||||
if (res.statusCode !== 200) {
|
||||
const errMsg = `请求失败(${res.statusCode})`;
|
||||
uni.showToast({ title: errMsg, icon: "none", duration: 2000 });
|
||||
reject(errMsg);
|
||||
reject({ msg: `请求异常 ${res.statusCode}`, code: res.statusCode });
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理业务状态码(后端返回的data里)
|
||||
const resData = res.data || {}; // 兼容后端返回空的情况
|
||||
const resData = res.data || {};
|
||||
|
||||
// 优先处理token过期(401)
|
||||
// token 过期
|
||||
if (resData.code === 401) {
|
||||
uni.showToast({ title: '登录过期,请重新登录', icon: 'none', duration: 2000 });
|
||||
uni.showToast({ title: '登录过期,请重新登录', icon: 'none' });
|
||||
uni.clearStorageSync('token');
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
|
||||
}, 1500);
|
||||
reject('token 过期');
|
||||
reject({ msg: '登录过期', code: 401 });
|
||||
return;
|
||||
}
|
||||
|
||||
// 业务成功(code=200)
|
||||
// 成功
|
||||
if (resData.code === 200) {
|
||||
resolve(resData); // 只返回核心数据,简化页面调用
|
||||
}
|
||||
// 业务失败(code=500)
|
||||
else if (resData.code === 500) {
|
||||
const errMsg = resData.msg || '请求失败';
|
||||
uni.showToast({ title: errMsg, icon: "none", duration: 2000 });
|
||||
// resolve(null)
|
||||
reject(errMsg);
|
||||
resolve(resData);
|
||||
}
|
||||
// 业务失败
|
||||
else {
|
||||
const errMsg = resData.msg || '业务异常';
|
||||
uni.showToast({ title: errMsg, icon: "none", duration: 2000 });
|
||||
reject(errMsg);
|
||||
reject({ msg: resData.msg || '请求失败', code: resData.code, data: resData });
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading(); // 关闭加载提示
|
||||
const errMsg = err.msg || '网络请求失败';
|
||||
uni.showToast({ title: errMsg, icon: "none", duration: 2000 });
|
||||
reject(err);
|
||||
uni.hideLoading();
|
||||
reject({ msg: '网络异常', code: -1, raw: err });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const get = (url, data) => request(url, data, 'GET');
|
||||
export const post = (url, data) => request(url, data, 'POST');
|
||||
// export const deleteMethod = (url, data) => request(url, data, 'DELETE');
|
||||
// export const putMethod = (url, data) => request(url, data, 'PUT');
|
||||
|
||||
|
||||
// 上传
|
||||
export const upload = (filePath, url) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: baseUrl + url,
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
|
||||
"clientid": "resident"
|
||||
},
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data);
|
||||
resolve(data.data || ''); // 直接返回图片地址
|
||||
} catch (e) {
|
||||
resolve('');
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user