tianheng-ui 0.0.40 → 0.0.43

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