@ebiz/designer-components 0.1.124 → 0.1.126
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/README.md +29 -29
- package/dist/designer-components.css +1 -1
- package/dist/index.mjs +35548 -33511
- package/dist/{pdf-C9oIcL2N.js → pdf-KomaE0u5.js} +891 -891
- package/package.json +1 -1
- package/src/App.vue +26 -26
- package/src/apiService/SIMPLE_DATA_SERVICE.md +284 -284
- package/src/apiService/mockDataService.js +115 -115
- package/src/apiService/simpleDataService.js +312 -312
- package/src/assets/base.css +86 -86
- package/src/assets/logo.svg +1 -1
- package/src/components/Button.vue +149 -149
- package/src/components/DataContainer.vue +40 -40
- package/src/components/EbizApproval.vue +366 -366
- package/src/components/EbizApprovalDetail.vue +169 -169
- package/src/components/EbizApprovalForm.vue +534 -534
- package/src/components/EbizApprovalV2.vue +713 -713
- package/src/components/EbizAutoForm.vue +596 -596
- package/src/components/EbizAvatar.vue +115 -115
- package/src/components/EbizCheckbox.vue +93 -93
- package/src/components/EbizCheckboxGroup.vue +69 -69
- package/src/components/EbizDepartmentSelector.vue +148 -148
- package/src/components/EbizDescriptions.vue +340 -340
- package/src/components/EbizDescriptionsItem.vue +47 -47
- package/src/components/EbizDetailBlock.vue +81 -81
- package/src/components/EbizDetailItem.vue +559 -559
- package/src/components/EbizDetailView.md +438 -438
- package/src/components/EbizDetailView.vue +355 -355
- package/src/components/EbizDialog.vue +260 -260
- package/src/components/EbizDictionarySelect.vue +229 -229
- package/src/components/EbizDiv.vue +40 -40
- package/src/components/EbizDivider.vue +96 -96
- package/src/components/EbizDormDashboard.vue +314 -314
- package/src/components/EbizDropdown.vue +135 -135
- package/src/components/EbizDropdownItem.vue +85 -85
- package/src/components/EbizEmployeeInfo.vue +144 -144
- package/src/components/EbizEmployeeSelector.vue +1160 -1160
- package/src/components/EbizFileList.vue +502 -502
- package/src/components/EbizMap.vue +541 -541
- package/src/components/EbizMeetingRoomSelector.vue +1149 -1149
- package/src/components/EbizMobileMeetingRoomSelector.vue +727 -727
- package/src/components/EbizOkrTree.vue +99 -99
- package/src/components/EbizPageHeader.vue +98 -98
- package/src/components/EbizPagination.vue +162 -162
- package/src/components/EbizParkingDashboard.vue +152 -152
- package/src/components/EbizPdfViewer.vue +540 -540
- package/src/components/EbizPopconfirm.vue +47 -47
- package/src/components/EbizQrCode.vue +167 -167
- package/src/components/EbizRadio.vue +86 -86
- package/src/components/EbizRadioGroup.vue +83 -83
- package/src/components/EbizRemoteSelect.vue +232 -232
- package/src/components/EbizRichTextEditor.vue +338 -338
- package/src/components/EbizRouteBreadcrumb.vue +46 -46
- package/src/components/EbizSApprovalProcess.vue +1456 -1426
- package/src/components/EbizSelect.vue +85 -85
- package/src/components/EbizSpace.vue +100 -100
- package/src/components/EbizStatistic.vue +149 -149
- package/src/components/EbizStatsCard.vue +113 -113
- package/src/components/EbizSwiper.vue +113 -113
- package/src/components/EbizSwiperItem.vue +13 -13
- package/src/components/EbizSwitch.vue +85 -85
- package/src/components/EbizTabHeader.vue +132 -132
- package/src/components/EbizTabPanel.vue +22 -22
- package/src/components/EbizTable.vue +469 -469
- package/src/components/EbizTableColumn.vue +116 -116
- package/src/components/EbizTableSort.vue +179 -179
- package/src/components/EbizTabs.vue +142 -142
- package/src/components/EbizTdesignButtonDialog.vue +332 -332
- package/src/components/EbizTdesignLoading.vue +107 -107
- package/src/components/EbizTimePicker.vue +143 -143
- package/src/components/EbizTitle.vue +91 -91
- package/src/components/EbizTree.vue +141 -141
- package/src/components/EbizTreeMergeTable.vue +1494 -1494
- package/src/components/EbizTreeSelector.vue +469 -469
- package/src/components/EbizVideo.vue +553 -553
- package/src/components/EbizVxeTable.vue +290 -290
- package/src/components/Form.vue +28 -28
- package/src/components/Home.vue +7 -7
- package/src/components/LaunchInterview.vue +526 -526
- package/src/components/MyComponent.vue +39 -39
- package/src/components/Table.vue +45 -45
- package/src/components/TdesignAlert.vue +115 -115
- package/src/components/TdesignButton.vue +135 -135
- package/src/components/TdesignCalendar/index.vue +145 -145
- package/src/components/TdesignCard.vue +195 -195
- package/src/components/TdesignCol.vue +101 -101
- package/src/components/TdesignCollapse.vue +142 -142
- package/src/components/TdesignCollapsePanel.vue +79 -79
- package/src/components/TdesignDatePicker.vue +124 -124
- package/src/components/TdesignDescriptions.vue +74 -74
- package/src/components/TdesignDescriptionsItem.vue +50 -50
- package/src/components/TdesignDialog.vue +225 -225
- package/src/components/TdesignForm.vue +138 -138
- package/src/components/TdesignFormItem.vue +105 -105
- package/src/components/TdesignGrid.vue +55 -55
- package/src/components/TdesignIcon.vue +67 -67
- package/src/components/TdesignImage.vue +162 -162
- package/src/components/TdesignImageViewer.vue +200 -200
- package/src/components/TdesignInput.vue +242 -242
- package/src/components/TdesignSelect.vue +446 -446
- package/src/components/TdesignTag.vue +117 -117
- package/src/components/TdesignTextarea.vue +142 -142
- package/src/components/TdesignTimeline.vue +58 -58
- package/src/components/TdesignTimelineItem.vue +71 -71
- package/src/components/TdesignUpload.vue +414 -414
- package/src/components/TdesignWatermark.vue +107 -107
- package/src/components/ebiz-form/components/cascader.vue +61 -61
- package/src/components/ebiz-form/components/checkbox.vue +37 -37
- package/src/components/ebiz-form/components/city.vue +137 -137
- package/src/components/ebiz-form/components/date-panel.vue +52 -52
- package/src/components/ebiz-form/components/date-range-panel.vue +52 -52
- package/src/components/ebiz-form/components/date-range.vue +56 -56
- package/src/components/ebiz-form/components/date.vue +52 -52
- package/src/components/ebiz-form/components/editor-multi-language.vue +47 -47
- package/src/components/ebiz-form/components/editor.vue +78 -78
- package/src/components/ebiz-form/components/file-multi-language.vue +52 -52
- package/src/components/ebiz-form/components/file.vue +149 -149
- package/src/components/ebiz-form/components/images-multi-language.vue +52 -52
- package/src/components/ebiz-form/components/images.vue +129 -129
- package/src/components/ebiz-form/components/img-multi-language.vue +51 -51
- package/src/components/ebiz-form/components/img.vue +129 -129
- package/src/components/ebiz-form/components/number.vue +50 -50
- package/src/components/ebiz-form/components/radio.vue +28 -28
- package/src/components/ebiz-form/components/select.vue +119 -119
- package/src/components/ebiz-form/components/switch.vue +23 -23
- package/src/components/ebiz-form/components/text-multi-language.vue +47 -47
- package/src/components/ebiz-form/components/text.vue +52 -52
- package/src/components/ebiz-form/components/textarea-multi-language.vue +48 -48
- package/src/components/ebiz-form/components/textarea.vue +29 -29
- package/src/components/ebiz-form/components/video-multi-language.vue +51 -51
- package/src/components/ebiz-form/components/video.vue +97 -97
- package/src/components/ebiz-form/index.vue +157 -157
- package/src/components/examples/PopconfirmExample.vue +149 -149
- package/src/components/icons/IconCommunity.vue +7 -7
- package/src/components/icons/IconDocumentation.vue +7 -7
- package/src/components/icons/IconEcosystem.vue +7 -7
- package/src/components/icons/IconSupport.vue +7 -7
- package/src/components/icons/IconTooling.vue +19 -19
- package/src/components/mItems/UserInfo.vue +349 -349
- package/src/components/senior/EbizApprovalList/ApprovalList.vue +127 -127
- package/src/components/senior/EbizSData/index.vue +280 -280
- package/src/components/senior/EbizSDialog/index.vue +776 -776
- package/src/components/senior/EbizSForm/README.md +157 -157
- package/src/components/senior/EbizSForm/index.vue +667 -667
- package/src/components/senior/EbizSForm/item.vue +1011 -1011
- package/src/components/senior/EbizSForm/mItems/DateTimePicker.vue +51 -51
- package/src/components/senior/EbizSForm/mItems/Picker.vue +63 -63
- package/src/index.js +327 -327
- package/src/main.js +55 -55
- package/src/router/index.js +436 -436
- package/src/utils/formatCode.js +24 -24
- package/src/utils/generateImportStatement.js +52 -52
- package/src/utils/hasJsx.js +25 -25
- package/src/utils/index.js +166 -166
- package/src/utils/mergeOptions.js +29 -29
- package/src/utils/parseRequiredBlocks.js +18 -18
- package/src/utils/vue-sfc-validator.js +155 -155
- package/src/views/Button.vue +23 -23
- package/src/views/CheckboxDemo.vue +104 -104
- package/src/views/DataContainer.vue +19 -19
- package/src/views/DialogDemo.vue +125 -125
- package/src/views/EbizApprovalDemo.vue +87 -87
- package/src/views/EbizApprovalFormDemo.vue +207 -207
- package/src/views/EbizAutoFormDemo.vue +129 -129
- package/src/views/EbizAvatar.vue +223 -223
- package/src/views/EbizDepartmentSelectorDemo.vue +169 -169
- package/src/views/EbizDetailBlockDemo.vue +30 -30
- package/src/views/EbizDetailViewDemo.vue +412 -412
- package/src/views/EbizDormDashboardDemo.vue +87 -87
- package/src/views/EbizEmployeeInfo.vue +249 -249
- package/src/views/EbizEmployeeSelector.vue +85 -85
- package/src/views/EbizFileListDemo.vue +339 -339
- package/src/views/EbizMap.vue +201 -201
- package/src/views/EbizMeetingRoomSelectorDemo.vue +293 -293
- package/src/views/EbizMobileMeetingRoomSelectorDemo.vue +566 -566
- package/src/views/EbizParkingDashboardDemo.vue +28 -28
- package/src/views/EbizRadioDemo.vue +151 -151
- package/src/views/EbizSDataDemo.vue +136 -136
- package/src/views/EbizSDialogDemo.vue +303 -303
- package/src/views/EbizSForm/index.vue +352 -352
- package/src/views/EbizSFormDemo.vue +420 -420
- package/src/views/EbizSpace.vue +185 -185
- package/src/views/EbizSwiper.vue +157 -157
- package/src/views/EbizTdesignButtonDialogExample.vue +437 -437
- package/src/views/Form.vue +19 -19
- package/src/views/GridDemo.vue +238 -238
- package/src/views/Home.vue +156 -156
- package/src/views/LaunchInterviewDemo.vue +111 -111
- package/src/views/Mindmap.vue +17 -17
- package/src/views/MyComponent.vue +19 -19
- package/src/views/OkrTree.vue +19 -19
- package/src/views/PageHeaderDemo.vue +104 -104
- package/src/views/PaginationDemo.vue +96 -96
- package/src/views/PdfViewerDemo.vue +433 -433
- package/src/views/PermissionBoxDemo.vue +85 -85
- package/src/views/PopconfirmDemo.vue +80 -80
- package/src/views/RemoteSelect.vue +350 -350
- package/src/views/StatisticDemo.vue +190 -190
- package/src/views/SwitchDemo.vue +79 -79
- package/src/views/Table.vue +19 -19
- package/src/views/TableDemo.vue +334 -334
- package/src/views/TableSortDemo.vue +143 -143
- package/src/views/TableView.vue +68 -68
- package/src/views/TabsDemo.vue +282 -282
- package/src/views/TagDemo.vue +101 -101
- package/src/views/TdesignAlert.vue +98 -98
- package/src/views/TdesignButton.vue +190 -190
- package/src/views/TdesignCalendar.vue +94 -94
- package/src/views/TdesignCard.vue +296 -296
- package/src/views/TdesignCollapse.vue +293 -293
- package/src/views/TdesignDatePicker.vue +187 -187
- package/src/views/TdesignDescriptions.vue +101 -101
- package/src/views/TdesignForm.vue +248 -248
- package/src/views/TdesignIcon.vue +203 -203
- package/src/views/TdesignImage.vue +215 -215
- package/src/views/TdesignImageViewer.vue +198 -198
- package/src/views/TdesignInput.vue +252 -252
- package/src/views/TdesignSelect.vue +473 -473
- package/src/views/TdesignSwiper.vue +157 -157
- package/src/views/TextareaDemo.vue +93 -93
- package/src/views/TimePickerDemo.vue +146 -146
- package/src/views/TimelineDemo.vue +160 -160
- package/src/views/Title.vue +19 -19
- package/src/views/TreeDemo.vue +254 -254
- package/src/views/TreeMergeTableDemo.vue +239 -239
- package/src/views/TreeSelectorDemo.vue +245 -245
- package/src/views/UploadDemo.vue +128 -128
- package/src/views/VideoDemo.vue +245 -245
- package/src/views/VxeTableDemo.vue +279 -279
- package/src/views/WatermarkDemo.vue +85 -85
|
@@ -1,503 +1,503 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ebiz-file-list" :class="{ 'mini-mode': size === 'mini' }">
|
|
3
|
-
<div v-if="computedFiles.length === 0" class="empty-state">
|
|
4
|
-
<div>-</div>
|
|
5
|
-
</div>
|
|
6
|
-
<div v-else class="file-list-container" :class="{ 'mini-container': size === 'mini' }">
|
|
7
|
-
<div v-for="(file, index) in computedFiles" :key="index" class="file-item"
|
|
8
|
-
:class="{ 'mini-item': size === 'mini' }" @click="handleFileClick(file)">
|
|
9
|
-
<!-- 图片文件直接显示缩略图 -->
|
|
10
|
-
<div v-if="isImage(file.extension)" class="file-icon">
|
|
11
|
-
<t-image :src="file.url" :alt="file.name" fit="cover" loading="lazy"
|
|
12
|
-
:style="{ width: actualImageSize, height: actualImageSize, borderRadius: '4px' }" error="" />
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
<!-- 非图片文件显示图标 -->
|
|
16
|
-
<div v-else class="file-icon">
|
|
17
|
-
<t-icon :name="getFileIcon(file.extension)" :size="actualImageSize"
|
|
18
|
-
:style="{ color: getFileColor(file.extension) }" />
|
|
19
|
-
</div>
|
|
20
|
-
|
|
21
|
-
<div v-if="size !== 'mini'" class="file-info">
|
|
22
|
-
<div class="file-name" :title="file.name">{{ file.name }}</div>
|
|
23
|
-
<div class="file-meta">
|
|
24
|
-
<span v-if="showFileType" class="file-type">{{ file.extension?.toUpperCase() || '未知' }}</span>
|
|
25
|
-
<span v-if="showFileSize && file.size" class="file-size">{{ formatFileSize(file.size) }}</span>
|
|
26
|
-
</div>
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
<!-- 操作按钮 -->
|
|
30
|
-
<div v-if="showActions && size !== 'mini'" class="file-actions">
|
|
31
|
-
<t-button size="small" variant="text" @click.stop="handleDownload(file)"
|
|
32
|
-
:title="isImage(file.extension) ? '查看' : '下载'">
|
|
33
|
-
<t-icon :name="isImage(file.extension) ? 'view-list' : 'download'" />
|
|
34
|
-
</t-button>
|
|
35
|
-
<t-button v-if="allowDelete" size="small" variant="text" theme="danger"
|
|
36
|
-
@click.stop="handleDelete(file, index)" title="删除">
|
|
37
|
-
<t-icon name="delete" />
|
|
38
|
-
</t-button>
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
42
|
-
|
|
43
|
-
<!-- 图片预览弹窗 -->
|
|
44
|
-
<t-image-viewer v-model:visible="previewVisible" :images="previewImages" :index="previewIndex" :close-on-esc="true"
|
|
45
|
-
@close="previewVisible = false" />
|
|
46
|
-
</div>
|
|
47
|
-
</template>
|
|
48
|
-
|
|
49
|
-
<script>
|
|
50
|
-
export default {
|
|
51
|
-
name: "EbizFileList"
|
|
52
|
-
}
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
<script setup>
|
|
56
|
-
import { defineProps, defineEmits, computed, ref } from 'vue';
|
|
57
|
-
import { Image as TImage, ImageViewer as TImageViewer, Icon as TIcon, Button as TButton } from 'tdesign-vue-next';
|
|
58
|
-
|
|
59
|
-
const props = defineProps({
|
|
60
|
-
// 文件列表数据,支持数组或字符串(逗号分隔)
|
|
61
|
-
files: {
|
|
62
|
-
type: [Array, String],
|
|
63
|
-
default: () => []
|
|
64
|
-
},
|
|
65
|
-
// 尺寸大小,支持default和mini
|
|
66
|
-
size: {
|
|
67
|
-
type: String,
|
|
68
|
-
default: 'default'
|
|
69
|
-
},
|
|
70
|
-
// 图片尺寸
|
|
71
|
-
imageSize: {
|
|
72
|
-
type: String,
|
|
73
|
-
default: '50px'
|
|
74
|
-
},
|
|
75
|
-
// 是否显示文件大小
|
|
76
|
-
showFileSize: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
default: true
|
|
79
|
-
},
|
|
80
|
-
// 是否显示文件类型
|
|
81
|
-
showFileType: {
|
|
82
|
-
type: Boolean,
|
|
83
|
-
default: true
|
|
84
|
-
},
|
|
85
|
-
// 是否显示操作按钮
|
|
86
|
-
showActions: {
|
|
87
|
-
type: Boolean,
|
|
88
|
-
default: true
|
|
89
|
-
},
|
|
90
|
-
// 是否允许删除
|
|
91
|
-
allowDelete: {
|
|
92
|
-
type: Boolean,
|
|
93
|
-
default: false
|
|
94
|
-
},
|
|
95
|
-
// 文件基础URL(用于相对路径)
|
|
96
|
-
baseUrl: {
|
|
97
|
-
type: String,
|
|
98
|
-
default: ''
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const emit = defineEmits(['file-click', 'file-download', 'file-delete', 'file-preview']);
|
|
103
|
-
|
|
104
|
-
// 预览相关状态
|
|
105
|
-
const previewVisible = ref(false);
|
|
106
|
-
const previewImages = ref([]);
|
|
107
|
-
const previewIndex = ref(0);
|
|
108
|
-
|
|
109
|
-
// 获取完整URL
|
|
110
|
-
const getFullUrl = (url) => {
|
|
111
|
-
if (!url) return '';
|
|
112
|
-
if (url.startsWith('http') || url.startsWith('data:')) return url;
|
|
113
|
-
return props.baseUrl + url;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// 获取文件扩展名
|
|
117
|
-
const getFileExtension = (filename) => {
|
|
118
|
-
if (!filename) return '';
|
|
119
|
-
// 移除查询参数和锚点
|
|
120
|
-
const cleanFilename = filename.split('?')[0].split('#')[0];
|
|
121
|
-
const parts = cleanFilename.split('.');
|
|
122
|
-
return parts.length > 1 ? parts.pop().toLowerCase() : '';
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// 提取文件名
|
|
126
|
-
const extractFileName = (url) => {
|
|
127
|
-
if (!url) return '未知文件';
|
|
128
|
-
|
|
129
|
-
// 移除查询参数和锚点
|
|
130
|
-
const cleanUrl = url.split('?')[0].split('#')[0];
|
|
131
|
-
const parts = cleanUrl.split('/');
|
|
132
|
-
let fileName = parts[parts.length - 1] || '未知文件';
|
|
133
|
-
|
|
134
|
-
// 如果文件名为空或只是扩展名,生成一个默认名称
|
|
135
|
-
if (!fileName || fileName.startsWith('.')) {
|
|
136
|
-
const extension = getFileExtension(fileName || url);
|
|
137
|
-
fileName = extension ? `文件.${extension}` : '未知文件';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return fileName;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// 解析文件信息
|
|
144
|
-
const parseFileInfo = (url) => {
|
|
145
|
-
const fullUrl = getFullUrl(url);
|
|
146
|
-
const fileName = extractFileName(url);
|
|
147
|
-
const extension = getFileExtension(fileName);
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
name: fileName,
|
|
151
|
-
url: fullUrl,
|
|
152
|
-
extension,
|
|
153
|
-
size: null
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// 计算文件列表
|
|
158
|
-
const computedFiles = computed(() => {
|
|
159
|
-
let fileList = [];
|
|
160
|
-
|
|
161
|
-
if (typeof props.files === 'string') {
|
|
162
|
-
if (!props.files.trim()) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// 判断是否为JSON字符串
|
|
167
|
-
const trimmedFiles = props.files.trim();
|
|
168
|
-
if (trimmedFiles.startsWith('[') && trimmedFiles.endsWith(']')) {
|
|
169
|
-
try {
|
|
170
|
-
// 尝试解析JSON字符串
|
|
171
|
-
const parsedArray = JSON.parse(trimmedFiles);
|
|
172
|
-
if (Array.isArray(parsedArray)) {
|
|
173
|
-
// 解析成功,处理数组中的每个元素
|
|
174
|
-
fileList = parsedArray.map(item => {
|
|
175
|
-
if (typeof item === 'string') {
|
|
176
|
-
// 数组中的字符串元素,作为URL处理
|
|
177
|
-
return parseFileInfo(item);
|
|
178
|
-
} else if (item && typeof item === 'object') {
|
|
179
|
-
// 对象格式的文件信息
|
|
180
|
-
const url = item.url || item.src || item.path || '';
|
|
181
|
-
return {
|
|
182
|
-
name: item.name || extractFileName(url),
|
|
183
|
-
url: getFullUrl(url),
|
|
184
|
-
size: item.size || null,
|
|
185
|
-
extension: item.extension || getFileExtension(url || item.name || ''),
|
|
186
|
-
...item
|
|
187
|
-
};
|
|
188
|
-
} else {
|
|
189
|
-
// 其他情况,返回默认对象
|
|
190
|
-
return {
|
|
191
|
-
name: '未知文件',
|
|
192
|
-
url: '',
|
|
193
|
-
extension: '',
|
|
194
|
-
size: null
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
// 解析出来不是数组,按普通字符串处理
|
|
200
|
-
fileList = [parseFileInfo(trimmedFiles)];
|
|
201
|
-
}
|
|
202
|
-
} catch (e) {
|
|
203
|
-
// JSON解析失败,按普通字符串处理
|
|
204
|
-
fileList = [parseFileInfo(trimmedFiles)];
|
|
205
|
-
}
|
|
206
|
-
} else if (props.files.includes(',')) {
|
|
207
|
-
// 逗号分隔的多个URL
|
|
208
|
-
const urls = props.files.split(',').map(url => url.trim()).filter(url => url);
|
|
209
|
-
fileList = urls.map(url => parseFileInfo(url));
|
|
210
|
-
} else {
|
|
211
|
-
// 单个URL
|
|
212
|
-
fileList = [parseFileInfo(props.files.trim())];
|
|
213
|
-
}
|
|
214
|
-
} else if (Array.isArray(props.files)) {
|
|
215
|
-
// 数组格式
|
|
216
|
-
fileList = props.files.map(file => {
|
|
217
|
-
if (typeof file === 'string') {
|
|
218
|
-
// 数组中的字符串元素,直接作为URL处理
|
|
219
|
-
return parseFileInfo(file);
|
|
220
|
-
} else if (file && typeof file === 'object') {
|
|
221
|
-
// 对象格式的文件信息
|
|
222
|
-
const url = file.url || file.src || file.path || '';
|
|
223
|
-
return {
|
|
224
|
-
name: file.name || extractFileName(url),
|
|
225
|
-
url: getFullUrl(url),
|
|
226
|
-
size: file.size || null,
|
|
227
|
-
extension: file.extension || getFileExtension(url || file.name || ''),
|
|
228
|
-
...file
|
|
229
|
-
};
|
|
230
|
-
} else {
|
|
231
|
-
// 其他情况,返回默认对象
|
|
232
|
-
return {
|
|
233
|
-
name: '未知文件',
|
|
234
|
-
url: '',
|
|
235
|
-
extension: '',
|
|
236
|
-
size: null
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}).filter(file => file.url); // 过滤掉没有URL的文件
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return fileList;
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// 判断是否为图片
|
|
246
|
-
const isImage = (extension) => {
|
|
247
|
-
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];
|
|
248
|
-
return imageExtensions.includes(extension?.toLowerCase());
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// 获取文件图标
|
|
252
|
-
const getFileIcon = (extension) => {
|
|
253
|
-
const iconMap = {
|
|
254
|
-
// 文档类
|
|
255
|
-
'pdf': 'file-pdf',
|
|
256
|
-
'doc': 'file-word',
|
|
257
|
-
'docx': 'file-word',
|
|
258
|
-
'xls': 'file-excel',
|
|
259
|
-
'xlsx': 'file-excel',
|
|
260
|
-
'ppt': 'file-powerpoint',
|
|
261
|
-
'pptx': 'file-powerpoint',
|
|
262
|
-
'txt': 'file-text',
|
|
263
|
-
'rtf': 'file-text',
|
|
264
|
-
// 代码类
|
|
265
|
-
'js': 'file-code',
|
|
266
|
-
'ts': 'file-code',
|
|
267
|
-
'html': 'file-code',
|
|
268
|
-
'css': 'file-code',
|
|
269
|
-
'json': 'file-code',
|
|
270
|
-
'xml': 'file-code',
|
|
271
|
-
// 压缩类
|
|
272
|
-
'zip': 'file-zip',
|
|
273
|
-
'rar': 'file-zip',
|
|
274
|
-
'7z': 'file-zip',
|
|
275
|
-
'tar': 'file-zip',
|
|
276
|
-
'gz': 'file-zip',
|
|
277
|
-
// 音视频类
|
|
278
|
-
'mp3': 'file-music',
|
|
279
|
-
'wav': 'file-music',
|
|
280
|
-
'mp4': 'file-video',
|
|
281
|
-
'avi': 'file-video',
|
|
282
|
-
'mov': 'file-video',
|
|
283
|
-
'wmv': 'file-video'
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
return iconMap[extension?.toLowerCase()] || 'file';
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// 获取文件颜色
|
|
290
|
-
const getFileColor = (extension) => {
|
|
291
|
-
const colorMap = {
|
|
292
|
-
'pdf': '#FF4757',
|
|
293
|
-
'doc': '#2E5BFF',
|
|
294
|
-
'docx': '#2E5BFF',
|
|
295
|
-
'xls': '#00A854',
|
|
296
|
-
'xlsx': '#00A854',
|
|
297
|
-
'ppt': '#FF8C42',
|
|
298
|
-
'pptx': '#FF8C42',
|
|
299
|
-
'txt': '#666666',
|
|
300
|
-
'zip': '#9C27B0',
|
|
301
|
-
'rar': '#9C27B0',
|
|
302
|
-
'mp3': '#FF9800',
|
|
303
|
-
'mp4': '#795548'
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
return colorMap[extension?.toLowerCase()] || '#666666';
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
// 计算实际使用的图片尺寸
|
|
310
|
-
const actualImageSize = computed(() => {
|
|
311
|
-
return props.size === 'mini' ? '20px' : props.imageSize;
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
// 格式化文件大小
|
|
315
|
-
const formatFileSize = (bytes) => {
|
|
316
|
-
if (!bytes) return '';
|
|
317
|
-
const units = ['B', 'KB', 'MB', 'GB'];
|
|
318
|
-
let size = bytes;
|
|
319
|
-
let unitIndex = 0;
|
|
320
|
-
|
|
321
|
-
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
322
|
-
size /= 1024;
|
|
323
|
-
unitIndex++;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return `${size.toFixed(1)} ${units[unitIndex]}`;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
// 是否可在线预览
|
|
330
|
-
const canPreviewOnline = (extension) => {
|
|
331
|
-
const onlinePreviewExtensions = ['pdf', 'txt', 'html', 'xml', 'json'];
|
|
332
|
-
return onlinePreviewExtensions.includes(extension?.toLowerCase());
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// 文件下载
|
|
336
|
-
const handleDownload = (file) => {
|
|
337
|
-
const link = document.createElement('a');
|
|
338
|
-
link.href = file.url;
|
|
339
|
-
link.download = file.name;
|
|
340
|
-
link.target = '_blank';
|
|
341
|
-
document.body.appendChild(link);
|
|
342
|
-
link.click();
|
|
343
|
-
document.body.removeChild(link);
|
|
344
|
-
|
|
345
|
-
emit('file-download', file);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// 图片预览
|
|
349
|
-
const handlePreview = (file) => {
|
|
350
|
-
const imageFiles = computedFiles.value.filter(f => isImage(f.extension));
|
|
351
|
-
previewImages.value = imageFiles.map(f => f.url);
|
|
352
|
-
previewIndex.value = imageFiles.findIndex(f => f.url === file.url);
|
|
353
|
-
previewVisible.value = true;
|
|
354
|
-
|
|
355
|
-
emit('file-preview', file);
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
// 文件点击处理
|
|
359
|
-
const handleFileClick = (file) => {
|
|
360
|
-
emit('file-click', file);
|
|
361
|
-
|
|
362
|
-
if (isImage(file.extension)) {
|
|
363
|
-
// 图片文件,显示预览
|
|
364
|
-
handlePreview(file);
|
|
365
|
-
} else if (canPreviewOnline(file.extension)) {
|
|
366
|
-
// 可在线预览的文件
|
|
367
|
-
window.open(file.url, '_blank');
|
|
368
|
-
} else {
|
|
369
|
-
// 其他文件,触发下载
|
|
370
|
-
handleDownload(file);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
// 文件删除
|
|
375
|
-
const handleDelete = (file, index) => {
|
|
376
|
-
emit('file-delete', file, index);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
// 图片加载错误处理
|
|
380
|
-
const handleImageError = () => {
|
|
381
|
-
// 图片加载失败时的处理
|
|
382
|
-
};
|
|
383
|
-
</script>
|
|
384
|
-
|
|
385
|
-
<style lang="less" scoped>
|
|
386
|
-
.ebiz-file-list {
|
|
387
|
-
width: 100%;
|
|
388
|
-
|
|
389
|
-
&.mini-mode {
|
|
390
|
-
.file-list-container {
|
|
391
|
-
display: flex;
|
|
392
|
-
flex-direction: row;
|
|
393
|
-
flex-wrap: wrap;
|
|
394
|
-
gap: 4px;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
.empty-state {
|
|
399
|
-
display: flex;
|
|
400
|
-
flex-direction: column;
|
|
401
|
-
padding: 10px;
|
|
402
|
-
color: #999;
|
|
403
|
-
|
|
404
|
-
p {
|
|
405
|
-
margin: 8px 0 0 0;
|
|
406
|
-
font-size: 12px;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
.file-list-container {
|
|
411
|
-
display: flex;
|
|
412
|
-
flex-direction: column;
|
|
413
|
-
gap: 8px;
|
|
414
|
-
|
|
415
|
-
&.mini-container {
|
|
416
|
-
flex-direction: row;
|
|
417
|
-
flex-wrap: wrap;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
.file-item {
|
|
422
|
-
display: flex;
|
|
423
|
-
align-items: center;
|
|
424
|
-
padding: 8px 12px;
|
|
425
|
-
border: 1px solid #e6e6e6;
|
|
426
|
-
border-radius: 6px;
|
|
427
|
-
cursor: pointer;
|
|
428
|
-
transition: all 0.3s;
|
|
429
|
-
background: #fff;
|
|
430
|
-
|
|
431
|
-
&.mini-item {
|
|
432
|
-
padding: 0;
|
|
433
|
-
border: none;
|
|
434
|
-
background: transparent;
|
|
435
|
-
box-shadow: none;
|
|
436
|
-
margin-right: 8px;
|
|
437
|
-
margin-bottom: 8px;
|
|
438
|
-
|
|
439
|
-
&:hover {
|
|
440
|
-
border-color: transparent;
|
|
441
|
-
box-shadow: none;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
&:hover {
|
|
446
|
-
border-color: #0052d9;
|
|
447
|
-
box-shadow: 0 2px 8px rgba(0, 82, 217, 0.15);
|
|
448
|
-
|
|
449
|
-
.file-actions {
|
|
450
|
-
opacity: 1;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
.file-icon {
|
|
456
|
-
margin-right: 12px;
|
|
457
|
-
flex-shrink: 0;
|
|
458
|
-
display: flex;
|
|
459
|
-
align-items: center;
|
|
460
|
-
justify-content: center;
|
|
461
|
-
width: v-bind(actualImageSize);
|
|
462
|
-
height: v-bind(actualImageSize);
|
|
463
|
-
|
|
464
|
-
.mini-item & {
|
|
465
|
-
margin-right: 0;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
.file-info {
|
|
470
|
-
flex: 1;
|
|
471
|
-
min-width: 0;
|
|
472
|
-
|
|
473
|
-
.file-name {
|
|
474
|
-
font-size: 14px;
|
|
475
|
-
font-weight: 500;
|
|
476
|
-
color: #333;
|
|
477
|
-
margin-bottom: 3px;
|
|
478
|
-
overflow: hidden;
|
|
479
|
-
text-overflow: ellipsis;
|
|
480
|
-
white-space: nowrap;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
.file-meta {
|
|
484
|
-
display: flex;
|
|
485
|
-
gap: 8px;
|
|
486
|
-
|
|
487
|
-
.file-size,
|
|
488
|
-
.file-type {
|
|
489
|
-
font-size: 12px;
|
|
490
|
-
color: #999;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
.file-actions {
|
|
496
|
-
display: flex;
|
|
497
|
-
gap: 4px;
|
|
498
|
-
opacity: 0;
|
|
499
|
-
transition: opacity 0.3s;
|
|
500
|
-
flex-shrink: 0;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ebiz-file-list" :class="{ 'mini-mode': size === 'mini' }">
|
|
3
|
+
<div v-if="computedFiles.length === 0" class="empty-state">
|
|
4
|
+
<div>-</div>
|
|
5
|
+
</div>
|
|
6
|
+
<div v-else class="file-list-container" :class="{ 'mini-container': size === 'mini' }">
|
|
7
|
+
<div v-for="(file, index) in computedFiles" :key="index" class="file-item"
|
|
8
|
+
:class="{ 'mini-item': size === 'mini' }" @click="handleFileClick(file)">
|
|
9
|
+
<!-- 图片文件直接显示缩略图 -->
|
|
10
|
+
<div v-if="isImage(file.extension)" class="file-icon">
|
|
11
|
+
<t-image :src="file.url" :alt="file.name" fit="cover" loading="lazy"
|
|
12
|
+
:style="{ width: actualImageSize, height: actualImageSize, borderRadius: '4px' }" error="" />
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<!-- 非图片文件显示图标 -->
|
|
16
|
+
<div v-else class="file-icon">
|
|
17
|
+
<t-icon :name="getFileIcon(file.extension)" :size="actualImageSize"
|
|
18
|
+
:style="{ color: getFileColor(file.extension) }" />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div v-if="size !== 'mini'" class="file-info">
|
|
22
|
+
<div class="file-name" :title="file.name">{{ file.name }}</div>
|
|
23
|
+
<div class="file-meta">
|
|
24
|
+
<span v-if="showFileType" class="file-type">{{ file.extension?.toUpperCase() || '未知' }}</span>
|
|
25
|
+
<span v-if="showFileSize && file.size" class="file-size">{{ formatFileSize(file.size) }}</span>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<!-- 操作按钮 -->
|
|
30
|
+
<div v-if="showActions && size !== 'mini'" class="file-actions">
|
|
31
|
+
<t-button size="small" variant="text" @click.stop="handleDownload(file)"
|
|
32
|
+
:title="isImage(file.extension) ? '查看' : '下载'">
|
|
33
|
+
<t-icon :name="isImage(file.extension) ? 'view-list' : 'download'" />
|
|
34
|
+
</t-button>
|
|
35
|
+
<t-button v-if="allowDelete" size="small" variant="text" theme="danger"
|
|
36
|
+
@click.stop="handleDelete(file, index)" title="删除">
|
|
37
|
+
<t-icon name="delete" />
|
|
38
|
+
</t-button>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<!-- 图片预览弹窗 -->
|
|
44
|
+
<t-image-viewer v-model:visible="previewVisible" :images="previewImages" :index="previewIndex" :close-on-esc="true"
|
|
45
|
+
@close="previewVisible = false" />
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
export default {
|
|
51
|
+
name: "EbizFileList"
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<script setup>
|
|
56
|
+
import { defineProps, defineEmits, computed, ref } from 'vue';
|
|
57
|
+
import { Image as TImage, ImageViewer as TImageViewer, Icon as TIcon, Button as TButton } from 'tdesign-vue-next';
|
|
58
|
+
|
|
59
|
+
const props = defineProps({
|
|
60
|
+
// 文件列表数据,支持数组或字符串(逗号分隔)
|
|
61
|
+
files: {
|
|
62
|
+
type: [Array, String],
|
|
63
|
+
default: () => []
|
|
64
|
+
},
|
|
65
|
+
// 尺寸大小,支持default和mini
|
|
66
|
+
size: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: 'default'
|
|
69
|
+
},
|
|
70
|
+
// 图片尺寸
|
|
71
|
+
imageSize: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: '50px'
|
|
74
|
+
},
|
|
75
|
+
// 是否显示文件大小
|
|
76
|
+
showFileSize: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: true
|
|
79
|
+
},
|
|
80
|
+
// 是否显示文件类型
|
|
81
|
+
showFileType: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: true
|
|
84
|
+
},
|
|
85
|
+
// 是否显示操作按钮
|
|
86
|
+
showActions: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: true
|
|
89
|
+
},
|
|
90
|
+
// 是否允许删除
|
|
91
|
+
allowDelete: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: false
|
|
94
|
+
},
|
|
95
|
+
// 文件基础URL(用于相对路径)
|
|
96
|
+
baseUrl: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: ''
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const emit = defineEmits(['file-click', 'file-download', 'file-delete', 'file-preview']);
|
|
103
|
+
|
|
104
|
+
// 预览相关状态
|
|
105
|
+
const previewVisible = ref(false);
|
|
106
|
+
const previewImages = ref([]);
|
|
107
|
+
const previewIndex = ref(0);
|
|
108
|
+
|
|
109
|
+
// 获取完整URL
|
|
110
|
+
const getFullUrl = (url) => {
|
|
111
|
+
if (!url) return '';
|
|
112
|
+
if (url.startsWith('http') || url.startsWith('data:')) return url;
|
|
113
|
+
return props.baseUrl + url;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// 获取文件扩展名
|
|
117
|
+
const getFileExtension = (filename) => {
|
|
118
|
+
if (!filename) return '';
|
|
119
|
+
// 移除查询参数和锚点
|
|
120
|
+
const cleanFilename = filename.split('?')[0].split('#')[0];
|
|
121
|
+
const parts = cleanFilename.split('.');
|
|
122
|
+
return parts.length > 1 ? parts.pop().toLowerCase() : '';
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// 提取文件名
|
|
126
|
+
const extractFileName = (url) => {
|
|
127
|
+
if (!url) return '未知文件';
|
|
128
|
+
|
|
129
|
+
// 移除查询参数和锚点
|
|
130
|
+
const cleanUrl = url.split('?')[0].split('#')[0];
|
|
131
|
+
const parts = cleanUrl.split('/');
|
|
132
|
+
let fileName = parts[parts.length - 1] || '未知文件';
|
|
133
|
+
|
|
134
|
+
// 如果文件名为空或只是扩展名,生成一个默认名称
|
|
135
|
+
if (!fileName || fileName.startsWith('.')) {
|
|
136
|
+
const extension = getFileExtension(fileName || url);
|
|
137
|
+
fileName = extension ? `文件.${extension}` : '未知文件';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return fileName;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// 解析文件信息
|
|
144
|
+
const parseFileInfo = (url) => {
|
|
145
|
+
const fullUrl = getFullUrl(url);
|
|
146
|
+
const fileName = extractFileName(url);
|
|
147
|
+
const extension = getFileExtension(fileName);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
name: fileName,
|
|
151
|
+
url: fullUrl,
|
|
152
|
+
extension,
|
|
153
|
+
size: null
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 计算文件列表
|
|
158
|
+
const computedFiles = computed(() => {
|
|
159
|
+
let fileList = [];
|
|
160
|
+
|
|
161
|
+
if (typeof props.files === 'string') {
|
|
162
|
+
if (!props.files.trim()) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 判断是否为JSON字符串
|
|
167
|
+
const trimmedFiles = props.files.trim();
|
|
168
|
+
if (trimmedFiles.startsWith('[') && trimmedFiles.endsWith(']')) {
|
|
169
|
+
try {
|
|
170
|
+
// 尝试解析JSON字符串
|
|
171
|
+
const parsedArray = JSON.parse(trimmedFiles);
|
|
172
|
+
if (Array.isArray(parsedArray)) {
|
|
173
|
+
// 解析成功,处理数组中的每个元素
|
|
174
|
+
fileList = parsedArray.map(item => {
|
|
175
|
+
if (typeof item === 'string') {
|
|
176
|
+
// 数组中的字符串元素,作为URL处理
|
|
177
|
+
return parseFileInfo(item);
|
|
178
|
+
} else if (item && typeof item === 'object') {
|
|
179
|
+
// 对象格式的文件信息
|
|
180
|
+
const url = item.url || item.src || item.path || '';
|
|
181
|
+
return {
|
|
182
|
+
name: item.name || extractFileName(url),
|
|
183
|
+
url: getFullUrl(url),
|
|
184
|
+
size: item.size || null,
|
|
185
|
+
extension: item.extension || getFileExtension(url || item.name || ''),
|
|
186
|
+
...item
|
|
187
|
+
};
|
|
188
|
+
} else {
|
|
189
|
+
// 其他情况,返回默认对象
|
|
190
|
+
return {
|
|
191
|
+
name: '未知文件',
|
|
192
|
+
url: '',
|
|
193
|
+
extension: '',
|
|
194
|
+
size: null
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
} else {
|
|
199
|
+
// 解析出来不是数组,按普通字符串处理
|
|
200
|
+
fileList = [parseFileInfo(trimmedFiles)];
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
// JSON解析失败,按普通字符串处理
|
|
204
|
+
fileList = [parseFileInfo(trimmedFiles)];
|
|
205
|
+
}
|
|
206
|
+
} else if (props.files.includes(',')) {
|
|
207
|
+
// 逗号分隔的多个URL
|
|
208
|
+
const urls = props.files.split(',').map(url => url.trim()).filter(url => url);
|
|
209
|
+
fileList = urls.map(url => parseFileInfo(url));
|
|
210
|
+
} else {
|
|
211
|
+
// 单个URL
|
|
212
|
+
fileList = [parseFileInfo(props.files.trim())];
|
|
213
|
+
}
|
|
214
|
+
} else if (Array.isArray(props.files)) {
|
|
215
|
+
// 数组格式
|
|
216
|
+
fileList = props.files.map(file => {
|
|
217
|
+
if (typeof file === 'string') {
|
|
218
|
+
// 数组中的字符串元素,直接作为URL处理
|
|
219
|
+
return parseFileInfo(file);
|
|
220
|
+
} else if (file && typeof file === 'object') {
|
|
221
|
+
// 对象格式的文件信息
|
|
222
|
+
const url = file.url || file.src || file.path || '';
|
|
223
|
+
return {
|
|
224
|
+
name: file.name || extractFileName(url),
|
|
225
|
+
url: getFullUrl(url),
|
|
226
|
+
size: file.size || null,
|
|
227
|
+
extension: file.extension || getFileExtension(url || file.name || ''),
|
|
228
|
+
...file
|
|
229
|
+
};
|
|
230
|
+
} else {
|
|
231
|
+
// 其他情况,返回默认对象
|
|
232
|
+
return {
|
|
233
|
+
name: '未知文件',
|
|
234
|
+
url: '',
|
|
235
|
+
extension: '',
|
|
236
|
+
size: null
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}).filter(file => file.url); // 过滤掉没有URL的文件
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return fileList;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// 判断是否为图片
|
|
246
|
+
const isImage = (extension) => {
|
|
247
|
+
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];
|
|
248
|
+
return imageExtensions.includes(extension?.toLowerCase());
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// 获取文件图标
|
|
252
|
+
const getFileIcon = (extension) => {
|
|
253
|
+
const iconMap = {
|
|
254
|
+
// 文档类
|
|
255
|
+
'pdf': 'file-pdf',
|
|
256
|
+
'doc': 'file-word',
|
|
257
|
+
'docx': 'file-word',
|
|
258
|
+
'xls': 'file-excel',
|
|
259
|
+
'xlsx': 'file-excel',
|
|
260
|
+
'ppt': 'file-powerpoint',
|
|
261
|
+
'pptx': 'file-powerpoint',
|
|
262
|
+
'txt': 'file-text',
|
|
263
|
+
'rtf': 'file-text',
|
|
264
|
+
// 代码类
|
|
265
|
+
'js': 'file-code',
|
|
266
|
+
'ts': 'file-code',
|
|
267
|
+
'html': 'file-code',
|
|
268
|
+
'css': 'file-code',
|
|
269
|
+
'json': 'file-code',
|
|
270
|
+
'xml': 'file-code',
|
|
271
|
+
// 压缩类
|
|
272
|
+
'zip': 'file-zip',
|
|
273
|
+
'rar': 'file-zip',
|
|
274
|
+
'7z': 'file-zip',
|
|
275
|
+
'tar': 'file-zip',
|
|
276
|
+
'gz': 'file-zip',
|
|
277
|
+
// 音视频类
|
|
278
|
+
'mp3': 'file-music',
|
|
279
|
+
'wav': 'file-music',
|
|
280
|
+
'mp4': 'file-video',
|
|
281
|
+
'avi': 'file-video',
|
|
282
|
+
'mov': 'file-video',
|
|
283
|
+
'wmv': 'file-video'
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
return iconMap[extension?.toLowerCase()] || 'file';
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// 获取文件颜色
|
|
290
|
+
const getFileColor = (extension) => {
|
|
291
|
+
const colorMap = {
|
|
292
|
+
'pdf': '#FF4757',
|
|
293
|
+
'doc': '#2E5BFF',
|
|
294
|
+
'docx': '#2E5BFF',
|
|
295
|
+
'xls': '#00A854',
|
|
296
|
+
'xlsx': '#00A854',
|
|
297
|
+
'ppt': '#FF8C42',
|
|
298
|
+
'pptx': '#FF8C42',
|
|
299
|
+
'txt': '#666666',
|
|
300
|
+
'zip': '#9C27B0',
|
|
301
|
+
'rar': '#9C27B0',
|
|
302
|
+
'mp3': '#FF9800',
|
|
303
|
+
'mp4': '#795548'
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
return colorMap[extension?.toLowerCase()] || '#666666';
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// 计算实际使用的图片尺寸
|
|
310
|
+
const actualImageSize = computed(() => {
|
|
311
|
+
return props.size === 'mini' ? '20px' : props.imageSize;
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// 格式化文件大小
|
|
315
|
+
const formatFileSize = (bytes) => {
|
|
316
|
+
if (!bytes) return '';
|
|
317
|
+
const units = ['B', 'KB', 'MB', 'GB'];
|
|
318
|
+
let size = bytes;
|
|
319
|
+
let unitIndex = 0;
|
|
320
|
+
|
|
321
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
322
|
+
size /= 1024;
|
|
323
|
+
unitIndex++;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return `${size.toFixed(1)} ${units[unitIndex]}`;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// 是否可在线预览
|
|
330
|
+
const canPreviewOnline = (extension) => {
|
|
331
|
+
const onlinePreviewExtensions = ['pdf', 'txt', 'html', 'xml', 'json'];
|
|
332
|
+
return onlinePreviewExtensions.includes(extension?.toLowerCase());
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// 文件下载
|
|
336
|
+
const handleDownload = (file) => {
|
|
337
|
+
const link = document.createElement('a');
|
|
338
|
+
link.href = file.url;
|
|
339
|
+
link.download = file.name;
|
|
340
|
+
link.target = '_blank';
|
|
341
|
+
document.body.appendChild(link);
|
|
342
|
+
link.click();
|
|
343
|
+
document.body.removeChild(link);
|
|
344
|
+
|
|
345
|
+
emit('file-download', file);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// 图片预览
|
|
349
|
+
const handlePreview = (file) => {
|
|
350
|
+
const imageFiles = computedFiles.value.filter(f => isImage(f.extension));
|
|
351
|
+
previewImages.value = imageFiles.map(f => f.url);
|
|
352
|
+
previewIndex.value = imageFiles.findIndex(f => f.url === file.url);
|
|
353
|
+
previewVisible.value = true;
|
|
354
|
+
|
|
355
|
+
emit('file-preview', file);
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// 文件点击处理
|
|
359
|
+
const handleFileClick = (file) => {
|
|
360
|
+
emit('file-click', file);
|
|
361
|
+
|
|
362
|
+
if (isImage(file.extension)) {
|
|
363
|
+
// 图片文件,显示预览
|
|
364
|
+
handlePreview(file);
|
|
365
|
+
} else if (canPreviewOnline(file.extension)) {
|
|
366
|
+
// 可在线预览的文件
|
|
367
|
+
window.open(file.url, '_blank');
|
|
368
|
+
} else {
|
|
369
|
+
// 其他文件,触发下载
|
|
370
|
+
handleDownload(file);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// 文件删除
|
|
375
|
+
const handleDelete = (file, index) => {
|
|
376
|
+
emit('file-delete', file, index);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// 图片加载错误处理
|
|
380
|
+
const handleImageError = () => {
|
|
381
|
+
// 图片加载失败时的处理
|
|
382
|
+
};
|
|
383
|
+
</script>
|
|
384
|
+
|
|
385
|
+
<style lang="less" scoped>
|
|
386
|
+
.ebiz-file-list {
|
|
387
|
+
width: 100%;
|
|
388
|
+
|
|
389
|
+
&.mini-mode {
|
|
390
|
+
.file-list-container {
|
|
391
|
+
display: flex;
|
|
392
|
+
flex-direction: row;
|
|
393
|
+
flex-wrap: wrap;
|
|
394
|
+
gap: 4px;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.empty-state {
|
|
399
|
+
display: flex;
|
|
400
|
+
flex-direction: column;
|
|
401
|
+
padding: 10px;
|
|
402
|
+
color: #999;
|
|
403
|
+
|
|
404
|
+
p {
|
|
405
|
+
margin: 8px 0 0 0;
|
|
406
|
+
font-size: 12px;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.file-list-container {
|
|
411
|
+
display: flex;
|
|
412
|
+
flex-direction: column;
|
|
413
|
+
gap: 8px;
|
|
414
|
+
|
|
415
|
+
&.mini-container {
|
|
416
|
+
flex-direction: row;
|
|
417
|
+
flex-wrap: wrap;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.file-item {
|
|
422
|
+
display: flex;
|
|
423
|
+
align-items: center;
|
|
424
|
+
padding: 8px 12px;
|
|
425
|
+
border: 1px solid #e6e6e6;
|
|
426
|
+
border-radius: 6px;
|
|
427
|
+
cursor: pointer;
|
|
428
|
+
transition: all 0.3s;
|
|
429
|
+
background: #fff;
|
|
430
|
+
|
|
431
|
+
&.mini-item {
|
|
432
|
+
padding: 0;
|
|
433
|
+
border: none;
|
|
434
|
+
background: transparent;
|
|
435
|
+
box-shadow: none;
|
|
436
|
+
margin-right: 8px;
|
|
437
|
+
margin-bottom: 8px;
|
|
438
|
+
|
|
439
|
+
&:hover {
|
|
440
|
+
border-color: transparent;
|
|
441
|
+
box-shadow: none;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
&:hover {
|
|
446
|
+
border-color: #0052d9;
|
|
447
|
+
box-shadow: 0 2px 8px rgba(0, 82, 217, 0.15);
|
|
448
|
+
|
|
449
|
+
.file-actions {
|
|
450
|
+
opacity: 1;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.file-icon {
|
|
456
|
+
margin-right: 12px;
|
|
457
|
+
flex-shrink: 0;
|
|
458
|
+
display: flex;
|
|
459
|
+
align-items: center;
|
|
460
|
+
justify-content: center;
|
|
461
|
+
width: v-bind(actualImageSize);
|
|
462
|
+
height: v-bind(actualImageSize);
|
|
463
|
+
|
|
464
|
+
.mini-item & {
|
|
465
|
+
margin-right: 0;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.file-info {
|
|
470
|
+
flex: 1;
|
|
471
|
+
min-width: 0;
|
|
472
|
+
|
|
473
|
+
.file-name {
|
|
474
|
+
font-size: 14px;
|
|
475
|
+
font-weight: 500;
|
|
476
|
+
color: #333;
|
|
477
|
+
margin-bottom: 3px;
|
|
478
|
+
overflow: hidden;
|
|
479
|
+
text-overflow: ellipsis;
|
|
480
|
+
white-space: nowrap;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
.file-meta {
|
|
484
|
+
display: flex;
|
|
485
|
+
gap: 8px;
|
|
486
|
+
|
|
487
|
+
.file-size,
|
|
488
|
+
.file-type {
|
|
489
|
+
font-size: 12px;
|
|
490
|
+
color: #999;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.file-actions {
|
|
496
|
+
display: flex;
|
|
497
|
+
gap: 4px;
|
|
498
|
+
opacity: 0;
|
|
499
|
+
transition: opacity 0.3s;
|
|
500
|
+
flex-shrink: 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
503
|
</style>
|