export function uploadOne(action, msg) { let that = this; return new Promise((resolve, reject) => { uni.chooseImage({ count: 1, async success(res) { if (res.tempFilePaths && res.tempFilePaths[0]) { let file = res.tempFilePaths[0]; let urls = await uploadImage(action, file, msg); resolve(JSON.parse(urls)); } else { reject() } }, fail(err) { reject(err) } }) }) } export function uploadImage(action, path, msg = "上传中") { uni.showLoading({ title: msg }) return new Promise((resolve, reject) => { uni.uploadFile({ url: url_config + action, filePath: path, fileType: "image", dataType: 'json', name: 'file', header: {}, success: (uploadFileRes) => { uni.hideLoading(); resolve(uploadFileRes.data) }, fail: (err) => { uni.hideLoading(); uni.showToast({ icon: 'none', title: '上传失败' }) reject(err) } }); }) }