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.
37 lines
757 B
37 lines
757 B
4 years ago
|
import functions from "./functions.js";
|
||
|
|
||
|
const apiUrl = `${functions.getDomain()}/api/upload`;
|
||
|
|
||
|
export default function() {
|
||
|
|
||
|
return new Promise((relove, reject) => {
|
||
|
|
||
|
uni.chooseImage({
|
||
|
count: 1, //默认9
|
||
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
||
|
sourceType: ['album',"camera"], //从相册选择
|
||
|
success: function(res) {
|
||
|
|
||
|
let path = res.tempFilePaths[0];
|
||
|
uni.uploadFile({
|
||
|
url: apiUrl,
|
||
|
filePath: path,
|
||
|
name: 'file',
|
||
|
formData: {},
|
||
|
success: (uploadFileRes) => {
|
||
|
let res = JSON.parse(uploadFileRes.data);
|
||
|
if (res.code == 200) {
|
||
|
relove(res.data);
|
||
|
} else {
|
||
|
functions.error(res.msg);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
}
|
||
|
});
|
||
|
|
||
|
})
|
||
|
|
||
|
}
|