xunfeiAI/config/requesta.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-10-14 21:20:04 +08:00
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
HTTP_REQUEST_URL_ONE,
HEADER,
TOKENNAME
} from '@/config/app';
/**
* 发送请求
*/
function baseRequest(url, method, data, {
noAuth = false,
noVerify = false
}) {
let Url = HTTP_REQUEST_URL_ONE,
header = HEADER;
// if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token;
return new Promise((reslove, reject) => {
uni.request({
url: Url + '/' + url,
method: method || 'GET',
header: header,
data: data || {},
success: (res) => {
// #ifdef APP-PLUS
2023-11-01 15:06:35 +08:00
console.log('app', Url + '/api/' + url, res.data);
2023-10-14 21:20:04 +08:00
// #endif
if (noVerify)
reslove(res.data, res);
else if (res.data.status == 200)
reslove(res.data, res);
else if ([410000, 410001, 410002, 40000].indexOf(res.data.status) !== -1) {
reject(res.data);
}else if (res.data.code == 0||res.data.code ==1) {
reslove(res.data, res);
} else if (res.data.status == 501) {
uni.reLaunch({
url: '/pages/error/index'
})
reject(res.data);
} else
reject(res.data.message || '系统错误');
},
fail: (message) => {
console.log(message,'3333333333');
reject('请求失败');
}
})
});
}
const request = {};
['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
request[method] = (api, data, opt) => baseRequest(api, method, data, opt || {})
});
export default request;