You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
952 B
50 lines
952 B
|
|
|
|
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)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|