This commit is contained in:
2026-01-05 12:47:14 +08:00
commit 1fc846fae3
1614 changed files with 162035 additions and 0 deletions

100
api/house_request.ts Normal file
View File

@@ -0,0 +1,100 @@
// 针对仓库的Api接口
import config from '@/config';
import { goToLoginPage } from '@/utils/helper';
// 定义请求参数接口
interface Options {
url : string; // 请求路径不包含基础URL
method ?: 'GET' | 'POST'; // 请求方法默认为GET
data ?: any; // POST请求体数据
params ?: any; // GET请求参数与data二选一
dataType ?: string; // 返回数据格式默认json
responseType ?: string; // 响应数据类型默认text
}
// 定义响应数据结构接口
interface Response {
code : number;
msg ?: string;
data : any;
}
// /**
// * 获取图片上传的完整URL
// * @returns {string} 完整的图片上传URL包含基础URL、wxapp_id和token参数
// */
// export const getUploadImageUrl = () => {
// return config.api_base_url + '/store.upload/image' + '&wxapp_id=10001&token=' + uni.getStorageSync('token');
// };
/**
* 封装uni.request的通用请求方法
* @param {Options} options 请求配置项
* @returns {Promise} 返回Promise对象
*
* 功能说明:
* 1. 自动拼接基础URL和认证参数
* 2. 统一处理登录状态code=-1跳转登录页
* 3. 统一处理错误提示code=0显示Toast
* 4. 成功时返回data字段code=1
*/
export const houseRequest = (options : Options) => {
return new Promise((resolve, reject) => {
uni.request({
// 拼接完整请求URL基础URL + 路径 + 固定参数)
url: config.house_api_base_url + options.url + '&wxapp_id=10001&token=' + uni.getStorageSync('token'),
method: options.method || 'GET', // 默认GET方法
data: options.data || options.params || {}, // 兼容data/params传参
dataType: options.dataType || 'json', // 默认json格式
responseType: options.responseType || 'text', // 默认text类型
// 请求成功回调
success(res) {
const ret : Response = res.data;
// console.log(ret);
// 状态码处理
switch (ret.code) {
case -1: // 未登录状态
goToLoginPage();
break;
case 1: // 成功状态
// console.log(options.url);
// if (options.url === '/parts.order/preview') {
// console.log('ressss', ret);
// resolve(ret);
// break;
// }
resolve(ret.data); // 返回data字段
break;
case 0: // 失败状态
// console.log(options.url);
// if (options.url === '/parts.order/preview') {
// console.log('ressss', ret);
// resolve(ret);
// break;
// }
uni.showToast({
title: ret.msg || '操作失败', // 显示错误信息
icon: 'none', // 不显示图标
});
break;
}
},
// 请求失败回调
fail(err) {
uni.$emit('z-paging-error-emit');
reject(err); // 返回错误对象
uni.showToast({
title: '网络请求失败',
icon: 'none',
});
},
});
});
};