54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
|
import { baseUrl, apiPath } from "@/peach/config";
|
||
|
|
||
|
const FileApi = {
|
||
|
// 上传文件
|
||
|
uploadFile: (file) => {
|
||
|
const token = uni.getStorageSync("token");
|
||
|
uni.showLoading({
|
||
|
title: "上传中",
|
||
|
});
|
||
|
return new Promise((resolve, reject) => {
|
||
|
uni.uploadFile({
|
||
|
url: baseUrl + apiPath + "/infra/file/upload",
|
||
|
filePath: file,
|
||
|
name: "file",
|
||
|
header: {
|
||
|
// Accept: 'text/json',
|
||
|
Accept: "*/*",
|
||
|
"tenant-id": "1",
|
||
|
// Authorization: 'Bearer test247',
|
||
|
},
|
||
|
success: (uploadFileRes) => {
|
||
|
let result = JSON.parse(uploadFileRes.data);
|
||
|
console.log(result);
|
||
|
if (result.error === 1) {
|
||
|
uni.showToast({
|
||
|
icon: "none",
|
||
|
title: result.msg,
|
||
|
});
|
||
|
} else {
|
||
|
uni.showToast({
|
||
|
icon: "none",
|
||
|
title: "上传成功",
|
||
|
});
|
||
|
return resolve(result);
|
||
|
}
|
||
|
},
|
||
|
fail: (error) => {
|
||
|
console.log("上传失败:", error);
|
||
|
uni.showToast({
|
||
|
title: "上传失败",
|
||
|
icon: "none",
|
||
|
});
|
||
|
return resolve(false);
|
||
|
},
|
||
|
complete: () => {
|
||
|
uni.hideLoading();
|
||
|
},
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
};
|
||
|
|
||
|
export default FileApi;
|