diff --git a/src/components/upload/upload.vue b/src/components/upload/upload.vue
index 93cee85c..8f948bcf 100644
--- a/src/components/upload/upload.vue
+++ b/src/components/upload/upload.vue
@@ -202,6 +202,24 @@
}
},
post (file) {
+ // check format
+ if (this.format.length) {
+ const _file_format = file.name.split('.').pop().toLocaleLowerCase();
+ const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format);
+ if (!checked) {
+ this.onFormatError(file);
+ return false;
+ }
+ }
+
+ // check maxSize
+ if (this.maxSize) {
+ if (file.size > this.maxSize * 1024) {
+ this.onExceededSize(file);
+ return false;
+ }
+ }
+
this.handleStart(file);
let formData = new FormData();
formData.append(this.name, file);
@@ -235,24 +253,6 @@
showProgress: true
};
- // check format
- if (this.format.length) {
- const _file_format = _file.name.split('.').pop().toLocaleLowerCase();
- const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format);
- if (checked) {
- this.onFormatError(file);
- return;
- }
- }
-
- // check maxSize
- if (this.maxSize) {
- if (_file.size > this.maxSize * 1024) {
- this.onExceededSize(file);
- return;
- }
- }
-
this.fileList.push(_file);
},
getFile (file) {
diff --git a/src/styles/components/upload.less b/src/styles/components/upload.less
index ba93d58f..4f2aabdc 100644
--- a/src/styles/components/upload.less
+++ b/src/styles/components/upload.less
@@ -16,7 +16,7 @@
overflow: hidden;
position: relative;
- & + span{
+ & > span{
cursor: pointer;
transition: color @transition-time @ease-in-out;
i{
@@ -30,7 +30,7 @@
&:hover{
background: @input-disabled-bg;
- & + span{
+ & > span{
color: @primary-color;
i{
color: @text-color;
diff --git a/test/routers/upload.vue b/test/routers/upload.vue
index e9076bc5..b07ae166 100644
--- a/test/routers/upload.vue
+++ b/test/routers/upload.vue
@@ -1,56 +1,125 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
- 上传
-
-
-
-
+ action="//jsonplaceholder.typicode.com/posts/"
+ style="display: inline-block;width:58px;">
+
+
+
+
+
+
+
\ No newline at end of file
+ computed: {
+ uploadList () {
+ return this.$refs.upload ? this.$refs.upload.fileList : [];
+ }
+ },
+ methods: {
+ handleView (name) {
+ this.imgName = name;
+ this.visible = true;
+ },
+ handleRemove (file) {
+ // 从 upload 实例删除数据
+ const fileList = this.$refs.upload.fileList;
+ this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
+ },
+ handleSuccess (res, file) {
+ // 因为上传过程为实例,这里模拟添加 url
+ file.url = 'https://o5wwk8baw.qnssl.com/7eb99afb9d5f317c912f08b5212fd69a/avatar';
+ file.name = '7eb99afb9d5f317c912f08b5212fd69a';
+ },
+ handleFormatError (file) {
+ this.$Notice.warning({
+ title: '文件格式不正确',
+ desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
+ });
+ },
+ handleMaxSize (file) {
+ this.$Notice.warning({
+ title: '超出文件大小限制',
+ desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
+ });
+ }
+ }
+ }
+
+