tianheng-ui 0.1.81 → 0.1.84

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.
Files changed (32) hide show
  1. package/README.md +72 -15
  2. package/lib/theme-chalk/fonts/formMaking-iconfont.svg +155 -155
  3. package/lib/theme-chalk/fonts/th-iconfont.css +2402 -2402
  4. package/lib/theme-chalk/js/axios.js +87 -87
  5. package/lib/tianheng-ui.js +13 -13
  6. package/package.json +87 -86
  7. package/packages/CodeEditor/index.vue +3 -2
  8. package/packages/FormMaking/GenerateForm.vue +392 -392
  9. package/packages/FormMaking/Upload/index.vue +571 -571
  10. package/packages/FormMaking/WidgetFooter.vue +16 -0
  11. package/packages/FormMaking/WidgetForm.vue +145 -146
  12. package/packages/FormMaking/WidgetTools.vue +21 -16
  13. package/packages/FormMaking/custom/config.js +120 -2
  14. package/packages/FormMaking/custom/configs/number.vue +0 -5
  15. package/packages/FormMaking/custom/configs/page-table.vue +146 -0
  16. package/packages/FormMaking/custom/index.js +1 -1
  17. package/packages/FormMaking/custom/items/page-table.vue +250 -0
  18. package/packages/FormMaking/custom/register.js +43 -43
  19. package/packages/FormMaking/iconfont/demo.css +539 -539
  20. package/packages/FormMaking/iconfont/demo_index.html +1159 -1159
  21. package/packages/FormMaking/iconfont/formMaking-iconfont.css +189 -189
  22. package/packages/FormMaking/iconfont/formMaking-iconfont.svg +155 -155
  23. package/packages/FormMaking/index.js +33 -33
  24. package/packages/FormMaking/index.vue +6 -1
  25. package/packages/FormMaking/lang/en-US.js +187 -187
  26. package/packages/FormMaking/lang/zh-CN.js +187 -187
  27. package/packages/FormMaking/network/axios.js +88 -88
  28. package/packages/FormMaking/styles/index.scss +216 -216
  29. package/packages/FormMaking/util/generateCode.js +427 -157
  30. package/packages/FormMaking/util/index.js +98 -98
  31. package/packages/TableMaking/network/axios.js +88 -88
  32. package/packages/TableMaking/widgetConfig.vue +1 -1
