eoss-ui 0.6.50 → 0.6.52

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 (218) hide show
  1. package/lib/eoss-ui.common.js +577 -530
  2. package/lib/flow-list.js +110 -87
  3. package/lib/flow.js +306 -282
  4. package/lib/index.js +1 -1
  5. package/lib/main.js +132 -132
  6. package/lib/qr-code.js +13 -13
  7. package/lib/upload.js +6 -6
  8. package/package.json +159 -159
  9. package/packages/button/index.js +5 -5
  10. package/packages/button/src/main.vue +418 -418
  11. package/packages/button-group/index.js +5 -5
  12. package/packages/button-group/src/main.vue +298 -298
  13. package/packages/calendar/index.js +5 -5
  14. package/packages/card/index.js +5 -5
  15. package/packages/card/src/main.vue +156 -156
  16. package/packages/cascader/index.js +5 -5
  17. package/packages/cascader/src/main.vue +168 -168
  18. package/packages/checkbox-group/index.js +5 -5
  19. package/packages/checkbox-group/src/main.vue +333 -333
  20. package/packages/clients/index.js +5 -5
  21. package/packages/clients/src/main.vue +144 -144
  22. package/packages/data-table/index.js +5 -5
  23. package/packages/data-table/src/children.vue +39 -39
  24. package/packages/data-table/src/column.vue +989 -989
  25. package/packages/data-table/src/main.vue +1822 -1822
  26. package/packages/data-table/src/sizer.vue +195 -195
  27. package/packages/data-table-form/index.js +5 -5
  28. package/packages/data-table-form/src/checkbox.vue +101 -101
  29. package/packages/data-table-form/src/colgroup.vue +17 -17
  30. package/packages/data-table-form/src/main.vue +181 -181
  31. package/packages/data-table-form/src/radio.vue +65 -65
  32. package/packages/data-table-form/src/table.vue +233 -233
  33. package/packages/data-table-form/src/tbody.vue +336 -336
  34. package/packages/data-table-form/src/thead.vue +68 -68
  35. package/packages/date-picker/index.js +5 -5
  36. package/packages/date-picker/src/main.vue +236 -236
  37. package/packages/dialog/index.js +5 -5
  38. package/packages/enable-drag/index.js +5 -5
  39. package/packages/enterprise/index.js +5 -5
  40. package/packages/enterprise/src/main.vue +66 -66
  41. package/packages/error-page/index.js +5 -5
  42. package/packages/error-page/src/main.vue +44 -44
  43. package/packages/flow/index.js +5 -5
  44. package/packages/flow/src/component/CommonOpinions.vue +345 -345
  45. package/packages/flow/src/component/CustomPreset.vue +322 -322
  46. package/packages/flow/src/component/FileList.vue +99 -99
  47. package/packages/flow/src/component/Preset.vue +255 -255
  48. package/packages/flow/src/component/SendMsg.vue +229 -229
  49. package/packages/flow/src/component/TimeLimit.vue +190 -190
  50. package/packages/flow/src/component/taskUnionExamine.vue +611 -611
  51. package/packages/flow/src/form.vue +121 -121
  52. package/packages/flow/src/freeStartFlow.vue +2843 -2843
  53. package/packages/flow/src/main.vue +3131 -3108
  54. package/packages/flow/src/processForm.vue +1031 -1031
  55. package/packages/flow/src/processReject.vue +293 -293
  56. package/packages/flow/src/reset.vue +902 -902
  57. package/packages/flow/src/startTaskRead.vue +597 -597
  58. package/packages/flow/src/supervise.vue +138 -138
  59. package/packages/flow/src/table.vue +58 -58
  60. package/packages/flow-group/index.js +5 -5
  61. package/packages/flow-group/src/main.vue +688 -688
  62. package/packages/flow-list/index.js +5 -5
  63. package/packages/flow-list/src/main.vue +1434 -1411
  64. package/packages/form/index.js +5 -5
  65. package/packages/form/src/main.vue +3583 -3583
  66. package/packages/form/src/table.vue +1426 -1426
  67. package/packages/handle-user/index.js +5 -5
  68. package/packages/handle-user/src/main.vue +138 -138
  69. package/packages/handler/index.js +5 -5
  70. package/packages/handler/src/main.vue +493 -493
  71. package/packages/icon/index.js +5 -5
  72. package/packages/icon/src/main.vue +101 -101
  73. package/packages/icons/index.js +5 -5
  74. package/packages/icons/src/main.vue +81 -81
  75. package/packages/input/index.js +5 -5
  76. package/packages/input/src/main.vue +356 -356
  77. package/packages/input-number/index.js +5 -5
  78. package/packages/input-number/src/main.vue +106 -106
  79. package/packages/label/index.js +5 -5
  80. package/packages/label/src/main.vue +457 -457
  81. package/packages/layout/index.js +5 -5
  82. package/packages/layout/src/item.vue +152 -152
  83. package/packages/layout/src/main.vue +31 -31
  84. package/packages/login/index.js +5 -5
  85. package/packages/login/src/main.vue +1935 -1935
  86. package/packages/login/src/resetPassword.vue +562 -562
  87. package/packages/main/index.js +5 -5
  88. package/packages/main/src/default/message.vue +249 -249
  89. package/packages/main/src/default/notice.vue +157 -157
  90. package/packages/main/src/default/userinfo.vue +503 -503
  91. package/packages/main/src/public/online.vue +89 -89
  92. package/packages/main/src/public/search.vue +461 -461
  93. package/packages/main/src/public/settings.vue +221 -221
  94. package/packages/main/src/simplicity/apps.vue +388 -388
  95. package/packages/main/src/simplicity/avatar.vue +82 -82
  96. package/packages/main/src/simplicity/handler.vue +259 -259
  97. package/packages/main/src/simplicity/index.vue +2064 -2064
  98. package/packages/main/src/simplicity/lists.vue +84 -84
  99. package/packages/main/src/simplicity/menu-list.vue +128 -128
  100. package/packages/main/src/simplicity/message.vue +259 -259
  101. package/packages/main/src/simplicity/notice.vue +190 -190
  102. package/packages/main/src/simplicity/router-page.vue +45 -45
  103. package/packages/main/src/simplicity/sub-menu.vue +241 -241
  104. package/packages/main/src/simplicity/user.vue +257 -257
  105. package/packages/main/src/simplicity/userinfo.vue +312 -312
  106. package/packages/menu/index.js +5 -5
  107. package/packages/menu/src/main.vue +536 -536
  108. package/packages/nav/index.js +5 -5
  109. package/packages/nav/src/main.vue +351 -351
  110. package/packages/notify/index.js +5 -5
  111. package/packages/notify/src/main.vue +538 -538
  112. package/packages/page/index.js +5 -5
  113. package/packages/page/src/main.vue +167 -167
  114. package/packages/pagination/index.js +5 -5
  115. package/packages/pagination/src/main.vue +96 -96
  116. package/packages/player/index.js +5 -5
  117. package/packages/player/src/main.vue +194 -194
  118. package/packages/qr-code/index.js +5 -5
  119. package/packages/qr-code/src/main.vue +170 -170
  120. package/packages/radio-group/index.js +6 -6
  121. package/packages/radio-group/src/main.vue +319 -319
  122. package/packages/retrial-auth/index.js +5 -5
  123. package/packages/retrial-auth/src/main.vue +280 -280
  124. package/packages/select/index.js +5 -5
  125. package/packages/select/src/main.vue +775 -775
  126. package/packages/select-ganged/index.js +5 -5
  127. package/packages/select-ganged/src/main.vue +724 -724
  128. package/packages/selector/index.js +5 -5
  129. package/packages/selector/src/main.vue +687 -687
  130. package/packages/selector-panel/index.js +5 -5
  131. package/packages/selector-panel/src/main.vue +1027 -1027
  132. package/packages/selector-panel/src/selection.vue +177 -177
  133. package/packages/selector-panel/src/tree.vue +129 -129
  134. package/packages/sizer/index.js +5 -5
  135. package/packages/sizer/src/main.vue +254 -254
  136. package/packages/steps/index.js +5 -5
  137. package/packages/steps/src/main.vue +181 -181
  138. package/packages/switch/index.js +5 -5
  139. package/packages/switch/src/main.vue +154 -154
  140. package/packages/table-form/index.js +5 -5
  141. package/packages/tabs/index.js +5 -5
  142. package/packages/tabs/src/main.vue +788 -788
  143. package/packages/tabs-panel/index.js +5 -5
  144. package/packages/tabs-panel/src/main.vue +29 -29
  145. package/packages/theme-chalk/src/base.scss +260 -260
  146. package/packages/theme-chalk/src/button-group.scss +175 -175
  147. package/packages/theme-chalk/src/button.scss +24 -24
  148. package/packages/theme-chalk/src/calendar.scss +113 -113
  149. package/packages/theme-chalk/src/card.scss +99 -99
  150. package/packages/theme-chalk/src/checkbox-group.scss +8 -8
  151. package/packages/theme-chalk/src/clients.scss +87 -87
  152. package/packages/theme-chalk/src/data-table-form.scss +67 -67
  153. package/packages/theme-chalk/src/data-table.scss +293 -293
  154. package/packages/theme-chalk/src/date-picker.scss +7 -7
  155. package/packages/theme-chalk/src/dialog.scss +77 -77
  156. package/packages/theme-chalk/src/enable-drag.scss +181 -181
  157. package/packages/theme-chalk/src/enterprise.scss +5 -5
  158. package/packages/theme-chalk/src/error-page.scss +18 -18
  159. package/packages/theme-chalk/src/flow-group.scss +110 -110
  160. package/packages/theme-chalk/src/flow-list.scss +36 -36
  161. package/packages/theme-chalk/src/flow.scss +335 -335
  162. package/packages/theme-chalk/src/form.scss +496 -496
  163. package/packages/theme-chalk/src/handle-user.scss +40 -40
  164. package/packages/theme-chalk/src/handler.scss +143 -143
  165. package/packages/theme-chalk/src/icon.scss +1789 -1789
  166. package/packages/theme-chalk/src/icons.scss +99 -99
  167. package/packages/theme-chalk/src/input.scss +9 -9
  168. package/packages/theme-chalk/src/label.scss +24 -24
  169. package/packages/theme-chalk/src/layout.scss +46 -46
  170. package/packages/theme-chalk/src/login.scss +969 -969
  171. package/packages/theme-chalk/src/main.scss +663 -663
  172. package/packages/theme-chalk/src/menu.scss +222 -222
  173. package/packages/theme-chalk/src/mixins/color.scss +117 -117
  174. package/packages/theme-chalk/src/nav.scss +111 -111
  175. package/packages/theme-chalk/src/page.scss +3 -3
  176. package/packages/theme-chalk/src/pagination.scss +29 -29
  177. package/packages/theme-chalk/src/player.scss +9 -9
  178. package/packages/theme-chalk/src/qr-code.scss +17 -17
  179. package/packages/theme-chalk/src/radio-group.scss +9 -9
  180. package/packages/theme-chalk/src/retrial-auth.scss +38 -38
  181. package/packages/theme-chalk/src/select-ganged.scss +8 -8
  182. package/packages/theme-chalk/src/select.scss +8 -8
  183. package/packages/theme-chalk/src/selector-panel.scss +204 -204
  184. package/packages/theme-chalk/src/selector.scss +91 -91
  185. package/packages/theme-chalk/src/simplicity.scss +1265 -1265
  186. package/packages/theme-chalk/src/sizer.scss +36 -36
  187. package/packages/theme-chalk/src/steps.scss +88 -88
  188. package/packages/theme-chalk/src/switch.scss +3 -3
  189. package/packages/theme-chalk/src/table-form.scss +1 -1
  190. package/packages/theme-chalk/src/tabs.scss +87 -87
  191. package/packages/theme-chalk/src/tips.scss +7 -7
  192. package/packages/theme-chalk/src/toolbar.scss +179 -179
  193. package/packages/theme-chalk/src/tree-group.scss +72 -72
  194. package/packages/theme-chalk/src/tree.scss +165 -165
  195. package/packages/theme-chalk/src/upload.scss +167 -167
  196. package/packages/theme-chalk/src/wxlogin.scss +3 -3
  197. package/packages/tips/index.js +5 -5
  198. package/packages/tips/src/main.vue +141 -141
  199. package/packages/toolbar/index.js +5 -5
  200. package/packages/toolbar/src/main.vue +430 -430
  201. package/packages/tree/index.js +5 -5
  202. package/packages/tree-group/index.js +5 -5
  203. package/packages/upload/index.js +5 -5
  204. package/packages/upload/src/main.vue +1339 -1335
  205. package/packages/upload/src/picture.js +15 -15
  206. package/packages/wujie/index.js +5 -5
  207. package/packages/wujie/src/main.vue +145 -145
  208. package/packages/wxlogin/index.js +5 -5
  209. package/packages/wxlogin/src/main.vue +128 -128
  210. package/src/config/api.js +281 -281
  211. package/src/config/image.js +2 -2
  212. package/src/index.js +1 -1
  213. package/src/utils/bus.js +3 -3
  214. package/src/utils/date-util.js +312 -312
  215. package/src/utils/http.js +50 -50
  216. package/src/utils/rules.js +18 -18
  217. package/src/utils/store.js +21 -21
  218. package/src/utils/webSocket.js +107 -107
