@newview/file-ui 0.0.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/README.md +11 -0
- package/dist/file-ui.mjs +15439 -0
- package/dist/file-ui.umd.js +1 -0
- package/dist/style.css +1 -0
- package/package-dev.json +38 -0
- package/package-publish.json +59 -0
- package/package.json +39 -0
- package/src/ComFormUp/ComFormUp.ts +131 -0
- package/src/ComFormUp/ComFormUp.vue +27 -0
- package/src/ComFormUp/index.ts +2 -0
- package/src/TextEditor/TextEditor.ts +207 -0
- package/src/TextEditor/TextEditor.vue +23 -0
- package/src/TextEditor/index.ts +2 -0
- package/src/UploadFile/FilePreview.ts +181 -0
- package/src/UploadFile/FilePreview.vue +32 -0
- package/src/UploadFile/UploadFile.ts +483 -0
- package/src/UploadFile/UploadFile.vue +239 -0
- package/src/UploadFile/index.ts +3 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +19 -0
- package/tsconfig.node.json +9 -0
- package/types/ComFormUp.d.ts +27 -0
- package/types/FilePreview.d.ts +5 -0
- package/types/FilePreviewInstance.d.ts +9 -0
- package/types/TextEditor.d.ts +26 -0
- package/types/UploadFile.d.ts +5 -0
- package/types/UploadFileInstance.d.ts +5 -0
- package/types/index.d.ts +7 -0
- package/vite.config.ts +50 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 功能名称:文件预览
|
|
3
|
+
* 创 建 人:弋强
|
|
4
|
+
* 日 期:2023/02/16 08:40:44
|
|
5
|
+
*/
|
|
6
|
+
import { BaseInstance } from '@newview/base-vue';
|
|
7
|
+
import { defineComponent, ref, reactive, computed, onMounted, onUnmounted, Ref, PropType, nextTick, watch, ExtractPropTypes, SetupContext } from 'vue'
|
|
8
|
+
import { GridOptions, GridInstance, GloablValueType } from '@newview/ui'
|
|
9
|
+
import { QueryWrapper } from '@newview/infrastructure'
|
|
10
|
+
import { OSSFileApi, FileApi } from "@newview/fileservice-api";
|
|
11
|
+
|
|
12
|
+
// 一、Emits 类型定义
|
|
13
|
+
// type EmitsType = ('clearRadioRow' | 'change' | 'delete' | 'addchild')[];
|
|
14
|
+
// update:modelValue 更改显隐状态
|
|
15
|
+
type EmitsType = ('update:modelValue')[];
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// 二、Props 定义
|
|
19
|
+
const propDefine = {
|
|
20
|
+
modelValue: {
|
|
21
|
+
// 是否显示
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false
|
|
24
|
+
},
|
|
25
|
+
fileInfo: {
|
|
26
|
+
// 带入的参数
|
|
27
|
+
type: Object as PropType<any>,
|
|
28
|
+
default: () => { }
|
|
29
|
+
},
|
|
30
|
+
previewList: {
|
|
31
|
+
// 按钮权限码
|
|
32
|
+
type: Array<string>,
|
|
33
|
+
default: () => []
|
|
34
|
+
},
|
|
35
|
+
previewIndex: {
|
|
36
|
+
// 预览Index
|
|
37
|
+
type: Number,
|
|
38
|
+
default: 0
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// 三、组件信息定义
|
|
44
|
+
export default defineComponent({
|
|
45
|
+
name: 'FilePreview',
|
|
46
|
+
components: {},
|
|
47
|
+
emits: ['update:modelValue'], // 例如: ['clearRadioRow', 'change', 'delete', 'addchild']
|
|
48
|
+
props: propDefine,
|
|
49
|
+
setup(props, ctx) {
|
|
50
|
+
return new FilePreviewInstance(props, ctx);
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// 四、组件实例, 具体业务
|
|
56
|
+
export class FilePreviewInstance extends BaseInstance {
|
|
57
|
+
private props: ExtractPropTypes<typeof propDefine>;
|
|
58
|
+
private ctx: SetupContext<EmitsType>;
|
|
59
|
+
// API实例化
|
|
60
|
+
private ossFileApi: OSSFileApi = new OSSFileApi();
|
|
61
|
+
private fileApi: FileApi = new FileApi();
|
|
62
|
+
|
|
63
|
+
// 全局属性
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
constructor(props: ExtractPropTypes<typeof propDefine>, ctx: SetupContext<EmitsType>) {
|
|
67
|
+
super()
|
|
68
|
+
this.props = props;
|
|
69
|
+
this.ctx = ctx;
|
|
70
|
+
|
|
71
|
+
this.useFilePreview();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#region 业务逻辑 - 文件预览
|
|
75
|
+
|
|
76
|
+
// 私有属性 | private
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// 响应属性 | ref、reactive、computed
|
|
80
|
+
previewImage = ref(false);
|
|
81
|
+
previewIfr = ref(false);
|
|
82
|
+
ifrUrl = ref('');
|
|
83
|
+
|
|
84
|
+
// 私有方法 | private 方法名() {}
|
|
85
|
+
/**
|
|
86
|
+
* 初始化
|
|
87
|
+
*/
|
|
88
|
+
private useFilePreview() {
|
|
89
|
+
watch(() => this.props['modelValue'], () => {
|
|
90
|
+
if (this.props['modelValue']) {
|
|
91
|
+
this.doView(this.props.fileInfo);
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
if (this.props['modelValue']) {
|
|
96
|
+
this.doView(this.props.fileInfo);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 预览文件
|
|
102
|
+
*/
|
|
103
|
+
private async doView(fileInfo: any) {
|
|
104
|
+
const fileUrl = await this.ossFileApi.getSignatureUrlByFileInfo(fileInfo);
|
|
105
|
+
if (this.isImage(fileInfo)) {
|
|
106
|
+
// 预览 图片
|
|
107
|
+
this.previewImage.value = true;
|
|
108
|
+
} else if (this.isOffice(fileInfo)) {
|
|
109
|
+
// 预览 Office
|
|
110
|
+
this.ifrUrl.value = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(fileUrl)}`;
|
|
111
|
+
this.previewIfr.value = true;
|
|
112
|
+
} else if (this.isVedio(fileInfo)) {
|
|
113
|
+
// 播放 Vedio
|
|
114
|
+
this.ifrUrl.value = `${fileUrl}`;
|
|
115
|
+
this.previewIfr.value = true;
|
|
116
|
+
} else if (this.isPDF(fileInfo)) {
|
|
117
|
+
// 预览 PDF
|
|
118
|
+
this.ifrUrl.value = `/static/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(fileUrl)}`
|
|
119
|
+
this.previewIfr.value = true;
|
|
120
|
+
} else {
|
|
121
|
+
// 下载文件
|
|
122
|
+
const downloadUrl = this.fileApi.getFileUrl(fileInfo.Token, fileInfo.Id);
|
|
123
|
+
window.open(downloadUrl);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 是否为Office
|
|
129
|
+
* @param fileInfo
|
|
130
|
+
*/
|
|
131
|
+
private isOffice(fileInfo: any) {
|
|
132
|
+
const ext = fileInfo.FileExt;
|
|
133
|
+
return ext == 'doc' || ext == 'docx' || ext == 'ppt' || ext == "pptx" || ext == "xls" || ext == "xlsx";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 是否为Vedio
|
|
138
|
+
* @param fileInfo
|
|
139
|
+
*/
|
|
140
|
+
private isVedio(fileInfo: any) {
|
|
141
|
+
const ext = fileInfo.FileExt;
|
|
142
|
+
return ext == 'mov' || ext == 'mp3' || ext == 'mp4';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 是否为PDF
|
|
147
|
+
* @param fileInfo
|
|
148
|
+
*/
|
|
149
|
+
private isPDF(fileInfo: any) {
|
|
150
|
+
const ext = fileInfo.FileExt;
|
|
151
|
+
return ext == 'pdf';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 是否为图片
|
|
156
|
+
* @param fileInfo
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
private isImage(fileInfo: any) {
|
|
160
|
+
const ext = fileInfo.FileExt;
|
|
161
|
+
return ext == 'jpg' || ext == 'png' || ext == 'jpeg' || ext == "gif" || ext == "svg";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// 响应式方法 | xxx = () => {}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 关闭预览
|
|
169
|
+
*/
|
|
170
|
+
doClose = (value: boolean) => {
|
|
171
|
+
if (value) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.ctx.emit('update:modelValue', false);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
//#endregion 业务逻辑 - 文件预览 END
|
|
180
|
+
|
|
181
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
功能名称:文件预览
|
|
3
|
+
创 建 人:弋强
|
|
4
|
+
日 期:2023/02/16 08:40:22
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<!-- 图片预览 -->
|
|
8
|
+
<ImagePreview v-model="previewImage" :preview-list="previewList" :initial-index="previewIndex" @on-close="doClose"/>
|
|
9
|
+
<!-- 图片预览 END -->
|
|
10
|
+
|
|
11
|
+
<Modal v-model="previewIfr" fullscreen :mask="true" :mask-closable="false" :width="1000" footer-hide :title="'文件预览 - ' + fileInfo.FileName" @on-visible-change="doClose">
|
|
12
|
+
<div class="ifr-container">
|
|
13
|
+
<iframe :src="ifrUrl" class="ifr-content" :title="fileInfo.fileInfo"> </iframe>
|
|
14
|
+
</div>
|
|
15
|
+
</Modal>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script lang="ts" src="./FilePreview.ts"></script>
|
|
19
|
+
|
|
20
|
+
<style scoped lang="scss">
|
|
21
|
+
.ifr-container {
|
|
22
|
+
height: calc(100% + 32px);
|
|
23
|
+
margin: -16px;
|
|
24
|
+
}
|
|
25
|
+
.ifr-content {
|
|
26
|
+
height: 100%;
|
|
27
|
+
width: 100%;
|
|
28
|
+
border: 0px;
|
|
29
|
+
padding: 0px;
|
|
30
|
+
margin: 0px;
|
|
31
|
+
}
|
|
32
|
+
</style>
|