import request from '@/common/request.js'
import config from '../config.js'
import {
	getToken
} from '../common/auth.js'

/**
 * 单一文件上传接口
 * @file 文件地址 
 * @url 上传路径
 * @formData 上传数据
 */
export function UploadOne(file, formData = {}) {
	let header = {}
	if (getToken()) {
		header['Authorization'] = 'Bearer ' + getToken()
	}
	return new Promise((resolve, reject) => {
		try {
			uni.uploadFile({
				url: '/api/file/upload',
				filePath: file,
				name: 'file',
				formData: formData,
				header: header,
				success: (res) => {
					let r = JSON.parse(res.data)
					resolve(r)
				},
				fail: (err) => {
					uni.showToast({
						title: '服务器休息中，请稍后再试',
						icon: "none",
						position: "center",
						duration: 3000
					});
				},
				complete: (e) => {

				}
			})
		} catch {
			uni.showToast({
				title: '网速不好哦！在试试',
				icon: "none",
				position: "center",
				duration: 3000
			})
			uni.hideLoading()
		}

	})
}



export function UploadSomeFile(file, formData = {}) {
	let header = {}
	if (getToken()) {
		header['Authorization'] = 'Bearer ' + getToken()
	}
	return new Promise((resolve, reject) => {
		try {
			uni.uploadFile({
				url: '/api/file/uploadForm',
				// filePath: file,
				// name: 'file',
				files:file,
				formData: formData,
				header: header,
				success: (res) => {
					let r = JSON.parse(res.data)
					resolve(r)
				},
				fail: (err) => {
					uni.showToast({
						title: '服务器休息中，请稍后再试',
						icon: "none",
						position: "center",
						duration: 3000
					});
				},
				complete: (e) => {

				}
			})
		} catch {
			uni.showToast({
				title: '网速不好哦！在试试',
				icon: "none",
				position: "center",
				duration: 3000
			})
			uni.hideLoading()
		}

	})
}



export function UploadSome(data) {
    return request({
        url: '/api/file/uploadMul',
        method: 'post',
        data: data
    })
}

