2024-07-25 16:11:07 +00:00
|
|
|
import { baseUrl, apiPath, tenantId } from '@/sheep/config';
|
2024-01-20 05:13:28 +00:00
|
|
|
|
2023-12-16 14:52:32 +00:00
|
|
|
const FileApi = {
|
|
|
|
// 上传文件
|
|
|
|
uploadFile: (file) => {
|
2024-01-20 05:13:28 +00:00
|
|
|
// TODO 芋艿:访问令牌的接入;
|
2023-12-16 14:52:32 +00:00
|
|
|
const token = uni.getStorageSync('token');
|
|
|
|
uni.showLoading({
|
|
|
|
title: '上传中',
|
|
|
|
});
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
uni.uploadFile({
|
2024-01-20 05:13:28 +00:00
|
|
|
url: baseUrl + apiPath + '/infra/file/upload',
|
2023-12-16 14:52:32 +00:00
|
|
|
filePath: file,
|
|
|
|
name: 'file',
|
|
|
|
header: {
|
|
|
|
// Accept: 'text/json',
|
2024-07-25 16:11:07 +00:00
|
|
|
Accept: '*/*',
|
|
|
|
'tenant-id': tenantId,
|
2024-01-13 11:34:27 +00:00
|
|
|
// Authorization: 'Bearer test247',
|
2023-12-16 14:52:32 +00:00
|
|
|
},
|
|
|
|
success: (uploadFileRes) => {
|
|
|
|
let result = JSON.parse(uploadFileRes.data);
|
|
|
|
if (result.error === 1) {
|
|
|
|
uni.showToast({
|
|
|
|
icon: 'none',
|
|
|
|
title: result.msg,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return resolve(result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: (error) => {
|
|
|
|
console.log('上传失败:', error);
|
|
|
|
return resolve(false);
|
|
|
|
},
|
|
|
|
complete: () => {
|
|
|
|
uni.hideLoading();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FileApi;
|