eoss-ui 0.6.20 → 0.6.22

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 (100) hide show
  1. package/lib/eoss-ui.common.js +439 -420
  2. package/lib/flow.js +118 -118
  3. package/lib/form.js +3 -3
  4. package/lib/index.js +1 -1
  5. package/lib/login.js +69 -60
  6. package/lib/main.js +220 -210
  7. package/lib/qr-code.js +13 -13
  8. package/lib/theme-chalk/index.css +1 -1
  9. package/lib/theme-chalk/login.css +1 -1
  10. package/lib/theme-chalk/selector.css +1 -1
  11. package/package.json +157 -157
  12. package/packages/.DS_Store +0 -0
  13. package/packages/button/src/main.vue +418 -418
  14. package/packages/button-group/src/main.vue +298 -298
  15. package/packages/checkbox-group/.DS_Store +0 -0
  16. package/packages/checkbox-group/src/main.vue +333 -333
  17. package/packages/clients/src/main.vue +144 -144
  18. package/packages/data-table/.DS_Store +0 -0
  19. package/packages/data-table/src/children.vue +39 -39
  20. package/packages/data-table/src/column.vue +983 -983
  21. package/packages/data-table/src/main.vue +1812 -1812
  22. package/packages/data-table/src/sizer.vue +195 -195
  23. package/packages/date-picker/src/main.vue +236 -236
  24. package/packages/dialog/.DS_Store +0 -0
  25. package/packages/flow/src/main.vue +2731 -2731
  26. package/packages/flow-group/src/main.vue +684 -684
  27. package/packages/form/src/main.vue +3582 -3582
  28. package/packages/form/src/table.vue +1420 -1420
  29. package/packages/handle-user/src/main.vue +134 -134
  30. package/packages/handler/.DS_Store +0 -0
  31. package/packages/handler/src/main.vue +374 -374
  32. package/packages/icon/src/main.vue +101 -101
  33. package/packages/input/src/main.vue +356 -356
  34. package/packages/login/.DS_Store +0 -0
  35. package/packages/login/src/main.vue +1857 -1851
  36. package/packages/login/src/resetPassword.vue +562 -557
  37. package/packages/main/.DS_Store +0 -0
  38. package/packages/main/src/.DS_Store +0 -0
  39. package/packages/main/src/default/message.vue +249 -249
  40. package/packages/main/src/default/notice.vue +157 -157
  41. package/packages/main/src/default/userinfo.vue +494 -494
  42. package/packages/main/src/main.vue +65 -57
  43. package/packages/main/src/public/online.vue +89 -89
  44. package/packages/main/src/public/search.vue +454 -454
  45. package/packages/main/src/public/settings.vue +221 -221
  46. package/packages/main/src/simplicity/apps.vue +388 -388
  47. package/packages/main/src/simplicity/avatar.vue +82 -82
  48. package/packages/main/src/simplicity/handler.vue +183 -183
  49. package/packages/main/src/simplicity/index.vue +1931 -1930
  50. package/packages/main/src/simplicity/lists.vue +84 -84
  51. package/packages/main/src/simplicity/menu-list.vue +128 -128
  52. package/packages/main/src/simplicity/message.vue +259 -259
  53. package/packages/main/src/simplicity/notice.vue +190 -190
  54. package/packages/main/src/simplicity/router-page.vue +45 -45
  55. package/packages/main/src/simplicity/sub-menu.vue +241 -241
  56. package/packages/main/src/simplicity/user.vue +248 -248
  57. package/packages/main/src/simplicity/userinfo.vue +306 -304
  58. package/packages/menu/src/main.vue +536 -536
  59. package/packages/pagination/src/main.vue +96 -96
  60. package/packages/qr-code/src/main.vue +170 -170
  61. package/packages/radio-group/src/main.vue +319 -319
  62. package/packages/select/src/main.vue +761 -761
  63. package/packages/selector/src/main.vue +677 -677
  64. package/packages/selector-panel/src/main.vue +1020 -1020
  65. package/packages/selector-panel/src/selection.vue +160 -160
  66. package/packages/tabs/src/main.vue +788 -788
  67. package/packages/theme-chalk/lib/index.css +1 -1
  68. package/packages/theme-chalk/lib/login.css +1 -1
  69. package/packages/theme-chalk/lib/selector.css +1 -1
  70. package/packages/theme-chalk/src/.DS_Store +0 -0
  71. package/packages/theme-chalk/src/base.scss +260 -260
  72. package/packages/theme-chalk/src/button-group.scss +175 -175
  73. package/packages/theme-chalk/src/calendar.scss +113 -113
  74. package/packages/theme-chalk/src/clients.scss +87 -87
  75. package/packages/theme-chalk/src/common/var.scss +4 -1
  76. package/packages/theme-chalk/src/data-table.scss +276 -276
  77. package/packages/theme-chalk/src/dialog.scss +77 -77
  78. package/packages/theme-chalk/src/flow-group.scss +110 -110
  79. package/packages/theme-chalk/src/form.scss +496 -496
  80. package/packages/theme-chalk/src/handler.scss +133 -133
  81. package/packages/theme-chalk/src/icon.scss +1745 -1745
  82. package/packages/theme-chalk/src/icons.scss +99 -99
  83. package/packages/theme-chalk/src/login.scss +928 -917
  84. package/packages/theme-chalk/src/main.scss +632 -632
  85. package/packages/theme-chalk/src/menu.scss +222 -222
  86. package/packages/theme-chalk/src/nav.scss +125 -125
  87. package/packages/theme-chalk/src/pagination.scss +29 -29
  88. package/packages/theme-chalk/src/selector-panel.scss +204 -204
  89. package/packages/theme-chalk/src/selector.scss +1 -1
  90. package/packages/theme-chalk/src/simplicity.scss +1246 -1246
  91. package/packages/theme-chalk/src/tabs.scss +87 -87
  92. package/packages/theme-chalk/src/toolbar.scss +179 -179
  93. package/packages/theme-chalk/src/tree-group.scss +72 -72
  94. package/packages/theme-chalk/src/tree.scss +165 -165
  95. package/packages/upload/src/main.vue +1313 -1313
  96. package/packages/wujie/src/main.vue +145 -145
  97. package/src/.DS_Store +0 -0
  98. package/src/config/api.js +236 -236
  99. package/src/config/image.js +2 -2
  100. package/src/index.js +157 -157
