adtec-core-package 2.8.1 → 2.8.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -23,5 +23,8 @@ export default {
23
23
  },
24
24
  fileStatusConfirmation(ids: string[]): Promise<ISysUploadFiles[]> {
25
25
  return request.post(basePath + 'fileStatusConfirmation', ids)
26
+ },
27
+ delSysUploadFiles(ids: string[]): Promise<Record<string, string>> {
28
+ return request.post(basePath + 'delSysUploadFiles', ids)
26
29
  }
27
30
  }
@@ -0,0 +1,469 @@
1
+ <!--创建人 丁盼-->
2
+ <!--说明: 文档上传组件-->
3
+ <!--创建时间: 2024/12/2 下午1:59-->
4
+ <!--修改时间: 2024/12/2 下午1:59-->
5
+ <template>
6
+ <div v-if="!isEdit">
7
+ <el-auto-tool-tip v-if="uploadFilesList?.length">
8
+ <template #tooltipContent>
9
+ <div style="display:flex;flex-direction:column">
10
+ <span
11
+ v-for="item in uploadFilesList"
12
+ :key="item.id"
13
+ style="margin: 0 2px"
14
+ >{{ item.name }}
15
+ </span>
16
+ </div>
17
+ </template>
18
+ <template #content>
19
+ <div style="display:flex;flex-direction:column">
20
+ <div v-for="item in uploadFilesList" :key="item.id"
21
+ class="file-item"
22
+ style="display:flex; align-items:center;overflow: hidden">
23
+ <el-icons :model-value="getIcon(item.name)" style="margin-right: 5px"></el-icons>
24
+ <span class="link-name" @click="fileView(item.id)">{{ item.name }}</span>
25
+ </div>
26
+ </div>
27
+ </template>
28
+ </el-auto-tool-tip>
29
+ <div style="text-align: center;color: var(--el-disabled-text-color)" v-else>
30
+ 暂无附件
31
+ </div>
32
+ </div>
33
+ <el-upload
34
+ v-else
35
+ ref="ref_upload"
36
+ :file-list="uploadFilesList"
37
+ @success="success"
38
+ @remove="remove"
39
+ @preview="preview"
40
+ :auto-upload="autoUpload"
41
+ @error="error"
42
+ v-loading="loading"
43
+ @exceed="exceed"
44
+ @progress="progress"
45
+ :before-upload="beforeUpload"
46
+ drag
47
+ :accept="getAccept"
48
+ :action="'/api/doc/uploadFile/' + business + '/' + businessId + '/' + association"
49
+ multiple
50
+ :limit="limit"
51
+ :headers="uploadHeaders"
52
+ >
53
+ <el-icon class="el-icon--upload">
54
+ <upload-filled />
55
+ </el-icon>
56
+ <div class="el-upload__text">拖动文件或<em>点击上传</em></div>
57
+ <div class="el-upload__tip">最大上传文件大小{{ size }}MB</div>
58
+ <template #file="{ file }">
59
+ <el-flex
60
+ class="file-class"
61
+ @mousemove="mousemove(file.name)"
62
+ @mouseout="mouseout"
63
+ @click="preview(file)"
64
+ height="20px"
65
+ :width="itemWidth"
66
+ >
67
+ <el-flex align="center" justify="flex-start" style="overflow: hidden">
68
+ <el-tooltip class="box-item" :content="file.name" placement="top">
69
+ <el-text truncated style="cursor: pointer">
70
+ <el-icons :model-value="getIcon(file.name)" style="margin-right: 5px"></el-icons>
71
+ {{ file.name }}
72
+ </el-text>
73
+ </el-tooltip>
74
+ </el-flex>
75
+ <el-flex align="center" justify="flex-end" width="50px">
76
+ <el-text v-if="!file?.businessId && file.percentage !== 100"
77
+ >{{ file.percentage }}%
78
+ </el-text>
79
+ <el-icons
80
+ v-if="file?.businessId || file.percentage === 100"
81
+ @click.prevent.stop="fileClick(file)"
82
+ :model-value="file.name === hoverfileName ? 'adtec-close' : 'adtec-success'"
83
+ style="color: var(--el-color-success); font-size: 14px"
84
+ :style="{
85
+ color:
86
+ file.name === hoverfileName ? 'var(--el-color-danger)' : 'var(--el-color-success)',
87
+ }"
88
+ ></el-icons>
89
+ </el-flex>
90
+ </el-flex>
91
+ </template>
92
+ </el-upload>
93
+ </template>
94
+
95
+ <script setup lang="ts">
96
+ import { UploadFilled } from '@element-plus/icons-vue'
97
+ import { computed, onMounted, ref } from 'vue'
98
+ import { ElMessage, ElMessageBox, type UploadFile, type UploadFiles, type UploadUserFile } from 'element-plus'
99
+ import type { ISysUploadFiles } from '../../interface/ISysUploadFiles'
100
+ //@ts-ignore
101
+ import useFileView from '../../hooks/useFileView.ts'
102
+ import documentApi from '../../api/DocumentApi.ts'
103
+ import frameworkUtils from '../../utils/FrameworkUtils.ts'
104
+ import { userInfoStore } from '../../stores/userInfoStore'
105
+
106
+ const { fileView: fileView } = useFileView()
107
+ const uploadHeaders = ref({
108
+ Authorization: ''
109
+ })
110
+ const emit = defineEmits(['success'])
111
+ const userInfo = userInfoStore()
112
+ const ref_upload = ref()
113
+ const deleteFiles = ref<ISysUploadFiles[]>([])
114
+ const hoverfileName = ref('')
115
+ const props = defineProps({
116
+ /**
117
+ * @description 上传文件数量
118
+ * @default 1
119
+ */
120
+ limit: {
121
+ type: Number,
122
+ default: 1
123
+ },
124
+ /**
125
+ * @description 纵向排列
126
+ * @default false
127
+ */
128
+ vertical: {
129
+ type: Boolean,
130
+ default: false
131
+ },
132
+ /**
133
+ * @description 上传文件类型
134
+ * @default ''
135
+ * @type {'images'|'document'|'txt'|'pdf'|'word'|'excel'|'ppt'}
136
+ */
137
+ accept: {
138
+ type: String,
139
+ default: ''
140
+ },
141
+ /**
142
+ * @description 业务类型
143
+ * @default 'default'
144
+ */
145
+ business: {
146
+ type: String,
147
+ default: 'default'
148
+ },
149
+ /**
150
+ * @description 业务id
151
+ * @default ''
152
+ */
153
+ businessId: {
154
+ type: String,
155
+ default: 'default'
156
+ },
157
+ /**
158
+ * 文件列表
159
+ */
160
+ uploadFilesList: {
161
+ type: Array<ISysUploadFiles>,
162
+ default: () => []
163
+ },
164
+ /**
165
+ * @description 是否编辑状态
166
+ * @default 'true'
167
+ * @type {true|false}
168
+ */
169
+ isEdit: {
170
+ type: Boolean,
171
+ default: true
172
+ },
173
+ /**
174
+ * @description 文档上传是否默认关联,默认不关联
175
+ * @default 'false'
176
+ * @type {true|false}
177
+ */
178
+ association: {
179
+ type: Boolean,
180
+ default: false
181
+ },
182
+ size: {
183
+ type: Number,
184
+ default: 50
185
+ },
186
+ //附件宽度
187
+ itemWidth: {
188
+ type: String,
189
+ default: '100%'
190
+ },
191
+ isConfirmDelete: {
192
+ type: Boolean,
193
+ default: true
194
+ },
195
+ overwrite: {
196
+ type: Boolean,
197
+ default: true
198
+ },
199
+ autoUpload: {
200
+ type: Boolean,
201
+ default: true
202
+ }
203
+ })
204
+ const mousemove = (fileName: string) => {
205
+ hoverfileName.value = fileName
206
+ }
207
+ const mouseout = () => {
208
+ hoverfileName.value = ''
209
+ }
210
+ const getAccept = computed(() => {
211
+ if (props.accept === 'images') {
212
+ return '.jpg,.jpeg,.png,.gif,.bmp'
213
+ } else if (props.accept === 'document') {
214
+ return '.txt,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
215
+ } else if (props.accept === 'txt') {
216
+ return '.txt'
217
+ } else if (props.accept === 'pdf') {
218
+ return '.pdf' // 正确配置,仅允许 pdf
219
+ } else if (props.accept === 'word') {
220
+ return '.doc,.docx'
221
+ } else if (props.accept === 'excel') {
222
+ return '.xls,.xlsx'
223
+ } else if (props.accept === 'ppt') {
224
+ return '.ppt,.pptx'
225
+ } else {
226
+ return undefined
227
+ }
228
+ })
229
+ const getIcon = (fileName: string) => {
230
+ const type: string = fileName.split('.').pop() + ''
231
+ if ('.jpg,.jpeg,.png,.gif,.bmp,.JPG,.JPEG,.PBG,.GIF,.BMP'.includes(type)) {
232
+ return 'adtec-image'
233
+ } else if ('txt'.includes(type)) {
234
+ return 'adtec-text'
235
+ } else if ('pdf'.includes(type)) {
236
+ return 'adtec-pdf'
237
+ } else if ('doc,docx'.includes(type)) {
238
+ return 'adtec-word'
239
+ } else if ('xls,xlsx'.includes(type)) {
240
+ return 'adtec-excel'
241
+ } else if ('ppt,pptx'.includes(type)) {
242
+ return 'adtec-ppt'
243
+ } else {
244
+ return 'adtec-text'
245
+ }
246
+ }
247
+ const success = (response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
248
+ if (response.code === '0') {
249
+ props.uploadFilesList.push(response.data as ISysUploadFiles)
250
+ } else {
251
+ ElMessage.error(response.msg)
252
+ ref_upload.value?.handleRemove(uploadFile)
253
+ }
254
+ for (let i = loadingFiles.value.length - 1; i >= 0; i--) {
255
+ if (loadingFiles.value[i] === uploadFile.name) {
256
+ loadingFiles.value.splice(i, 1)
257
+ }
258
+ }
259
+ ElMessage.success('上传成功')
260
+ emit('success', { files: props.uploadFilesList, deleteFiles: deleteFiles.value })
261
+ loading.value = false
262
+ }
263
+ const loading = defineModel<boolean>('loading')
264
+ const loadingFiles = ref<string[]>([])
265
+ // watch(
266
+ // loadingFiles,
267
+ // (val) => {
268
+ // if (props.autoUpload) {
269
+ // if (val.length > 0) {
270
+ // loading.value = true
271
+ // } else {
272
+ // loading.value = false
273
+ // }
274
+ // }
275
+ // },
276
+ // { deep: true }
277
+ // )
278
+ const beforeUpload = async (file: File) => {
279
+ const f = props.uploadFilesList.find((c) => c.name === file.name)
280
+ if (f) {
281
+ ElMessage.warning(file.name + ',文件已存在')
282
+ return false
283
+ } else if (file.size > props.size * 1024 * 1024) {
284
+ ElMessage.warning('文件大小不能超过' + props.size + 'MB')
285
+ return false
286
+ }
287
+ const acceptSuffixes = getAccept.value
288
+ ?.split(',')
289
+ .map(suffix => suffix.slice(1).toLowerCase())
290
+ const fileSuffix = file.name.split('.').pop()?.toLowerCase()
291
+ if (acceptSuffixes && !acceptSuffixes.includes(fileSuffix ?? '')) {
292
+ ElMessage.error(`文件 ${file.name} 格式不支持,仅允许 ${getAccept.value}!`)
293
+ setTimeout(() => {
294
+ ref_upload.value?.clearFiles(['ready'])
295
+ }, 1)
296
+ return false
297
+ }
298
+ loadingFiles.value.push(file.name)
299
+ return true
300
+ }
301
+ const fileClick = async (file: UploadFile & ISysUploadFiles) => {
302
+ if (file.name === hoverfileName.value) {
303
+ if (file.createBy && userInfo.getUserInfo.userCode !== file.createBy) {
304
+ ElMessage.warning('您没有权限删除此文件!')
305
+ return
306
+ }
307
+ if (!props.isConfirmDelete) {
308
+ const flag = await ElMessageBox.confirm('删除不可恢复!您确定删除此附件?', '提示', {
309
+ confirmButtonText: '确定',
310
+ cancelButtonText: '取消',
311
+ type: 'warning'
312
+ })
313
+ if (!flag) {
314
+ return
315
+ }
316
+ }
317
+ ref_upload.value?.handleRemove(file)
318
+ } else {
319
+ preview(file)
320
+ }
321
+ }
322
+ // 处理覆盖逻辑
323
+ const exceed = async (files: File[], uploadFiles: UploadUserFile[]) => {
324
+ if (props.limit === 1 && props.overwrite && props.uploadFilesList.length >= 1) {
325
+ const existingFile = props.uploadFilesList[0]
326
+ if (!props.isConfirmDelete) {
327
+ const flag = await ElMessageBox.confirm('只允许上传一个附件,是否点击确定覆盖原有附件?', '提示', {
328
+ confirmButtonText: '确定',
329
+ cancelButtonText: '取消',
330
+ type: 'warning'
331
+ })
332
+ if (!flag) {
333
+ return
334
+ }
335
+ try {
336
+ loading.value = true
337
+ await documentApi.delSysUploadFile(existingFile.id).catch(err => {
338
+ frameworkUtils.messageError(err)
339
+ })
340
+ } catch (err) {
341
+ frameworkUtils.messageError(err)
342
+ return
343
+ } finally {
344
+ loading.value = false
345
+ }
346
+ }
347
+ props.uploadFilesList.splice(0, 1)
348
+ ref_upload.value?.clearFiles()
349
+ if (files.length > 0) {
350
+ const canUpload = await beforeUpload(files[0])
351
+ if (canUpload) {
352
+ deleteFiles.value.push(existingFile)
353
+ ref_upload.value?.handleStart(files[0])
354
+ props.autoUpload && ref_upload.value?.submit()
355
+ } else {
356
+ props.uploadFilesList.push(existingFile)
357
+ }
358
+ }
359
+ } else {
360
+ ElMessage.warning(`最多上传${props.limit}个文件,上传文件数量已达到限制`)
361
+ }
362
+ }
363
+ const error = (error: Error, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
364
+ ElMessage.error('上传失败')
365
+ for (let i = loadingFiles.value.length - 1; i >= 0; i--) {
366
+ if (loadingFiles.value[i] === uploadFile.name) {
367
+ loadingFiles.value.splice(i, 1)
368
+ }
369
+ }
370
+ loading.value = false
371
+ }
372
+ const preview = async (uploadFile: UploadFile) => {
373
+ const file = props.uploadFilesList.find((c) => c.name === uploadFile.name)
374
+ if (file) {
375
+ //if ((uploadFile.response as any).code === '0') {
376
+ // const data = (uploadFile.response as any).data as ISysUploadFiles
377
+ fileView(file.id)
378
+ }
379
+ }
380
+ const remove = async (file: UploadFile, isConfirm: boolean = true) => {
381
+ // if ((file.response as any).code === '0') {
382
+ // const data = (file.response as any).data as ISysUploadFiles
383
+ const find = props.uploadFilesList.find((c) => c.name === file.name)
384
+ if (find) {
385
+ try {
386
+ if (!isConfirm && !props.isConfirmDelete) {
387
+ await documentApi.delSysUploadFile(find.id)
388
+ }
389
+ props.uploadFilesList.splice(props.uploadFilesList.indexOf(find), 1)
390
+ deleteFiles.value.push(find)
391
+ } catch (err: any) {
392
+ frameworkUtils.messageError(err)
393
+ }
394
+ }
395
+ // }
396
+ }
397
+ const progress = (event: { percent: number }, file: UploadFile) => {
398
+ loading.value = true
399
+ }
400
+ const confirm = async () => {
401
+ try {
402
+ loading.value = true
403
+ if (props.isConfirmDelete && deleteFiles.value.length > 0) {
404
+ await documentApi.delSysUploadFiles(deleteFiles.value.map(item => item.id))
405
+ if (!loadingFiles.value?.length) {
406
+ ElMessage.success('操作成功')
407
+ emit('success', { files: props.uploadFilesList, deleteFiles: deleteFiles.value })
408
+ }
409
+ }
410
+ if (!props.autoUpload) {
411
+ ref_upload.value?.submit()
412
+ }
413
+ } catch (err: any) {
414
+ frameworkUtils.messageError(err)
415
+ loading.value = false
416
+ } finally {
417
+ if (props.autoUpload) {
418
+ loading.value = false
419
+ }
420
+ }
421
+ }
422
+ onMounted(() => {
423
+ uploadHeaders.value.Authorization = sessionStorage.getItem('Authorization') + ''
424
+ })
425
+ defineExpose({
426
+ remove,
427
+ confirm
428
+ })
429
+ </script>
430
+ <style scoped lang="scss">
431
+ .file-class {
432
+ }
433
+
434
+ .file-class :hover {
435
+ color: var(--el-color-primary);
436
+ }
437
+
438
+ :deep {
439
+ .el-icon--upload {
440
+ margin-bottom: 0;
441
+ }
442
+ }
443
+
444
+ .file-item {
445
+ position: relative;
446
+ padding: 2px 0;
447
+ border-radius: 4px;
448
+ transition: background-color 0.2s ease;
449
+
450
+ &:hover {
451
+ background-color: var(--el-fill-color-light);
452
+
453
+ .delete-icon {
454
+ visibility: visible;
455
+ opacity: 1;
456
+ transform: scale(1);
457
+ }
458
+ }
459
+ }
460
+
461
+ .link-name {
462
+ cursor: pointer;
463
+ }
464
+
465
+ .link-name:hover {
466
+ color: var(--el-color-primary);
467
+ text-decoration: underline;
468
+ }
469
+ </style>
@@ -279,7 +279,7 @@ const beforeUpload = (file: File) => {
279
279
  const fileClick = async (file: UploadFile & ISysUploadFiles) => {
280
280
  if (file.name === hoverfileName.value) {
281
281
  if (file.createBy && userInfo.getUserInfo.userCode !== file.createBy) {
282
- frameworkUtils.messageError('您没有权限删除此文件!')
282
+ ElMessage.warning('您没有权限删除此文件!')
283
283
  return
284
284
  }
285
285
  const flag = await ElMessageBox.confirm('删除不可恢复!您确定删除此附件?', '提示', {