xianniu-ui 0.5.2 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xianniu-ui",
3
- "version": "0.5.2",
3
+ "version": "0.5.5",
4
4
  "private": false,
5
5
  "main": "lib/xianniu-ui.umd.min.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  "@vue/cli-plugin-router": "~4.5.0",
35
35
  "@vue/cli-service": "~4.5.0",
36
36
  "@vue/component-compiler-utils": "^2.6.0",
37
- "axios": "^0.26.1",
37
+ "axios": "^1.4.0",
38
38
  "babel-eslint": "^10.1.0",
39
39
  "babel-plugin-component": "^1.1.1",
40
40
  "babel-plugin-module-resolver": "^2.7.1",
@@ -78,6 +78,7 @@
78
78
  height: 80px;
79
79
  line-height: 80px;
80
80
  font-size: 14px;
81
+ position: relative;
81
82
  .el-upload-list__item {
82
83
  width: 80px;
83
84
  height: 80px;
@@ -92,31 +93,31 @@
92
93
  font-size: 20px;
93
94
  }
94
95
  }
95
- .process {
96
- position: absolute;
97
- left: 0;
98
- top: 0;
99
- background: rgba($color: #000000, $alpha: 0.4);
100
- width: 100%;
101
- height: 100%;
102
-
103
- .el-progress {
104
- width: 40%;
105
- height: auto;
106
- .el-progress-circle {
107
- width: 99% !important;
108
- height: 99% !important;
109
- }
110
- .el-progress__text {
111
- color: #fff;
112
- font-size: 12px !important;
113
- }
114
- }
115
- }
96
+
116
97
  }
117
98
  }
