You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.4 KiB
101 lines
2.4 KiB
const http = uni.$u.http;
|
|
const {
|
|
environment
|
|
} = require('@/config/environment.js')
|
|
|
|
/**
|
|
* 混入默认个性化配置
|
|
* @param {*} config
|
|
* @returns
|
|
*/
|
|
function mixinCustom(config) {
|
|
config.custom = Object.assign({
|
|
auth: true,
|
|
toast: true,
|
|
catch: true,
|
|
loading: true
|
|
}, config.custom || {});
|
|
return config;
|
|
}
|
|
|
|
/**
|
|
* 格式化get请求url参数,将对象解析为字符串
|
|
* @param {*} url
|
|
* @param {*} params
|
|
* @returns
|
|
*/
|
|
function urlFormater(url, params) {
|
|
if (params) {
|
|
let paramList = [];
|
|
for (let key in params) {
|
|
paramList.push(key + '=' + params[key])
|
|
}
|
|
return url.indexOf('?') > -1 ? (url + '&' + paramList.join('&')) : (url + '?' + paramList.join('&'))
|
|
}
|
|
return url;
|
|
}
|
|
|
|
const openrequest = {
|
|
// post提交
|
|
post(url, params, type, config = {}) {
|
|
url = environment.quarzApi + url
|
|
config = mixinCustom(config)
|
|
let path = url;
|
|
//param:拼接上传
|
|
if (type && type == 'param') {
|
|
path = urlFormater(url, params)
|
|
}
|
|
return http.post(path, params, config);
|
|
},
|
|
// get提交
|
|
get(url, params, config = {}) {
|
|
url = environment.quarzApi + url
|
|
config = mixinCustom(config)
|
|
let path = urlFormater(url, params)
|
|
return http.get(path, config);
|
|
},
|
|
|
|
// put提交
|
|
put(url, params, config = {}) {
|
|
url = environment.quarzApi + url
|
|
config = mixinCustom(config)
|
|
return http.put(url, params, config);
|
|
},
|
|
|
|
// delete提交
|
|
delete(url, params, config = {}) {
|
|
url = environment.quarzApi + url
|
|
config = mixinCustom(config)
|
|
return http.delete(url, params, config);
|
|
},
|
|
|
|
uploadFile(fileBizType, fileType) {
|
|
return new Promise((resolve, reject) => {
|
|
uni.chooseImage({
|
|
success: (res) => {
|
|
const tempFilePaths = res.tempFilePaths;
|
|
uni.uploadFile({
|
|
url: environment.openURL + environment.fileUploadURL, //仅为示例,非真实的接口地址
|
|
filePath: tempFilePaths[0],
|
|
name: 'file',
|
|
formData: {
|
|
'prefixFolder': 'AGENT',
|
|
'fileBizType': fileBizType, // 例:cert_bank_front_agent
|
|
'fileType': fileType, // 例:IMG
|
|
},
|
|
success: (uploadFileRes) => {
|
|
let fileData = JSON.parse(uploadFileRes.data);
|
|
resolve(fileData)
|
|
},
|
|
fail: (error) => {
|
|
reject(error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
};
|
|
|
|
export default openrequest;
|
|
|