tianheng-ui 0.0.47 → 0.0.50

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.
@@ -1,572 +1,572 @@
1
- <template>
2
- <div class="fm-uplaod-container" :id="uploadId">
3
- <draggable
4
- class="drag-img-list"
5
- v-model="fileList"
6
- v-bind="{ group: uploadId, ghostClass: 'ghost', animation: 200 }"
7
- :no-transition-on-drag="true"
8
- >
9
- <div
10
- :id="item.key"
11
- :style="{ width: width + 'px', height: height + 'px' }"
12
- :class="{
13
- uploading: item.status == 'uploading',
14
- 'is-success': item.status == 'success',
15
- 'is-diabled': disabled
16
- }"
17
- class="upload-file"
18
- v-for="item in fileList"
19
- :key="item.key"
20
- >
21
- <img :src="item.url" />
22
-
23
- <el-progress
24
- v-if="item.status == 'uploading'"
25
- :width="miniWidth * 0.9"
26
- class="upload-progress"
27
- type="circle"
28
- :percentage="item.percent"
29
- ></el-progress>
30
-
31
- <label class="item-status" v-if="item.status == 'success'">
32
- <i class="el-icon-upload-success el-icon-check"></i>
33
- </label>
34
-
35
- <div
36
- class="uplaod-action"
37
- :style="{ height: miniWidth / 4 + 'px' }"
38
- v-if="!disabled"
39
- >
40
- <i
41
- class="iconfont icon-tupianyulan"
42
- title="预览"
43
- @click="handlePreviewFile(item.key)"
44
- :style="{ 'font-size': miniWidth / 8 + 'px' }"
45
- ></i>
46
- <i
47
- v-if="isEdit"
48
- class="iconfont icon-sync1"
49
- title="替换"
50
- @click="handleEdit(item.key)"
51
- :style="{ 'font-size': miniWidth / 8 + 'px' }"
52
- ></i>
53
- <i
54
- v-if="isDelete && fileList.length > min"
55
- class="iconfont icon-delete"
56
- title="删除"
57
- @click="handleRemove(item.key)"
58
- :style="{ 'font-size': miniWidth / 8 + 'px' }"
59
- ></i>
60
- </div>
61
- </div>
62
- </draggable>
63
-
64
- <div
65
- class="el-upload el-upload--picture-card"
66
- :class="{ 'is-disabled': disabled }"
67
- v-show="(!isQiniu || (isQiniu && token)) && fileList.length < length"
68
- :style="{ width: width + 'px', height: height + 'px' }"
69
- @click.self="handleAdd"
70
- >
71
- <i
72
- class="el-icon-plus"
73
- @click.self="handleAdd"
74
- :style="{
75
- fontSize: miniWidth / 4 + 'px',
76
- marginTop: -miniWidth / 8 + 'px',
77
- marginLeft: -miniWidth / 8 + 'px'
78
- }"
79
- ></i>
80
- <input
81
- accept="image/*"
82
- v-if="multiple"
83
- multiple
84
- ref="uploadInput"
85
- @change="handleChange"
86
- type="file"
87
- :style="{ width: 0, height: 0 }"
88
- name="file"
89
- class="el-upload__input upload-input"
90
- />
91
- <input
92
- accept="image/*"
93
- v-else
94
- ref="uploadInput"
95
- @change="handleChange"
96
- type="file"
97
- :style="{ width: 0, height: 0 }"
98
- name="file"
99
- class="el-upload__input upload-input"
100
- />
101
- </div>
102
- </div>
103
- </template>
104
-
105
- <script>
106
- import Viewer from "viewerjs";
107
- import Draggable from "vuedraggable";
108
- // import * as qiniu from 'qiniu-js'
109
- require("viewerjs/dist/viewer.css");
110
- export default {
111
- components: {
112
- Draggable
113
- },
114
- props: {
115
- value: {
116
- type: Array,
117
- default: () => []
118
- },
119
- width: {
120
- type: Number,
121
- default: 100
122
- },
123
- height: {
124
- type: Number,
125
- default: 100
126
- },
127
- token: {
128
- type: String,
129
- default: ""
130
- },
131
- domain: {
132
- type: String,
133
- default: ""
134
- },
135
- multiple: {
136
- type: Boolean,
137
- default: false
138
- },
139
- length: {
140
- type: Number,
141
- default: 9
142
- },
143
- isQiniu: {
144
- type: Boolean,
145
- default: false
146
- },
147
- isDelete: {
148
- type: Boolean,
149
- default: false
150
- },
151
- min: {
152
- type: Number,
153
- default: 0
154
- },
155
- meitu: {
156
- type: Boolean,
157
- default: false
158
- },
159
- isEdit: {
160
- type: Boolean,
161
- default: false
162
- },
163
- action: {
164
- type: String,
165
- default: ""
166
- },
167
- disabled: {
168
- type: Boolean,
169
- default: false
170
- }
171
- },
172
- data() {
173
- return {
174
- fileList: this.value.map(item => {
175
- return {
176
- key: item.key
177
- ? item.key
178
- : new Date().getTime() + "_" + Math.ceil(Math.random() * 99999),
179
- url: item.url,
180
- percent: item.percent ? item.percent : 100,
181
- status: item.status ? item.status : "success"
182
- };
183
- }),
184
- viewer: null,
185
- uploadId: "upload_" + new Date().getTime(),
186
- editIndex: -1,
187
- meituIndex: -1
188
- };
189
- },
190
- computed: {
191
- miniWidth() {
192
- if (this.width > this.height) {
193
- return this.height;
194
- } else {
195
- return this.width;
196
- }
197
- }
198
- },
199
- mounted() {
200
- this.$emit("input", this.fileList);
201
- },
202
- methods: {
203
- handleChange() {
204
- console.log(this.$refs.uploadInput.files);
205
- const files = this.$refs.uploadInput.files;
206
-
207
- for (let i = 0; i < files.length; i++) {
208
- const file = files[i];
209
- const reader = new FileReader();
210
- const key =
211
- new Date().getTime() + "_" + Math.ceil(Math.random() * 99999);
212
- reader.readAsDataURL(file);
213
- reader.onload = () => {
214
- if (this.editIndex >= 0) {
215
- this.$set(this.fileList, this.editIndex, {
216
- key,
217
- url: reader.result,
218
- percent: 0,
219
- status: "uploading"
220
- });
221
-
222
- this.editIndex = -1;
223
- } else {
224
- this.fileList.push({
225
- key,
226
- url: reader.result,
227
- percent: 0,
228
- status: "uploading"
229
- });
230
- }
231
-
232
- this.$nextTick(() => {
233
- if (this.isQiniu) {
234
- this.uplaodAction2(reader.result, file, key);
235
- } else {
236
- this.uplaodAction(reader.result, file, key);
237
- }
238
- });
239
- };
240
- }
241
- this.$refs.uploadInput.value = [];
242
- },
243
- uplaodAction(res, file, key) {
244
- let changeIndex = this.fileList.findIndex(item => item.key === key);
245
- console.log(this.fileList.findIndex(item => item.key === key));
246
- const xhr = new XMLHttpRequest();
247
-
248
- const url = this.action;
249
- xhr.open("POST", url, true);
250
- // xhr.setRequestHeader('Content-Type', 'multipart/form-data')
251
-
252
- let formData = new FormData();
253
- formData.append("file", file);
254
-
255
- xhr.onreadystatechange = () => {
256
- console.log(xhr);
257
- if (xhr.readyState === 4) {
258
- let resData = JSON.parse(xhr.response);
259
- if (resData && resData.url) {
260
- this.$set(
261
- this.fileList,
262
- this.fileList.findIndex(item => item.key === key),
263
- {
264
- ...this.fileList[
265
- this.fileList.findIndex(item => item.key === key)
266
- ],
267
- url: resData.url,
268
- percent: 100
269
- }
270
- );
271
- setTimeout(() => {
272
- this.$set(
273
- this.fileList,
274
- this.fileList.findIndex(item => item.key === key),
275
- {
276
- ...this.fileList[
277
- this.fileList.findIndex(item => item.key === key)
278
- ],
279
- status: "success"
280
- }
281
- );
282
- this.$emit("input", this.fileList);
283
- }, 200);
284
- } else {
285
- this.$set(
286
- this.fileList,
287
- this.fileList.findIndex(item => item.key === key),
288
- {
289
- ...this.fileList[
290
- this.fileList.findIndex(item => item.key === key)
291
- ],
292
- status: "error"
293
- }
294
- );
295
- this.fileList.splice(
296
- this.fileList.findIndex(item => item.key === key),
297
- 1
298
- );
299
- }
300
- }
301
- };
302
- xhr.upload.onprogress = res => {
303
- console.log("progress", res);
304
- if (res.total && res.loaded) {
305
- this.$set(
306
- this.fileList[this.fileList.findIndex(item => item.key === key)],
307
- "percent",
308
- (res.loaded / res.total) * 100
309
- );
310
- }
311
- };
312
-
313
- xhr.send(formData);
314
- },
315
- uplaodAction2(res, file, key) {
316
- const _this = this;
317
- const observable = qiniu.upload(
318
- file,
319
- key,
320
- this.token,
321
- {
322
- fname: key,
323
- mimeType: []
324
- },
325
- {
326
- useCdnDomain: true
327
- }
328
- );
329
- observable.subscribe({
330
- next(res) {
331
- _this.$set(
332
- _this.fileList[_this.fileList.findIndex(item => item.key === key)],
333
- "percent",
334
- parseInt(res.total.percent)
335
- );
336
- },
337
- error(err) {
338
- _this.$set(
339
- _this.fileList,
340
- _this.fileList.findIndex(item => item.key === key),
341
- {
342
- ..._this.fileList[
343
- _this.fileList.findIndex(item => item.key === key)
344
- ],
345
- status: "error"
346
- }
347
- );
348
- _this.fileList.splice(
349
- _this.fileList.findIndex(item => item.key === key),
350
- 1
351
- );
352
- },
353
- complete(res) {
354
- _this.$set(
355
- _this.fileList,
356
- _this.fileList.findIndex(item => item.key === key),
357
- {
358
- ..._this.fileList[
359
- _this.fileList.findIndex(item => item.key === key)
360
- ],
361
- url: _this.domain + res.key,
362
- percent: 100
363
- }
364
- );
365
- setTimeout(() => {
366
- _this.$set(
367
- _this.fileList,
368
- _this.fileList.findIndex(item => item.key === key),
369
- {
370
- ..._this.fileList[
371
- _this.fileList.findIndex(item => item.key === key)
372
- ],
373
- status: "success"
374
- }
375
- );
376
- _this.$emit("input", _this.fileList);
377
- }, 200);
378
- }
379
- });
380
- },
381
- handleRemove(key) {
382
- this.fileList.splice(
383
- this.fileList.findIndex(item => item.key === key),
384
- 1
385
- );
386
- },
387
- handleEdit(key) {
388
- this.editIndex = this.fileList.findIndex(item => item.key === key);
389
-
390
- this.$refs.uploadInput.click();
391
- },
392
- handleMeitu(key) {
393
- this.$emit(
394
- "on-meitu",
395
- this.fileList.findIndex(item => item.key === key)
396
- );
397
- },
398
- handleAdd() {
399
- if (!this.disabled) {
400
- this.editIndex = -1;
401
- this.$refs.uploadInput.click();
402
- }
403
- },
404
- handlePreviewFile(key) {
405
- this.viewer && this.viewer.destroy();
406
- this.uploadId = "upload_" + new Date().getTime();
407
-
408
- console.log(this.viewer);
409
- this.$nextTick(() => {
410
- this.viewer = new Viewer(document.getElementById(this.uploadId));
411
- this.viewer.view(this.fileList.findIndex(item => item.key === key));
412
- });
413
- }
414
- },
415
- watch: {
416
- fileList: {
417
- deep: true,
418
- handler(val) {
419
- // this.$emit('input', this.fileList)
420
- }
421
- }
422
- }
423
- };
424
- </script>
425
-
426
- <style lang="scss">
427
- .fm-uplaod-container {
428
- .is-disabled {
429
- position: relative;
430
-
431
- &::after {
432
- position: absolute;
433
- top: 0;
434
- bottom: 0;
435
- left: 0;
436
- right: 0;
437
- // background: rgba(0,0,0,.1);
438
- content: "";
439
- display: block;
440
- cursor: not-allowed;
441
- }
442
- }
443
-
444
- .upload-file {
445
- margin: 0 10px 10px 0;
446
- display: inline-flex;
447
- justify-content: center;
448
- align-items: center;
449
- // background: #fff;
450
- overflow: hidden;
451
- background-color: #fff;
452
- border: 1px solid #c0ccda;
453
- border-radius: 6px;
454
- box-sizing: border-box;
455
- position: relative;
456
- vertical-align: top;
457
- &:hover {
458
- .uplaod-action {
459
- display: flex;
460
- }
461
- }
462
- .uplaod-action {
463
- position: absolute;
464
- // top: 0;
465
- // height: 30px;
466
- bottom: 0;
467
- left: 0;
468
- right: 0;
469
- background: rgba(0, 0, 0, 0.6);
470
- display: none;
471
- justify-content: center;
472
- align-items: center;
473
- i {
474
- color: #fff;
475
- cursor: pointer;
476
- margin: 0 5px;
477
- }
478
- }
479
- &.is-success {
480
- .item-status {
481
- position: absolute;
482
- right: -15px;
483
- top: -6px;
484
- width: 40px;
485
- height: 24px;
486
- background: #13ce66;
487
- text-align: center;
488
- transform: rotate(45deg);
489
- box-shadow: 0 0 1pc 1px rgba(0, 0, 0, 0.2);
490
- & > i {
491
- font-size: 12px;
492
- margin-top: 11px;
493
- color: #fff;
494
- transform: rotate(-45deg);
495
- }
496
- }
497
- }
498
- &.uploading {
499
- &:before {
500
- display: block;
501
- content: "";
502
- position: absolute;
503
- top: 0;
504
- left: 0;
505
- right: 0;
506
- bottom: 0;
507
- background: rgba(0, 0, 0, 0.3);
508
- }
509
- }
510
- .upload-progress {
511
- position: absolute;
512
- .el-progress__text {
513
- color: #fff;
514
- font-size: 16px !important;
515
- }
516
- }
517
- img {
518
- max-width: 100%;
519
- max-height: 100%;
520
- vertical-align: middle;
521
- }
522
- }
523
- .el-upload--picture-card {
524
- position: relative;
525
- overflow: hidden;
526
- .el-icon-plus {
527
- position: absolute;
528
- top: 50%;
529
- left: 50%;
530
- }
531
- }
532
- .upload-input {
533
- position: absolute;
534
- top: 0;
535
- left: 0;
536
- right: 0;
537
- bottom: 0;
538
- display: block;
539
- opacity: 0;
540
- cursor: pointer;
541
- }
542
-
543
- .drag-img-list {
544
- display: inline;
545
-
546
- .ghost {
547
- position: relative;
548
- &::after {
549
- width: 100%;
550
- height: 100%;
551
- display: block;
552
- content: "";
553
- background: #fbfdff;
554
- position: absolute;
555
- top: 0;
556
- bottom: 0;
557
- left: 0;
558
- right: 0;
559
- border: 1px dashed #3bb3c2;
560
- }
561
- }
562
-
563
- & > div {
564
- cursor: move;
565
- }
566
- }
567
- }
568
-
569
- .viewer-container {
570
- z-index: 9999 !important;
571
- }
572
- </style>
1
+ <template>
2
+ <div class="fm-uplaod-container" :id="uploadId">
3
+ <draggable
4
+ class="drag-img-list"
5
+ v-model="fileList"
6
+ v-bind="{ group: uploadId, ghostClass: 'ghost', animation: 200 }"
7
+ :no-transition-on-drag="true"
8
+ >
9
+ <div
10
+ :id="item.key"
11
+ :style="{ width: width + 'px', height: height + 'px' }"
12
+ :class="{
13
+ uploading: item.status == 'uploading',
14
+ 'is-success': item.status == 'success',
15
+ 'is-diabled': disabled
16
+ }"
17
+ class="upload-file"
18
+ v-for="item in fileList"
19
+ :key="item.key"
20
+ >
21
+ <img :src="item.url" />
22
+
23
+ <el-progress
24
+ v-if="item.status == 'uploading'"
25
+ :width="miniWidth * 0.9"
26
+ class="upload-progress"
27
+ type="circle"
28
+ :percentage="item.percent"
29
+ ></el-progress>
30
+
31
+ <label class="item-status" v-if="item.status == 'success'">
32
+ <i class="el-icon-upload-success el-icon-check"></i>
33
+ </label>
34
+
35
+ <div
36
+ class="uplaod-action"
37
+ :style="{ height: miniWidth / 4 + 'px' }"
38
+ v-if="!disabled"
39
+ >
40
+ <i
41
+ class="iconfont icon-tupianyulan"
42
+ title="预览"
43
+ @click="handlePreviewFile(item.key)"
44
+ :style="{ 'font-size': miniWidth / 8 + 'px' }"
45
+ ></i>
46
+ <i
47
+ v-if="isEdit"
48
+ class="iconfont icon-sync1"
49
+ title="替换"
50
+ @click="handleEdit(item.key)"
51
+ :style="{ 'font-size': miniWidth / 8 + 'px' }"
52
+ ></i>
53
+ <i
54
+ v-if="isDelete && fileList.length > min"
55
+ class="iconfont icon-delete"
56
+ title="删除"
57
+ @click="handleRemove(item.key)"
58
+ :style="{ 'font-size': miniWidth / 8 + 'px' }"
59
+ ></i>
60
+ </div>
61
+ </div>
62
+ </draggable>
63
+
64
+ <div
65
+ class="el-upload el-upload--picture-card"
66
+ :class="{ 'is-disabled': disabled }"
67
+ v-show="(!isQiniu || (isQiniu && token)) && fileList.length < length"
68
+ :style="{ width: width + 'px', height: height + 'px' }"
69
+ @click.self="handleAdd"
70
+ >
71
+ <i
72
+ class="el-icon-plus"
73
+ @click.self="handleAdd"
74
+ :style="{
75
+ fontSize: miniWidth / 4 + 'px',
76
+ marginTop: -miniWidth / 8 + 'px',
77
+ marginLeft: -miniWidth / 8 + 'px'
78
+ }"
79
+ ></i>
80
+ <input
81
+ accept="image/*"
82
+ v-if="multiple"
83
+ multiple
84
+ ref="uploadInput"
85
+ @change="handleChange"
86
+ type="file"
87
+ :style="{ width: 0, height: 0 }"
88
+ name="file"
89
+ class="el-upload__input upload-input"
90
+ />
91
+ <input
92
+ accept="image/*"
93
+ v-else
94
+ ref="uploadInput"
95
+ @change="handleChange"
96
+ type="file"
97
+ :style="{ width: 0, height: 0 }"
98
+ name="file"
99
+ class="el-upload__input upload-input"
100
+ />
101
+ </div>
102
+ </div>
103
+ </template>
104
+
105
+ <script>
106
+ import Viewer from "viewerjs";
107
+ import Draggable from "vuedraggable";
108
+ // import * as qiniu from 'qiniu-js'
109
+ require("viewerjs/dist/viewer.css");
110
+ export default {
111
+ components: {
112
+ Draggable
113
+ },
114
+ props: {
115
+ value: {
116
+ type: Array,
117
+ default: () => []
118
+ },
119
+ width: {
120
+ type: Number,
121
+ default: 100
122
+ },
123
+ height: {
124
+ type: Number,
125
+ default: 100
126
+ },
127
+ token: {
128
+ type: String,
129
+ default: ""
130
+ },
131
+ domain: {
132
+ type: String,
133
+ default: ""
134
+ },
135
+ multiple: {
136
+ type: Boolean,
137
+ default: false
138
+ },
139
+ length: {
140
+ type: Number,
141
+ default: 9
142
+ },
143
+ isQiniu: {
144
+ type: Boolean,
145
+ default: false
146
+ },
147
+ isDelete: {
148
+ type: Boolean,
149
+ default: false
150
+ },
151
+ min: {
152
+ type: Number,
153
+ default: 0
154
+ },
155
+ meitu: {
156
+ type: Boolean,
157
+ default: false
158
+ },
159
+ isEdit: {
160
+ type: Boolean,
161
+ default: false
162
+ },
163
+ action: {
164
+ type: String,
165
+ default: ""
166
+ },
167
+ disabled: {
168
+ type: Boolean,
169
+ default: false
170
+ }
171
+ },
172
+ data() {
173
+ return {
174
+ fileList: this.value.map(item => {
175
+ return {
176
+ key: item.key
177
+ ? item.key
178
+ : new Date().getTime() + "_" + Math.ceil(Math.random() * 99999),
179
+ url: item.url,
180
+ percent: item.percent ? item.percent : 100,
181
+ status: item.status ? item.status : "success"
182
+ };
183
+ }),
184
+ viewer: null,
185
+ uploadId: "upload_" + new Date().getTime(),
186
+ editIndex: -1,
187
+ meituIndex: -1
188
+ };
189
+ },
190
+ computed: {
191
+ miniWidth() {
192
+ if (this.width > this.height) {
193
+ return this.height;
194
+ } else {
195
+ return this.width;
196
+ }
197
+ }
198
+ },
199
+ mounted() {
200
+ this.$emit("input", this.fileList);
201
+ },
202
+ methods: {
203
+ handleChange() {
204
+ console.log(this.$refs.uploadInput.files);
205
+ const files = this.$refs.uploadInput.files;
206
+
207
+ for (let i = 0; i < files.length; i++) {
208
+ const file = files[i];
209
+ const reader = new FileReader();
210
+ const key =
211
+ new Date().getTime() + "_" + Math.ceil(Math.random() * 99999);
212
+ reader.readAsDataURL(file);
213
+ reader.onload = () => {
214
+ if (this.editIndex >= 0) {
215
+ this.$set(this.fileList, this.editIndex, {
216
+ key,
217
+ url: reader.result,
218
+ percent: 0,
219
+ status: "uploading"
220
+ });
221
+
222
+ this.editIndex = -1;
223
+ } else {
224
+ this.fileList.push({
225
+ key,
226
+ url: reader.result,
227
+ percent: 0,
228
+ status: "uploading"
229
+ });
230
+ }
231
+
232
+ this.$nextTick(() => {
233
+ if (this.isQiniu) {
234
+ this.uplaodAction2(reader.result, file, key);
235
+ } else {
236
+ this.uplaodAction(reader.result, file, key);
237
+ }
238
+ });
239
+ };
240
+ }
241
+ this.$refs.uploadInput.value = [];
242
+ },
243
+ uplaodAction(res, file, key) {
244
+ let changeIndex = this.fileList.findIndex(item => item.key === key);
245
+ console.log(this.fileList.findIndex(item => item.key === key));
246
+ const xhr = new XMLHttpRequest();
247
+
248
+ const url = this.action;
249
+ xhr.open("POST", url, true);
250
+ // xhr.setRequestHeader('Content-Type', 'multipart/form-data')
251
+
252
+ let formData = new FormData();
253
+ formData.append("file", file);
254
+
255
+ xhr.onreadystatechange = () => {
256
+ console.log(xhr);
257
+ if (xhr.readyState === 4) {
258
+ let resData = JSON.parse(xhr.response);
259
+ if (resData && resData.url) {
260
+ this.$set(
261
+ this.fileList,
262
+ this.fileList.findIndex(item => item.key === key),
263
+ {
264
+ ...this.fileList[
265
+ this.fileList.findIndex(item => item.key === key)
266
+ ],
267
+ url: resData.url,
268
+ percent: 100
269
+ }
270
+ );
271
+ setTimeout(() => {
272
+ this.$set(
273
+ this.fileList,
274
+ this.fileList.findIndex(item => item.key === key),
275
+ {
276
+ ...this.fileList[
277
+ this.fileList.findIndex(item => item.key === key)
278
+ ],
279
+ status: "success"
280
+ }
281
+ );
282
+ this.$emit("input", this.fileList);
283
+ }, 200);
284
+ } else {
285
+ this.$set(
286
+ this.fileList,
287
+ this.fileList.findIndex(item => item.key === key),
288
+ {
289
+ ...this.fileList[
290
+ this.fileList.findIndex(item => item.key === key)
291
+ ],
292
+ status: "error"
293
+ }
294
+ );
295
+ this.fileList.splice(
296
+ this.fileList.findIndex(item => item.key === key),
297
+ 1
298
+ );
299
+ }
300
+ }
301
+ };
302
+ xhr.upload.onprogress = res => {
303
+ console.log("progress", res);
304
+ if (res.total && res.loaded) {
305
+ this.$set(
306
+ this.fileList[this.fileList.findIndex(item => item.key === key)],
307
+ "percent",
308
+ (res.loaded / res.total) * 100
309
+ );
310
+ }
311
+ };
312
+
313
+ xhr.send(formData);
314
+ },
315
+ uplaodAction2(res, file, key) {
316
+ const _this = this;
317
+ const observable = qiniu.upload(
318
+ file,
319
+ key,
320
+ this.token,
321
+ {
322
+ fname: key,
323
+ mimeType: []
324
+ },
325
+ {
326
+ useCdnDomain: true
327
+ }
328
+ );
329
+ observable.subscribe({
330
+ next(res) {
331
+ _this.$set(
332
+ _this.fileList[_this.fileList.findIndex(item => item.key === key)],
333
+ "percent",
334
+ parseInt(res.total.percent)
335
+ );
336
+ },
337
+ error(err) {
338
+ _this.$set(
339
+ _this.fileList,
340
+ _this.fileList.findIndex(item => item.key === key),
341
+ {
342
+ ..._this.fileList[
343
+ _this.fileList.findIndex(item => item.key === key)
344
+ ],
345
+ status: "error"
346
+ }
347
+ );
348
+ _this.fileList.splice(
349
+ _this.fileList.findIndex(item => item.key === key),
350
+ 1
351
+ );
352
+ },
353
+ complete(res) {
354
+ _this.$set(
355
+ _this.fileList,
356
+ _this.fileList.findIndex(item => item.key === key),
357
+ {
358
+ ..._this.fileList[
359
+ _this.fileList.findIndex(item => item.key === key)
360
+ ],
361
+ url: _this.domain + res.key,
362
+ percent: 100
363
+ }
364
+ );
365
+ setTimeout(() => {
366
+ _this.$set(
367
+ _this.fileList,
368
+ _this.fileList.findIndex(item => item.key === key),
369
+ {
370
+ ..._this.fileList[
371
+ _this.fileList.findIndex(item => item.key === key)
372
+ ],
373
+ status: "success"
374
+ }
375
+ );
376
+ _this.$emit("input", _this.fileList);
377
+ }, 200);
378
+ }
379
+ });
380
+ },
381
+ handleRemove(key) {
382
+ this.fileList.splice(
383
+ this.fileList.findIndex(item => item.key === key),
384
+ 1
385
+ );
386
+ },
387
+ handleEdit(key) {
388
+ this.editIndex = this.fileList.findIndex(item => item.key === key);
389
+
390
+ this.$refs.uploadInput.click();
391
+ },
392
+ handleMeitu(key) {
393
+ this.$emit(
394
+ "on-meitu",
395
+ this.fileList.findIndex(item => item.key === key)
396
+ );
397
+ },
398
+ handleAdd() {
399
+ if (!this.disabled) {
400
+ this.editIndex = -1;
401
+ this.$refs.uploadInput.click();
402
+ }
403
+ },
404
+ handlePreviewFile(key) {
405
+ this.viewer && this.viewer.destroy();
406
+ this.uploadId = "upload_" + new Date().getTime();
407
+
408
+ console.log(this.viewer);
409
+ this.$nextTick(() => {
410
+ this.viewer = new Viewer(document.getElementById(this.uploadId));
411
+ this.viewer.view(this.fileList.findIndex(item => item.key === key));
412
+ });
413
+ }
414
+ },
415
+ watch: {
416
+ fileList: {
417
+ deep: true,
418
+ handler(val) {
419
+ // this.$emit('input', this.fileList)
420
+ }
421
+ }
422
+ }
423
+ };
424
+ </script>
425
+
426
+ <style lang="scss">
427
+ .fm-uplaod-container {
428
+ .is-disabled {
429
+ position: relative;
430
+
431
+ &::after {
432
+ position: absolute;
433
+ top: 0;
434
+ bottom: 0;
435
+ left: 0;
436
+ right: 0;
437
+ // background: rgba(0,0,0,.1);
438
+ content: "";
439
+ display: block;
440
+ cursor: not-allowed;
441
+ }
442
+ }
443
+
444
+ .upload-file {
445
+ margin: 0 10px 10px 0;
446
+ display: inline-flex;
447
+ justify-content: center;
448
+ align-items: center;
449
+ // background: #fff;
450
+ overflow: hidden;
451
+ background-color: #fff;
452
+ border: 1px solid #c0ccda;
453
+ border-radius: 6px;
454
+ box-sizing: border-box;
455
+ position: relative;
456
+ vertical-align: top;
457
+ &:hover {
458
+ .uplaod-action {
459
+ display: flex;
460
+ }
461
+ }
462
+ .uplaod-action {
463
+ position: absolute;
464
+ // top: 0;
465
+ // height: 30px;
466
+ bottom: 0;
467
+ left: 0;
468
+ right: 0;
469
+ background: rgba(0, 0, 0, 0.6);
470
+ display: none;
471
+ justify-content: center;
472
+ align-items: center;
473
+ i {
474
+ color: #fff;
475
+ cursor: pointer;
476
+ margin: 0 5px;
477
+ }
478
+ }
479
+ &.is-success {
480
+ .item-status {
481
+ position: absolute;
482
+ right: -15px;
483
+ top: -6px;
484
+ width: 40px;
485
+ height: 24px;
486
+ background: #13ce66;
487
+ text-align: center;
488
+ transform: rotate(45deg);
489
+ box-shadow: 0 0 1pc 1px rgba(0, 0, 0, 0.2);
490
+ & > i {
491
+ font-size: 12px;
492
+ margin-top: 11px;
493
+ color: #fff;
494
+ transform: rotate(-45deg);
495
+ }
496
+ }
497
+ }
498
+ &.uploading {
499
+ &:before {
500
+ display: block;
501
+ content: "";
502
+ position: absolute;
503
+ top: 0;
504
+ left: 0;
505
+ right: 0;
506
+ bottom: 0;
507
+ background: rgba(0, 0, 0, 0.3);
508
+ }
509
+ }
510
+ .upload-progress {
511
+ position: absolute;
512
+ .el-progress__text {
513
+ color: #fff;
514
+ font-size: 16px !important;
515
+ }
516
+ }
517
+ img {
518
+ max-width: 100%;
519
+ max-height: 100%;
520
+ vertical-align: middle;
521
+ }
522
+ }
523
+ .el-upload--picture-card {
524
+ position: relative;
525
+ overflow: hidden;
526
+ .el-icon-plus {
527
+ position: absolute;
528
+ top: 50%;
529
+ left: 50%;
530
+ }
531
+ }
532
+ .upload-input {
533
+ position: absolute;
534
+ top: 0;
535
+ left: 0;
536
+ right: 0;
537
+ bottom: 0;
538
+ display: block;
539
+ opacity: 0;
540
+ cursor: pointer;
541
+ }
542
+
543
+ .drag-img-list {
544
+ display: inline;
545
+
546
+ .ghost {
547
+ position: relative;
548
+ &::after {
549
+ width: 100%;
550
+ height: 100%;
551
+ display: block;
552
+ content: "";
553
+ background: #fbfdff;
554
+ position: absolute;
555
+ top: 0;
556
+ bottom: 0;
557
+ left: 0;
558
+ right: 0;
559
+ border: 1px dashed #3bb3c2;
560
+ }
561
+ }
562
+
563
+ & > div {
564
+ cursor: move;
565
+ }
566
+ }
567
+ }
568
+
569
+ .viewer-container {
570
+ z-index: 9999 !important;
571
+ }
572
+ </style>