import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';

const { uploadUrl = '' } = useGlobSetting();

/**
 * @description: Upload interface
 */
export function uploadApi(params: UploadFileParams, onUploadProgress: (progressEvent: ProgressEvent) => void) {


  console.log("uploadUrl",uploadUrl)

  const currentYear = new Date().getFullYear();
  const currentMoth = new Date().getMonth()+1; // 获取当前日期
  const bizPath = 'filelib/' + currentYear+"/"+(currentMoth<10?"0"+currentMoth:currentMoth);
  
  if(!params.data){
    params["data"]=  {biz:bizPath}
  } else if(!params.data.biz) {
    params["data"].biz= bizPath
  }
 
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: uploadUrl+"/sys/common/upload",
      onUploadProgress,
    },
    params,
    { 
      success:function(data) {
        return data;
      },
      isReturnResponse: true 
    }
  );
}
/**
 * @description: Upload interface
 */
export function uploadImg(params: UploadFileParams, onUploadProgress: (progressEvent: ProgressEvent) => void) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${uploadUrl}/sys/common/upload`,
      onUploadProgress,
    },
    params,
    { 
      isReturnResponse: true 
    }
  );
}
