feat: make drag-file-upload support pdf file type
Showing
1 changed file
with
50 additions
and
33 deletions
@@ -7,23 +7,26 @@ | @@ -7,23 +7,26 @@ | ||
7 | :progress="uploadList[0].showProgress" | 7 | :progress="uploadList[0].showProgress" |
8 | :percentage="uploadList[0].percentage" | 8 | :percentage="uploadList[0].percentage" |
9 | :remove="true" | 9 | :remove="true" |
10 | - @remove-image="handleRemove"></image-purview> | 10 | + @remove-image="handleRemove" |
11 | + ></image-purview> | ||
11 | 12 | ||
12 | - <div class="upload-box" v-show="!uploadList[0]"> | ||
13 | - <Upload ref="upload" | 13 | + <div v-show="!uploadList[0]" class="upload-box"> |
14 | + <Upload | ||
15 | + ref="upload" | ||
14 | :show-upload-list="false" | 16 | :show-upload-list="false" |
15 | - :data="{bucket: bucket}" | 17 | + :data="{ bucket: bucket }" |
16 | :on-success="handleSuccess" | 18 | :on-success="handleSuccess" |
17 | :on-error="handleError" | 19 | :on-error="handleError" |
18 | :default-file-list="defaultList" | 20 | :default-file-list="defaultList" |
19 | - :format="['jpg','jpeg','png']" | 21 | + :format="format" |
20 | :max-size="2048" | 22 | :max-size="2048" |
21 | :on-format-error="handleFormatError" | 23 | :on-format-error="handleFormatError" |
22 | :on-exceeded-size="handleMaxSize" | 24 | :on-exceeded-size="handleMaxSize" |
23 | - action="/Api/upload/image"> | ||
24 | - <Icon type="ios-cloud-upload-outline" title="上传图片"></Icon> | 25 | + action="/Api/upload/image" |
26 | + > | ||
27 | + <Icon type="ios-cloud-upload-outline" :title="uploadIconTitle"></Icon> | ||
25 | </Upload> | 28 | </Upload> |
26 | - <Icon type="ios-cloud-outline" v-if="skn" title="调用图片服务" @click.native="browseOnline"></Icon> | 29 | + <Icon v-if="skn" type="ios-cloud-outline" title="调用图片服务" @click.native="browseOnline"></Icon> |
27 | </div> | 30 | </div> |
28 | 31 | ||
29 | <modal-skn-image v-model="sknImageModel" :skn="skn" @selected="selected"></modal-skn-image> | 32 | <modal-skn-image v-model="sknImageModel" :skn="skn" @selected="selected"></modal-skn-image> |
@@ -33,13 +36,13 @@ | @@ -33,13 +36,13 @@ | ||
33 | import _ from 'lodash'; | 36 | import _ from 'lodash'; |
34 | 37 | ||
35 | export default { | 38 | export default { |
36 | - name: 'drag-file-upload', | 39 | + name: 'DragFileUpload', |
37 | props: { | 40 | props: { |
38 | id: { | 41 | id: { |
39 | - type: Object | 42 | + type: Object, |
40 | }, | 43 | }, |
41 | defaultFile: { | 44 | defaultFile: { |
42 | - type: String | 45 | + type: String, |
43 | }, | 46 | }, |
44 | skn: { | 47 | skn: { |
45 | type: [String, Number], | 48 | type: [String, Number], |
@@ -48,11 +51,27 @@ export default { | @@ -48,11 +51,27 @@ export default { | ||
48 | type: String, | 51 | type: String, |
49 | default() { | 52 | default() { |
50 | return 'goodsimg'; | 53 | return 'goodsimg'; |
51 | - } | ||
52 | - } | 54 | + }, |
55 | + }, | ||
56 | + format: { | ||
57 | + type: Array, | ||
58 | + default() { | ||
59 | + return ['jpg', 'jpeg', 'png']; | ||
60 | + }, | ||
61 | + }, | ||
62 | + formatErrMsg: { | ||
63 | + type: Function, | ||
64 | + default() { | ||
65 | + return file => `文件 ${file.name} 格式不正确,请上传 jpg 或 png 格式的图片。`; | ||
66 | + }, | ||
67 | + }, | ||
68 | + uploadIconTitle: { | ||
69 | + type: String, | ||
70 | + default: '上传图片', | ||
71 | + }, | ||
53 | }, | 72 | }, |
54 | data() { | 73 | data() { |
55 | - let _this = this; | 74 | + const _this = this; |
56 | 75 | ||
57 | return { | 76 | return { |
58 | imgUrl: '', | 77 | imgUrl: '', |
@@ -60,17 +79,27 @@ export default { | @@ -60,17 +79,27 @@ export default { | ||
60 | show: true, | 79 | show: true, |
61 | sknImageModel: false, | 80 | sknImageModel: false, |
62 | uploadList: [], | 81 | uploadList: [], |
63 | - defaultList: _this.defaultFile ? [{url: _this.defaultFile}] : [] | 82 | + defaultList: _this.defaultFile ? [{ url: _this.defaultFile }] : [], |
64 | }; | 83 | }; |
65 | }, | 84 | }, |
85 | + watch: { | ||
86 | + defaultFile(newValue) { | ||
87 | + if (newValue) { | ||
88 | + this.defaultList = [{ url: newValue }]; | ||
89 | + } | ||
90 | + }, | ||
91 | + }, | ||
92 | + mounted() { | ||
93 | + this.uploadList = this.$refs.upload.fileList; | ||
94 | + }, | ||
66 | methods: { | 95 | methods: { |
67 | handleView(url) { | 96 | handleView(url) { |
68 | this.imgUrl = url; | 97 | this.imgUrl = url; |
69 | this.visible = true; | 98 | this.visible = true; |
70 | }, | 99 | }, |
71 | handleRemove() { | 100 | handleRemove() { |
72 | - let file = this.uploadList[0]; | ||
73 | - let files = this.$refs.upload.fileList; | 101 | + const file = this.uploadList[0]; |
102 | + const files = this.$refs.upload.fileList; | ||
74 | 103 | ||
75 | this.$refs.upload.fileList.splice(files.indexOf(file), 1); | 104 | this.$refs.upload.fileList.splice(files.indexOf(file), 1); |
76 | this.uploadList = this.$refs.upload.fileList; | 105 | this.uploadList = this.$refs.upload.fileList; |
@@ -91,38 +120,26 @@ export default { | @@ -91,38 +120,26 @@ export default { | ||
91 | handleFormatError(file) { | 120 | handleFormatError(file) { |
92 | this.$Notice.warning({ | 121 | this.$Notice.warning({ |
93 | title: '文件格式不正确', | 122 | title: '文件格式不正确', |
94 | - desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。' | 123 | + desc: this.formatErrMsg(file), |
95 | }); | 124 | }); |
96 | }, | 125 | }, |
97 | handleMaxSize(file) { | 126 | handleMaxSize(file) { |
98 | this.$Notice.warning({ | 127 | this.$Notice.warning({ |
99 | title: '超出文件大小限制', | 128 | title: '超出文件大小限制', |
100 | - desc: '文件 ' + file.name + ' 太大,不能超过 2M。' | 129 | + desc: '文件 ' + file.name + ' 太大,不能超过 2M。', |
101 | }); | 130 | }); |
102 | }, | 131 | }, |
103 | browseOnline() { | 132 | browseOnline() { |
104 | this.sknImageModel = true; | 133 | this.sknImageModel = true; |
105 | }, | 134 | }, |
106 | selected(url) { | 135 | selected(url) { |
107 | - this.uploadList = this.defaultList = [{url}]; | ||
108 | - this.$emit('success', this.id, {url}); | 136 | + this.uploadList = this.defaultList = [{ url }]; |
137 | + this.$emit('success', this.id, { url }); | ||
109 | }, | 138 | }, |
110 | - | ||
111 | }, | 139 | }, |
112 | - mounted() { | ||
113 | - this.uploadList = this.$refs.upload.fileList; | ||
114 | - }, | ||
115 | - watch: { | ||
116 | - defaultFile: function(newValue) { | ||
117 | - if (newValue) { | ||
118 | - this.defaultList = [{url: newValue}]; | ||
119 | - } | ||
120 | - } | ||
121 | - } | ||
122 | }; | 140 | }; |
123 | </script> | 141 | </script> |
124 | <style lang="scss"> | 142 | <style lang="scss"> |
125 | - | ||
126 | .upload-box { | 143 | .upload-box { |
127 | width: 100px; | 144 | width: 100px; |
128 | height: 100px; | 145 | height: 100px; |
-
Please register or login to post a comment