acdr-ui/dist/dev/mp-weixin/modules/mall/sheep/api/infra/file.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
2024-10-01 09:15:35 +08:00
const common_vendor = require("../../../../../common/vendor.js");
const modules_mall_sheep_config_index = require("../../config/index.js");
2024-09-19 07:20:14 +08:00
const FileApi = {
// 上传文件
uploadFile: (file) => {
common_vendor.index.getStorageSync("token");
common_vendor.index.showLoading({
title: "上传中"
});
return new Promise((resolve, reject) => {
common_vendor.index.uploadFile({
2024-10-01 09:15:35 +08:00
url: modules_mall_sheep_config_index.baseUrl + modules_mall_sheep_config_index.apiPath + "/infra/file/upload",
2024-09-19 07:20:14 +08:00
filePath: file,
name: "file",
header: {
// Accept: 'text/json',
Accept: "*/*",
2024-10-01 09:15:35 +08:00
"tenant-id": modules_mall_sheep_config_index.tenantId
2024-09-19 07:20:14 +08:00
// Authorization: 'Bearer test247',
},
success: (uploadFileRes) => {
const result = JSON.parse(uploadFileRes.data);
if (result.error === 1) {
common_vendor.index.showToast({
icon: "none",
title: result.msg
});
} else {
return resolve(result);
}
},
fail: (error) => {
console.log("上传失败:", error);
return resolve(false);
},
complete: () => {
common_vendor.index.hideLoading();
}
});
});
}
};
exports.FileApi = FileApi;