2024-07-24 14:45:27 +08:00
|
|
|
|
import config from '../config/common' // 配置文件
|
|
|
|
|
|
import handle401 from './handle401'
|
|
|
|
|
|
// import MD5 from 'md5'
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
send(params) {
|
|
|
|
|
|
let pages = getCurrentPages()
|
|
|
|
|
|
let currentPage = pages[pages.length - 1]
|
|
|
|
|
|
let options = currentPage.options
|
|
|
|
|
|
let tenantId = ''
|
|
|
|
|
|
console.log(options, 'options')
|
|
|
|
|
|
if (options.Company == 'DCJD') {
|
|
|
|
|
|
tenantId = 'A0000025'
|
|
|
|
|
|
} else if (options.Company == 'GXBB') {
|
|
|
|
|
|
tenantId = 'A0000028'
|
|
|
|
|
|
} else if (options.Company == 'LYYL') {
|
|
|
|
|
|
tenantId = 'A0000024'
|
|
|
|
|
|
} else if (options.Company == 'LYXT') {
|
|
|
|
|
|
tenantId = '0002'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tenantId = '0001'
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(tenantId, 'tenantId')
|
|
|
|
|
|
let url = params.url;
|
|
|
|
|
|
let method = params.method || "get";
|
|
|
|
|
|
let data = params.data || {};
|
|
|
|
|
|
let header = {
|
|
|
|
|
|
// 'Blade-Auth': uni.getStorageSync('token') || '',
|
|
|
|
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
|
|
|
|
// 'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
|
|
|
|
|
|
'Tenant': tenantId, // avue配置相关
|
2024-07-24 14:45:27 +08:00
|
|
|
|
...params.header
|
2024-07-31 09:59:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (method == "post") {
|
|
|
|
|
|
header = {
|
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
|
|
'Tenant': tenantId,
|
|
|
|
|
|
...params.header
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url: config.serviceHost(url),
|
|
|
|
|
|
method: method,
|
|
|
|
|
|
header: header,
|
|
|
|
|
|
data: data,
|
|
|
|
|
|
// timeout,
|
|
|
|
|
|
success(response) {
|
|
|
|
|
|
const res = response
|
|
|
|
|
|
// 根据返回的状态码做出对应的操作
|
|
|
|
|
|
//获取成功
|
|
|
|
|
|
// console.log(res.statusCode);
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
|
resolve(res.data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.clearStorageSync()
|
|
|
|
|
|
switch (res.statusCode) {
|
|
|
|
|
|
case 401:
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'error',
|
|
|
|
|
|
title: '请稍后重试...',
|
|
|
|
|
|
duration: 3000,
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 10)
|
2024-07-25 14:55:26 +08:00
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 404:
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'error',
|
|
|
|
|
|
title: '请求地址不存在...',
|
|
|
|
|
|
duration: 3000,
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 10)
|
2024-07-25 14:55:26 +08:00
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: 'error',
|
|
|
|
|
|
title: '服务器内部错误...',
|
|
|
|
|
|
duration: 3000,
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 10)
|
2024-07-25 14:55:26 +08:00
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2024-07-24 14:45:27 +08:00
|
|
|
|
}
|
2024-07-31 09:59:56 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
console.log(err)
|
|
|
|
|
|
if (err.errMsg.indexOf('request:fail') !== -1) {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '网络异常',
|
|
|
|
|
|
icon: "error",
|
|
|
|
|
|
duration: 2000
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 10)
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '未知异常',
|
|
|
|
|
|
duration: 2000
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 10)
|
2024-07-25 14:55:26 +08:00
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
reject(err);
|
2024-07-25 14:55:26 +08:00
|
|
|
|
|
2024-07-31 09:59:56 +08:00
|
|
|
|
},
|
|
|
|
|
|
complete() {
|
|
|
|
|
|
// 不管成功还是失败都会执行
|
|
|
|
|
|
// uni.hideLoading();
|
|
|
|
|
|
uni.hideToast();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}).catch(() => {});
|
|
|
|
|
|
},
|
|
|
|
|
|
upload(url = '', filePath) {
|
|
|
|
|
|
const appInfoData = uni.getStorageSync('appInfo')
|
|
|
|
|
|
const tenant = uni.getStorageSync('Tenant') || ''
|
|
|
|
|
|
const userId = appInfoData?.User?.ID || ''
|
|
|
|
|
|
const orgId = appInfoData?.User?.ORG_ID || ''
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
uni.showLoading()
|
|
|
|
|
|
uni.uploadFile({
|
|
|
|
|
|
url: url,
|
|
|
|
|
|
filePath: filePath[0],
|
|
|
|
|
|
name: 'file',
|
|
|
|
|
|
formData: {
|
|
|
|
|
|
OrgId: orgId,
|
|
|
|
|
|
userID: userId
|
|
|
|
|
|
},
|
|
|
|
|
|
header: {
|
|
|
|
|
|
Tenant: tenant,
|
|
|
|
|
|
userid: userId
|
|
|
|
|
|
},
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
|
resolve(JSON.parse(res.data))
|
|
|
|
|
|
const uploadResult = JSON.parse(res.data)
|
|
|
|
|
|
if (uploadResult.IsSuccessful) {
|
|
|
|
|
|
resolve(uploadResult.Data)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
reject(uploadResult.ErrorMessage)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
|
console.log(err)
|
2024-07-24 14:45:27 +08:00
|
|
|
|
}
|
2024-07-31 09:59:56 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-07-24 14:45:27 +08:00
|
|
|
|
|
|
|
|
|
|
}
|