@@ -1,1313 +1,1313 @@
1
- <template>
2
- <el-upload
3
- v-if="isRender && uploadUrl"
4
- ref="upload"
5
- v-bind="$attrs"
6
- class="es-upload"
7
- :list-type="listType"
8
- :wait="1000"
9
- :height="boxHeight"
10
- :multiple="portrait ? false : multiple"
11
- :action="uploadUrl"
12
- :show-file-list="showList"
13
- :file-list="lists"
14
- :result-file="resultFile"
15
- :disabled="isDisabled || isReadonly"
16
- :readonly="isReadonly"
17
- :class="[
18
- {
19
- 'es-avatar-uploader': portrait && !$slots.default,
20
- 'es-upload-readonly': isReadonly && !downloads
21
- },
22
- 'es-upload-' + listType
23
- ]"
24
- :previewAdjunct="host + previewAdjunct"
25
- :headers="headers"
26
- :data="datas"
27
- :show-info="showList ? showInfo : []"
28
- :auto-upload="autoUpload"
29
- :response="true"
30
- :operate="operate"
31
- :accept="accepts"
32
- :drag-sort="isSort"
33
- :preview="preview"
34
- :exclude="excludes"
35
- :download="isDownload"
36
- :deleted="isRemove"
37
- :icons="_icons"
38
- :picture="_picture"
39
- :before-upload="handleBeforeUpload"
40
- :before-remove="handleBeforeRemove"
41
- :on-preview="handlePreview"
42
- :on-downloads="handleDownloads"
43
- :on-download="handleDownload"
44
- :on-sort="handleSort"
45
- :on-success="handleSuccess"
46
- :on-change="handleChange"
47
- :on-remove="handleRemove"
48
- :on-error="handleError"
49
- >
50
- <template v-if="prepend">
51
- <template v-if="Array.isArray(prepend)">
52
- <el-button
53
- v-for="(item, index) in prepend"
54
- v-bind="{ ...item, size: btnSize }"
55
- :key="index"
56
- @click.stop="handleClick(item)"
57
- >
58
- {{ item.label || item.text }}
59
- </el-button>
60
- </template>
61
- <el-button
62
- v-else
63
- v-bind="{ ...prepend, size: btnSize }"
64
- @click.stop="handleClick(prepend)"
65
- >
66
- {{ prepend.label || prepend.text }}
67
- </el-button>
68
- </template>
69
- <slot>
70
- <expand-dom v-if="render" :render="render"></expand-dom>
71
- <template v-else>
72
- <template v-if="portrait">
73
- <img
74
- v-if="profile"
75
- :src="profile"
76
- class="avatar"
77
- :style="{ width: width, height: height }"
78
- />
79
- <i
80
- v-else
81
- class="avatar-uploader-icon"
82
- :class="{ 'el-icon-plus': !isReadonly, 'is-disabled': isDisabled }"
83
- :style="{ width: width, height: height, lineHeight: height }"
84
- ></i>
85
- </template>
86
- <template v-else>
87
- <template v-if="!isReadonly">
88
- <i
89
- class="el-icon-plus es-uploader-icon"
90
- :class="{ 'is-disabled': isDisabled }"
91
- v-if="selectType === 'icon-plus'"
92
- ></i>
93
- <el-button
94
- v-else
95
- class="es-upload-button"
96
- :class="icon"
97
- :type="selectType"
98
- :size="btnSize"
99
- :disabled="isDisabled"
100
- >{{
101
- text ? text : autoUpload ? '点击上传' : '选择文件'
102
- }}</el-button
103
- >
104
- <el-button
105
- class="es-upload-button"
106
- v-if="!autoUpload"
107
- :type="uploadType"
108
- :size="btnSize"
109
- :disabled="isDisabled"
110
- @click.stop="handleUpload"
111
- >
112
- 上传文件
113
- </el-button>
114
- </template>
115
- <el-button
116
- v-if="showFileList && isDownloads"
117
- slot="handle"
118
- class="es-upload-button es-upload-downloads"
119
- :size="btnSize"
120
- @click.stop="handleDownloads"
121
- >
122
- 批量下载
123
- </el-button>
124
- </template>
125
- </template>
126
- </slot>
127
- <template v-if="append">
128
- <template v-if="Array.isArray(append)">
129
- <el-button
130
- v-for="(item, index) in append"
131
- v-bind="{ ...item, size: btnSize }"
132
- :key="index"
133
- @click.stop="handleClick(item)"
134
- >
135
- {{ item.label || item.text }}
136
- </el-button>
137
- </template>
138
- <el-button
139
- v-else
140
- v-bind="{ ...append, size: btnSize }"
141
- @click.stop="handleClick(append)"
142
- >
143
- {{ append.label || append.text }}
144
- </el-button>
145
- </template>
146
- <template slot="tip">
147
- <slot name="tip">
148
- <div v-if="tips" class="el-upload__tip">{{ tips }}</div>
149
- </slot>
150
- </template>
151
- <el-image-viewer
152
- slot="dialog"
153
- v-if="previewScale && showImg"
154
- :z-index="9999"
155
- :initial-index="0"
156
- :url-list="[imgUrl]"
157
- :on-close="closeViewer"
158
- ></el-image-viewer>
159
- <es-dialog v-else :title="title" :visible.sync="showImg" slot="dialog">
160
- <div
161
- v-loading="imgChange"
162
- element-loading-background="rgba(0, 0, 0, 0.8)"
163
- class="es-upload-dialog"
164
- >
165
- <img v-show="!imgChange" ref="showImg" :src="imgUrl" :style="styles" />
166
- </div>
167
- </es-dialog>
168
- <es-dialog :title="title" :visible.sync="showVideo" slot="dialog">
169
- <es-player
170
- autoplay
171
- type="video/mp4"
172
- :is-pause="!showVideo"
173
- :source="source"
174
- ></es-player>
175
- </es-dialog>
176
- </el-upload>
177
- </template>
178
- <script>
179
- import {
180
- getAdjunctProperties,
181
- uploads,
182
- uploadOnlyOne,
183
- getAdjunctFileInfos,
184
- uploadDownloads,
185
- previewAdjunctOffice,
186
- previewAdjunct,
187
- previewAdjunct2,
188
- uploadSort,
189
- delAdjunct,
190
- downloadByAdjunctId
191
- } from 'eoss-ui/src/config/api.js';
192
- import { debounce } from 'throttle-debounce';
193
- import util from 'eoss-ui/src/utils/util.js';
194
- import picture from './picture.js';
195
- import store from 'eoss-ui/src/utils/store';
196
- import { Base64 } from 'js-base64';
197
- export default {
198
- name: 'EsUpload',
199
- components: {
200
- expandDom: {
201
- functional: true,
202
- props: {
203
- render: [Function, String]
204
- },
205
- render: (h, ctx) => {
206
- if (typeof ctx.props.render == 'string') {
207
- try {
208
- return util.toFunction(ctx.props.render)(h, params);
209
- } catch (error) {
210
- throw error;
211
- }
212
- }
213
- return ctx.props.render(h);
214
- }
215
- }
216
- },
217
- inheritAttrs: false,
218
- inject: {
219
- elForm: {
220
- default: ''
221
- },
222
- elFormItem: {
223
- default: ''
224
- }
225
- },
226
- props: {
227
- prepend: [Array, Object],
228
- append: [Array, Object],
229
- render: Function,
230
- template: String,
231
- value: [String, Array, Object],
232
- name: String,
233
- method: {
234
- type: String,
235
- default: 'get'
236
- },
237
- text: String,
238
- icon: String,
239
- headers: {
240
- type: Object,
241
- default() {
242
- return util.getStorage();
243
- }
244
- },
245
- listType: {
246
- type: String,
247
- default: 'text' // text,picture,picture-card
248
- },
249
- operate: {
250
- type: Boolean,
251
- default: true
252
- },
253
- accept: String,
254
- // 附件code
255
- code: String,
256
- // 业务id
257
- ownId: String,
258
- //附件文档id
259
- documentId: String,
260
- requiredOwnId: {
261
- type: Boolean,
262
- default: true
263
- },
264
- //
265
- downloads: {
266
- type: Boolean,
267
- default: false
268
- },
269
- // 附件扩展编码
270
- extendCode: String,
271
- // 是否添加文件md5值
272
- fileMd5: {
273
- type: Boolean,
274
- default: false
275
- },
276
- // 额外的参数
277
- data: {
278
- type: Object,
279
- default() {
280
- return {};
281
- }
282
- },
283
- param: {
284
- type: Object,
285
- default() {
286
- return {};
287
- }
288
- },
289
- // 单文件大小
290
- size: Number,
291
- totalSize: Number,
292
- // 是否头像模式上传
293
- portrait: {
294
- type: Boolean,
295
- default: false
296
- },
297
- photo: [String, Boolean],
298
- //头像按钮框宽度
299
- width: String,
300
- //头像按钮框高度度
301
- height: String,
302
- // 自定义的文字提示
303
- tips: {
304
- type: String,
305
- default: ''
306
- },
307
- dragSort: {
308
- type: Boolean,
309
- default: false
310
- },
311
- // 上传成功后绑定到file的内容
312
- showInfo: {
313
- type: Array,
314
- default() {
315
- return ['uploadTime', 'fileSize', 'userName'];
316
- }
317
- },
318
- // 上传地址
319
- action: String,
320
- // 自动上传
321
- autoUpload: {
322
- type: Boolean,
323
- default: true
324
- },
325
- // 是否支持多选文件
326
- multiple: {
327
- type: Boolean,
328
- default: true
329
- },
330
- // 显示文件列表
331
- showFileList: {
332
- type: Boolean,
333
- default: true
334
- },
335
- // 上传的文件列表
336
- fileList: [Array, String],
337
- requestFiles: {
338
- type: Boolean,
339
- default: true
340
- },
341
- filesParam: {
342
- type: Object,
343
- default() {
344
- return {};
345
- }
346
- },
347
- state: {
348
- type: Number,
349
- default: 1
350
- },
351
- selectType: {
352
- type: String,
353
- default: 'primary'
354
- },
355
- uploadType: {
356
- type: String,
357
- default: 'success'
358
- },
359
- host: {
360
- type: String,
361
- default() {
362
- return util.getStorage('host') ? util.getStorage('host') : '';
363
- }
364
- },
365
- message: Object,
366
- btnSize: {
367
- type: String,
368
- default: 'medium'
369
- },
370
- // 只读
371
- readonly: {
372
- type: Boolean,
373
- default: false
374
- },
375
- disabled: Boolean,
376
- preview: { type: [Boolean, String], default: true },
377
- exclude: String,
378
- download: { type: [Boolean, String], default: true },
379
- deleted: { type: [Boolean, String], default: true },
380
- remove: { type: [Boolean, String], default: true },
381
- beforeUpload: Function,
382
- onPreview: Function,
383
- // 文件列表排序
384
- onSort: Function,
385
- beforeRemove: Function,
386
- onDownloads: Function,
387
- onDownload: Function,
388
- onSort: Function,
389
- onSuccess: Function,
390
- onChange: Function,
391
- onRemove: Function,
392
- onError: Function,
393
- dangerouslyUseHTMLString: Boolean,
394
- fileCount: Number,
395
- listHeight: String,
396
- display: Boolean,
397
- resultFile: {
398
- type: Boolean,
399
- default: true
400
- },
401
- properties: {
402
- type: String,
403
- default() {
404
- return getAdjunctProperties;
405
- }
406
- },
407
- icons: {
408
- type: Object,
409
- default() {
410
- return {};
411
- }
412
- },
413
- picture: {
414
- type: Object,
415
- default() {
416
- return {};
417
- }
418
- },
419
- previewScale: {
420
- type: Boolean,
421
- default: true
422
- },
423
- useCaseCode: String
424
- },
425
- data() {
426
- return {
427
- uploadUrl: this.action,
428
- lists: [],
429
- image: '',
430
- fileAccept: '',
431
- fileSize: 0,
432
- fileTotalSize: 0,
433
- filesTotalSize: 0,
434
- showImg: false,
435
- imgChange: false,
436
- title: '',
437
- imgUrl: '',
438
- styles: {},
439
- showVideo: false,
440
- videoChange: false,
441
- source: '',
442
- excludeNames: '',
443
- boxHeight: this.listHeight,
444
- previewAdjunct: previewAdjunct,
445
- kkfileview: null,
446
- dochubConfig: {}
447
- };
448
- },
449
- computed: {
450
- isRender() {
451
- let useCaseCodes = util.getStorage('useCaseCodes');
452
- if (useCaseCodes && this.useCaseCode) {
453
- return useCaseCodes.indexOf(this.useCaseCode) > -1;
454
- }
455
- return true;
456
- },
457
- _icons() {
458
- return {
459
- ppt: 'es-icon-ppt',
460
- png: 'es-icon-picture',
461
- gif: 'es-icon-picture',
462
- jpg: 'es-icon-picture',
463
- xls: 'es-icon-excel',
464
- xlsx: 'es-icon-excel',
465
- docx: 'es-icon-word',
466
- doc: 'es-icon-word',
467
- rar: 'es-icon-zip',
468
- zip: 'es-icon-zip',
469
- txt: 'es-icon-txt',
470
- ipa: 'es-icon-ios',
471
- apk: 'es-icon-android',
472
- mp4: 'es-icon-video',
473
- avi: 'es-icon-video',
474
- mp3: 'es-icon-audioo',
475
- wma: 'es-icon-audioo',
476
- pdf: 'es-icon-pdf',
477
- ...this.icons
478
- };
479
- },
480
- _picture() {
481
- return {
482
- ...picture,
483
- ...this.picture
484
- };
485
- },
486
- show() {
487
- if ((this.photo && typeof this.photo === 'string') || this.value) {
488
- return false;
489
- }
490
- return this.showFileList;
491
- },
492
- excludes() {
493
- return this.exclude ? this.exclude : this.excludeNames;
494
- },
495
- accepts() {
496
- return this.accept
497
- ? this.accept
498
- : this.fileAccept
499
- ? this.fileAccept
500
- : this.portrait
501
- ? 'image/*'
502
- : undefined;
503
- },
504
- _size() {
505
- return this.size ? this.size : this.fileSize ? this.fileSize : 0;
506
- },
507
- _totalSize() {
508
- return this.totalSize
509
- ? this.totalSize
510
- : this.fileTotalSize
511
- ? this.fileTotalSize
512
- : 0;
513
- },
514
- getAdjunctFileInfos() {
515
- return typeof this.fileList === 'string'
516
- ? this.fileList
517
- : getAdjunctFileInfos;
518
- },
519
- showList() {
520
- return this.portrait ? false : this.showFileList;
521
- },
522
- isDownloads() {
523
- return this.downloads;
524
- },
525
- isDownload() {
526
- if (this.download) {
527
- return true;
528
- }
529
- return false;
530
- },
531
- isDisabled() {
532
- return this.disabled || (this.elForm || {}).disabled;
533
- },
534
- isReadonly() {
535
- return this.readonly || (this.elForm || {}).readonly;
536
- },
537
- isRemove() {
538
- if (this.remove == false || this.deleted == false) {
539
- return false;
540
- }
541
- return true;
542
- },
543
- isSort() {
544
- return this.dragSort && !this.isDisabled && this.isReadonly;
545
- },
546
- datas() {
547
- if (this.data) {
548
- return util.extend({}, this.data, this.params);
549
- }
550
- return this.params;
551
- },
552
- params() {
553
- let params = { userId: util.getStorage('userId'), ...this.param };
554
- if (this.code !== undefined) {
555
- params.code = this.code;
556
- params.bucketCode = this.code;
557
- }
558
- if (this.ownId !== undefined) {
559
- params.ownId = this.ownId;
560
- params.businessId = this.ownId;
561
- }
562
- return params;
563
- },
564
- showMessage() {
565
- if (this.message !== undefined) {
566
- return util.extend({}, { success: true, error: true }, this.message);
567
- }
568
- return { success: true, error: true };
569
- },
570
- profile() {
571
- if (this.image) {
572
- if (typeof this.image === 'string') {
573
- return this.image;
574
- }
575
- return (
576
- this.host + this.previewAdjunct + '?adjunctId=' + this.image.adjunctId
577
- );
578
- }
579
- if (this.value) {
580
- if (typeof this.value === 'string') {
581
- if (this.value.indexOf('data:image/') === 0) {
582
- return this.value;
583
- } else if (this.value.indexOf(this.previewAdjunct) > -1) {
584
- let val =
585
- this.host +
586
- util.jointUrl({
587
- url: this.value,
588
- reg: '/main2'
589
- });
590
- return val;
591
- } else if (this.value.indexOf('/') === -1) {
592
- return this.host + this.previewAdjunct + '?adjunctId=' + this.value;
593
- }
594
- return this.value;
595
- } else if (Array.isArray(this.value)) {
596
- let adjunctId = this.value[0].response
597
- ? this.value[0].response.adjunctId
598
- : this.value[0].adjunctId;
599
- return this.host + this.previewAdjunct + '?adjunctId=' + adjunctId;
600
- } else {
601
- let adjunctId = this.value.response
602
- ? this.value.response.adjunctId
603
- : this.value.adjunctId;
604
- return this.host + this.previewAdjunct + '?adjunctId=' + adjunctId;
605
- }
606
- }
607
- if (this.photo && typeof this.photo === 'string') {
608
- if (this.photo.indexOf('data:image/') === 0) {
609
- return this.photo;
610
- } else if (this.photo.indexOf(this.previewAdjunct) > -1) {
611
- let val =
612
- this.host +
613
- util.jointUrl({
614
- url: this.value,
615
- reg: '/main2'
616
- });
617
- return val;
618
- } else if (this.photo.indexOf('/') === -1) {
619
- return this.host + this.previewAdjunct + '?adjunctId=' + this.photo;
620
- }
621
- }
622
- return this.photo;
623
- }
624
- },
625
- watch: {
626
- fileList: {
627
- immediate: true,
628
- deep: true,
629
- handler(val) {
630
- if (Array.isArray(val) && val.length > 0) {
631
- this.lists = val;
632
- let filesTotalSize = 0;
633
- val.forEach((item) => {
634
- if (
635
- Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
636
- item.fileSize
637
- ) {
638
- filesTotalSize += parseFloat(item.fileSize, 10);
639
- } else {
640
- filesTotalSize += item.size
641
- ? Math.round((item.size / 1024) * 10) / 10
642
- : 0;
643
- }
644
- });
645
- this.filesTotalSize = filesTotalSize;
646
- this.$emit('input', val);
647
- }
648
- }
649
- },
650
- value: {
651
- immediate: true,
652
- deep: true,
653
- handler(val) {
654
- if (val && typeof val === 'object' && this.showFileList) {
655
- if (Array.isArray(val)) {
656
- this.lists = val;
657
- } else {
658
- this.lists = [val];
659
- }
660
- }
661
- }
662
- },
663
- params: {
664
- deep: true,
665
- handler(val) {
666
- this.getFiles(val);
667
- }
668
- },
669
- lists: {
670
- deep: true,
671
- handler(val) {
672
- this.$emit('update:fileCount', val.length);
673
- }
674
- },
675
- display(val) {
676
- val && this.getHeight();
677
- }
678
- },
679
- beforeCreate() {
680
- this.getFiles = debounce(500, (params) => {
681
- this.getFileLists(params);
682
- });
683
- this.getAdjunctPropertie = debounce(500, () => {
684
- this.getAdjunctProperties();
685
- });
686
- },
687
- created() {
688
- const dochubConfig = sessionStorage.getItem('dochubConfig');
689
- if (dochubConfig) {
690
- this.dochubConfig = JSON.parse(dochubConfig);
691
- }
692
- this.getAdjunctPropertie();
693
- },
694
- mounted() {
695
- this.$nextTick(() => {
696
- this.getHeight();
697
- });
698
- },
699
- methods: {
700
- getHeight() {
701
- if (this.height === 'auto') {
702
- let pt =
703
- parseInt(util.getStyle(this.$el.parentNode, 'padding-top'), 10) || 0;
704
- let pb =
705
- parseInt(util.getStyle(this.$el.parentNode, 'padding-bottom'), 10) ||
706
- 0;
707
- let btn = this.$refs.upload
708
- ? this.$refs.upload.$children[0].$el.offsetHeight || 0
709
- : 0;
710
- this.boxHeight =
711
- this.$el.parentNode.offsetHeight - pt - pb - btn + 'px';
712
- }
713
- },
714
- //根据code获取附件参数配置
715
- getAdjunctProperties() {
716
- if (this.code !== undefined) {
717
- let config = store.get(this.code);
718
- if (config) {
719
- this.fileAccept = config.accept;
720
- this.fileSize = config.size;
721
- this.fileTotalSize = config.totalSize;
722
- if (config.dochubConfig) {
723
- this.dochubConfig = config.dochubConfig;
724
- }
725
-
726
- let url =
727
- this.portrait || this.documentId
728
- ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
729
- : this.dochubConfig.uploadDocumentUrl || uploads;
730
- this.uploadUrl = url.indexOf(this.host) > -1 ? url : this.host + url;
731
- this.requestFiles && this.getFiles(this.params);
732
- } else {
733
- util
734
- .ajax({
735
- method: this.method,
736
- url: this.properties,
737
- data: { code: this.code, ...this.param },
738
- params: { code: this.code, ...this.param }
739
- })
740
- .then((res) => {
741
- if (res.rCode === 0) {
742
- if (res.results) {
743
- this.excludeNames = res.results.excludeName;
744
- if (res.results.fileTypeExtName) {
745
- let fileTypeExtName =
746
- res.results.fileTypeExtName.split(';');
747
- this.fileAccept = fileTypeExtName
748
- .filter((item) => {
749
- return item;
750
- })
751
- .join(',');
752
- }
753
- if (res.results.dochubConfig) {
754
- this.dochubConfig = res.results.dochubConfig;
755
- sessionStorage.setItem(
756
- 'dochubConfig',
757
- JSON.stringify(res.results.dochubConfig)
758
- );
759
- }
760
- let url = this.portrait
761
- ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
762
- : this.dochubConfig.uploadDocumentUrl || uploads;
763
- this.uploadUrl =
764
- url.indexOf(this.host) > -1 ? url : this.host + url;
765
- if (res.results.kkViewRootPath) {
766
- this.kkfileview = res.results.kkViewRootPath;
767
- }
768
- this.fileSize = res.results.limitFileSize
769
- ? res.results.limitFileSize
770
- : 0;
771
- this.fileTotalSize = res.results.limitTotalSize;
772
- store.set(this.code, {
773
- accept: this.fileAccept,
774
- size: this.fileSize,
775
- totalSize: this.fileTotalSize,
776
- dochubConfig: this.dochubConfig
777
- });
778
- }
779
- this.requestFiles && this.getFiles(this.params);
780
- }
781
- })
782
- .catch((err) => {
783
- if (err.message && err.message !== 'canceled') {
784
- this.$message.error(err.message);
785
- }
786
- });
787
- }
788
- }
789
- },
790
- getFileLists(params) {
791
- if (
792
- !this.show ||
793
- (this.fileList &&
794
- Array.isArray(this.fileList) &&
795
- this.fileList.length) ||
796
- (this.requiredOwnId &&
797
- !Object.prototype.hasOwnProperty.call(params, 'ownId'))
798
- ) {
799
- return false;
800
- }
801
- let url =
802
- typeof this.fileList === 'string'
803
- ? this.fileList
804
- : this.dochubConfig.getDocumentList
805
- ? this.dochubConfig.getDocumentList
806
- : getAdjunctFileInfos;
807
- util
808
- .ajax({
809
- method: this.method,
810
- url: url,
811
- data: params,
812
- params: params,
813
- format: false
814
- })
815
- .then((res) => {
816
- if (res.rCode === 0) {
817
- if (this.portrait === true) {
818
- this.image = JSON.parse(JSON.stringify(res.results))[0];
819
- } else {
820
- this.lists = JSON.parse(JSON.stringify(res.results));
821
- let filesTotalSize = 0;
822
- this.lists.forEach((item) => {
823
- if (
824
- Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
825
- item.fileSize
826
- ) {
827
- filesTotalSize += parseFloat(item.fileSize, 10);
828
- } else {
829
- filesTotalSize += item.size
830
- ? Math.round((item.size / 1024) * 10) / 10
831
- : 0;
832
- }
833
- });
834
- this.filesTotalSize = filesTotalSize;
835
- if (this.lists.length) {
836
- this.$emit('input', this.lists);
837
- }
838
- }
839
- } else {
840
- let msg = res.msg || '系统错误,请联系管理员!';
841
- this.$message.error(msg);
842
- }
843
- })
844
- .catch((err) => {
845
- if (err.message && err.message !== 'canceled') {
846
- this.$message.error(err.message);
847
- }
848
- });
849
- },
850
- handleUpload() {
851
- this.$refs.upload.submit();
852
- },
853
- openKkfileview(file) {
854
- let host = util.win.location.origin;
855
- if (this.host) {
856
- if (util.startWith(this.host, 'http')) {
857
- host = this.host;
858
- } else {
859
- host += this.host;
860
- }
861
- }
862
- let url = encodeURIComponent(
863
- Base64.encode(
864
- host +
865
- (typeof this.download === 'string'
866
- ? this.download
867
- : downloadByAdjunctId) +
868
- `?adjunctId=${
869
- file.adjunctId || file.response.adjunctId
870
- }&fullfilename=${file.originalName}`
871
- )
872
- );
873
- util.win.open(`${this.kkfileview}?url=${url}`);
874
- },
875
- handlePreview(res) {
876
- if (this.preview) {
877
- if (this.onPreview) {
878
- this.onPreview(res);
879
- } else {
880
- let file = res.response ? res.response : res;
881
- let url =
882
- typeof this.preview === 'string'
883
- ? this.preview
884
- : typeof this.preview === 'function'
885
- ? this.preview(file)
886
- : null;
887
- if (res.status === 'success') {
888
- let suffix = file.suffix;
889
- suffix = suffix.toLowerCase();
890
- if (this.dochubConfig.previewDocumentUrl) {
891
- if (
892
- suffix.includes('jpge') ||
893
- suffix.includes('jpg') ||
894
- suffix.includes('gif') ||
895
- suffix.includes('png')
896
- ) {
897
- this.imgUrl =
898
- res.url && util.startWith(url, ['http', '/', true])
899
- ? res.url
900
- : this.host +
901
- (url
902
- ? url
903
- : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`);
904
- this.title = file.originalName;
905
- this.showImg = true;
906
- this.$nextTick(() => {
907
- this.loadImage();
908
- });
909
- } else if (suffix.includes('mp4')) {
910
- this.source = {
911
- src:
912
- this.host +
913
- (url
914
- ? url
915
- : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`)
916
- };
917
- this.title = file.originalName;
918
- this.showVideo = true;
919
- } else {
920
- util.win.open(
921
- this.host +
922
- (url
923
- ? url
924
- : `${this.dochubConfig.previewDocumentUrl}?documentId=${file.adjunctId}&action=附件预览`)
925
- );
926
- }
927
- } else {
928
- if (
929
- suffix.includes('doc') ||
930
- suffix.includes('docx') ||
931
- suffix.includes('xls') ||
932
- suffix.includes('xlsx') ||
933
- suffix.includes('ppt')
934
- ) {
935
- if (this.kkfileview) {
936
- this.openKkfileview(file);
937
- } else {
938
- util.win.open(
939
- this.host +
940
- (url ? url : previewAdjunctOffice) +
941
- '?cmd=view&bucketName=' +
942
- file.absolutePath +
943
- '&fileId=' +
944
- file.adjunctId +
945
- '&fileName=' +
946
- file.newName
947
- );
948
- }
949
- } else if (suffix.includes('pdf')) {
950
- if (this.kkfileview) {
951
- this.openKkfileview(file);
952
- } else {
953
- util.win.open(
954
- this.host +
955
- (url ? url : previewAdjunct2) +
956
- '/' +
957
- file.originalName +
958
- '?adjunctId=' +
959
- file.adjunctId
960
- );
961
- }
962
- } else if (
963
- suffix.includes('jpge') ||
964
- suffix.includes('jpg') ||
965
- suffix.includes('gif') ||
966
- suffix.includes('png')
967
- ) {
968
- this.imgUrl =
969
- res.url && util.startWith(url, ['http', '/', true])
970
- ? res.url
971
- : this.host +
972
- (url ? url : this.previewAdjunct) +
973
- '?adjunctId=' +
974
- file.adjunctId;
975
- this.title = file.originalName;
976
- this.showImg = true;
977
- this.$nextTick(() => {
978
- this.loadImage();
979
- });
980
- } else if (suffix.includes('mp4')) {
981
- this.source = {
982
- src:
983
- this.host +
984
- (url ? url : this.previewAdjunct) +
985
- '?adjunctId=' +
986
- file.adjunctId
987
- };
988
- this.title = file.originalName;
989
- this.showVideo = true;
990
- } else {
991
- if (this.kkfileview) {
992
- this.openKkfileview(file);
993
- } else {
994
- util.win.open(
995
- this.host +
996
- (url ? url : this.previewAdjunct) +
997
- '?adjunctId=' +
998
- file.adjunctId
999
- );
1000
- }
1001
- }
1002
- }
1003
- } else {
1004
- util.win.open(URL.createObjectURL(file.raw));
1005
- }
1006
- }
1007
- }
1008
- },
1009
- closeViewer() {
1010
- this.showImg = false;
1011
- },
1012
- loadImage() {
1013
- this.$refs.showImg &&
1014
- (this.$refs.showImg.onload = () => {
1015
- this.imgChange = false;
1016
- let w = this.$refs.showImg.naturalWidth;
1017
- let h = this.$refs.showImg.naturalHeight;
1018
- let pw = this.$refs.showImg.parentNode.offsetWidth;
1019
- let ph = this.$refs.showImg.parentNode.offsetHeight;
1020
- if (w / h > pw / ph) {
1021
- this.styles = { 'max-width': '100%' };
1022
- } else {
1023
- this.styles = { 'max-height': '100%' };
1024
- }
1025
- if (w < pw) {
1026
- this.styles.width = w + 'px';
1027
- }
1028
- if (h < ph) {
1029
- this.styles.height = h + 'px';
1030
- }
1031
- });
1032
- },
1033
- isLt(file) {
1034
- let flag = false;
1035
- let flieArr = file.name.split('.');
1036
- let suffix = '.' + flieArr[flieArr.length - 1].toLowerCase();
1037
- if (this.accepts) {
1038
- let accepts = this.accepts.toLowerCase().split(',');
1039
- flag = accepts.includes(suffix);
1040
- if (!flag) {
1041
- this.$message.error(`文件类型错误,请上传${this.accepts}类型文件!`);
1042
- return flag;
1043
- }
1044
- }
1045
- let size = this._size;
1046
- let text = '单个附件';
1047
- let se = Math.round((file.size / 1024) * 10) / 10;
1048
- if (this._size === 0 && this._totalSize === 0) {
1049
- flag = true;
1050
- } else if (this._size > 0 && this._totalSize === 0) {
1051
- flag = se < this._size;
1052
- size = this._size;
1053
- text = '单个附件';
1054
- } else if (this._size === 0 && this._totalSize > 0) {
1055
- flag = this.filesTotalSize + se < this._totalSize;
1056
- size = this._totalSize;
1057
- text = '附件总';
1058
- } else {
1059
- flag = se < this._size && this.filesTotalSize + se < this._totalSize;
1060
- if (se < this._size) {
1061
- size = this._size;
1062
- text = '单个附件';
1063
- } else {
1064
- size = this._totalSize;
1065
- text = '附件总';
1066
- }
1067
- }
1068
- if (!flag) {
1069
- this.$message.error(`上传${text}大小不能超过${size}KB!`);
1070
- return flag;
1071
- }
1072
- return flag;
1073
- },
1074
- handleBeforeUpload(file) {
1075
- const flag = this.isLt(file);
1076
- if (this.portrait) {
1077
- if (flag && this.beforeUpload) {
1078
- return this.beforeUpload(file);
1079
- }
1080
- return flag;
1081
- }
1082
- if (this.beforeUpload) {
1083
- if (flag) {
1084
- return this.beforeUpload(file);
1085
- }
1086
- return flag;
1087
- }
1088
- return flag;
1089
- },
1090
- handleBeforeRemove(file, fileList) {
1091
- if (file && file.status === 'success') {
1092
- return this.$confirm('确定删除文件吗?', '提示', {
1093
- confirmButtonText: '确定',
1094
- cancelButtonText: '取消',
1095
- type: 'warning'
1096
- })
1097
- .then(() => {
1098
- if (this.beforeRemove) {
1099
- return this.beforeRemove(file, fileList);
1100
- } else if (file.status === 'success') {
1101
- let userName =
1102
- file.userName ||
1103
- (file.response && file.response.userName) ||
1104
- util.getStorage('userName');
1105
- // eslint-disable-next-line no-undef
1106
- return new Promise((resolve, reject) => {
1107
- let url =
1108
- typeof this.deleted === 'string'
1109
- ? this.deleted
1110
- : this.remove === 'string'
1111
- ? this.remove
1112
- : this.dochubConfig.deleteDocumentUrl || delAdjunct;
1113
- util
1114
- .ajax({
1115
- method: this.method,
1116
- url: url,
1117
- data: {
1118
- userName: userName,
1119
- documentId: file.adjunctId || file.response.adjunctId,
1120
- id: file.adjunctId || file.response.adjunctId
1121
- },
1122
- params: {
1123
- userName: userName,
1124
- documentId: file.adjunctId || file.response.adjunctId,
1125
- id: file.adjunctId || file.response.adjunctId
1126
- }
1127
- })
1128
- .then((res) => {
1129
- if (res.rCode === 0) {
1130
- let se =
1131
- this.filesTotalSize -
1132
- Math.round((file.size / 1024) * 10) / 10;
1133
- this.filesTotalSize = se;
1134
- this.$message.success(res.msg);
1135
- resolve();
1136
- } else {
1137
- let msg = res.msg || '系统错误,请联系管理员!';
1138
- this.$message.error(msg);
1139
- reject();
1140
- }
1141
- })
1142
- .catch((err) => {
1143
- if (err.message && err.message !== 'canceled') {
1144
- this.$message.error(err.message);
1145
- }
1146
- });
1147
- });
1148
- }
1149
- return true;
1150
- })
1151
- .catch(() => {
1152
- return flag;
1153
- });
1154
- }
1155
- },
1156
- handleDownloads() {
1157
- let url =
1158
- typeof this.downloads === 'string'
1159
- ? this.downloads
1160
- : this.dochubConfig.compressDownloadDocumentUrl || uploadDownloads;
1161
- util.win.open(
1162
- this.host +
1163
- url +
1164
- '?ownId=' +
1165
- this.ownId +
1166
- '&code=' +
1167
- this.code +
1168
- (this.extendCode ? '&extendCode=' + this.extendCode : '')
1169
- );
1170
- },
1171
- handleDownload(file) {
1172
- if (file.status === 'success') {
1173
- let url =
1174
- typeof this.download === 'string'
1175
- ? this.download
1176
- : this.dochubConfig.downloadDocumentUrl || downloadByAdjunctId;
1177
- util.win.open(
1178
- this.host +
1179
- url +
1180
- '?adjunctId=' +
1181
- (file.adjunctId || file.response.adjunctId) +
1182
- '&documentId=' +
1183
- (file.adjunctId || file.response.adjunctId)
1184
- );
1185
- } else {
1186
- this.aLinkDownload(file);
1187
- }
1188
- },
1189
- handleClick(res) {
1190
- if (res.event && typeof res.event === 'function') {
1191
- res.event(res);
1192
- } else {
1193
- this.$emit('click', res);
1194
- }
1195
- },
1196
- aLinkDownload(file) {
1197
- var a = document.createElement('a');
1198
- let event = new MouseEvent('click');
1199
- a.href = URL.createObjectURL(file.raw);
1200
- a.download = file.name;
1201
- a.dispatchEvent(event);
1202
- },
1203
- handleSort(files) {
1204
- if (this.isSort) {
1205
- if (this.onSort) {
1206
- this.onSort(files);
1207
- } else {
1208
- let ids = files.map((item) => {
1209
- if (item.status === 'success') {
1210
- return item.adjunctId || item.response.adjunctId;
1211
- }
1212
- });
1213
- ids = ids.join(',');
1214
- util
1215
- .ajax({
1216
- method: this.method,
1217
- url: this.dochubConfig.sortDocumentsUrl || uploadSort,
1218
- data: {
1219
- ids: ids
1220
- },
1221
- params: {
1222
- ids: ids
1223
- }
1224
- })
1225
- .then((res) => {
1226
- if (res.rCode === 0) {
1227
- this.$message.success(res.msg);
1228
- } else {
1229
- let msg = res.msg || '系统错误,请联系管理员!';
1230
- this.$message.error(msg);
1231
- }
1232
- })
1233
- .catch((err) => {
1234
- if (err.message && err.message !== 'canceled') {
1235
- this.$message.error(err.message);
1236
- }
1237
- });
1238
- }
1239
- }
1240
- },
1241
- handleSuccess(response, file, fileList) {
1242
- if (this.portrait) {
1243
- this.image = URL.createObjectURL(file.raw);
1244
- }
1245
- if (this.showMessage.success) {
1246
- if (response.rCode) {
1247
- if (this.dangerouslyUseHTMLString) {
1248
- this.$alert(
1249
- response.msg ? response.msg : '上传失败:请联系管理员',
1250
- '提示',
1251
- {
1252
- dangerouslyUseHTMLString: true,
1253
- setHeight: response.msg
1254
- }
1255
- ).catch();
1256
- } else {
1257
- this.$message({
1258
- type: 'error',
1259
- message: response.msg || '成功!'
1260
- });
1261
- }
1262
- } else {
1263
- this.$message.success(response.msg);
1264
- }
1265
- }
1266
- let se =
1267
- this.filesTotalSize +
1268
- (this.resultFile ? Math.round((file.size / 1024) * 10) / 10 : 0);
1269
- this.filesTotalSize = se;
1270
- this.onSuccess &&
1271
- this.onSuccess(response, file, fileList, this.dochubConfig);
1272
- this.$emit('success', response, file, fileList, this.dochubConfig);
1273
- if (this.resultFile) {
1274
- if (this.portrait) {
1275
- this.$emit('input', file);
1276
- } else {
1277
- this.$emit('input', fileList);
1278
- }
1279
- if (this.elForm) {
1280
- this.elForm.clearValidate(this.name);
1281
- }
1282
- }
1283
- },
1284
- handleChange(file, fileList) {
1285
- this.$emit('change', fileList);
1286
- this.onChange && this.onChange(file, fileList);
1287
- },
1288
- handleRemove(file, fileList) {
1289
- this.$emit('input', fileList.length ? fileList : '');
1290
- this.$emit('remove', file, fileList);
1291
- this.$emit('change', fileList);
1292
- this.onRemove && this.onRemove(file, fileList);
1293
- },
1294
- handleError(err, file, fileList) {
1295
- if (this.showMessage.error) {
1296
- if (this.dangerouslyUseHTMLString) {
1297
- this.$alert(err.msg ? err.msg : '上传失败:请联系管理员', '提示', {
1298
- dangerouslyUseHTMLString: true,
1299
- setHeight: err.msg
1300
- }).catch();
1301
- } else {
1302
- this.$message({
1303
- type: 'error',
1304
- message: '上传失败:' + (err.msg ? err.msg : '请联系管理员')
1305
- });
1306
- }
1307
- }
1308
- this.$emit('error', err, file, fileList);
1309
- this.onError && this.onError(err, file, fileList);
1310
- }
1311
- }
1312
- };
1313
- </script>
1
+ <template>
2
+ <el-upload
3
+ v-if="isRender && uploadUrl"
4
+ ref="upload"
5
+ v-bind="$attrs"
6
+ class="es-upload"
7
+ :list-type="listType"
8
+ :wait="1000"
9
+ :height="boxHeight"
10
+ :multiple="portrait ? false : multiple"
11
+ :action="uploadUrl"
12
+ :show-file-list="showList"
13
+ :file-list="lists"
14
+ :result-file="resultFile"
15
+ :disabled="isDisabled || isReadonly"
16
+ :readonly="isReadonly"
17
+ :class="[
18
+ {
19
+ 'es-avatar-uploader': portrait && !$slots.default,
20
+ 'es-upload-readonly': isReadonly && !downloads
21
+ },
22
+ 'es-upload-' + listType
23
+ ]"
24
+ :previewAdjunct="host + previewAdjunct"
25
+ :headers="headers"
26
+ :data="datas"
27
+ :show-info="showList ? showInfo : []"
28
+ :auto-upload="autoUpload"
29
+ :response="true"
30
+ :operate="operate"
31
+ :accept="accepts"
32
+ :drag-sort="isSort"
33
+ :preview="preview"
34
+ :exclude="excludes"
35
+ :download="isDownload"
36
+ :deleted="isRemove"
37
+ :icons="_icons"
38
+ :picture="_picture"
39
+ :before-upload="handleBeforeUpload"
40
+ :before-remove="handleBeforeRemove"
41
+ :on-preview="handlePreview"
42
+ :on-downloads="handleDownloads"
43
+ :on-download="handleDownload"
44
+ :on-sort="handleSort"
45
+ :on-success="handleSuccess"
46
+ :on-change="handleChange"
47
+ :on-remove="handleRemove"
48
+ :on-error="handleError"
49
+ >
50
+ <template v-if="prepend">
51
+ <template v-if="Array.isArray(prepend)">
52
+ <el-button
53
+ v-for="(item, index) in prepend"
54
+ v-bind="{ ...item, size: btnSize }"
55
+ :key="index"
56
+ @click.stop="handleClick(item)"
57
+ >
58
+ {{ item.label || item.text }}
59
+ </el-button>
60
+ </template>
61
+ <el-button
62
+ v-else
63
+ v-bind="{ ...prepend, size: btnSize }"
64
+ @click.stop="handleClick(prepend)"
65
+ >
66
+ {{ prepend.label || prepend.text }}
67
+ </el-button>
68
+ </template>
69
+ <slot>
70
+ <expand-dom v-if="render" :render="render"></expand-dom>
71
+ <template v-else>
72
+ <template v-if="portrait">
73
+ <img
74
+ v-if="profile"
75
+ :src="profile"
76
+ class="avatar"
77
+ :style="{ width: width, height: height }"
78
+ />
79
+ <i
80
+ v-else
81
+ class="avatar-uploader-icon"
82
+ :class="{ 'el-icon-plus': !isReadonly, 'is-disabled': isDisabled }"
83
+ :style="{ width: width, height: height, lineHeight: height }"
84
+ ></i>
85
+ </template>
86
+ <template v-else>
87
+ <template v-if="!isReadonly">
88
+ <i
89
+ class="el-icon-plus es-uploader-icon"
90
+ :class="{ 'is-disabled': isDisabled }"
91
+ v-if="selectType === 'icon-plus'"
92
+ ></i>
93
+ <el-button
94
+ v-else
95
+ class="es-upload-button"
96
+ :class="icon"
97
+ :type="selectType"
98
+ :size="btnSize"
99
+ :disabled="isDisabled"
100
+ >{{
101
+ text ? text : autoUpload ? '点击上传' : '选择文件'
102
+ }}</el-button
103
+ >
104
+ <el-button
105
+ class="es-upload-button"
106
+ v-if="!autoUpload"
107
+ :type="uploadType"
108
+ :size="btnSize"
109
+ :disabled="isDisabled"
110
+ @click.stop="handleUpload"
111
+ >
112
+ 上传文件
113
+ </el-button>
114
+ </template>
115
+ <el-button
116
+ v-if="showFileList && isDownloads"
117
+ slot="handle"
118
+ class="es-upload-button es-upload-downloads"
119
+ :size="btnSize"
120
+ @click.stop="handleDownloads"
121
+ >
122
+ 批量下载
123
+ </el-button>
124
+ </template>
125
+ </template>
126
+ </slot>
127
+ <template v-if="append">
128
+ <template v-if="Array.isArray(append)">
129
+ <el-button
130
+ v-for="(item, index) in append"
131
+ v-bind="{ ...item, size: btnSize }"
132
+ :key="index"
133
+ @click.stop="handleClick(item)"
134
+ >
135
+ {{ item.label || item.text }}
136
+ </el-button>
137
+ </template>
138
+ <el-button
139
+ v-else
140
+ v-bind="{ ...append, size: btnSize }"
141
+ @click.stop="handleClick(append)"
142
+ >
143
+ {{ append.label || append.text }}
144
+ </el-button>
145
+ </template>
146
+ <template slot="tip">
147
+ <slot name="tip">
148
+ <div v-if="tips" class="el-upload__tip">{{ tips }}</div>
149
+ </slot>
150
+ </template>
151
+ <el-image-viewer
152
+ slot="dialog"
153
+ v-if="previewScale && showImg"
154
+ :z-index="9999"
155
+ :initial-index="0"
156
+ :url-list="[imgUrl]"
157
+ :on-close="closeViewer"
158
+ ></el-image-viewer>
159
+ <es-dialog v-else :title="title" :visible.sync="showImg" slot="dialog">
160
+ <div
161
+ v-loading="imgChange"
162
+ element-loading-background="rgba(0, 0, 0, 0.8)"
163
+ class="es-upload-dialog"
164
+ >
165
+ <img v-show="!imgChange" ref="showImg" :src="imgUrl" :style="styles" />
166
+ </div>
167
+ </es-dialog>
168
+ <es-dialog :title="title" :visible.sync="showVideo" slot="dialog">
169
+ <es-player
170
+ autoplay
171
+ type="video/mp4"
172
+ :is-pause="!showVideo"
173
+ :source="source"
174
+ ></es-player>
175
+ </es-dialog>
176
+ </el-upload>
177
+ </template>
178
+ <script>
179
+ import {
180
+ getAdjunctProperties,
181
+ uploads,
182
+ uploadOnlyOne,
183
+ getAdjunctFileInfos,
184
+ uploadDownloads,
185
+ previewAdjunctOffice,
186
+ previewAdjunct,
187
+ previewAdjunct2,
188
+ uploadSort,
189
+ delAdjunct,
190
+ downloadByAdjunctId
191
+ } from 'eoss-ui/src/config/api.js';
192
+ import { debounce } from 'throttle-debounce';
193
+ import util from 'eoss-ui/src/utils/util.js';
194
+ import picture from './picture.js';
195
+ import store from 'eoss-ui/src/utils/store';
196
+ import { Base64 } from 'js-base64';
197
+ export default {
198
+ name: 'EsUpload',
199
+ components: {
200
+ expandDom: {
201
+ functional: true,
202
+ props: {
203
+ render: [Function, String]
204
+ },
205
+ render: (h, ctx) => {
206
+ if (typeof ctx.props.render == 'string') {
207
+ try {
208
+ return util.toFunction(ctx.props.render)(h, params);
209
+ } catch (error) {
210
+ throw error;
211
+ }
212
+ }
213
+ return ctx.props.render(h);
214
+ }
215
+ }
216
+ },
217
+ inheritAttrs: false,
218
+ inject: {
219
+ elForm: {
220
+ default: ''
221
+ },
222
+ elFormItem: {
223
+ default: ''
224
+ }
225
+ },
226
+ props: {
227
+ prepend: [Array, Object],
228
+ append: [Array, Object],
229
+ render: Function,
230
+ template: String,
231
+ value: [String, Array, Object],
232
+ name: String,
233
+ method: {
234
+ type: String,
235
+ default: 'get'
236
+ },
237
+ text: String,
238
+ icon: String,
239
+ headers: {
240
+ type: Object,
241
+ default() {
242
+ return util.getStorage();
243
+ }
244
+ },
245
+ listType: {
246
+ type: String,
247
+ default: 'text' // text,picture,picture-card
248
+ },
249
+ operate: {
250
+ type: Boolean,
251
+ default: true
252
+ },
253
+ accept: String,
254
+ // 附件code
255
+ code: String,
256
+ // 业务id
257
+ ownId: String,
258
+ //附件文档id
259
+ documentId: String,
260
+ requiredOwnId: {
261
+ type: Boolean,
262
+ default: true
263
+ },
264
+ //
265
+ downloads: {
266
+ type: Boolean,
267
+ default: false
268
+ },
269
+ // 附件扩展编码
270
+ extendCode: String,
271
+ // 是否添加文件md5值
272
+ fileMd5: {
273
+ type: Boolean,
274
+ default: false
275
+ },
276
+ // 额外的参数
277
+ data: {
278
+ type: Object,
279
+ default() {
280
+ return {};
281
+ }
282
+ },
283
+ param: {
284
+ type: Object,
285
+ default() {
286
+ return {};
287
+ }
288
+ },
289
+ // 单文件大小
290
+ size: Number,
291
+ totalSize: Number,
292
+ // 是否头像模式上传
293
+ portrait: {
294
+ type: Boolean,
295
+ default: false
296
+ },
297
+ photo: [String, Boolean],
298
+ //头像按钮框宽度
299
+ width: String,
300
+ //头像按钮框高度度
301
+ height: String,
302
+ // 自定义的文字提示
303
+ tips: {
304
+ type: String,
305
+ default: ''
306
+ },
307
+ dragSort: {
308
+ type: Boolean,
309
+ default: false
310
+ },
311
+ // 上传成功后绑定到file的内容
312
+ showInfo: {
313
+ type: Array,
314
+ default() {
315
+ return ['uploadTime', 'fileSize', 'userName'];
316
+ }
317
+ },
318
+ // 上传地址
319
+ action: String,
320
+ // 自动上传
321
+ autoUpload: {
322
+ type: Boolean,
323
+ default: true
324
+ },
325
+ // 是否支持多选文件
326
+ multiple: {
327
+ type: Boolean,
328
+ default: true
329
+ },
330
+ // 显示文件列表
331
+ showFileList: {
332
+ type: Boolean,
333
+ default: true
334
+ },
335
+ // 上传的文件列表
336
+ fileList: [Array, String],
337
+ requestFiles: {
338
+ type: Boolean,
339
+ default: true
340
+ },
341
+ filesParam: {
342
+ type: Object,
343
+ default() {
344
+ return {};
345
+ }
346
+ },
347
+ state: {
348
+ type: Number,
349
+ default: 1
350
+ },
351
+ selectType: {
352
+ type: String,
353
+ default: 'primary'
354
+ },
355
+ uploadType: {
356
+ type: String,
357
+ default: 'success'
358
+ },
359
+ host: {
360
+ type: String,
361
+ default() {
362
+ return util.getStorage('host') ? util.getStorage('host') : '';
363
+ }
364
+ },
365
+ message: Object,
366
+ btnSize: {
367
+ type: String,
368
+ default: 'medium'
369
+ },
370
+ // 只读
371
+ readonly: {
372
+ type: Boolean,
373
+ default: false
374
+ },
375
+ disabled: Boolean,
376
+ preview: { type: [Boolean, String], default: true },
377
+ exclude: String,
378
+ download: { type: [Boolean, String], default: true },
379
+ deleted: { type: [Boolean, String], default: true },
380
+ remove: { type: [Boolean, String], default: true },
381
+ beforeUpload: Function,
382
+ onPreview: Function,
383
+ // 文件列表排序
384
+ onSort: Function,
385
+ beforeRemove: Function,
386
+ onDownloads: Function,
387
+ onDownload: Function,
388
+ onSort: Function,
389
+ onSuccess: Function,
390
+ onChange: Function,
391
+ onRemove: Function,
392
+ onError: Function,
393
+ dangerouslyUseHTMLString: Boolean,
394
+ fileCount: Number,
395
+ listHeight: String,
396
+ display: Boolean,
397
+ resultFile: {
398
+ type: Boolean,
399
+ default: true
400
+ },
401
+ properties: {
402
+ type: String,
403
+ default() {
404
+ return getAdjunctProperties;
405
+ }
406
+ },
407
+ icons: {
408
+ type: Object,
409
+ default() {
410
+ return {};
411
+ }
412
+ },
413
+ picture: {
414
+ type: Object,
415
+ default() {
416
+ return {};
417
+ }
418
+ },
419
+ previewScale: {
420
+ type: Boolean,
421
+ default: true
422
+ },
423
+ useCaseCode: String
424
+ },
425
+ data() {
426
+ return {
427
+ uploadUrl: this.action,
428
+ lists: [],
429
+ image: '',
430
+ fileAccept: '',
431
+ fileSize: 0,
432
+ fileTotalSize: 0,
433
+ filesTotalSize: 0,
434
+ showImg: false,
435
+ imgChange: false,
436
+ title: '',
437
+ imgUrl: '',
438
+ styles: {},
439
+ showVideo: false,
440
+ videoChange: false,
441
+ source: '',
442
+ excludeNames: '',
443
+ boxHeight: this.listHeight,
444
+ previewAdjunct: previewAdjunct,
445
+ kkfileview: null,
446
+ dochubConfig: {}
447
+ };
448
+ },
449
+ computed: {
450
+ isRender() {
451
+ let useCaseCodes = util.getStorage('useCaseCodes');
452
+ if (useCaseCodes && this.useCaseCode) {
453
+ return useCaseCodes.indexOf(this.useCaseCode) > -1;
454
+ }
455
+ return true;
456
+ },
457
+ _icons() {
458
+ return {
459
+ ppt: 'es-icon-ppt',
460
+ png: 'es-icon-picture',
461
+ gif: 'es-icon-picture',
462
+ jpg: 'es-icon-picture',
463
+ xls: 'es-icon-excel',
464
+ xlsx: 'es-icon-excel',
465
+ docx: 'es-icon-word',
466
+ doc: 'es-icon-word',
467
+ rar: 'es-icon-zip',
468
+ zip: 'es-icon-zip',
469
+ txt: 'es-icon-txt',
470
+ ipa: 'es-icon-ios',
471
+ apk: 'es-icon-android',
472
+ mp4: 'es-icon-video',
473
+ avi: 'es-icon-video',
474
+ mp3: 'es-icon-audioo',
475
+ wma: 'es-icon-audioo',
476
+ pdf: 'es-icon-pdf',
477
+ ...this.icons
478
+ };
479
+ },
480
+ _picture() {
481
+ return {
482
+ ...picture,
483
+ ...this.picture
484
+ };
485
+ },
486
+ show() {
487
+ if ((this.photo && typeof this.photo === 'string') || this.value) {
488
+ return false;
489
+ }
490
+ return this.showFileList;
491
+ },
492
+ excludes() {
493
+ return this.exclude ? this.exclude : this.excludeNames;
494
+ },
495
+ accepts() {
496
+ return this.accept
497
+ ? this.accept
498
+ : this.fileAccept
499
+ ? this.fileAccept
500
+ : this.portrait
501
+ ? 'image/*'
502
+ : undefined;
503
+ },
504
+ _size() {
505
+ return this.size ? this.size : this.fileSize ? this.fileSize : 0;
506
+ },
507
+ _totalSize() {
508
+ return this.totalSize
509
+ ? this.totalSize
510
+ : this.fileTotalSize
511
+ ? this.fileTotalSize
512
+ : 0;
513
+ },
514
+ getAdjunctFileInfos() {
515
+ return typeof this.fileList === 'string'
516
+ ? this.fileList
517
+ : getAdjunctFileInfos;
518
+ },
519
+ showList() {
520
+ return this.portrait ? false : this.showFileList;
521
+ },
522
+ isDownloads() {
523
+ return this.downloads;
524
+ },
525
+ isDownload() {
526
+ if (this.download) {
527
+ return true;
528
+ }
529
+ return false;
530
+ },
531
+ isDisabled() {
532
+ return this.disabled || (this.elForm || {}).disabled;
533
+ },
534
+ isReadonly() {
535
+ return this.readonly || (this.elForm || {}).readonly;
536
+ },
537
+ isRemove() {
538
+ if (this.remove == false || this.deleted == false) {
539
+ return false;
540
+ }
541
+ return true;
542
+ },
543
+ isSort() {
544
+ return this.dragSort && !this.isDisabled && this.isReadonly;
545
+ },
546
+ datas() {
547
+ if (this.data) {
548
+ return util.extend({}, this.data, this.params);
549
+ }
550
+ return this.params;
551
+ },
552
+ params() {
553
+ let params = { userId: util.getStorage('userId'), ...this.param };
554
+ if (this.code !== undefined) {
555
+ params.code = this.code;
556
+ params.bucketCode = this.code;
557
+ }
558
+ if (this.ownId !== undefined) {
559
+ params.ownId = this.ownId;
560
+ params.businessId = this.ownId;
561
+ }
562
+ return params;
563
+ },
564
+ showMessage() {
565
+ if (this.message !== undefined) {
566
+ return util.extend({}, { success: true, error: true }, this.message);
567
+ }
568
+ return { success: true, error: true };
569
+ },
570
+ profile() {
571
+ if (this.image) {
572
+ if (typeof this.image === 'string') {
573
+ return this.image;
574
+ }
575
+ return (
576
+ this.host + this.previewAdjunct + '?adjunctId=' + this.image.adjunctId
577
+ );
578
+ }
579
+ if (this.value) {
580
+ if (typeof this.value === 'string') {
581
+ if (this.value.indexOf('data:image/') === 0) {
582
+ return this.value;
583
+ } else if (this.value.indexOf(this.previewAdjunct) > -1) {
584
+ let val =
585
+ this.host +
586
+ util.jointUrl({
587
+ url: this.value,
588
+ reg: '/main2'
589
+ });
590
+ return val;
591
+ } else if (this.value.indexOf('/') === -1) {
592
+ return this.host + this.previewAdjunct + '?adjunctId=' + this.value;
593
+ }
594
+ return this.value;
595
+ } else if (Array.isArray(this.value)) {
596
+ let adjunctId = this.value[0].response
597
+ ? this.value[0].response.adjunctId
598
+ : this.value[0].adjunctId;
599
+ return this.host + this.previewAdjunct + '?adjunctId=' + adjunctId;
600
+ } else {
601
+ let adjunctId = this.value.response
602
+ ? this.value.response.adjunctId
603
+ : this.value.adjunctId;
604
+ return this.host + this.previewAdjunct + '?adjunctId=' + adjunctId;
605
+ }
606
+ }
607
+ if (this.photo && typeof this.photo === 'string') {
608
+ if (this.photo.indexOf('data:image/') === 0) {
609
+ return this.photo;
610
+ } else if (this.photo.indexOf(this.previewAdjunct) > -1) {
611
+ let val =
612
+ this.host +
613
+ util.jointUrl({
614
+ url: this.value,
615
+ reg: '/main2'
616
+ });
617
+ return val;
618
+ } else if (this.photo.indexOf('/') === -1) {
619
+ return this.host + this.previewAdjunct + '?adjunctId=' + this.photo;
620
+ }
621
+ }
622
+ return this.photo;
623
+ }
624
+ },
625
+ watch: {
626
+ fileList: {
627
+ immediate: true,
628
+ deep: true,
629
+ handler(val) {
630
+ if (Array.isArray(val) && val.length > 0) {
631
+ this.lists = val;
632
+ let filesTotalSize = 0;
633
+ val.forEach((item) => {
634
+ if (
635
+ Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
636
+ item.fileSize
637
+ ) {
638
+ filesTotalSize += parseFloat(item.fileSize, 10);
639
+ } else {
640
+ filesTotalSize += item.size
641
+ ? Math.round((item.size / 1024) * 10) / 10
642
+ : 0;
643
+ }
644
+ });
645
+ this.filesTotalSize = filesTotalSize;
646
+ this.$emit('input', val);
647
+ }
648
+ }
649
+ },
650
+ value: {
651
+ immediate: true,
652
+ deep: true,
653
+ handler(val) {
654
+ if (val && typeof val === 'object' && this.showFileList) {
655
+ if (Array.isArray(val)) {
656
+ this.lists = val;
657
+ } else {
658
+ this.lists = [val];
659
+ }
660
+ }
661
+ }
662
+ },
663
+ params: {
664
+ deep: true,
665
+ handler(val) {
666
+ this.getFiles(val);
667
+ }
668
+ },
669
+ lists: {
670
+ deep: true,
671
+ handler(val) {
672
+ this.$emit('update:fileCount', val.length);
673
+ }
674
+ },
675
+ display(val) {
676
+ val && this.getHeight();
677
+ }
678
+ },
679
+ beforeCreate() {
680
+ this.getFiles = debounce(500, (params) => {
681
+ this.getFileLists(params);
682
+ });
683
+ this.getAdjunctPropertie = debounce(500, () => {
684
+ this.getAdjunctProperties();
685
+ });
686
+ },
687
+ created() {
688
+ const dochubConfig = sessionStorage.getItem('dochubConfig');
689
+ if (dochubConfig) {
690
+ this.dochubConfig = JSON.parse(dochubConfig);
691
+ }
692
+ this.getAdjunctPropertie();
693
+ },
694
+ mounted() {
695
+ this.$nextTick(() => {
696
+ this.getHeight();
697
+ });
698
+ },
699
+ methods: {
700
+ getHeight() {
701
+ if (this.height === 'auto') {
702
+ let pt =
703
+ parseInt(util.getStyle(this.$el.parentNode, 'padding-top'), 10) || 0;
704
+ let pb =
705
+ parseInt(util.getStyle(this.$el.parentNode, 'padding-bottom'), 10) ||
706
+ 0;
707
+ let btn = this.$refs.upload
708
+ ? this.$refs.upload.$children[0].$el.offsetHeight || 0
709
+ : 0;
710
+ this.boxHeight =
711
+ this.$el.parentNode.offsetHeight - pt - pb - btn + 'px';
712
+ }
713
+ },
714
+ //根据code获取附件参数配置
715
+ getAdjunctProperties() {
716
+ if (this.code !== undefined) {
717
+ let config = store.get(this.code);
718
+ if (config) {
719
+ this.fileAccept = config.accept;
720
+ this.fileSize = config.size;
721
+ this.fileTotalSize = config.totalSize;
722
+ if (config.dochubConfig) {
723
+ this.dochubConfig = config.dochubConfig;
724
+ }
725
+
726
+ let url =
727
+ this.portrait || this.documentId
728
+ ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
729
+ : this.dochubConfig.uploadDocumentUrl || uploads;
730
+ this.uploadUrl = url.indexOf(this.host) > -1 ? url : this.host + url;
731
+ this.requestFiles && this.getFiles(this.params);
732
+ } else {
733
+ util
734
+ .ajax({
735
+ method: this.method,
736
+ url: this.properties,
737
+ data: { code: this.code, ...this.param },
738
+ params: { code: this.code, ...this.param }
739
+ })
740
+ .then((res) => {
741
+ if (res.rCode === 0) {
742
+ if (res.results) {
743
+ this.excludeNames = res.results.excludeName;
744
+ if (res.results.fileTypeExtName) {
745
+ let fileTypeExtName =
746
+ res.results.fileTypeExtName.split(';');
747
+ this.fileAccept = fileTypeExtName
748
+ .filter((item) => {
749
+ return item;
750
+ })
751
+ .join(',');
752
+ }
753
+ if (res.results.dochubConfig) {
754
+ this.dochubConfig = res.results.dochubConfig;
755
+ sessionStorage.setItem(
756
+ 'dochubConfig',
757
+ JSON.stringify(res.results.dochubConfig)
758
+ );
759
+ }
760
+ let url = this.portrait
761
+ ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
762
+ : this.dochubConfig.uploadDocumentUrl || uploads;
763
+ this.uploadUrl =
764
+ url.indexOf(this.host) > -1 ? url : this.host + url;
765
+ if (res.results.kkViewRootPath) {
766
+ this.kkfileview = res.results.kkViewRootPath;
767
+ }
768
+ this.fileSize = res.results.limitFileSize
769
+ ? res.results.limitFileSize
770
+ : 0;
771
+ this.fileTotalSize = res.results.limitTotalSize;
772
+ store.set(this.code, {
773
+ accept: this.fileAccept,
774
+ size: this.fileSize,
775
+ totalSize: this.fileTotalSize,
776
+ dochubConfig: this.dochubConfig
777
+ });
778
+ }
779
+ this.requestFiles && this.getFiles(this.params);
780
+ }
781
+ })
782
+ .catch((err) => {
783
+ if (err.message && err.message !== 'canceled') {
784
+ this.$message.error(err.message);
785
+ }
786
+ });
787
+ }
788
+ }
789
+ },
790
+ getFileLists(params) {
791
+ if (
792
+ !this.show ||
793
+ (this.fileList &&
794
+ Array.isArray(this.fileList) &&
795
+ this.fileList.length) ||
796
+ (this.requiredOwnId &&
797
+ !Object.prototype.hasOwnProperty.call(params, 'ownId'))
798
+ ) {
799
+ return false;
800
+ }
801
+ let url =
802
+ typeof this.fileList === 'string'
803
+ ? this.fileList
804
+ : this.dochubConfig.getDocumentList
805
+ ? this.dochubConfig.getDocumentList
806
+ : getAdjunctFileInfos;
807
+ util
808
+ .ajax({
809
+ method: this.method,
810
+ url: url,
811
+ data: params,
812
+ params: params,
813
+ format: false
814
+ })
815
+ .then((res) => {
816
+ if (res.rCode === 0) {
817
+ if (this.portrait === true) {
818
+ this.image = JSON.parse(JSON.stringify(res.results))[0];
819
+ } else {
820
+ this.lists = JSON.parse(JSON.stringify(res.results));
821
+ let filesTotalSize = 0;
822
+ this.lists.forEach((item) => {
823
+ if (
824
+ Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
825
+ item.fileSize
826
+ ) {
827
+ filesTotalSize += parseFloat(item.fileSize, 10);
828
+ } else {
829
+ filesTotalSize += item.size
830
+ ? Math.round((item.size / 1024) * 10) / 10
831
+ : 0;
832
+ }
833
+ });
834
+ this.filesTotalSize = filesTotalSize;
835
+ if (this.lists.length) {
836
+ this.$emit('input', this.lists);
837
+ }
838
+ }
839
+ } else {
840
+ let msg = res.msg || '系统错误,请联系管理员!';
841
+ this.$message.error(msg);
842
+ }
843
+ })
844
+ .catch((err) => {
845
+ if (err.message && err.message !== 'canceled') {
846
+ this.$message.error(err.message);
847
+ }
848
+ });
849
+ },
850
+ handleUpload() {
851
+ this.$refs.upload.submit();
852
+ },
853
+ openKkfileview(file) {
854
+ let host = util.win.location.origin;
855
+ if (this.host) {
856
+ if (util.startWith(this.host, 'http')) {
857
+ host = this.host;
858
+ } else {
859
+ host += this.host;
860
+ }
861
+ }
862
+ let url = encodeURIComponent(
863
+ Base64.encode(
864
+ host +
865
+ (typeof this.download === 'string'
866
+ ? this.download
867
+ : downloadByAdjunctId) +
868
+ `?adjunctId=${
869
+ file.adjunctId || file.response.adjunctId
870
+ }&fullfilename=${file.originalName}`
871
+ )
872
+ );
873
+ util.win.open(`${this.kkfileview}?url=${url}`);
874
+ },
875
+ handlePreview(res) {
876
+ if (this.preview) {
877
+ if (this.onPreview) {
878
+ this.onPreview(res);
879
+ } else {
880
+ let file = res.response ? res.response : res;
881
+ let url =
882
+ typeof this.preview === 'string'
883
+ ? this.preview
884
+ : typeof this.preview === 'function'
885
+ ? this.preview(file)
886
+ : null;
887
+ if (res.status === 'success') {
888
+ let suffix = file.suffix;
889
+ suffix = suffix.toLowerCase();
890
+ if (this.dochubConfig.previewDocumentUrl) {
891
+ if (
892
+ suffix.includes('jpge') ||
893
+ suffix.includes('jpg') ||
894
+ suffix.includes('gif') ||
895
+ suffix.includes('png')
896
+ ) {
897
+ this.imgUrl =
898
+ res.url && util.startWith(url, ['http', '/', true])
899
+ ? res.url
900
+ : this.host +
901
+ (url
902
+ ? url
903
+ : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`);
904
+ this.title = file.originalName;
905
+ this.showImg = true;
906
+ this.$nextTick(() => {
907
+ this.loadImage();
908
+ });
909
+ } else if (suffix.includes('mp4')) {
910
+ this.source = {
911
+ src:
912
+ this.host +
913
+ (url
914
+ ? url
915
+ : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`)
916
+ };
917
+ this.title = file.originalName;
918
+ this.showVideo = true;
919
+ } else {
920
+ util.win.open(
921
+ this.host +
922
+ (url
923
+ ? url
924
+ : `${this.dochubConfig.previewDocumentUrl}?documentId=${file.adjunctId}&action=附件预览`)
925
+ );
926
+ }
927
+ } else {
928
+ if (
929
+ suffix.includes('doc') ||
930
+ suffix.includes('docx') ||
931
+ suffix.includes('xls') ||
932
+ suffix.includes('xlsx') ||
933
+ suffix.includes('ppt')
934
+ ) {
935
+ if (this.kkfileview) {
936
+ this.openKkfileview(file);
937
+ } else {
938
+ util.win.open(
939
+ this.host +
940
+ (url ? url : previewAdjunctOffice) +
941
+ '?cmd=view&bucketName=' +
942
+ file.absolutePath +
943
+ '&fileId=' +
944
+ file.adjunctId +
945
+ '&fileName=' +
946
+ file.newName
947
+ );
948
+ }
949
+ } else if (suffix.includes('pdf')) {
950
+ if (this.kkfileview) {
951
+ this.openKkfileview(file);
952
+ } else {
953
+ util.win.open(
954
+ this.host +
955
+ (url ? url : previewAdjunct2) +
956
+ '/' +
957
+ file.originalName +
958
+ '?adjunctId=' +
959
+ file.adjunctId
960
+ );
961
+ }
962
+ } else if (
963
+ suffix.includes('jpge') ||
964
+ suffix.includes('jpg') ||
965
+ suffix.includes('gif') ||
966
+ suffix.includes('png')
967
+ ) {
968
+ this.imgUrl =
969
+ res.url && util.startWith(url, ['http', '/', true])
970
+ ? res.url
971
+ : this.host +
972
+ (url ? url : this.previewAdjunct) +
973
+ '?adjunctId=' +
974
+ file.adjunctId;
975
+ this.title = file.originalName;
976
+ this.showImg = true;
977
+ this.$nextTick(() => {
978
+ this.loadImage();
979
+ });
980
+ } else if (suffix.includes('mp4')) {
981
+ this.source = {
982
+ src:
983
+ this.host +
984
+ (url ? url : this.previewAdjunct) +
985
+ '?adjunctId=' +
986
+ file.adjunctId
987
+ };
988
+ this.title = file.originalName;
989
+ this.showVideo = true;
990
+ } else {
991
+ if (this.kkfileview) {
992
+ this.openKkfileview(file);
993
+ } else {
994
+ util.win.open(
995
+ this.host +
996
+ (url ? url : this.previewAdjunct) +
997
+ '?adjunctId=' +
998
+ file.adjunctId
999
+ );
1000
+ }
1001
+ }
1002
+ }
1003
+ } else {
1004
+ util.win.open(URL.createObjectURL(file.raw));
1005
+ }
1006
+ }
1007
+ }
1008
+ },
1009
+ closeViewer() {
1010
+ this.showImg = false;
1011
+ },
1012
+ loadImage() {
1013
+ this.$refs.showImg &&
1014
+ (this.$refs.showImg.onload = () => {
1015
+ this.imgChange = false;
1016
+ let w = this.$refs.showImg.naturalWidth;
1017
+ let h = this.$refs.showImg.naturalHeight;
1018
+ let pw = this.$refs.showImg.parentNode.offsetWidth;
1019
+ let ph = this.$refs.showImg.parentNode.offsetHeight;
1020
+ if (w / h > pw / ph) {
1021
+ this.styles = { 'max-width': '100%' };
1022
+ } else {
1023
+ this.styles = { 'max-height': '100%' };
1024
+ }
1025
+ if (w < pw) {
1026
+ this.styles.width = w + 'px';
1027
+ }
1028
+ if (h < ph) {
1029
+ this.styles.height = h + 'px';
1030
+ }
1031
+ });
1032
+ },
1033
+ isLt(file) {
1034
+ let flag = false;
1035
+ let flieArr = file.name.split('.');
1036
+ let suffix = '.' + flieArr[flieArr.length - 1].toLowerCase();
1037
+ if (this.accepts) {
1038
+ let accepts = this.accepts.toLowerCase().split(',');
1039
+ flag = accepts.includes(suffix);
1040
+ if (!flag) {
1041
+ this.$message.error(`文件类型错误,请上传${this.accepts}类型文件!`);
1042
+ return flag;
1043
+ }
1044
+ }
1045
+ let size = this._size;
1046
+ let text = '单个附件';
1047
+ let se = Math.round((file.size / 1024) * 10) / 10;
1048
+ if (this._size === 0 && this._totalSize === 0) {
1049
+ flag = true;
1050
+ } else if (this._size > 0 && this._totalSize === 0) {
1051
+ flag = se < this._size;
1052
+ size = this._size;
1053
+ text = '单个附件';
1054
+ } else if (this._size === 0 && this._totalSize > 0) {
1055
+ flag = this.filesTotalSize + se < this._totalSize;
1056
+ size = this._totalSize;
1057
+ text = '附件总';
1058
+ } else {
1059
+ flag = se < this._size && this.filesTotalSize + se < this._totalSize;
1060
+ if (se < this._size) {
1061
+ size = this._size;
1062
+ text = '单个附件';
1063
+ } else {
1064
+ size = this._totalSize;
1065
+ text = '附件总';
1066
+ }
1067
+ }
1068
+ if (!flag) {
1069
+ this.$message.error(`上传${text}大小不能超过${size}KB!`);
1070
+ return flag;
1071
+ }
1072
+ return flag;
1073
+ },
1074
+ handleBeforeUpload(file) {
1075
+ const flag = this.isLt(file);
1076
+ if (this.portrait) {
1077
+ if (flag && this.beforeUpload) {
1078
+ return this.beforeUpload(file);
1079
+ }
1080
+ return flag;
1081
+ }
1082
+ if (this.beforeUpload) {
1083
+ if (flag) {
1084
+ return this.beforeUpload(file);
1085
+ }
1086
+ return flag;
1087
+ }
1088
+ return flag;
1089
+ },
1090
+ handleBeforeRemove(file, fileList) {
1091
+ if (file && file.status === 'success') {
1092
+ return this.$confirm('确定删除文件吗?', '提示', {
1093
+ confirmButtonText: '确定',
1094
+ cancelButtonText: '取消',
1095
+ type: 'warning'
1096
+ })
1097
+ .then(() => {
1098
+ if (this.beforeRemove) {
1099
+ return this.beforeRemove(file, fileList);
1100
+ } else if (file.status === 'success') {
1101
+ let userName =
1102
+ file.userName ||
1103
+ (file.response && file.response.userName) ||
1104
+ util.getStorage('userName');
1105
+ // eslint-disable-next-line no-undef
1106
+ return new Promise((resolve, reject) => {
1107
+ let url =
1108
+ typeof this.deleted === 'string'
1109
+ ? this.deleted
1110
+ : this.remove === 'string'
1111
+ ? this.remove
1112
+ : this.dochubConfig.deleteDocumentUrl || delAdjunct;
1113
+ util
1114
+ .ajax({
1115
+ method: this.method,
1116
+ url: url,
1117
+ data: {
1118
+ userName: userName,
1119
+ documentId: file.adjunctId || file.response.adjunctId,
1120
+ id: file.adjunctId || file.response.adjunctId
1121
+ },
1122
+ params: {
1123
+ userName: userName,
1124
+ documentId: file.adjunctId || file.response.adjunctId,
1125
+ id: file.adjunctId || file.response.adjunctId
1126
+ }
1127
+ })
1128
+ .then((res) => {
1129
+ if (res.rCode === 0) {
1130
+ let se =
1131
+ this.filesTotalSize -
1132
+ Math.round((file.size / 1024) * 10) / 10;
1133
+ this.filesTotalSize = se;
1134
+ this.$message.success(res.msg);
1135
+ resolve();
1136
+ } else {
1137
+ let msg = res.msg || '系统错误,请联系管理员!';
1138
+ this.$message.error(msg);
1139
+ reject();
1140
+ }
1141
+ })
1142
+ .catch((err) => {
1143
+ if (err.message && err.message !== 'canceled') {
1144
+ this.$message.error(err.message);
1145
+ }
1146
+ });
1147
+ });
1148
+ }
1149
+ return true;
1150
+ })
1151
+ .catch(() => {
1152
+ return flag;
1153
+ });
1154
+ }
1155
+ },
1156
+ handleDownloads() {
1157
+ let url =
1158
+ typeof this.downloads === 'string'
1159
+ ? this.downloads
1160
+ : this.dochubConfig.compressDownloadDocumentUrl || uploadDownloads;
1161
+ util.win.open(
1162
+ this.host +
1163
+ url +
1164
+ '?ownId=' +
1165
+ this.ownId +
1166
+ '&code=' +
1167
+ this.code +
1168
+ (this.extendCode ? '&extendCode=' + this.extendCode : '')
1169
+ );
1170
+ },
1171
+ handleDownload(file) {
1172
+ if (file.status === 'success') {
1173
+ let url =
1174
+ typeof this.download === 'string'
1175
+ ? this.download
1176
+ : this.dochubConfig.downloadDocumentUrl || downloadByAdjunctId;
1177
+ util.win.open(
1178
+ this.host +
1179
+ url +
1180
+ '?adjunctId=' +
1181
+ (file.adjunctId || file.response.adjunctId) +
1182
+ '&documentId=' +
1183
+ (file.adjunctId || file.response.adjunctId)
1184
+ );
1185
+ } else {
1186
+ this.aLinkDownload(file);
1187
+ }
1188
+ },
1189
+ handleClick(res) {
1190
+ if (res.event && typeof res.event === 'function') {
1191
+ res.event(res);
1192
+ } else {
1193
+ this.$emit('click', res);
1194
+ }
1195
+ },
1196
+ aLinkDownload(file) {
1197
+ var a = document.createElement('a');
1198
+ let event = new MouseEvent('click');
1199
+ a.href = URL.createObjectURL(file.raw);
1200
+ a.download = file.name;
1201
+ a.dispatchEvent(event);
1202
+ },
1203
+ handleSort(files) {
1204
+ if (this.isSort) {
1205
+ if (this.onSort) {
1206
+ this.onSort(files);
1207
+ } else {
1208
+ let ids = files.map((item) => {
1209
+ if (item.status === 'success') {
1210
+ return item.adjunctId || item.response.adjunctId;
1211
+ }
1212
+ });
1213
+ ids = ids.join(',');
1214
+ util
1215
+ .ajax({
1216
+ method: this.method,
1217
+ url: this.dochubConfig.sortDocumentsUrl || uploadSort,
1218
+ data: {
1219
+ ids: ids
1220
+ },
1221
+ params: {
1222
+ ids: ids
1223
+ }
1224
+ })
1225
+ .then((res) => {
1226
+ if (res.rCode === 0) {
1227
+ this.$message.success(res.msg);
1228
+ } else {
1229
+ let msg = res.msg || '系统错误,请联系管理员!';
1230
+ this.$message.error(msg);
1231
+ }
1232
+ })
1233
+ .catch((err) => {
1234
+ if (err.message && err.message !== 'canceled') {
1235
+ this.$message.error(err.message);
1236
+ }
1237
+ });
1238
+ }
1239
+ }
1240
+ },
1241
+ handleSuccess(response, file, fileList) {
1242
+ if (this.portrait) {
1243
+ this.image = URL.createObjectURL(file.raw);
1244
+ }
1245
+ if (this.showMessage.success) {
1246
+ if (response.rCode) {
1247
+ if (this.dangerouslyUseHTMLString) {
1248
+ this.$alert(
1249
+ response.msg ? response.msg : '上传失败:请联系管理员',
1250
+ '提示',
1251
+ {
1252
+ dangerouslyUseHTMLString: true,
1253
+ setHeight: response.msg
1254
+ }
1255
+ ).catch();
1256
+ } else {
1257
+ this.$message({
1258
+ type: 'error',
1259
+ message: response.msg || '成功!'
1260
+ });
1261
+ }
1262
+ } else {
1263
+ this.$message.success(response.msg);
1264
+ }
1265
+ }
1266
+ let se =
1267
+ this.filesTotalSize +
1268
+ (this.resultFile ? Math.round((file.size / 1024) * 10) / 10 : 0);
1269
+ this.filesTotalSize = se;
1270
+ this.onSuccess &&
1271
+ this.onSuccess(response, file, fileList, this.dochubConfig);
1272
+ this.$emit('success', response, file, fileList, this.dochubConfig);
1273
+ if (this.resultFile) {
1274
+ if (this.portrait) {
1275
+ this.$emit('input', file);
1276
+ } else {
1277
+ this.$emit('input', fileList);
1278
+ }
1279
+ if (this.elForm) {
1280
+ this.elForm.clearValidate(this.name);
1281
+ }
1282
+ }
1283
+ },
1284
+ handleChange(file, fileList) {
1285
+ this.$emit('change', fileList);
1286
+ this.onChange && this.onChange(file, fileList);
1287
+ },
1288
+ handleRemove(file, fileList) {
1289
+ this.$emit('input', fileList.length ? fileList : '');
1290
+ this.$emit('remove', file, fileList);
1291
+ this.$emit('change', fileList);
1292
+ this.onRemove && this.onRemove(file, fileList);
1293
+ },
1294
+ handleError(err, file, fileList) {
1295
+ if (this.showMessage.error) {
1296
+ if (this.dangerouslyUseHTMLString) {
1297
+ this.$alert(err.msg ? err.msg : '上传失败:请联系管理员', '提示', {
1298
+ dangerouslyUseHTMLString: true,
1299
+ setHeight: err.msg
1300
+ }).catch();
1301
+ } else {
1302
+ this.$message({
1303
+ type: 'error',
1304
+ message: '上传失败:' + (err.msg ? err.msg : '请联系管理员')
1305
+ });
1306
+ }
1307
+ }
1308
+ this.$emit('error', err, file, fileList);
1309
+ this.onError && this.onError(err, file, fileList);
1310
+ }
1311
+ }
1312
+ };
1313
+ </script>