import { request } from '../libs/request.js'
import {getToken} from '@/libs/auth.js';
import config from "@/config/index.js"
/**
 * 单文件上传
 * @param data
 */
export function uploadFile(data) {
  return request({
    url: '/admin/uploadFile',
    method: 'POST',
    data
  })
}
/**
 * 多文件上传
 * @param data
 */
export function uploadFiles(data) {
  return request({
    url: '/admin/uploadFiles',
    method: 'POST',
    data
  })
}
/*单独服务部署*/
export const uploadApi=({formData,filePath,callback})=>{
	return new Promise(function(resolve,reject){
		const uploadTask=uni.uploadFile({
			url: config.uploadFile+'/admin/uploadFiles',
			filePath,
			name: 'files',
			header:{
				[config.TokenKey]:getToken(),
				appID: config.appID,
				appKey: config.appKey,
				appSecret: config.appSecret,
				permitTplId: config.permitTplId
			},
			formData,
			success: (uploadFileRes) => {
				resolve(uploadFileRes.data)
			},
			fail({errMsg}){
				reject(errMsg)
			}
		});	
		if(callback){
			callback(uploadTask);
		}			
	})
}	
