|
|
<template>
|
|
|
<div class="upload">
|
|
|
<form v-el:form v-on:change="upload">
|
|
|
<input id="{{inputId}}" type="file" name="filename">
|
|
|
<input id="{{inputId}}" type="file" name="filename" accept="image/*">
|
|
|
</form>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
const yoho = require('yoho');
|
|
|
const $ = require('jquery');
|
|
|
const modal = require('common/modal');
|
|
|
const tip = require('common/tip');
|
|
|
|
|
|
module.exports = {
|
|
|
props: ['imageList', 'bucket'],
|
...
|
...
|
@@ -21,6 +24,7 @@ |
|
|
const formData = new FormData(this.$els.form);
|
|
|
|
|
|
formData.append('bucket', this.bucket || '');
|
|
|
yoho.showLoading(true)
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
url: '/api/upload/image',
|
...
|
...
|
@@ -37,7 +41,21 @@ |
|
|
} else {
|
|
|
modal.alert(res.message);
|
|
|
}
|
|
|
});
|
|
|
})
|
|
|
.fail((jqXhr, textStatus, errorThrow)=> {
|
|
|
let message;
|
|
|
|
|
|
switch (jqXhr.status) {
|
|
|
case 413:
|
|
|
message = '图片太大了~';
|
|
|
break;
|
|
|
default:
|
|
|
message = '上传出错~'
|
|
|
}
|
|
|
|
|
|
tip(message);
|
|
|
})
|
|
|
.always(()=>yoho.showLoading(false));
|
|
|
}
|
|
|
}
|
|
|
};
|
...
|
...
|
|