@jari-ace/element-plus-component 0.3.4 → 0.4.0
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/dist/components/upload/FilePreviewer.vue.d.ts +59 -0
- package/dist/components/upload/FilePreviewer.vue.d.ts.map +1 -0
- package/dist/components/upload/FilePreviewer.vue.js +169 -0
- package/dist/components/upload/FilePreviewer.vue.js.map +1 -0
- package/dist/components/upload/index.d.ts +23 -0
- package/dist/components/upload/index.d.ts.map +1 -1
- package/dist/components/upload/index.js +2 -0
- package/dist/components/upload/index.js.map +1 -1
- package/lib/index.css +1 -1
- package/lib/index.js +3732 -3645
- package/lib/index.umd.cjs +26 -26
- package/package.json +1 -1
- package/packages/components/upload/FilePreviewer.vue +245 -0
- package/packages/components/upload/index.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
- 版权所有 (c) 2026 江苏杰瑞信息科技有限公司
|
|
3
|
+
-
|
|
4
|
+
- 此文件属于JARI.ACE平台项目,修改、分发必须遵守杰瑞信科商业软件许可协议
|
|
5
|
+
-
|
|
6
|
+
-->
|
|
7
|
+
|
|
8
|
+
<!--
|
|
9
|
+
* FilePreviewer 组件
|
|
10
|
+
*
|
|
11
|
+
* 用途:用于根据 attachToken 预览附件列表中的第一个可预览文件
|
|
12
|
+
*
|
|
13
|
+
* 功能特点:
|
|
14
|
+
* - 自动获取附件列表并识别可预览文件
|
|
15
|
+
* - 支持多种文件格式预览(PDF、Office文档、图片等)
|
|
16
|
+
* - 使用 Element Plus 按钮组件,支持完整的外观自定义
|
|
17
|
+
* - 集成 PdfViewerModal 进行文件预览
|
|
18
|
+
*
|
|
19
|
+
* 使用示例:
|
|
20
|
+
*
|
|
21
|
+
* 基础用法:
|
|
22
|
+
* <FilePreviewer attachToken="your-attach-token" />
|
|
23
|
+
*
|
|
24
|
+
* 自定义按钮外观:
|
|
25
|
+
* <FilePreviewer
|
|
26
|
+
* attachToken="your-attach-token"
|
|
27
|
+
* buttonType="primary"
|
|
28
|
+
* buttonSize="medium"
|
|
29
|
+
* buttonText="查看文件"
|
|
30
|
+
* buttonIcon="View"
|
|
31
|
+
* />
|
|
32
|
+
*
|
|
33
|
+
* 高级自定义:
|
|
34
|
+
* <FilePreviewer
|
|
35
|
+
* attachToken="your-attach-token"
|
|
36
|
+
* buttonClass="my-custom-button"
|
|
37
|
+
* buttonRound
|
|
38
|
+
* buttonPlain={false}
|
|
39
|
+
* />
|
|
40
|
+
-->
|
|
41
|
+
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
import {createAxiosWithoutCache, type FileInfo, useFilesApi} from "@jari-ace/app-bolts";
|
|
44
|
+
import {computed, ref} from "vue";
|
|
45
|
+
import {ElButton} from "element-plus";
|
|
46
|
+
import PdfViewerModal from "./pdf-viewer/PdfViewerModal.vue";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* FilePreviewer 组件属性定义
|
|
50
|
+
*
|
|
51
|
+
* @property {string} attachToken - 附件令牌,用于获取文件列表(必需)
|
|
52
|
+
* @property {string} [buttonType='warning'] - 按钮类型,可选值:primary/success/warning/danger/info
|
|
53
|
+
* @property {string} [buttonSize='small'] - 按钮尺寸,可选值:large/medium/small
|
|
54
|
+
* @property {boolean} [buttonPlain=true] - 是否使用朴素按钮样式
|
|
55
|
+
* @property {boolean} [buttonRound=false] - 是否圆角按钮
|
|
56
|
+
* @property {boolean} [buttonCircle=false] - 是否圆形按钮
|
|
57
|
+
* @property {boolean} [buttonDisabled=false] - 按钮是否禁用
|
|
58
|
+
* @property {any} [buttonIcon] - 按钮图标,可以是 Element Plus 图标组件
|
|
59
|
+
* @property {string} [buttonText='预览'] - 按钮文本内容
|
|
60
|
+
* @property {string} [buttonClass] - 自定义按钮 CSS 类名
|
|
61
|
+
*/
|
|
62
|
+
const props = defineProps<{
|
|
63
|
+
/**
|
|
64
|
+
* 附件令牌
|
|
65
|
+
*/
|
|
66
|
+
attachToken: string,
|
|
67
|
+
/**
|
|
68
|
+
* 按钮类型
|
|
69
|
+
*/
|
|
70
|
+
buttonType?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text' | 'default',
|
|
71
|
+
/**
|
|
72
|
+
* 按钮尺寸
|
|
73
|
+
*/
|
|
74
|
+
buttonSize?: string,
|
|
75
|
+
/**
|
|
76
|
+
* 按钮是否朴素
|
|
77
|
+
*/
|
|
78
|
+
buttonPlain?: boolean,
|
|
79
|
+
/**
|
|
80
|
+
* 按钮是否圆角
|
|
81
|
+
*/
|
|
82
|
+
buttonRound?: boolean,
|
|
83
|
+
/**
|
|
84
|
+
* 按钮是否圆形
|
|
85
|
+
*/
|
|
86
|
+
buttonCircle?: boolean,
|
|
87
|
+
/**
|
|
88
|
+
* 按钮是否禁用
|
|
89
|
+
*/
|
|
90
|
+
buttonDisabled?: boolean,
|
|
91
|
+
/**
|
|
92
|
+
* 按钮图标
|
|
93
|
+
*/
|
|
94
|
+
buttonIcon?: any,
|
|
95
|
+
/**
|
|
96
|
+
* 按钮文本
|
|
97
|
+
*/
|
|
98
|
+
buttonText?: string,
|
|
99
|
+
/**
|
|
100
|
+
* 按钮类名
|
|
101
|
+
*/
|
|
102
|
+
buttonClass?: string,
|
|
103
|
+
}>();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 组件内部状态管理
|
|
107
|
+
*/
|
|
108
|
+
const axios = createAxiosWithoutCache();
|
|
109
|
+
const api = useFilesApi(axios);
|
|
110
|
+
const files = ref<FileInfo[]>([]); // 存储文件列表
|
|
111
|
+
const pdfViewerVisible = ref(false); // 控制 PDF 查看器模态框显示
|
|
112
|
+
const pdfSrc = ref(""); // PDF 文件源地址
|
|
113
|
+
const loading = ref(false); // 加载状态
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 按钮属性计算属性
|
|
117
|
+
* 用于处理 Element Plus 按钮的类型安全
|
|
118
|
+
*/
|
|
119
|
+
const buttonProps = computed(() => (
|
|
120
|
+
{
|
|
121
|
+
type: (
|
|
122
|
+
props.buttonType || 'warning'
|
|
123
|
+
) as any,
|
|
124
|
+
size: (
|
|
125
|
+
props.buttonSize || 'small'
|
|
126
|
+
) as any
|
|
127
|
+
}
|
|
128
|
+
));
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 可预览文件扩展名列表
|
|
132
|
+
* 支持多种文档格式:Office文档、PDF、图片、文本等
|
|
133
|
+
*/
|
|
134
|
+
const previewableFileExts = [".doc", ".docx", ".xls", ".xlsx", ".wps", ".et",
|
|
135
|
+
".csv", ".txt", ".rtf", ".odt", "ods", ".mht", ".ppt", ".pptx", ".odp", ".pdf", "xps", "."];
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 计算属性:检查是否存在可预览的文件
|
|
139
|
+
* 遍历文件列表,检查是否有文件扩展名在可预览列表中
|
|
140
|
+
*/
|
|
141
|
+
const hasPreviewableFiles = computed(() => {
|
|
142
|
+
return files.value.some(file => previewableFileExts.some(ext => file.fileName.endsWith(ext)));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 计算属性:获取第一个可预览的文件
|
|
147
|
+
* 用于确定要预览哪个文件
|
|
148
|
+
*/
|
|
149
|
+
const firstPreviewableFile = computed(() => {
|
|
150
|
+
return files.value.find(file => previewableFileExts.some(ext => file.fileName.endsWith(ext)));
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 加载文件列表
|
|
155
|
+
* 根据 attachToken 从服务器获取关联的文件列表
|
|
156
|
+
*
|
|
157
|
+
* @async
|
|
158
|
+
* @returns {Promise<void>}
|
|
159
|
+
*/
|
|
160
|
+
async function loadFileInfos() {
|
|
161
|
+
if (!props.attachToken) {
|
|
162
|
+
files.value = [];
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
loading.value = true;
|
|
168
|
+
files.value = await api.getFileList(props.attachToken);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error('Failed to load file list:', error);
|
|
171
|
+
files.value = [];
|
|
172
|
+
} finally {
|
|
173
|
+
loading.value = false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 预览第一个可预览的文件
|
|
179
|
+
* 构建预览 URL 并显示 PDF 查看器模态框
|
|
180
|
+
*
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
function previewFirstFile() {
|
|
184
|
+
const file = firstPreviewableFile.value;
|
|
185
|
+
if (!file) {
|
|
186
|
+
console.warn('No previewable files found');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 构建预览 URL,使用文件 token 或 ID
|
|
191
|
+
pdfSrc.value = new URL("uploads/preview/" + (
|
|
192
|
+
file.token || file.id
|
|
193
|
+
), location.origin).toString();
|
|
194
|
+
pdfViewerVisible.value = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 组件初始化
|
|
199
|
+
* 自动加载文件列表
|
|
200
|
+
*/
|
|
201
|
+
loadFileInfos();
|
|
202
|
+
</script>
|
|
203
|
+
|
|
204
|
+
<template>
|
|
205
|
+
<div class="file-previewer">
|
|
206
|
+
<!--
|
|
207
|
+
* 预览按钮
|
|
208
|
+
* 支持完整的 Element Plus 按钮属性自定义
|
|
209
|
+
* 当没有可预览文件时会自动禁用
|
|
210
|
+
* 点击时触发 previewFirstFile 函数
|
|
211
|
+
-->
|
|
212
|
+
<ElButton
|
|
213
|
+
:type="buttonProps.type"
|
|
214
|
+
:size="buttonProps.size"
|
|
215
|
+
:plain="buttonPlain !== undefined ? buttonPlain : true"
|
|
216
|
+
:round="buttonRound"
|
|
217
|
+
:circle="buttonCircle"
|
|
218
|
+
:loading="loading"
|
|
219
|
+
:disabled="buttonDisabled || !hasPreviewableFiles"
|
|
220
|
+
:icon="buttonIcon"
|
|
221
|
+
:class="buttonClass"
|
|
222
|
+
@click="previewFirstFile"
|
|
223
|
+
link>
|
|
224
|
+
{{ buttonText || '预览' }}
|
|
225
|
+
</ElButton>
|
|
226
|
+
|
|
227
|
+
<!--
|
|
228
|
+
* PDF 查看器模态框
|
|
229
|
+
* 用于显示可预览文件的内容
|
|
230
|
+
* 支持全屏显示和响应式布局
|
|
231
|
+
-->
|
|
232
|
+
<PdfViewerModal :src="pdfSrc" v-model="pdfViewerVisible"></PdfViewerModal>
|
|
233
|
+
</div>
|
|
234
|
+
</template>
|
|
235
|
+
|
|
236
|
+
<style lang="scss" scoped>
|
|
237
|
+
/**
|
|
238
|
+
* FilePreviewer 组件样式
|
|
239
|
+
* 使用内联块级显示,使按钮可以与其他元素并排显示
|
|
240
|
+
* 保持简洁的样式,让按钮本身的样式起主导作用
|
|
241
|
+
*/
|
|
242
|
+
.file-previewer {
|
|
243
|
+
display: inline-block;
|
|
244
|
+
}
|
|
245
|
+
</style>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { withInstall } from '../../utils/install'
|
|
2
2
|
import Upload from './uploader.vue'
|
|
3
3
|
import _JaUploader from './JaUploader.vue'
|
|
4
|
+
import _FilePreviewer from './FilePreviewer.vue'
|
|
4
5
|
export const JaUploader = withInstall(_JaUploader);
|
|
5
6
|
export const JaUploaderRaw = withInstall(Upload);
|
|
7
|
+
export const JaFilePreviewer = withInstall(_FilePreviewer);
|
|
6
8
|
export * from './types'
|