"use strict";
const common_vendor = require("../../../common/vendor.js");
const sheep_config_index = require("../../config/index.js");
const FileApi = {
  // 上传文件
  uploadFile: (file) => {
    common_vendor.index.getStorageSync("token");
    common_vendor.index.showLoading({
      title: "上传中"
    });
    return new Promise((resolve, reject) => {
      common_vendor.index.uploadFile({
        url: sheep_config_index.baseUrl + sheep_config_index.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);
          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;
