import {getToken} from '@/utils/auth.js';
import config from "@/config/index.js"
const baseUrl = process.env.NODE_ENV === 'development' ? config.base.dev : config.base.pro;
export const upload=({formData,filePath,callback})=>{
	uni.showLoading({
		mask:true,
		title:"上传中"
	})
	let unionid=uni.getStorageSync('unionid');
	let qrcode=uni.getStorageSync('qrcode');
	let isAccount=uni.getStorageSync('isAccount');
	return new Promise(function(resolve,reject){
		const uploadTask=uni.uploadFile({
			url: baseUrl+'/upload/file',
			filePath,
			header:{
				[config.TokenKey]:getToken(),
				AppID:config.appID,
				AppKey:config.appKey,
				AppSecret: config.appSecret,
				wxCode:unionid,
				ocId:qrcode.ocId,
				AppType:'mini',
				isAccount:isAccount
			},
			name: 'file',
			formData,
			success: (uploadFileRes) => {
				uni.hideLoading()
				resolve(uploadFileRes.data)
			},
			fail({errMsg}){
				uni.hideLoading({
					mask:true,
					title:"上传失败"
				})
				reject(errMsg)
			}
		});	
		if(callback){
			callback(uploadTask);
		}
				
	})
}	