@@ -1,1335 +1,1339 @@
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
- return this.dragSort && !this.isDisabled;
546
- },
547
- datas() {
548
- if (this.data) {
549
- return util.extend({}, this.data, this.params);
550
- }
551
- return this.params;
552
- },
553
- params() {
554
- let params = { userId: util.getStorage('userId'), ...this.param };
555
- if (this.code !== undefined) {
556
- params.code = this.code;
557
- params.bucketCode = this.code;
558
- }
559
- if (this.ownId !== undefined) {
560
- params.ownId = this.ownId;
561
- params.businessId = this.ownId;
562
- }
563
- return params;
564
- },
565
- showMessage() {
566
- if (this.message !== undefined) {
567
- return util.extend({}, { success: true, error: true }, this.message);
568
- }
569
- return { success: true, error: true };
570
- },
571
- profile() {
572
- const previewAdjunct =
573
- this.dochubConfig.downloadDocumentUrl || this.previewAdjunct;
574
- if (this.image) {
575
- if (typeof this.image === 'string') {
576
- return this.image;
577
- }
578
- return `${this.host}${previewAdjunct}?documentId=${
579
- this.image.adjunctId
580
- }&adjunctId=${this.image.adjunctId}&_tt=${new Date().getTime()}`;
581
- }
582
- if (this.value) {
583
- if (typeof this.value === 'string') {
584
- if (this.value.indexOf('data:image/') === 0) {
585
- return this.value;
586
- } else if (this.value.indexOf(previewAdjunct) > -1) {
587
- let val =
588
- this.host +
589
- util.jointUrl({
590
- url: this.value,
591
- reg: '/main2'
592
- });
593
- return val;
594
- } else if (this.value.indexOf('/') === -1) {
595
- return `${this.host}${previewAdjunct}?documentId=${
596
- this.value
597
- }&adjunctId=${this.value}&_tt=${new Date().getTime()}`;
598
- }
599
- return this.value;
600
- } else if (Array.isArray(this.value)) {
601
- let adjunctId = this.value[0].response
602
- ? this.value[0].response.adjunctId
603
- : this.value[0].adjunctId;
604
- return `${
605
- this.host
606
- }${previewAdjunct}?documentId=${adjunctId}&adjunctId=${adjunctId}&_tt=${new Date().getTime()}`;
607
- } else {
608
- let adjunctId = this.value.response
609
- ? this.value.response.adjunctId
610
- : this.value.adjunctId;
611
- return `${
612
- this.host
613
- }${previewAdjunct}?documentId=${adjunctId}&adjunctId=${adjunctId}&_tt=${new Date().getTime()}`;
614
- }
615
- }
616
- if (this.photo && typeof this.photo === 'string') {
617
- if (this.photo.indexOf('data:image/') === 0) {
618
- return this.photo;
619
- } else if (this.photo.indexOf(previewAdjunct) > -1) {
620
- let val =
621
- this.host +
622
- util.jointUrl({
623
- url: this.value,
624
- reg: '/main2'
625
- });
626
- return val;
627
- } else if (this.photo.indexOf('/') === -1) {
628
- return `${this.host}${previewAdjunct}?documentId=${
629
- this.photo
630
- }&adjunctId=${this.photo}&_tt=${new Date().getTime()}`;
631
- }
632
- }
633
- return this.photo;
634
- }
635
- },
636
- watch: {
637
- fileList: {
638
- immediate: true,
639
- deep: true,
640
- handler(val) {
641
- if (Array.isArray(val) && val.length > 0) {
642
- this.lists = val;
643
- let filesTotalSize = 0;
644
- val.forEach((item) => {
645
- if (
646
- Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
647
- item.fileSize
648
- ) {
649
- filesTotalSize += parseFloat(item.fileSize, 10);
650
- } else {
651
- filesTotalSize += item.size
652
- ? Math.round((item.size / 1024) * 10) / 10
653
- : 0;
654
- }
655
- });
656
- this.filesTotalSize = filesTotalSize;
657
- this.$emit('input', val);
658
- }
659
- }
660
- },
661
- value: {
662
- immediate: true,
663
- deep: true,
664
- handler(val) {
665
- if (val && typeof val === 'object' && this.showFileList) {
666
- if (Array.isArray(val)) {
667
- this.lists = val;
668
- } else {
669
- this.lists = [val];
670
- }
671
- }
672
- }
673
- },
674
- params: {
675
- deep: true,
676
- handler(val) {
677
- this.getFiles(val);
678
- }
679
- },
680
- lists: {
681
- deep: true,
682
- handler(val) {
683
- this.$emit('update:fileCount', val.length);
684
- this.$emit('getFilesAmount', val.length);
685
- }
686
- },
687
- display(val) {
688
- val && this.getHeight();
689
- }
690
- },
691
- beforeCreate() {
692
- this.getFiles = debounce(500, (params) => {
693
- this.getFileLists(params);
694
- });
695
- this.getAdjunctPropertie = debounce(500, () => {
696
- this.getAdjunctProperties();
697
- });
698
- },
699
- created() {
700
- const dochubConfig = sessionStorage.getItem('dochubConfig');
701
- if (dochubConfig) {
702
- this.dochubConfig = JSON.parse(dochubConfig);
703
- }
704
- this.getAdjunctPropertie();
705
- },
706
- mounted() {
707
- this.$nextTick(() => {
708
- this.getHeight();
709
- });
710
- },
711
- methods: {
712
- getHeight() {
713
- if (this.height === 'auto') {
714
- let pt =
715
- parseInt(util.getStyle(this.$el.parentNode, 'padding-top'), 10) || 0;
716
- let pb =
717
- parseInt(util.getStyle(this.$el.parentNode, 'padding-bottom'), 10) ||
718
- 0;
719
- let btn = this.$refs.upload
720
- ? this.$refs.upload.$children[0].$el.offsetHeight || 0
721
- : 0;
722
- this.boxHeight =
723
- this.$el.parentNode.offsetHeight - pt - pb - btn + 'px';
724
- }
725
- },
726
- //根据code获取附件参数配置
727
- getAdjunctProperties() {
728
- if (this.code !== undefined) {
729
- let config = store.get(this.code);
730
- if (config) {
731
- this.fileAccept = config.accept;
732
- this.fileSize = config.size;
733
- this.fileTotalSize = config.totalSize;
734
- if (config.dochubConfig) {
735
- this.dochubConfig = config.dochubConfig;
736
- }
737
-
738
- let url =
739
- this.portrait || this.documentId
740
- ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
741
- : this.dochubConfig.uploadDocumentUrl || uploads;
742
- this.uploadUrl = url.indexOf(this.host) > -1 ? url : this.host + url;
743
- this.requestFiles && this.getFiles(this.params);
744
- } else {
745
- util
746
- .ajax({
747
- method: this.method,
748
- url: this.properties,
749
- data: { code: this.code, ...this.param },
750
- params: { code: this.code, ...this.param }
751
- })
752
- .then((res) => {
753
- if (res.rCode === 0) {
754
- if (res.results) {
755
- this.excludeNames = res.results.excludeName;
756
- if (res.results.fileTypeExtName) {
757
- let fileTypeExtName =
758
- res.results.fileTypeExtName.split(';');
759
- this.fileAccept = fileTypeExtName
760
- .filter((item) => {
761
- return item;
762
- })
763
- .join(',');
764
- }
765
- if (res.results.dochubConfig) {
766
- this.dochubConfig = res.results.dochubConfig;
767
- sessionStorage.setItem(
768
- 'dochubConfig',
769
- JSON.stringify(res.results.dochubConfig)
770
- );
771
- }
772
- let url = this.portrait
773
- ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
774
- : this.dochubConfig.uploadDocumentUrl || uploads;
775
- this.uploadUrl =
776
- url.indexOf(this.host) > -1 ? url : this.host + url;
777
- if (res.results.kkViewRootPath) {
778
- this.kkfileview = res.results.kkViewRootPath;
779
- }
780
- this.fileSize = res.results.limitFileSize
781
- ? res.results.limitFileSize
782
- : 0;
783
- this.fileTotalSize = res.results.limitTotalSize;
784
- store.set(this.code, {
785
- accept: this.fileAccept,
786
- size: this.fileSize,
787
- totalSize: this.fileTotalSize,
788
- dochubConfig: this.dochubConfig
789
- });
790
- }
791
- this.requestFiles && this.getFiles(this.params);
792
- }
793
- })
794
- .catch((err) => {
795
- if (err.message && err.message !== 'canceled') {
796
- this.$message.error(err.message);
797
- }
798
- });
799
- }
800
- }
801
- },
802
- getFileLists(params) {
803
- if (
804
- !this.show ||
805
- (this.fileList &&
806
- Array.isArray(this.fileList) &&
807
- this.fileList.length) ||
808
- (this.requiredOwnId &&
809
- !Object.prototype.hasOwnProperty.call(params, 'ownId'))
810
- ) {
811
- return false;
812
- }
813
- let url =
814
- typeof this.fileList === 'string'
815
- ? this.fileList
816
- : this.dochubConfig.getDocumentList
817
- ? this.dochubConfig.getDocumentList
818
- : getAdjunctFileInfos;
819
- util
820
- .ajax({
821
- method: this.method,
822
- url: url,
823
- data: params,
824
- params: params,
825
- format: false
826
- })
827
- .then((res) => {
828
- if (res.rCode === 0) {
829
- if (this.portrait === true) {
830
- this.image = JSON.parse(JSON.stringify(res.results))[0];
831
- } else {
832
- this.lists = JSON.parse(JSON.stringify(res.results));
833
- let filesTotalSize = 0;
834
- this.lists.forEach((item) => {
835
- if (
836
- Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
837
- item.fileSize
838
- ) {
839
- filesTotalSize += parseFloat(item.fileSize, 10);
840
- } else {
841
- filesTotalSize += item.size
842
- ? Math.round((item.size / 1024) * 10) / 10
843
- : 0;
844
- }
845
- });
846
- this.filesTotalSize = filesTotalSize;
847
- if (this.lists.length) {
848
- this.$emit('input', this.lists);
849
- }
850
- }
851
- } else {
852
- let msg = res.msg || '系统错误,请联系管理员!';
853
- this.$message.error(msg);
854
- }
855
- })
856
- .catch((err) => {
857
- if (err.message && err.message !== 'canceled') {
858
- this.$message.error(err.message);
859
- }
860
- });
861
- },
862
- handleUpload() {
863
- this.$refs.upload.submit();
864
- },
865
- openKkfileview(file) {
866
- let host = util.win.location.origin;
867
- if (this.host) {
868
- if (util.startWith(this.host, 'http')) {
869
- host = this.host;
870
- } else {
871
- host += this.host;
872
- }
873
- }
874
- let url = encodeURIComponent(
875
- Base64.encode(
876
- host +
877
- (typeof this.download === 'string'
878
- ? this.download
879
- : downloadByAdjunctId) +
880
- `?adjunctId=${
881
- file.adjunctId || file.response.adjunctId
882
- }&fullfilename=${file.originalName}`
883
- )
884
- );
885
- util.win.open(`${this.kkfileview}?url=${url}`);
886
- },
887
- handlePreview(res) {
888
- if (this.preview) {
889
- if (this.onPreview) {
890
- this.onPreview(res);
891
- } else {
892
- let file = res.response ? res.response : res;
893
- let url =
894
- typeof this.preview === 'string'
895
- ? this.preview
896
- : typeof this.preview === 'function'
897
- ? this.preview(file)
898
- : null;
899
- if (res.status === 'success') {
900
- let suffix = file.suffix;
901
- suffix = suffix.toLowerCase();
902
- if (this.dochubConfig.previewDocumentUrl) {
903
- if (
904
- suffix.includes('jpge') ||
905
- suffix.includes('jpg') ||
906
- suffix.includes('gif') ||
907
- suffix.includes('png')
908
- ) {
909
- this.imgUrl =
910
- res.url && util.startWith(url, ['http', '/', true])
911
- ? res.url
912
- : this.host +
913
- (url
914
- ? url
915
- : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`);
916
- this.title = file.originalName;
917
- this.showImg = true;
918
- this.$nextTick(() => {
919
- this.loadImage();
920
- });
921
- } else if (suffix.includes('mp4')) {
922
- this.source = {
923
- src:
924
- this.host +
925
- (url
926
- ? url
927
- : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`)
928
- };
929
- this.title = file.originalName;
930
- this.showVideo = true;
931
- } else {
932
- util.win.open(
933
- this.host +
934
- (url
935
- ? url
936
- : `${this.dochubConfig.previewDocumentUrl}?documentId=${file.adjunctId}&action=附件预览`)
937
- );
938
- }
939
- } else {
940
- if (
941
- suffix.includes('doc') ||
942
- suffix.includes('docx') ||
943
- suffix.includes('xls') ||
944
- suffix.includes('xlsx') ||
945
- suffix.includes('ppt')
946
- ) {
947
- if (this.kkfileview) {
948
- this.openKkfileview(file);
949
- } else {
950
- util.win.open(
951
- this.host +
952
- (url ? url : previewAdjunctOffice) +
953
- '?cmd=view&bucketName=' +
954
- file.absolutePath +
955
- '&fileId=' +
956
- file.adjunctId +
957
- '&fileName=' +
958
- file.newName
959
- );
960
- }
961
- } else if (suffix.includes('pdf')) {
962
- if (this.kkfileview) {
963
- this.openKkfileview(file);
964
- } else {
965
- util.win.open(
966
- this.host +
967
- (url ? url : previewAdjunct2) +
968
- '/' +
969
- file.originalName +
970
- '?adjunctId=' +
971
- file.adjunctId
972
- );
973
- }
974
- } else if (
975
- suffix.includes('jpge') ||
976
- suffix.includes('jpg') ||
977
- suffix.includes('gif') ||
978
- suffix.includes('png')
979
- ) {
980
- this.imgUrl =
981
- res.url && util.startWith(url, ['http', '/', true])
982
- ? res.url
983
- : this.host +
984
- (url ? url : this.previewAdjunct) +
985
- '?adjunctId=' +
986
- file.adjunctId;
987
- this.title = file.originalName;
988
- this.showImg = true;
989
- this.$nextTick(() => {
990
- this.loadImage();
991
- });
992
- } else if (suffix.includes('mp4')) {
993
- this.source = {
994
- src:
995
- this.host +
996
- (url ? url : this.previewAdjunct) +
997
- '?adjunctId=' +
998
- file.adjunctId
999
- };
1000
- this.title = file.originalName;
1001
- this.showVideo = true;
1002
- } else {
1003
- if (this.kkfileview) {
1004
- this.openKkfileview(file);
1005
- } else {
1006
- util.win.open(
1007
- this.host +
1008
- (url ? url : this.previewAdjunct) +
1009
- '?adjunctId=' +
1010
- file.adjunctId
1011
- );
1012
- }
1013
- }
1014
- }
1015
- } else {
1016
- util.win.open(URL.createObjectURL(file.raw));
1017
- }
1018
- }
1019
- }
1020
- },
1021
- closeViewer() {
1022
- this.showImg = false;
1023
- },
1024
- loadImage() {
1025
- this.$refs.showImg &&
1026
- (this.$refs.showImg.onload = () => {
1027
- this.imgChange = false;
1028
- let w = this.$refs.showImg.naturalWidth;
1029
- let h = this.$refs.showImg.naturalHeight;
1030
- let pw = this.$refs.showImg.parentNode.offsetWidth;
1031
- let ph = this.$refs.showImg.parentNode.offsetHeight;
1032
- if (w / h > pw / ph) {
1033
- this.styles = { 'max-width': '100%' };
1034
- } else {
1035
- this.styles = { 'max-height': '100%' };
1036
- }
1037
- if (w < pw) {
1038
- this.styles.width = w + 'px';
1039
- }
1040
- if (h < ph) {
1041
- this.styles.height = h + 'px';
1042
- }
1043
- });
1044
- },
1045
- isLt(file) {
1046
- let flag = false;
1047
- let flieArr = file.name.split('.');
1048
- let suffix = '.' + flieArr[flieArr.length - 1].toLowerCase();
1049
- if (this.accepts) {
1050
- let accepts = this.accepts.toLowerCase().split(',');
1051
- flag = accepts.includes(suffix);
1052
- if (!flag) {
1053
- this.$message.error(`文件类型错误,请上传${this.accepts}类型文件!`);
1054
- return flag;
1055
- }
1056
- }
1057
- let size = this._size;
1058
- let text = '单个附件';
1059
- let se = Math.round((file.size / 1024) * 10) / 10;
1060
- if (this._size === 0 && this._totalSize === 0) {
1061
- flag = true;
1062
- } else if (this._size > 0 && this._totalSize === 0) {
1063
- flag = se < this._size;
1064
- size = this._size;
1065
- text = '单个附件';
1066
- } else if (this._size === 0 && this._totalSize > 0) {
1067
- flag = this.filesTotalSize + se < this._totalSize;
1068
- size = this._totalSize;
1069
- text = '附件总';
1070
- } else {
1071
- flag = se < this._size && this.filesTotalSize + se < this._totalSize;
1072
- if (se < this._size) {
1073
- size = this._size;
1074
- text = '单个附件';
1075
- } else {
1076
- size = this._totalSize;
1077
- text = '附件总';
1078
- }
1079
- }
1080
- if (!flag) {
1081
- this.$message.error(`上传${text}大小不能超过${size}KB!`);
1082
- return flag;
1083
- }
1084
- return flag;
1085
- },
1086
- handleBeforeUpload(file) {
1087
- const flag = this.isLt(file);
1088
- if (this.portrait) {
1089
- if (flag && this.beforeUpload) {
1090
- return this.beforeUpload(file);
1091
- }
1092
- return flag;
1093
- }
1094
- if (this.beforeUpload) {
1095
- if (flag) {
1096
- return this.beforeUpload(file);
1097
- }
1098
- return flag;
1099
- }
1100
- return flag;
1101
- },
1102
- handleBeforeRemove(file, fileList) {
1103
- if (file && file.status === 'success') {
1104
- return this.$confirm('确定删除文件吗?', '提示', {
1105
- confirmButtonText: '确定',
1106
- cancelButtonText: '取消',
1107
- type: 'warning'
1108
- })
1109
- .then(() => {
1110
- if (this.beforeRemove) {
1111
- return this.beforeRemove(file, fileList);
1112
- } else if (file.status === 'success') {
1113
- let userName =
1114
- file.userName ||
1115
- (file.response && file.response.userName) ||
1116
- util.getStorage('userName');
1117
- // eslint-disable-next-line no-undef
1118
- return new Promise((resolve, reject) => {
1119
- let url =
1120
- typeof this.deleted === 'string'
1121
- ? this.deleted
1122
- : this.remove === 'string'
1123
- ? this.remove
1124
- : this.dochubConfig.deleteDocumentUrl || delAdjunct;
1125
- util
1126
- .ajax({
1127
- method: this.method,
1128
- url: url,
1129
- data: {
1130
- userName: userName,
1131
- documentId: file.adjunctId || file.response.adjunctId,
1132
- id: file.adjunctId || file.response.adjunctId
1133
- },
1134
- params: {
1135
- userName: userName,
1136
- documentId: file.adjunctId || file.response.adjunctId,
1137
- id: file.adjunctId || file.response.adjunctId
1138
- }
1139
- })
1140
- .then((res) => {
1141
- if (res.rCode === 0) {
1142
- let se =
1143
- this.filesTotalSize -
1144
- Math.round((file.size / 1024) * 10) / 10;
1145
- this.filesTotalSize = se;
1146
- this.$message.success(res.msg);
1147
- resolve();
1148
- } else {
1149
- let msg = res.msg || '系统错误,请联系管理员!';
1150
- this.$message.error(msg);
1151
- reject();
1152
- }
1153
- })
1154
- .catch((err) => {
1155
- if (err.message && err.message !== 'canceled') {
1156
- this.$message.error(err.message);
1157
- }
1158
- });
1159
- });
1160
- }
1161
- return true;
1162
- })
1163
- .catch(() => {
1164
- return flag;
1165
- });
1166
- }
1167
- },
1168
- handleDownloads() {
1169
- let url =
1170
- typeof this.downloads === 'string'
1171
- ? this.downloads
1172
- : this.dochubConfig.compressDownloadDocumentUrl || uploadDownloads;
1173
- util.win.open(
1174
- this.host +
1175
- url +
1176
- '?ownId=' +
1177
- this.ownId +
1178
- '&code=' +
1179
- this.code +
1180
- (this.extendCode ? '&extendCode=' + this.extendCode : '')
1181
- );
1182
- },
1183
- handleDownload(file) {
1184
- if (file.status === 'success') {
1185
- let url =
1186
- typeof this.download === 'string'
1187
- ? this.download
1188
- : this.dochubConfig.downloadDocumentUrl || downloadByAdjunctId;
1189
- util.win.open(
1190
- this.host +
1191
- url +
1192
- '?adjunctId=' +
1193
- (file.adjunctId || file.response.adjunctId) +
1194
- '&documentId=' +
1195
- (file.adjunctId || file.response.adjunctId)
1196
- );
1197
- } else {
1198
- this.aLinkDownload(file);
1199
- }
1200
- },
1201
- handleClick(res) {
1202
- if (res.event && typeof res.event === 'function') {
1203
- res.event(res);
1204
- } else {
1205
- this.$emit('click', res);
1206
- }
1207
- },
1208
- aLinkDownload(file) {
1209
- var a = document.createElement('a');
1210
- let event = new MouseEvent('click');
1211
- a.href = URL.createObjectURL(file.raw);
1212
- a.download = file.name;
1213
- a.dispatchEvent(event);
1214
- },
1215
- handleSort(files) {
1216
- if (this.isSort) {
1217
- if (this.onSort) {
1218
- this.onSort(files);
1219
- } else {
1220
- let ids = files.map((item) => {
1221
- if (item.status === 'success') {
1222
- return item.adjunctId || item.response.adjunctId;
1223
- }
1224
- });
1225
- ids = ids.join(',');
1226
- util
1227
- .ajax({
1228
- method: this.method,
1229
- url: this.dochubConfig.sortDocumentsUrl || uploadSort,
1230
- data: {
1231
- ids: ids,
1232
- documentIds: ids,
1233
- ownId: this.ownId,
1234
- code: this.code,
1235
- bucketCode: this.code,
1236
- businessId: this.ownId
1237
- },
1238
- params: {
1239
- ids: ids,
1240
- documentIds: ids,
1241
- ownId: this.ownId,
1242
- code: this.code,
1243
- bucketCode: this.code,
1244
- businessId: this.ownId
1245
- }
1246
- })
1247
- .then((res) => {
1248
- if (res.rCode === 0) {
1249
- this.$message.success(res.msg);
1250
- } else {
1251
- let msg = res.msg || '系统错误,请联系管理员!';
1252
- this.$message.error(msg);
1253
- }
1254
- })
1255
- .catch((err) => {
1256
- if (err.message && err.message !== 'canceled') {
1257
- this.$message.error(err.message);
1258
- }
1259
- });
1260
- }
1261
- }
1262
- },
1263
- handleSuccess(response, file, fileList) {
1264
- if (this.portrait) {
1265
- this.image = URL.createObjectURL(file.raw);
1266
- }
1267
- if (this.showMessage.success) {
1268
- if (response.rCode) {
1269
- if (this.dangerouslyUseHTMLString) {
1270
- this.$alert(
1271
- response.msg ? response.msg : '上传失败:请联系管理员',
1272
- '提示',
1273
- {
1274
- dangerouslyUseHTMLString: true,
1275
- setHeight: response.msg
1276
- }
1277
- ).catch();
1278
- } else {
1279
- this.$message({
1280
- type: 'error',
1281
- message: response.msg || '成功!'
1282
- });
1283
- }
1284
- } else {
1285
- this.$message.success(response.msg);
1286
- }
1287
- }
1288
- let se =
1289
- this.filesTotalSize +
1290
- (this.resultFile ? Math.round((file.size / 1024) * 10) / 10 : 0);
1291
- this.filesTotalSize = se;
1292
- this.onSuccess &&
1293
- this.onSuccess(response, file, fileList, this.dochubConfig);
1294
- this.$emit('success', response, file, fileList, this.dochubConfig);
1295
- if (this.resultFile) {
1296
- if (this.portrait) {
1297
- this.$emit('input', file);
1298
- } else {
1299
- this.$emit('input', fileList);
1300
- }
1301
- if (this.elForm) {
1302
- this.elForm.clearValidate(this.name);
1303
- }
1304
- }
1305
- },
1306
- handleChange(file, fileList) {
1307
- this.$emit('change', fileList);
1308
- this.onChange && this.onChange(file, fileList);
1309
- },
1310
- handleRemove(file, fileList) {
1311
- this.$emit('input', fileList.length ? fileList : '');
1312
- this.$emit('remove', file, fileList);
1313
- this.$emit('change', fileList);
1314
- this.onRemove && this.onRemove(file, fileList);
1315
- },
1316
- handleError(err, file, fileList) {
1317
- if (this.showMessage.error) {
1318
- if (this.dangerouslyUseHTMLString) {
1319
- this.$alert(err.msg ? err.msg : '上传失败:请联系管理员', '提示', {
1320
- dangerouslyUseHTMLString: true,
1321
- setHeight: err.msg
1322
- }).catch();
1323
- } else {
1324
- this.$message({
1325
- type: 'error',
1326
- message: '上传失败:' + (err.msg ? err.msg : '请联系管理员')
1327
- });
1328
- }
1329
- }
1330
- this.$emit('error', err, file, fileList);
1331
- this.onError && this.onError(err, file, fileList);
1332
- }
1333
- }
1334
- };
1335
- </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
+ return this.dragSort && !this.isDisabled;
546
+ },
547
+ datas() {
548
+ if (this.data) {
549
+ return util.extend({}, this.data, this.params);
550
+ }
551
+ return this.params;
552
+ },
553
+ params() {
554
+ let params = { userId: util.getStorage('userId'), ...this.param };
555
+ if (this.code !== undefined) {
556
+ params.code = this.code;
557
+ params.bucketCode = this.code;
558
+ }
559
+ if (this.ownId !== undefined) {
560
+ params.ownId = this.ownId;
561
+ params.businessId = this.ownId;
562
+ }
563
+ return params;
564
+ },
565
+ showMessage() {
566
+ if (this.message !== undefined) {
567
+ return util.extend({}, { success: true, error: true }, this.message);
568
+ }
569
+ return { success: true, error: true };
570
+ },
571
+ profile() {
572
+ const previewAdjunct =
573
+ this.dochubConfig.downloadDocumentUrl || this.previewAdjunct;
574
+ if (this.image) {
575
+ if (typeof this.image === 'string') {
576
+ return this.image;
577
+ }
578
+ return `${this.host}${previewAdjunct}?documentId=${
579
+ this.image.adjunctId
580
+ }&adjunctId=${this.image.adjunctId}&_tt=${new Date().getTime()}`;
581
+ }
582
+ if (this.value) {
583
+ if (typeof this.value === 'string') {
584
+ if (this.value.indexOf('data:image/') === 0) {
585
+ return this.value;
586
+ } else if (this.value.indexOf(previewAdjunct) > -1) {
587
+ let val =
588
+ this.host +
589
+ util.jointUrl({
590
+ url: this.value,
591
+ reg: '/main2'
592
+ });
593
+ return val;
594
+ } else if (this.value.indexOf('/') === -1) {
595
+ return `${this.host}${previewAdjunct}?documentId=${
596
+ this.value
597
+ }&adjunctId=${this.value}&_tt=${new Date().getTime()}`;
598
+ }
599
+ return this.value;
600
+ } else if (Array.isArray(this.value)) {
601
+ let adjunctId = this.value[0].response
602
+ ? this.value[0].response.adjunctId
603
+ : this.value[0].adjunctId;
604
+ return `${
605
+ this.host
606
+ }${previewAdjunct}?documentId=${adjunctId}&adjunctId=${adjunctId}&_tt=${new Date().getTime()}`;
607
+ } else {
608
+ let adjunctId = this.value.response
609
+ ? this.value.response.adjunctId
610
+ : this.value.adjunctId;
611
+ return `${
612
+ this.host
613
+ }${previewAdjunct}?documentId=${adjunctId}&adjunctId=${adjunctId}&_tt=${new Date().getTime()}`;
614
+ }
615
+ }
616
+ if (this.photo && typeof this.photo === 'string') {
617
+ if (this.photo.indexOf('data:image/') === 0) {
618
+ return this.photo;
619
+ } else if (this.photo.indexOf(previewAdjunct) > -1) {
620
+ let val =
621
+ this.host +
622
+ util.jointUrl({
623
+ url: this.value,
624
+ reg: '/main2'
625
+ });
626
+ return val;
627
+ } else if (this.photo.indexOf('/') === -1) {
628
+ return `${this.host}${previewAdjunct}?documentId=${
629
+ this.photo
630
+ }&adjunctId=${this.photo}&_tt=${new Date().getTime()}`;
631
+ }
632
+ }
633
+ return this.photo;
634
+ }
635
+ },
636
+ watch: {
637
+ fileList: {
638
+ immediate: true,
639
+ deep: true,
640
+ handler(val) {
641
+ if (Array.isArray(val) && val.length > 0) {
642
+ this.lists = val;
643
+ let filesTotalSize = 0;
644
+ val.forEach((item) => {
645
+ if (
646
+ Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
647
+ item.fileSize
648
+ ) {
649
+ filesTotalSize += parseFloat(item.fileSize, 10);
650
+ } else {
651
+ filesTotalSize += item.size
652
+ ? Math.round((item.size / 1024) * 10) / 10
653
+ : 0;
654
+ }
655
+ });
656
+ this.filesTotalSize = filesTotalSize;
657
+ this.$emit('input', val);
658
+ }
659
+ }
660
+ },
661
+ value: {
662
+ immediate: true,
663
+ deep: true,
664
+ handler(val) {
665
+ if (val && typeof val === 'object' && this.showFileList) {
666
+ if (Array.isArray(val)) {
667
+ this.lists = val;
668
+ } else {
669
+ this.lists = [val];
670
+ }
671
+ }
672
+ }
673
+ },
674
+ params: {
675
+ deep: true,
676
+ handler(val) {
677
+ this.getFiles(val);
678
+ }
679
+ },
680
+ lists: {
681
+ deep: true,
682
+ handler(val) {
683
+ this.$emit('update:fileCount', val.length);
684
+ this.$emit('getFilesAmount', val.length);
685
+ }
686
+ },
687
+ display(val) {
688
+ val && this.getHeight();
689
+ }
690
+ },
691
+ beforeCreate() {
692
+ this.getFiles = debounce(500, (params) => {
693
+ this.getFileLists(params);
694
+ });
695
+ this.getAdjunctPropertie = debounce(500, () => {
696
+ this.getAdjunctProperties();
697
+ });
698
+ },
699
+ created() {
700
+ const dochubConfig = sessionStorage.getItem('dochubConfig');
701
+ if (dochubConfig) {
702
+ this.dochubConfig = JSON.parse(dochubConfig);
703
+ }
704
+ this.getAdjunctPropertie();
705
+ },
706
+ mounted() {
707
+ this.$nextTick(() => {
708
+ this.getHeight();
709
+ });
710
+ },
711
+ methods: {
712
+ getHeight() {
713
+ if (this.height === 'auto') {
714
+ let pt =
715
+ parseInt(util.getStyle(this.$el.parentNode, 'padding-top'), 10) || 0;
716
+ let pb =
717
+ parseInt(util.getStyle(this.$el.parentNode, 'padding-bottom'), 10) ||
718
+ 0;
719
+ let btn = this.$refs.upload
720
+ ? this.$refs.upload.$children[0].$el.offsetHeight || 0
721
+ : 0;
722
+ this.boxHeight =
723
+ this.$el.parentNode.offsetHeight - pt - pb - btn + 'px';
724
+ }
725
+ },
726
+ //根据code获取附件参数配置
727
+ getAdjunctProperties() {
728
+ if (this.code !== undefined) {
729
+ let config = store.get(this.code);
730
+ if (config) {
731
+ this.fileAccept = config.accept;
732
+ this.fileSize = config.size;
733
+ this.fileTotalSize = config.totalSize;
734
+ if (config.dochubConfig) {
735
+ this.dochubConfig = config.dochubConfig;
736
+ }
737
+
738
+ let url =
739
+ this.portrait || this.documentId
740
+ ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
741
+ : this.dochubConfig.uploadDocumentUrl || uploads;
742
+ this.uploadUrl = url.indexOf(this.host) > -1 ? url : this.host + url;
743
+ this.requestFiles && this.getFiles(this.params);
744
+ } else {
745
+ util
746
+ .ajax({
747
+ method: this.method,
748
+ url: this.properties,
749
+ data: { code: this.code, ...this.param },
750
+ params: { code: this.code, ...this.param }
751
+ })
752
+ .then((res) => {
753
+ if (res.rCode === 0) {
754
+ if (res.results) {
755
+ this.excludeNames = res.results.excludeName;
756
+ if (res.results.fileTypeExtName) {
757
+ let fileTypeExtName =
758
+ res.results.fileTypeExtName.split(';');
759
+ this.fileAccept = fileTypeExtName
760
+ .filter((item) => {
761
+ return item;
762
+ })
763
+ .join(',');
764
+ }
765
+ if (res.results.dochubConfig) {
766
+ this.dochubConfig = res.results.dochubConfig;
767
+ sessionStorage.setItem(
768
+ 'dochubConfig',
769
+ JSON.stringify(res.results.dochubConfig)
770
+ );
771
+ }
772
+ let url = this.portrait
773
+ ? this.dochubConfig.reuploadDocumentUrl || uploadOnlyOne
774
+ : this.dochubConfig.uploadDocumentUrl || uploads;
775
+ this.uploadUrl =
776
+ url.indexOf(this.host) > -1 ? url : this.host + url;
777
+ if (res.results.kkViewRootPath) {
778
+ this.kkfileview = res.results.kkViewRootPath;
779
+ }
780
+ this.fileSize = res.results.limitFileSize
781
+ ? res.results.limitFileSize
782
+ : 0;
783
+ this.fileTotalSize = res.results.limitTotalSize;
784
+ store.set(this.code, {
785
+ accept: this.fileAccept,
786
+ size: this.fileSize,
787
+ totalSize: this.fileTotalSize,
788
+ dochubConfig: this.dochubConfig
789
+ });
790
+ }
791
+ this.requestFiles && this.getFiles(this.params);
792
+ }
793
+ })
794
+ .catch((err) => {
795
+ if (err.message && err.message !== 'canceled') {
796
+ this.$message.error(err.message);
797
+ }
798
+ });
799
+ }
800
+ }
801
+ },
802
+ getFileLists(params) {
803
+ if (
804
+ !this.show ||
805
+ (this.fileList &&
806
+ Array.isArray(this.fileList) &&
807
+ this.fileList.length) ||
808
+ (this.requiredOwnId &&
809
+ !Object.prototype.hasOwnProperty.call(params, 'ownId'))
810
+ ) {
811
+ return false;
812
+ }
813
+ let url =
814
+ typeof this.fileList === 'string'
815
+ ? this.fileList
816
+ : this.dochubConfig.getDocumentList
817
+ ? this.dochubConfig.getDocumentList
818
+ : getAdjunctFileInfos;
819
+ util
820
+ .ajax({
821
+ method: this.method,
822
+ url: url,
823
+ data: params,
824
+ params: params,
825
+ format: false
826
+ })
827
+ .then((res) => {
828
+ if (res.rCode === 0) {
829
+ if (this.portrait === true) {
830
+ this.image = JSON.parse(JSON.stringify(res.results))[0];
831
+ } else {
832
+ this.lists = JSON.parse(JSON.stringify(res.results));
833
+ let filesTotalSize = 0;
834
+ this.lists.forEach((item) => {
835
+ if (
836
+ Object.prototype.hasOwnProperty.call(item, 'fileSize') &&
837
+ item.fileSize
838
+ ) {
839
+ filesTotalSize += parseFloat(item.fileSize, 10);
840
+ } else {
841
+ filesTotalSize += item.size
842
+ ? Math.round((item.size / 1024) * 10) / 10
843
+ : 0;
844
+ }
845
+ });
846
+ this.filesTotalSize = filesTotalSize;
847
+ if (this.lists.length) {
848
+ this.$emit('input', this.lists);
849
+ }
850
+ }
851
+ } else {
852
+ let msg = res.msg || '系统错误,请联系管理员!';
853
+ this.$message.error(msg);
854
+ }
855
+ })
856
+ .catch((err) => {
857
+ if (err.message && err.message !== 'canceled') {
858
+ this.$message.error(err.message);
859
+ }
860
+ });
861
+ },
862
+ handleUpload() {
863
+ this.$refs.upload.submit();
864
+ },
865
+ openKkfileview(file) {
866
+ let host = util.win.location.origin;
867
+ if (this.host) {
868
+ if (util.startWith(this.host, 'http')) {
869
+ host = this.host;
870
+ } else {
871
+ host += this.host;
872
+ }
873
+ }
874
+ let url = encodeURIComponent(
875
+ Base64.encode(
876
+ host +
877
+ (typeof this.download === 'string'
878
+ ? this.download
879
+ : downloadByAdjunctId) +
880
+ `?adjunctId=${
881
+ file.adjunctId || file.response.adjunctId
882
+ }&fullfilename=${file.originalName}`
883
+ )
884
+ );
885
+ util.win.open(`${this.kkfileview}?url=${url}`);
886
+ },
887
+ handlePreview(res) {
888
+ if (this.preview) {
889
+ if (this.onPreview) {
890
+ this.onPreview(res);
891
+ } else {
892
+ let file = res.response ? res.response : res;
893
+ let url =
894
+ typeof this.preview === 'string'
895
+ ? this.preview
896
+ : typeof this.preview === 'function'
897
+ ? this.preview(file)
898
+ : null;
899
+ if (res.status === 'success') {
900
+ let suffix = file.suffix;
901
+ suffix = suffix.toLowerCase();
902
+ if (this.dochubConfig.previewDocumentUrl) {
903
+ if (
904
+ suffix.includes('jpge') ||
905
+ suffix.includes('jpg') ||
906
+ suffix.includes('gif') ||
907
+ suffix.includes('png')
908
+ ) {
909
+ this.imgUrl =
910
+ res.url && util.startWith(url, ['http', '/', true])
911
+ ? res.url
912
+ : this.host +
913
+ (url
914
+ ? url
915
+ : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`);
916
+ this.title = file.originalName;
917
+ this.showImg = true;
918
+ this.$nextTick(() => {
919
+ this.loadImage();
920
+ });
921
+ } else if (suffix.includes('mp4')) {
922
+ this.source = {
923
+ src:
924
+ this.host +
925
+ (url
926
+ ? url
927
+ : `${this.dochubConfig.downloadDocumentUrl}?documentId=${file.adjunctId}`)
928
+ };
929
+ this.title = file.originalName;
930
+ this.showVideo = true;
931
+ } else {
932
+ util.win.open(
933
+ this.host +
934
+ (url
935
+ ? url
936
+ : `${this.dochubConfig.previewDocumentUrl}?documentId=${file.adjunctId}&action=附件预览`)
937
+ );
938
+ }
939
+ } else {
940
+ if (
941
+ suffix.includes('doc') ||
942
+ suffix.includes('docx') ||
943
+ suffix.includes('xls') ||
944
+ suffix.includes('xlsx') ||
945
+ suffix.includes('ppt')
946
+ ) {
947
+ if (this.kkfileview) {
948
+ this.openKkfileview(file);
949
+ } else {
950
+ util.win.open(
951
+ this.host +
952
+ (url ? url : previewAdjunctOffice) +
953
+ '?cmd=view&bucketName=' +
954
+ file.absolutePath +
955
+ '&fileId=' +
956
+ file.adjunctId +
957
+ '&fileName=' +
958
+ file.newName
959
+ );
960
+ }
961
+ } else if (suffix.includes('pdf')) {
962
+ if (this.kkfileview) {
963
+ this.openKkfileview(file);
964
+ } else {
965
+ util.win.open(
966
+ this.host +
967
+ (url ? url : previewAdjunct2) +
968
+ '/' +
969
+ file.originalName +
970
+ '?adjunctId=' +
971
+ file.adjunctId
972
+ );
973
+ }
974
+ } else if (
975
+ suffix.includes('jpge') ||
976
+ suffix.includes('jpg') ||
977
+ suffix.includes('gif') ||
978
+ suffix.includes('png')
979
+ ) {
980
+ this.imgUrl =
981
+ res.url && util.startWith(url, ['http', '/', true])
982
+ ? res.url
983
+ : this.host +
984
+ (url ? url : this.previewAdjunct) +
985
+ '?adjunctId=' +
986
+ file.adjunctId;
987
+ this.title = file.originalName;
988
+ this.showImg = true;
989
+ this.$nextTick(() => {
990
+ this.loadImage();
991
+ });
992
+ } else if (suffix.includes('mp4')) {
993
+ this.source = {
994
+ src:
995
+ this.host +
996
+ (url ? url : this.previewAdjunct) +
997
+ '?adjunctId=' +
998
+ file.adjunctId
999
+ };
1000
+ this.title = file.originalName;
1001
+ this.showVideo = true;
1002
+ } else {
1003
+ if (this.kkfileview) {
1004
+ this.openKkfileview(file);
1005
+ } else {
1006
+ util.win.open(
1007
+ this.host +
1008
+ (url ? url : this.previewAdjunct) +
1009
+ '?adjunctId=' +
1010
+ file.adjunctId
1011
+ );
1012
+ }
1013
+ }
1014
+ }
1015
+ } else {
1016
+ util.win.open(URL.createObjectURL(file.raw));
1017
+ }
1018
+ }
1019
+ }
1020
+ },
1021
+ closeViewer() {
1022
+ this.showImg = false;
1023
+ },
1024
+ loadImage() {
1025
+ this.$refs.showImg &&
1026
+ (this.$refs.showImg.onload = () => {
1027
+ this.imgChange = false;
1028
+ let w = this.$refs.showImg.naturalWidth;
1029
+ let h = this.$refs.showImg.naturalHeight;
1030
+ let pw = this.$refs.showImg.parentNode.offsetWidth;
1031
+ let ph = this.$refs.showImg.parentNode.offsetHeight;
1032
+ if (w / h > pw / ph) {
1033
+ this.styles = { 'max-width': '100%' };
1034
+ } else {
1035
+ this.styles = { 'max-height': '100%' };
1036
+ }
1037
+ if (w < pw) {
1038
+ this.styles.width = w + 'px';
1039
+ }
1040
+ if (h < ph) {
1041
+ this.styles.height = h + 'px';
1042
+ }
1043
+ });
1044
+ },
1045
+ isLt(file) {
1046
+ let flag = false;
1047
+ let flieArr = file.name.split('.');
1048
+ let suffix = '.' + flieArr[flieArr.length - 1].toLowerCase();
1049
+ if (this.accepts) {
1050
+ let accepts = this.accepts.toLowerCase().split(',');
1051
+ flag = accepts.includes(suffix);
1052
+ if (!flag) {
1053
+ this.$message.error(`文件类型错误,请上传${this.accepts}类型文件!`);
1054
+ return flag;
1055
+ }
1056
+ }
1057
+ let size = this._size;
1058
+ let text = '单个附件';
1059
+ let se = Math.round((file.size / 1024) * 10) / 10;
1060
+ if (this._size === 0 && this._totalSize === 0) {
1061
+ flag = true;
1062
+ } else if (this._size > 0 && this._totalSize === 0) {
1063
+ flag = se < this._size;
1064
+ size = this._size;
1065
+ text = '单个附件';
1066
+ } else if (this._size === 0 && this._totalSize > 0) {
1067
+ flag = this.filesTotalSize + se < this._totalSize;
1068
+ size = this._totalSize;
1069
+ text = '附件总';
1070
+ } else {
1071
+ flag = se < this._size && this.filesTotalSize + se < this._totalSize;
1072
+ if (se < this._size) {
1073
+ size = this._size;
1074
+ text = '单个附件';
1075
+ } else {
1076
+ size = this._totalSize;
1077
+ text = '附件总';
1078
+ }
1079
+ }
1080
+ if (!flag) {
1081
+ this.$message.error(`上传${text}大小不能超过${size}KB!`);
1082
+ return flag;
1083
+ }
1084
+ return flag;
1085
+ },
1086
+ handleBeforeUpload(file) {
1087
+ const flag = this.isLt(file);
1088
+ if (this.portrait) {
1089
+ if (flag && this.beforeUpload) {
1090
+ return this.beforeUpload(file);
1091
+ }
1092
+ return flag;
1093
+ }
1094
+ if (this.beforeUpload) {
1095
+ if (flag) {
1096
+ return this.beforeUpload(file);
1097
+ }
1098
+ return flag;
1099
+ }
1100
+ return flag;
1101
+ },
1102
+ handleBeforeRemove(file, fileList) {
1103
+ if (file && file.status === 'success') {
1104
+ return this.$confirm('确定删除文件吗?', '提示', {
1105
+ confirmButtonText: '确定',
1106
+ cancelButtonText: '取消',
1107
+ type: 'warning'
1108
+ })
1109
+ .then(() => {
1110
+ if (this.beforeRemove) {
1111
+ return this.beforeRemove(file, fileList);
1112
+ } else if (file.status === 'success') {
1113
+ let userName =
1114
+ file.userName ||
1115
+ (file.response && file.response.userName) ||
1116
+ util.getStorage('userName');
1117
+ // eslint-disable-next-line no-undef
1118
+ return new Promise((resolve, reject) => {
1119
+ let url =
1120
+ typeof this.deleted === 'string'
1121
+ ? this.deleted
1122
+ : this.remove === 'string'
1123
+ ? this.remove
1124
+ : this.dochubConfig.deleteDocumentUrl || delAdjunct;
1125
+ util
1126
+ .ajax({
1127
+ method: this.method,
1128
+ url: url,
1129
+ data: {
1130
+ userName: userName,
1131
+ documentId: file.adjunctId || file.response.adjunctId,
1132
+ id: file.adjunctId || file.response.adjunctId
1133
+ },
1134
+ params: {
1135
+ userName: userName,
1136
+ documentId: file.adjunctId || file.response.adjunctId,
1137
+ id: file.adjunctId || file.response.adjunctId
1138
+ }
1139
+ })
1140
+ .then((res) => {
1141
+ if (res.rCode === 0) {
1142
+ let se =
1143
+ this.filesTotalSize -
1144
+ Math.round((file.size / 1024) * 10) / 10;
1145
+ this.filesTotalSize = se;
1146
+ this.$message.success(res.msg);
1147
+ resolve();
1148
+ } else {
1149
+ let msg = res.msg || '系统错误,请联系管理员!';
1150
+ this.$message.error(msg);
1151
+ reject();
1152
+ }
1153
+ })
1154
+ .catch((err) => {
1155
+ if (err.message && err.message !== 'canceled') {
1156
+ this.$message.error(err.message);
1157
+ }
1158
+ });
1159
+ });
1160
+ }
1161
+ return true;
1162
+ })
1163
+ .catch(() => {
1164
+ return flag;
1165
+ });
1166
+ }
1167
+ },
1168
+ handleDownloads() {
1169
+ let url =
1170
+ typeof this.downloads === 'string'
1171
+ ? this.downloads
1172
+ : this.dochubConfig.compressDownloadDocumentUrl || uploadDownloads;
1173
+ util.win.open(
1174
+ this.host +
1175
+ url +
1176
+ '?ownId=' +
1177
+ this.ownId +
1178
+ '&code=' +
1179
+ this.code +
1180
+ (this.extendCode ? '&extendCode=' + this.extendCode : '') +
1181
+ '&businessId=' +
1182
+ this.ownId +
1183
+ '&fileName=文档.zip'+
1184
+ '&bucketCode=' + this.code
1185
+ );
1186
+ },
1187
+ handleDownload(file) {
1188
+ if (file.status === 'success') {
1189
+ let url =
1190
+ typeof this.download === 'string'
1191
+ ? this.download
1192
+ : this.dochubConfig.downloadDocumentUrl || downloadByAdjunctId;
1193
+ util.win.open(
1194
+ this.host +
1195
+ url +
1196
+ '?adjunctId=' +
1197
+ (file.adjunctId || file.response.adjunctId) +
1198
+ '&documentId=' +
1199
+ (file.adjunctId || file.response.adjunctId)
1200
+ );
1201
+ } else {
1202
+ this.aLinkDownload(file);
1203
+ }
1204
+ },
1205
+ handleClick(res) {
1206
+ if (res.event && typeof res.event === 'function') {
1207
+ res.event(res);
1208
+ } else {
1209
+ this.$emit('click', res);
1210
+ }
1211
+ },
1212
+ aLinkDownload(file) {
1213
+ var a = document.createElement('a');
1214
+ let event = new MouseEvent('click');
1215
+ a.href = URL.createObjectURL(file.raw);
1216
+ a.download = file.name;
1217
+ a.dispatchEvent(event);
1218
+ },
1219
+ handleSort(files) {
1220
+ if (this.isSort) {
1221
+ if (this.onSort) {
1222
+ this.onSort(files);
1223
+ } else {
1224
+ let ids = files.map((item) => {
1225
+ if (item.status === 'success') {
1226
+ return item.adjunctId || item.response.adjunctId;
1227
+ }
1228
+ });
1229
+ ids = ids.join(',');
1230
+ util
1231
+ .ajax({
1232
+ method: this.method,
1233
+ url: this.dochubConfig.sortDocumentsUrl || uploadSort,
1234
+ data: {
1235
+ ids: ids,
1236
+ documentIds: ids,
1237
+ ownId: this.ownId,
1238
+ code: this.code,
1239
+ bucketCode: this.code,
1240
+ businessId: this.ownId
1241
+ },
1242
+ params: {
1243
+ ids: ids,
1244
+ documentIds: ids,
1245
+ ownId: this.ownId,
1246
+ code: this.code,
1247
+ bucketCode: this.code,
1248
+ businessId: this.ownId
1249
+ }
1250
+ })
1251
+ .then((res) => {
1252
+ if (res.rCode === 0) {
1253
+ this.$message.success(res.msg);
1254
+ } else {
1255
+ let msg = res.msg || '系统错误,请联系管理员!';
1256
+ this.$message.error(msg);
1257
+ }
1258
+ })
1259
+ .catch((err) => {
1260
+ if (err.message && err.message !== 'canceled') {
1261
+ this.$message.error(err.message);
1262
+ }
1263
+ });
1264
+ }
1265
+ }
1266
+ },
1267
+ handleSuccess(response, file, fileList) {
1268
+ if (this.portrait) {
1269
+ this.image = URL.createObjectURL(file.raw);
1270
+ }
1271
+ if (this.showMessage.success) {
1272
+ if (response.rCode) {
1273
+ if (this.dangerouslyUseHTMLString) {
1274
+ this.$alert(
1275
+ response.msg ? response.msg : '上传失败:请联系管理员',
1276
+ '提示',
1277
+ {
1278
+ dangerouslyUseHTMLString: true,
1279
+ setHeight: response.msg
1280
+ }
1281
+ ).catch();
1282
+ } else {
1283
+ this.$message({
1284
+ type: 'error',
1285
+ message: response.msg || '成功!'
1286
+ });
1287
+ }
1288
+ } else {
1289
+ this.$message.success(response.msg);
1290
+ }
1291
+ }
1292
+ let se =
1293
+ this.filesTotalSize +
1294
+ (this.resultFile ? Math.round((file.size / 1024) * 10) / 10 : 0);
1295
+ this.filesTotalSize = se;
1296
+ this.onSuccess &&
1297
+ this.onSuccess(response, file, fileList, this.dochubConfig);
1298
+ this.$emit('success', response, file, fileList, this.dochubConfig);
1299
+ if (this.resultFile) {
1300
+ if (this.portrait) {
1301
+ this.$emit('input', file);
1302
+ } else {
1303
+ this.$emit('input', fileList);
1304
+ }
1305
+ if (this.elForm) {
1306
+ this.elForm.clearValidate(this.name);
1307
+ }
1308
+ }
1309
+ },
1310
+ handleChange(file, fileList) {
1311
+ this.$emit('change', fileList);
1312
+ this.onChange && this.onChange(file, fileList);
1313
+ },
1314
+ handleRemove(file, fileList) {
1315
+ this.$emit('input', fileList.length ? fileList : '');
1316
+ this.$emit('remove', file, fileList);
1317
+ this.$emit('change', fileList);
1318
+ this.onRemove && this.onRemove(file, fileList);
1319
+ },
1320
+ handleError(err, file, fileList) {
1321
+ if (this.showMessage.error) {
1322
+ if (this.dangerouslyUseHTMLString) {
1323
+ this.$alert(err.msg ? err.msg : '上传失败:请联系管理员', '提示', {
1324
+ dangerouslyUseHTMLString: true,
1325
+ setHeight: err.msg
1326
+ }).catch();
1327
+ } else {
1328
+ this.$message({
1329
+ type: 'error',
1330
+ message: '上传失败:' + (err.msg ? err.msg : '请联系管理员')
1331
+ });
1332
+ }
1333
+ }
1334
+ this.$emit('error', err, file, fileList);
1335
+ this.onError && this.onError(err, file, fileList);
1336
+ }
1337
+ }
1338
+ };
1339
+ </script>