// https://blog.csdn.net/WeiflR10/article/details/122978004
import { commonConfig } from '../common/config';
//直接导出这个方法
export function uploadImg(event,fileList) {
	return new Promise((resolve,reject)=>{
		// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
		let lists = [].concat(event.file)
		let fileListLen = fileList.length
		lists.map((item) => {
			fileList.push({
				...item
			})
		})
       // 这块把uview的改了一下 不用单独封装上传功能
		for (let i = 0; i < lists.length; i++) {
			uni.uploadFile({
				url: commonConfig.uploadFileUrl, // 测试地址
				filePath: lists[i].url, // 文件路径
				name: 'file',
				formData: {
					bucket: 'xusfood'
				},
				success: (res) => {
					let resolveData = {
						data: res.data,
						fileListLen: fileListLen
					}
                    // 成功之后返回resolveData
				    resolve(resolveData);
					fileListLen++
				}
			});
		}
	})
}