118
99
  &--slot {
119
100
  height: 100%;
101
+ .process {
102
+ position: absolute;
103
+ left: 0;
104
+ top: 0;
105
+ background: rgba($color: #000000, $alpha: 0.4);
106
+ width: 100%;
107
+ height: 100%;
108
+ .el-progress {
109
+ width: 70%;
110
+ height: auto;
111
+ .el-progress-circle {
112
+ width: 99% !important;
113
+ height: 99% !important;
114
+ }
115
+ .el-progress__text {
116
+ color: #fff !important;
117
+ font-size: 12px !important;
118
+ }
119
+ }
120
+ }
120
121
  &__ext {
121
122
  position: absolute;
122
123
  bottom: 0;
@@ -3,7 +3,7 @@
3
3
  ref="upload"
4
4
  :class="{
5
5
  'is-disabled': $attrs.disabled != undefined,
6
- 'is-hidden': preview
6
+ 'is-hidden': preview,
7
7
  }"
8
8
  class="xn-upload xn-upload-main"
9
9
  action="###"
@@ -26,7 +26,9 @@
26
26
  </template>
27
27
  <template v-else>
28
28
  <slot>
29
- <el-button icon="el-icon-upload" :disabled="$attrs.disabled">上传</el-button>
29
+ <el-button icon="el-icon-upload" :disabled="$attrs.disabled"
30
+ >上传</el-button
31
+ >
30
32
  </slot>
31
33
  </template>
32
34
  <div
@@ -36,26 +38,26 @@
36
38
  v-if="listType === 'picture-card'"
37
39
  >
38
40
  <uploadPop :file="file" @on-download="handleDownload(file)"></uploadPop>
39
- <template v-if="$utils.isImg(file)">
40
- <el-image
41
- class="el-upload-list__item-thumbnail"
42
- :src="file.url"
43
- fit="cover"
44
- :lazy="true"
45
- />
46
- </template>
47
- <template v-else>
48
- <div class="xn-upload-list__item-file">
49
- <div class="annex">
50
- <i class="el-icon el-icon-folder" />
51
- <span class="label">附件</span>
52
- </div>
53
- <div class="file-name">{{ file.name }}</div>
41
+ <template v-if="$utils.isImg(file)">
42
+ <el-image
43
+ class="el-upload-list__item-thumbnail"
44
+ :src="file.url"
45
+ fit="cover"
46
+ :lazy="true"
47
+ />
48
+ </template>
49
+ <template v-else>
50
+ <div class="xn-upload-list__item-file">
51
+ <div class="annex">
52
+ <i class="el-icon el-icon-folder" />
53
+ <span class="label">附件</span>
54
54
  </div>
55
- </template>
55
+ <div class="file-name">{{ file.name }}</div>
56
+ </div>
57
+ </template>
56
58
  <div v-if="file.status === 'uploading'" class="process">
57
59
  <el-progress
58
- :status="file.percentage === 100 ? 'success' : null"
60
+ :status="file.percentage === 100 && !isUploading ? 'success' : null"
59
61
  type="circle"
60
62
  :percentage="process(file.percentage)"
61
63
  :stroke-width="6"
@@ -126,19 +128,19 @@ export default {
126
128
 
127
129
  limit: {
128
130
  type: Number,
129
- default: 1,
131
+ default: 9,
130
132
  },
131
133
  tip: {
132
134
  type: String,
133
135
  default: "",
134
136
  },
135
137
  accept: {
136
- type: [Array,String],
138
+ type: [Array, String],
137
139
  default: () => ["jpg", "jpeg", "png", "pdf"],
138
140
  },
139
141
  maxSize: {
140
142
  type: Number,
141
- default: 1024 * 5 * 1024, // 最大限制 5M
143
+ default: 1024 * 50 * 1024, // 最大限制 50M
142
144
  },
143
145
  compress: {
144
146
  type: Number,
@@ -170,6 +172,8 @@ export default {
170
172
  viewList: [],
171
173
  files: [],
172
174
  successFiles: [],
175
+ isUploading: false,
176
+ file: {},
173
177
  };
174
178
  },
175
179
  computed: {
@@ -178,6 +182,9 @@ export default {
178
182
  return Math.floor(num);
179
183
  };
180
184
  },
185
+ fileSize() {
186
+ return this.$format.bytesToSize(this.file.size);
187
+ },
181
188
  },
182
189
  watch: {
183
190
  fileList: {
@@ -192,62 +199,43 @@ export default {
192
199
  immediate: true,
193
200
  },
194
201
  },
195
- created() {
196
- },
202
+ created() {},
197
203
  beforeDestroy() {
198
204
  this.$emit("update:fileList", []);
199
205
  },
200
206
  methods: {
201
207
  onBeforeUpload(file) {
202
208
  let fileExt = file.name.substring(file.name.lastIndexOf(".") + 1);
203
-
204
209
  // 判断上传格式
205
210
  fileExt = `${fileExt}`.toLowerCase();
206
-
207
- if (!this.accept.includes(fileExt) && this.accept !== '*') {
211
+ if (!this.accept.includes(fileExt) && this.accept !== "*") {
208
212
  this.$message.warning(`请上传指定格式【${this.accept}】`);
209
213
  return false;
210
214
  }
215
+ this.file = file;
216
+ if (file.size > 1024 * 1 * 1024) {
217
+ this.bigFileWarning();
218
+ }
219
+ return this.onExceedSize(file.size);
211
220
  },
212
- // handleCompress(file) {
213
- // const { compress } = this;
214
- // const _maxSize = parseFloat(this.maxSize);
215
- // let size = 0;
216
- // if (compress) {
217
- // size = compress;
218
- // } else {
219
- // size = file.size > _maxSize ? _maxSize / 1024 : file.size;
220
- // }
221
- // // return new Promise((resolve) => {
222
- // // imageConversion["compressAccurately"](file, size).then((result) => {
223
- // // resolve(result);
224
- // // });
225
- // // });
226
- // },
227
- onExceedSize(size, maxSize) {
228
- if (size > maxSize) {
221
+ onExceedSize(size) {
222
+ if (size > this.maxSize) {
229
223
  this.$message.warning(
230
- `最大不能超过${this.$utils.bytesToSize(maxSize)}`
224
+ `最大不能超过${this.$format.bytesToSize(this.maxSize)}`
231
225
  );
232
- return false;
226
+ return Promise.reject();
233
227
  }
234
- return true;
228
+ return Promise.resolve();
235
229
  },
236
230
  onChange(file, fileList) {
237
231
  this.files = fileList;
238
232
  },
239
233
  async onHttpUpload(file) {
240
234
  const formData = new FormData();
241
- // let result = null;
242
- // if (this.$utils.isImg(file.file.name)) {
243
- // result = await this.handleCompress(file.file);
244
- // var newFile = new window.File([result], file.file.name, {
245
- // type: file.file.type,
246
- // });
247
- // }
248
235
  const _file = file.file;
249
236
  formData.append("file", _file);
250
-
237
+ this.$emit("on-uploading");
238
+ this.isUploading = true;
251
239
  axios({
252
240
  method: "post",
253
241
  url: this.$XN.uploadUrl || "",
@@ -256,22 +244,28 @@ export default {
256
244
  "Content-Type": "application/x-www-form-urlencoded",
257
245
  xnToken: this.$storage.get("xnToken"),
258
246
  },
259
- onUploadProgress(progress) {
260
- const _progress = Math.round(
261
- (progress.loaded / progress.total) * 100
262
- );
247
+ onUploadProgress: (progress) => {
248
+ let _progress = Math.round((progress.loaded / progress.total) * 100);
249
+ _progress = _progress === 100 ? 99 : _progress;
263
250
  file.onProgress({ percent: _progress });
264
251
  },
265
252
  })
266
253
  .then((res) => {
267
- const { name, size, ext, imgFlag, url,fileId } = res.data.data;
268
- this.successFiles.push({name,size,ext,imgFlag,url,fileId});
254
+ const { name, size, ext, imgFlag, url, fileId } = res.data.data;
255
+ this.successFiles.push({ name, size, ext, imgFlag, url, fileId });
269
256
  file.onSuccess();
270
257
  this.$emit("update:fileList", this.successFiles);
271
258
  this.$emit("on-success", this.successFiles);
259
+ this.$emit("on-uploaded");
260
+ this.isUploading = false;
261
+ if (this.file.size > 1024 * 1 * 1024) {
262
+ this.$notify.closeAll()
263
+ this.bigFileSucces();
264
+ }
272
265
  })
273
- .catch(() => {
274
- // console.log(err);
266
+ .catch((err) => {
267
+ console.log(err);
268
+ this.$notify.closeAll()
275
269
  this.$emit("update:fileList", this.successFiles);
276
270
  file.onError();
277
271
  });
@@ -297,15 +291,23 @@ export default {
297
291
  this.imageView = file.url;
298
292
  });
299
293
  },
300
- async handleDownload({ url }) {
301
- const elt = document.createElement("a");
302
- elt.setAttribute("href", url);
303
- elt.setAttribute("download", "下载文件");
304
- elt.style.display = "none";
305
- elt.target = "_blank";
306
- document.body.appendChild(elt);
307
- elt.click();
308
- document.body.removeChild(elt);
294
+ async handleDownload(file) {
295
+ const { url, name } = file;
296
+ const x = new XMLHttpRequest();
297
+ x.open("GET", url, true);
298
+ x.responseType = "blob";
299
+ x.onload = function () {
300
+ const _url = window.URL.createObjectURL(x.response);
301
+ const elt = document.createElement("a");
302
+ elt.setAttribute("href", _url);
303
+ elt.setAttribute("download", name);
304
+ elt.style.display = "none";
305
+ elt.target = "_blank";
306
+ document.body.appendChild(elt);
307
+ elt.click();
308
+ document.body.removeChild(elt);
309
+ };
310
+ x.send();
309
311
  },
310
312
  handleRemove(file, fileList) {
311
313
  fileList.forEach((item, idx) => {
@@ -325,6 +327,26 @@ export default {
325
327
  closeViewer() {
326
328
  this.isShowImageView = false;
327
329
  },
330
+ bigFileWarning() {
331
+ return this.$notify({
332
+ title: "提示",
333
+ duration: 0,
334
+ dangerouslyUseHTMLString: true,
335
+ message: `
336
+ <p class="text-primary">当前文件体积过大,请您耐心等待。</p>
337
+ <p>名称:${this.file.name}</p>
338
+ <p>体积:${this.fileSize}</p>
339
+ `,
340
+ type: "warning",
341
+ });
342
+ },
343
+ bigFileSucces() {
344
+ return this.$notify({
345
+ title: "提示",
346
+ message: "上传成功",
347
+ type: "success",
348
+ });
349
+ },
328
350
  },
329
351
  };
330
352
  </script>