@@ -1,571 +1,571 @@
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
- const files = this.$refs.uploadInput.files;
205
-
206
- for (let i = 0; i < files.length; i++) {
207
- const file = files[i];
208
- const reader = new FileReader();
209
- const key =
210
- new Date().getTime() + "_" + Math.ceil(Math.random() * 99999);
211
- reader.readAsDataURL(file);
212
- reader.onload = () => {
213
- if (this.editIndex >= 0) {
214
- this.$set(this.fileList, this.editIndex, {
215
- key,
216
- url: reader.result,
217
- percent: 0,
218
- status: "uploading"
219
- });
220
-
221
- this.editIndex = -1;
222
- } else {
223
- this.fileList.push({
224
- key,
225
- url: reader.result,
226
- percent: 0,
227
- status: "uploading"
228
- });
229
- }
230
-
231
- this.$nextTick(() => {
232
- if (this.isQiniu) {
233
- this.uplaodAction2(reader.result, file, key);
234
- } else {
235
- this.uplaodAction(reader.result, file, key);
236
- }
237
- });
238
- };
239
- }
240
- this.$refs.uploadInput.value = [];
241
- },
242
- uplaodAction(res, file, key) {
243
- let changeIndex = this.fileList.findIndex(item => item.key === key);
244
- console.log(this.fileList.findIndex(item => item.key === key));
245
- const xhr = new XMLHttpRequest();
246
-
247
- const url = this.action;
248
- xhr.open("POST", url, true);
249
- // xhr.setRequestHeader('Content-Type', 'multipart/form-data')
250
-
251
- let formData = new FormData();
252
- formData.append("file", file);
253
-
254
- xhr.onreadystatechange = () => {
255
- console.log(xhr);
256
- if (xhr.readyState === 4) {
257
- let resData = JSON.parse(xhr.response);
258
- if (resData && resData.url) {
259
- this.$set(
260
- this.fileList,
261
- this.fileList.findIndex(item => item.key === key),
262
- {
263
- ...this.fileList[
264
- this.fileList.findIndex(item => item.key === key)
265
- ],
266
- url: resData.url,
267
- percent: 100
268
- }
269
- );
270
- setTimeout(() => {
271
- this.$set(
272
- this.fileList,
273
- this.fileList.findIndex(item => item.key === key),
274
- {
275
- ...this.fileList[
276
- this.fileList.findIndex(item => item.key === key)
277
- ],
278
- status: "success"
279
- }
280
- );
281
- this.$emit("input", this.fileList);
282
- }, 200);
283
- } else {
284
- this.$set(
285
- this.fileList,
286
- this.fileList.findIndex(item => item.key === key),
287
- {
288
- ...this.fileList[
289
- this.fileList.findIndex(item => item.key === key)
290
- ],
291
- status: "error"
292
- }
293
- );
294
- this.fileList.splice(
295
- this.fileList.findIndex(item => item.key === key),
296
- 1
297
- );
298
- }
299
- }
300
- };
301
- xhr.upload.onprogress = res => {
302
- console.log("progress", res);
303
- if (res.total && res.loaded) {
304
- this.$set(
305
- this.fileList[this.fileList.findIndex(item => item.key === key)],
306
- "percent",
307
- (res.loaded / res.total) * 100
308
- );
309
- }
310
- };
311
-
312
- xhr.send(formData);
313
- },
314
- uplaodAction2(res, file, key) {
315
- const _this = this;
316
- const observable = qiniu.upload(
317
- file,
318
- key,
319
- this.token,
320
- {
321
- fname: key,
322
- mimeType: []
323
- },
324
- {
325
- useCdnDomain: true
326
- }
327
- );
328
- observable.subscribe({
329
- next(res) {
330
- _this.$set(
331
- _this.fileList[_this.fileList.findIndex(item => item.key === key)],
332
- "percent",
333
- parseInt(res.total.percent)
334
- );
335
- },
336
- error(err) {
337
- _this.$set(
338
- _this.fileList,
339
- _this.fileList.findIndex(item => item.key === key),
340
- {
341
- ..._this.fileList[
342
- _this.fileList.findIndex(item => item.key === key)
343
- ],
344
- status: "error"
345
- }
346
- );
347
- _this.fileList.splice(
348
- _this.fileList.findIndex(item => item.key === key),
349
- 1
350
- );
351
- },
352
- complete(res) {
353
- _this.$set(
354
- _this.fileList,
355
- _this.fileList.findIndex(item => item.key === key),
356
- {
357
- ..._this.fileList[
358
- _this.fileList.findIndex(item => item.key === key)
359
- ],
360
- url: _this.domain + res.key,
361
- percent: 100
362
- }
363
- );
364
- setTimeout(() => {
365
- _this.$set(
366
- _this.fileList,
367
- _this.fileList.findIndex(item => item.key === key),
368
- {
369
- ..._this.fileList[
370
- _this.fileList.findIndex(item => item.key === key)
371
- ],
372
- status: "success"
373
- }
374
- );
375
- _this.$emit("input", _this.fileList);
376
- }, 200);
377
- }
378
- });
379
- },
380
- handleRemove(key) {
381
- this.fileList.splice(
382
- this.fileList.findIndex(item => item.key === key),
383
- 1
384
- );
385
- },
386
- handleEdit(key) {
387
- this.editIndex = this.fileList.findIndex(item => item.key === key);
388
-
389
- this.$refs.uploadInput.click();
390
- },
391
- handleMeitu(key) {
392
- this.$emit(
393
- "on-meitu",
394
- this.fileList.findIndex(item => item.key === key)
395
- );
396
- },
397
- handleAdd() {
398
- if (!this.disabled) {
399
- this.editIndex = -1;
400
- this.$refs.uploadInput.click();
401
- }
402
- },
403
- handlePreviewFile(key) {
404
- this.viewer && this.viewer.destroy();
405
- this.uploadId = "upload_" + new Date().getTime();
406
-
407
- console.log(this.viewer);
408
- this.$nextTick(() => {
409
- this.viewer = new Viewer(document.getElementById(this.uploadId));
410
- this.viewer.view(this.fileList.findIndex(item => item.key === key));
411
- });
412
- }
413
- },
414
- watch: {
415
- fileList: {
416
- deep: true,
417
- handler(val) {
418
- // this.$emit('input', this.fileList)
419
- }
420
- }
421
- }
422
- };
423
- </script>
424
-
425
- <style lang="scss">
426
- .fm-uplaod-container {
427
- .is-disabled {
428
- position: relative;
429
-
430
- &::after {
431
- position: absolute;
432
- top: 0;
433
- bottom: 0;
434
- left: 0;
435
- right: 0;
436
- // background: rgba(0,0,0,.1);
437
- content: "";
438
- display: block;
439
- cursor: not-allowed;
440
- }
441
- }
442
-
443
- .upload-file {
444
- margin: 0 10px 10px 0;
445
- display: inline-flex;
446
- justify-content: center;
447
- align-items: center;
448
- // background: #fff;
449
- overflow: hidden;
450
- background-color: #fff;
451
- border: 1px solid #c0ccda;
452
- border-radius: 6px;
453
- box-sizing: border-box;
454
- position: relative;
455
- vertical-align: top;
456
- &:hover {
457
- .uplaod-action {
458
- display: flex;
459
- }
460
- }
461
- .uplaod-action {
462
- position: absolute;
463
- // top: 0;
464
- // height: 30px;
465
- bottom: 0;
466
- left: 0;
467
- right: 0;
468
- background: rgba(0, 0, 0, 0.6);
469
- display: none;
470
- justify-content: center;
471
- align-items: center;
472
- i {
473
- color: #fff;
474
- cursor: pointer;
475
- margin: 0 5px;
476
- }
477
- }
478
- &.is-success {
479
- .item-status {
480
- position: absolute;
481
- right: -15px;
482
- top: -6px;
483
- width: 40px;
484
- height: 24px;
485
- background: #13ce66;
486
- text-align: center;
487
- transform: rotate(45deg);
488
- box-shadow: 0 0 1pc 1px rgba(0, 0, 0, 0.2);
489
- & > i {
490
- font-size: 12px;
491
- margin-top: 11px;
492
- color: #fff;
493
- transform: rotate(-45deg);
494
- }
495
- }
496
- }
497
- &.uploading {
498
- &:before {
499
- display: block;
500
- content: "";
501
- position: absolute;
502
- top: 0;
503
- left: 0;
504
- right: 0;
505
- bottom: 0;
506
- background: rgba(0, 0, 0, 0.3);
507
- }
508
- }
509
- .upload-progress {
510
- position: absolute;
511
- .el-progress__text {
512
- color: #fff;
513
- font-size: 16px !important;
514
- }
515
- }
516
- img {
517
- max-width: 100%;
518
- max-height: 100%;
519
- vertical-align: middle;
520
- }
521
- }
522
- .el-upload--picture-card {
523
- position: relative;
524
- overflow: hidden;
525
- .el-icon-plus {
526
- position: absolute;
527
- top: 50%;
528
- left: 50%;
529
- }
530
- }
531
- .upload-input {
532
- position: absolute;
533
- top: 0;
534
- left: 0;
535
- right: 0;
536
- bottom: 0;
537
- display: block;
538
- opacity: 0;
539
- cursor: pointer;
540
- }
541
-
542
- .drag-img-list {
543
- display: inline;
544
-
545
- .ghost {
546
- position: relative;
547
- &::after {
548
- width: 100%;
549
- height: 100%;
550
- display: block;
551
- content: "";
552
- background: #fbfdff;
553
- position: absolute;
554
- top: 0;
555
- bottom: 0;
556
- left: 0;
557
- right: 0;
558
- border: 1px dashed #3bb3c2;
559
- }
560
- }
561
-
562
- & > div {
563
- cursor: move;
564
- }
565
- }
566
- }
567
-
568
- .viewer-container {
569
- z-index: 9999 !important;
570
- }
571
- </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
+ const files = this.$refs.uploadInput.files;
205
+
206
+ for (let i = 0; i < files.length; i++) {
207
+ const file = files[i];
208
+ const reader = new FileReader();
209
+ const key =
210
+ new Date().getTime() + "_" + Math.ceil(Math.random() * 99999);
211
+ reader.readAsDataURL(file);
212
+ reader.onload = () => {
213
+ if (this.editIndex >= 0) {
214
+ this.$set(this.fileList, this.editIndex, {
215
+ key,
216
+ url: reader.result,
217
+ percent: 0,
218
+ status: "uploading"
219
+ });
220
+
221
+ this.editIndex = -1;
222
+ } else {
223
+ this.fileList.push({
224
+ key,
225
+ url: reader.result,
226
+ percent: 0,
227
+ status: "uploading"
228
+ });
229
+ }
230
+
231
+ this.$nextTick(() => {
232
+ if (this.isQiniu) {
233
+ this.uplaodAction2(reader.result, file, key);
234
+ } else {
235
+ this.uplaodAction(reader.result, file, key);
236
+ }
237
+ });
238
+ };
239
+ }
240
+ this.$refs.uploadInput.value = [];
241
+ },
242
+ uplaodAction(res, file, key) {
243
+ let changeIndex = this.fileList.findIndex(item => item.key === key);
244
+ console.log(this.fileList.findIndex(item => item.key === key));
245
+ const xhr = new XMLHttpRequest();
246
+
247
+ const url = this.action;
248
+ xhr.open("POST", url, true);
249
+ // xhr.setRequestHeader('Content-Type', 'multipart/form-data')
250
+
251
+ let formData = new FormData();
252
+ formData.append("file", file);
253
+
254
+ xhr.onreadystatechange = () => {
255
+ console.log(xhr);
256
+ if (xhr.readyState === 4) {
257
+ let resData = JSON.parse(xhr.response);
258
+ if (resData && resData.url) {
259
+ this.$set(
260
+ this.fileList,
261
+ this.fileList.findIndex(item => item.key === key),
262
+ {
263
+ ...this.fileList[
264
+ this.fileList.findIndex(item => item.key === key)
265
+ ],
266
+ url: resData.url,
267
+ percent: 100
268
+ }
269
+ );
270
+ setTimeout(() => {
271
+ this.$set(
272
+ this.fileList,
273
+ this.fileList.findIndex(item => item.key === key),
274
+ {
275
+ ...this.fileList[
276
+ this.fileList.findIndex(item => item.key === key)
277
+ ],
278
+ status: "success"
279
+ }
280
+ );
281
+ this.$emit("input", this.fileList);
282
+ }, 200);
283
+ } else {
284
+ this.$set(
285
+ this.fileList,
286
+ this.fileList.findIndex(item => item.key === key),
287
+ {
288
+ ...this.fileList[
289
+ this.fileList.findIndex(item => item.key === key)
290
+ ],
291
+ status: "error"
292
+ }
293
+ );
294
+ this.fileList.splice(
295
+ this.fileList.findIndex(item => item.key === key),
296
+ 1
297
+ );
298
+ }
299
+ }
300
+ };
301
+ xhr.upload.onprogress = res => {
302
+ console.log("progress", res);
303
+ if (res.total && res.loaded) {
304
+ this.$set(
305
+ this.fileList[this.fileList.findIndex(item => item.key === key)],
306
+ "percent",
307
+ (res.loaded / res.total) * 100
308
+ );
309
+ }
310
+ };
311
+
312
+ xhr.send(formData);
313
+ },
314
+ uplaodAction2(res, file, key) {
315
+ const _this = this;
316
+ const observable = qiniu.upload(
317
+ file,
318
+ key,
319
+ this.token,
320
+ {
321
+ fname: key,
322
+ mimeType: []
323
+ },
324
+ {
325
+ useCdnDomain: true
326
+ }
327
+ );
328
+ observable.subscribe({
329
+ next(res) {
330
+ _this.$set(
331
+ _this.fileList[_this.fileList.findIndex(item => item.key === key)],
332
+ "percent",
333
+ parseInt(res.total.percent)
334
+ );
335
+ },
336
+ error(err) {
337
+ _this.$set(
338
+ _this.fileList,
339
+ _this.fileList.findIndex(item => item.key === key),
340
+ {
341
+ ..._this.fileList[
342
+ _this.fileList.findIndex(item => item.key === key)
343
+ ],
344
+ status: "error"
345
+ }
346
+ );
347
+ _this.fileList.splice(
348
+ _this.fileList.findIndex(item => item.key === key),
349
+ 1
350
+ );
351
+ },
352
+ complete(res) {
353
+ _this.$set(
354
+ _this.fileList,
355
+ _this.fileList.findIndex(item => item.key === key),
356
+ {
357
+ ..._this.fileList[
358
+ _this.fileList.findIndex(item => item.key === key)
359
+ ],
360
+ url: _this.domain + res.key,
361
+ percent: 100
362
+ }
363
+ );
364
+ setTimeout(() => {
365
+ _this.$set(
366
+ _this.fileList,
367
+ _this.fileList.findIndex(item => item.key === key),
368
+ {
369
+ ..._this.fileList[
370
+ _this.fileList.findIndex(item => item.key === key)
371
+ ],
372
+ status: "success"
373
+ }
374
+ );
375
+ _this.$emit("input", _this.fileList);
376
+ }, 200);
377
+ }
378
+ });
379
+ },
380
+ handleRemove(key) {
381
+ this.fileList.splice(
382
+ this.fileList.findIndex(item => item.key === key),
383
+ 1
384
+ );
385
+ },
386
+ handleEdit(key) {
387
+ this.editIndex = this.fileList.findIndex(item => item.key === key);
388
+
389
+ this.$refs.uploadInput.click();
390
+ },
391
+ handleMeitu(key) {
392
+ this.$emit(
393
+ "on-meitu",
394
+ this.fileList.findIndex(item => item.key === key)
395
+ );
396
+ },
397
+ handleAdd() {
398
+ if (!this.disabled) {
399
+ this.editIndex = -1;
400
+ this.$refs.uploadInput.click();
401
+ }
402
+ },
403
+ handlePreviewFile(key) {
404
+ this.viewer && this.viewer.destroy();
405
+ this.uploadId = "upload_" + new Date().getTime();
406
+
407
+ console.log(this.viewer);
408
+ this.$nextTick(() => {
409
+ this.viewer = new Viewer(document.getElementById(this.uploadId));
410
+ this.viewer.view(this.fileList.findIndex(item => item.key === key));
411
+ });
412
+ }
413
+ },
414
+ watch: {
415
+ fileList: {
416
+ deep: true,
417
+ handler(val) {
418
+ // this.$emit('input', this.fileList)
419
+ }
420
+ }
421
+ }
422
+ };
423
+ </script>
424
+
425
+ <style lang="scss">
426
+ .fm-uplaod-container {
427
+ .is-disabled {
428
+ position: relative;
429
+
430
+ &::after {
431
+ position: absolute;
432
+ top: 0;
433
+ bottom: 0;
434
+ left: 0;
435
+ right: 0;
436
+ // background: rgba(0,0,0,.1);
437
+ content: "";
438
+ display: block;
439
+ cursor: not-allowed;
440
+ }
441
+ }
442
+
443
+ .upload-file {
444
+ margin: 0 10px 10px 0;
445
+ display: inline-flex;
446
+ justify-content: center;
447
+ align-items: center;
448
+ // background: #fff;
449
+ overflow: hidden;
450
+ background-color: #fff;
451
+ border: 1px solid #c0ccda;
452
+ border-radius: 6px;
453
+ box-sizing: border-box;
454
+ position: relative;
455
+ vertical-align: top;
456
+ &:hover {
457
+ .uplaod-action {
458
+ display: flex;
459
+ }
460
+ }
461
+ .uplaod-action {
462
+ position: absolute;
463
+ // top: 0;
464
+ // height: 30px;
465
+ bottom: 0;
466
+ left: 0;
467
+ right: 0;
468
+ background: rgba(0, 0, 0, 0.6);
469
+ display: none;
470
+ justify-content: center;
471
+ align-items: center;
472
+ i {
473
+ color: #fff;
474
+ cursor: pointer;
475
+ margin: 0 5px;
476
+ }
477
+ }
478
+ &.is-success {
479
+ .item-status {
480
+ position: absolute;
481
+ right: -15px;
482
+ top: -6px;
483
+ width: 40px;
484
+ height: 24px;
485
+ background: #13ce66;
486
+ text-align: center;
487
+ transform: rotate(45deg);
488
+ box-shadow: 0 0 1pc 1px rgba(0, 0, 0, 0.2);
489
+ & > i {
490
+ font-size: 12px;
491
+ margin-top: 11px;
492
+ color: #fff;
493
+ transform: rotate(-45deg);
494
+ }
495
+ }
496
+ }
497
+ &.uploading {
498
+ &:before {
499
+ display: block;
500
+ content: "";
501
+ position: absolute;
502
+ top: 0;
503
+ left: 0;
504
+ right: 0;
505
+ bottom: 0;
506
+ background: rgba(0, 0, 0, 0.3);
507
+ }
508
+ }
509
+ .upload-progress {
510
+ position: absolute;
511
+ .el-progress__text {
512
+ color: #fff;
513
+ font-size: 16px !important;
514
+ }
515
+ }
516
+ img {
517
+ max-width: 100%;
518
+ max-height: 100%;
519
+ vertical-align: middle;
520
+ }
521
+ }
522
+ .el-upload--picture-card {
523
+ position: relative;
524
+ overflow: hidden;
525
+ .el-icon-plus {
526
+ position: absolute;
527
+ top: 50%;
528
+ left: 50%;
529
+ }
530
+ }
531
+ .upload-input {
532
+ position: absolute;
533
+ top: 0;
534
+ left: 0;
535
+ right: 0;
536
+ bottom: 0;
537
+ display: block;
538
+ opacity: 0;
539
+ cursor: pointer;
540
+ }
541
+
542
+ .drag-img-list {
543
+ display: inline;
544
+
545
+ .ghost {
546
+ position: relative;
547
+ &::after {
548
+ width: 100%;
549
+ height: 100%;
550
+ display: block;
551
+ content: "";
552
+ background: #fbfdff;
553
+ position: absolute;
554
+ top: 0;
555
+ bottom: 0;
556
+ left: 0;
557
+ right: 0;
558
+ border: 1px dashed #3bb3c2;
559
+ }
560
+ }
561
+
562
+ & > div {
563
+ cursor: move;
564
+ }
565
+ }
566
+ }
567
+
568
+ .viewer-container {
569
+ z-index: 9999 !important;
570
+ }
571
+ </style>