@chenghongyu/xpt-file-viewer 1.1.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/.vscode/extensions.json +3 -0
- package/README.md +5 -0
- package/auto-imports.d.ts +12 -0
- package/components.d.ts +45 -0
- package/dist.zip +0 -0
- package/index.html +13 -0
- package/package.json +100 -0
- package/presets/eslint/.eslintrc-auto-import.json +462 -0
- package/presets/plugins/html.ts +14 -0
- package/presets/shared/env.ts +46 -0
- package/presets/shared/resolvers.ts +29 -0
- package/presets/tov.ts +132 -0
- package/presets/types/auto-imports.d.ts +806 -0
- package/presets/types/components.d.ts +164 -0
- package/presets/types/env.d.ts +17 -0
- package/public/favicon.svg +1 -0
- package/public/icons.svg +24 -0
- package/public/testfile/README.md +5 -0
- package/public/testfile/useFileContextMenu.js +74 -0
- package/public/testfile//345/217/221/347/245/250.pdf +0 -0
- package/public/testfile//346/216/245/346/224/266/345/207/275.docx +0 -0
- package/public/testfile//350/247/204/346/240/274/345/236/213/345/217/2671.txt +263 -0
- package/public/testfile//350/247/206/351/242/2211.mp4 +0 -0
- package/public/testfile//351/237/263/351/242/2211.mp3 +0 -0
- package/src/App.vue +8 -0
- package/src/api/admin/admin-2fa.js +18 -0
- package/src/api/admin/admin-download-log.js +37 -0
- package/src/api/admin/admin-login-log.js +9 -0
- package/src/api/admin/admin-permission.js +9 -0
- package/src/api/admin/admin-setting.js +121 -0
- package/src/api/admin/admin-share.js +20 -0
- package/src/api/admin/admin-short-link.js +49 -0
- package/src/api/admin/admin-sso.js +38 -0
- package/src/api/admin/admin-storage.js +189 -0
- package/src/api/admin/admin-user.js +61 -0
- package/src/api/home/common.js +9 -0
- package/src/api/home/file-operator.js +89 -0
- package/src/api/home/home.js +87 -0
- package/src/api/home/install.js +18 -0
- package/src/api/home/login.js +9 -0
- package/src/api/home/only-office.js +10 -0
- package/src/api/home/share.js +115 -0
- package/src/api/home/user.js +74 -0
- package/src/api/tools/tools-115.js +17 -0
- package/src/api/tools/tools-gd.js +13 -0
- package/src/api/tools/tools-s3.js +25 -0
- package/src/api/tools/tools-sharepoint.js +19 -0
- package/src/assets/hero.png +0 -0
- package/src/assets/icons/401.svg +1 -0
- package/src/assets/icons/403.svg +45 -0
- package/src/assets/icons/404.svg +1 -0
- package/src/assets/icons/500.svg +1 -0
- package/src/assets/icons/admin-login.svg +1 -0
- package/src/assets/icons/document.svg +1 -0
- package/src/assets/icons/empty.svg +145 -0
- package/src/assets/icons/file-type-apk.svg +1 -0
- package/src/assets/icons/file-type-archive.svg +1 -0
- package/src/assets/icons/file-type-audio.svg +1 -0
- package/src/assets/icons/file-type-back.svg +1 -0
- package/src/assets/icons/file-type-css.svg +1 -0
- package/src/assets/icons/file-type-deb.svg +1 -0
- package/src/assets/icons/file-type-dll.svg +1 -0
- package/src/assets/icons/file-type-doc.svg +1 -0
- package/src/assets/icons/file-type-document.svg +1 -0
- package/src/assets/icons/file-type-docx.svg +1 -0
- package/src/assets/icons/file-type-exe.svg +1 -0
- package/src/assets/icons/file-type-expression.svg +1 -0
- package/src/assets/icons/file-type-file.svg +1 -0
- package/src/assets/icons/file-type-folder.svg +1 -0
- package/src/assets/icons/file-type-html.svg +1 -0
- package/src/assets/icons/file-type-image.svg +1 -0
- package/src/assets/icons/file-type-java.svg +1 -0
- package/src/assets/icons/file-type-js.svg +1 -0
- package/src/assets/icons/file-type-less.svg +1 -0
- package/src/assets/icons/file-type-md.svg +1 -0
- package/src/assets/icons/file-type-office.svg +1 -0
- package/src/assets/icons/file-type-pdf.svg +1 -0
- package/src/assets/icons/file-type-php.svg +1 -0
- package/src/assets/icons/file-type-ppt.svg +1 -0
- package/src/assets/icons/file-type-pptx.svg +1 -0
- package/src/assets/icons/file-type-py.svg +1 -0
- package/src/assets/icons/file-type-rb.svg +1 -0
- package/src/assets/icons/file-type-root.svg +1 -0
- package/src/assets/icons/file-type-rpm.svg +1 -0
- package/src/assets/icons/file-type-rust.svg +1 -0
- package/src/assets/icons/file-type-script.svg +1 -0
- package/src/assets/icons/file-type-text.svg +1 -0
- package/src/assets/icons/file-type-three3d.svg +5 -0
- package/src/assets/icons/file-type-vbs.svg +1 -0
- package/src/assets/icons/file-type-video.svg +1 -0
- package/src/assets/icons/file-type-xls.svg +1 -0
- package/src/assets/icons/file-type-xlsx.svg +1 -0
- package/src/assets/icons/file-type-xml.svg +1 -0
- package/src/assets/icons/file-type-yaml.svg +1 -0
- package/src/assets/icons/file-upload.svg +1 -0
- package/src/assets/icons/github.svg +1 -0
- package/src/assets/icons/install-step.svg +40 -0
- package/src/assets/icons/reset-password.svg +1 -0
- package/src/assets/icons/storage-aliyun.svg +1 -0
- package/src/assets/icons/storage-baidu.svg +1 -0
- package/src/assets/icons/storage-doge-cloud.svg +207 -0
- package/src/assets/icons/storage-ftp.svg +13 -0
- package/src/assets/icons/storage-google-drive.svg +8 -0
- package/src/assets/icons/storage-huawei.svg +1 -0
- package/src/assets/icons/storage-local.svg +11 -0
- package/src/assets/icons/storage-minio.svg +1 -0
- package/src/assets/icons/storage-onedrive-china.svg +18 -0
- package/src/assets/icons/storage-onedrive.svg +4 -0
- package/src/assets/icons/storage-open115.svg +23 -0
- package/src/assets/icons/storage-qiniu.svg +1 -0
- package/src/assets/icons/storage-s3.svg +5 -0
- package/src/assets/icons/storage-sftp.svg +13 -0
- package/src/assets/icons/storage-sharepoint-china.svg +23 -0
- package/src/assets/icons/storage-sharepoint.svg +1 -0
- package/src/assets/icons/storage-tencent.svg +9 -0
- package/src/assets/icons/storage-ufile.svg +14 -0
- package/src/assets/icons/storage-upyun.svg +1 -0
- package/src/assets/icons/storage-webdav.svg +1 -0
- package/src/assets/icons/upload.svg +50 -0
- package/src/assets/icons/zfile-basic.svg +17 -0
- package/src/assets/icons/zfile-horizontal.svg +16 -0
- package/src/assets/icons/zfile.svg +1 -0
- package/src/assets/vite.svg +1 -0
- package/src/assets/vue.svg +1 -0
- package/src/components/HelloWorld.vue +319 -0
- package/src/components/common/QrCodePreview.vue +118 -0
- package/src/components/common/dialog/ZDialog.vue +171 -0
- package/src/components/common/dialog/types.ts +19 -0
- package/src/components/common/dialog/useDialog.ts +18 -0
- package/src/components/common/dialog/useDialogWithForm.ts +21 -0
- package/src/components/copy.vue +133 -0
- package/src/components/file/preview/AudioPlayer.vue +333 -0
- package/src/components/file/preview/CopyCode.vue +47 -0
- package/src/components/file/preview/FileGallery.vue +199 -0
- package/src/components/file/preview/ImageViewer.vue +432 -0
- package/src/components/file/preview/KkFileViewer.vue +86 -0
- package/src/components/file/preview/KkFileViewerDialog.vue +42 -0
- package/src/components/file/preview/MarkdownViewer.vue +102 -0
- package/src/components/file/preview/MarkdownViewerAsyncLoading.vue +17 -0
- package/src/components/file/preview/MarkdownViewerDialogAsyncLoading.vue +12 -0
- package/src/components/file/preview/OfficeViewer.vue +76 -0
- package/src/components/file/preview/OfficeViewerDialog.vue +55 -0
- package/src/components/file/preview/PdfViewer.vue +157 -0
- package/src/components/file/preview/PdfViewerDialog.vue +41 -0
- package/src/components/file/preview/TextViewer.vue +232 -0
- package/src/components/file/preview/TextViewerAsyncLoading.vue +22 -0
- package/src/components/file/preview/TextViewerDialog.vue +53 -0
- package/src/components/file/preview/Three3dPreview.vue +114 -0
- package/src/components/file/preview/Three3dPreviewDialog.vue +50 -0
- package/src/components/file/preview/VideoPlayer.vue +341 -0
- package/src/components/file/preview/VideoPlayerAsyncLoading.vue +45 -0
- package/src/components/file/preview/VideoPlayerDialog.vue +51 -0
- package/src/components/file/selectFolder/SelectFolder.vue +208 -0
- package/src/components/file/selectFolder/index.ts +50 -0
- package/src/components/file/selectFolder/types.ts +5 -0
- package/src/components/fileReview/AudioPlayer-copy.vue +333 -0
- package/src/components/fileReview/PdfViewer-copy.vue +157 -0
- package/src/components/fileReview/TextViewer-copy.vue +44 -0
- package/src/components/fileReview/VideoPlayer-copy.vue +341 -0
- package/src/components/messageBox/confirm/confirm.vue +137 -0
- package/src/components/messageBox/confirm/index.ts +27 -0
- package/src/components/messageBox/confirm/types.ts +15 -0
- package/src/components/messageBox/messageBox.ts +9 -0
- package/src/components/messageBox/prompt/index.ts +27 -0
- package/src/components/messageBox/prompt/prompt.vue +178 -0
- package/src/components/messageBox/prompt/types.ts +24 -0
- package/src/components/vue-codemirror/editor.vue +212 -0
- package/src/components/vue-codemirror/encodings.ts +27 -0
- package/src/components/vue-codemirror/index.vue +380 -0
- package/src/components/vue-codemirror/lang-code/cpp/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/css/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/dockerfile/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/erlang/index.ts +6 -0
- package/src/components/vue-codemirror/lang-code/go/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/html/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/java/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/javascript/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/json/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/jsx/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/lua/index.ts +6 -0
- package/src/components/vue-codemirror/lang-code/markdown/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/mysql/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/nginx/index.ts +6 -0
- package/src/components/vue-codemirror/lang-code/perl/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/pgsql/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/php/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/powershell/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/python/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/r/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/ruby/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/rust/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/shell/index.ts +5 -0
- package/src/components/vue-codemirror/lang-code/sql/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/stylus/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/swift/index.ts +4 -0
- package/src/components/vue-codemirror/lang-code/toml/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/tsx/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/typescript/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/vb/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/vbscript/index.ts +3 -0
- package/src/components/vue-codemirror/lang-code/xml/index.ts +2 -0
- package/src/components/vue-codemirror/lang-code/yaml/index.ts +3 -0
- package/src/components/vue-codemirror/languages.ts +8 -0
- package/src/components/vue-codemirror/themes.ts +5 -0
- package/src/components/vue-codemirror/toolbar.vue +183 -0
- package/src/components/vue-codemirror/types.ts +12 -0
- package/src/components.d.ts +49 -0
- package/src/composables/admin/layout/admin-layout.js +53 -0
- package/src/composables/admin/link/useLinkSetting.js +16 -0
- package/src/composables/admin/sso/baseSsoConfig.js +54 -0
- package/src/composables/admin/sso/useSsoConfig.js +176 -0
- package/src/composables/admin/storage/storage-copy.js +89 -0
- package/src/composables/admin/storage/storage-filter.js +64 -0
- package/src/composables/admin/storage/storage-list.js +202 -0
- package/src/composables/admin/storage/storage-password.js +101 -0
- package/src/composables/admin/storage/storage-readme.js +102 -0
- package/src/composables/admin/storage/utils/open115-util.js +61 -0
- package/src/composables/admin/useAdminSetting.js +60 -0
- package/src/composables/admin/useClientInfo.js +20 -0
- package/src/composables/admin/user/user-copy.js +79 -0
- package/src/composables/file/useBatchOperatorResult.js +19 -0
- package/src/composables/file/useFileContextMenu.js +74 -0
- package/src/composables/file/useFileData.js +243 -0
- package/src/composables/file/useFileLink.js +175 -0
- package/src/composables/file/useFileLoading.js +41 -0
- package/src/composables/file/useFileLongPressEvent.js +71 -0
- package/src/composables/file/useFileOperator.js +347 -0
- package/src/composables/file/useFilePreview.js +99 -0
- package/src/composables/file/useFilePwd.js +138 -0
- package/src/composables/file/useFileSelect.js +105 -0
- package/src/composables/file/useFileShare.js +39 -0
- package/src/composables/file/useFileUpload.js +1045 -0
- package/src/composables/file/useKkFileViewDialog.js +24 -0
- package/src/composables/file/useOfficeViewerDialog.js +20 -0
- package/src/composables/file/usePdfViewerDialog.js +22 -0
- package/src/composables/file/useShareActions.js +94 -0
- package/src/composables/file/useShareTableOperator.js +84 -0
- package/src/composables/file/useTableOperator.js +211 -0
- package/src/composables/file/useTextViewerDialog.js +22 -0
- package/src/composables/file/useThree3dPreviewDialog.js +23 -0
- package/src/composables/file/useVideoPlayerDialog.js +19 -0
- package/src/composables/header/useHeaderBreadcrumb.js +111 -0
- package/src/composables/header/useHeaderStorageList.js +150 -0
- package/src/composables/header/useSetting.js +58 -0
- package/src/composables/share/useShareData.js +178 -0
- package/src/composables/useDarks.ts +4 -0
- package/src/composables/useRouterData.js +41 -0
- package/src/constant/index.js +193 -0
- package/src/http/index.js +153 -0
- package/src/http/request.js +31 -0
- package/src/main.ts +23 -0
- package/src/stores/file-data.ts +108 -0
- package/src/stores/global-config.ts +115 -0
- package/src/stores/storage-config.ts +123 -0
- package/src/style.css +296 -0
- package/src/styles/admin.scss +91 -0
- package/src/styles/code-editor-variables.scss +52 -0
- package/src/styles/element-plus.scss +22 -0
- package/src/styles/error-page.css +26 -0
- package/src/styles/main.css +142 -0
- package/src/styles/tailwind/index.scss +33 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/models/base.ts +34 -0
- package/src/utils/models/file.ts +95 -0
- package/src/utils/models/path.ts +117 -0
- package/src/utils/models/qrcode.ts +21 -0
- package/src/utils/models/time.ts +132 -0
- package/src/utils/models/util.ts +42 -0
- package/src/utils/models/window.ts +14 -0
- package/stats.html +4950 -0
- package/tsconfig.app.json +16 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +57 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zfile-kkfile-viewer">
|
|
3
|
+
<div v-if="isLoading" class="viewer-status">
|
|
4
|
+
正在加载预览, 请稍候...
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div v-else-if="errorMessage" class="viewer-status error">
|
|
8
|
+
加载预览失败:{{ errorMessage }}
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<iframe v-else-if="iframeSrc"
|
|
12
|
+
:src="iframeSrc"
|
|
13
|
+
width="100%"
|
|
14
|
+
height="100%"
|
|
15
|
+
frameborder="0">
|
|
16
|
+
</iframe>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup>
|
|
21
|
+
import { ref, watchEffect } from 'vue';
|
|
22
|
+
import useStorageConfigStore from "~/stores/storage-config";
|
|
23
|
+
import { buildKkFileViewUrl } from "~/utils/models/path";
|
|
24
|
+
|
|
25
|
+
const storageConfigStore = useStorageConfigStore();
|
|
26
|
+
|
|
27
|
+
const props = defineProps({
|
|
28
|
+
url: String,
|
|
29
|
+
name: String
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const isLoading = ref(true);
|
|
33
|
+
const errorMessage = ref('');
|
|
34
|
+
const iframeSrc = ref('');
|
|
35
|
+
|
|
36
|
+
watchEffect(() => {
|
|
37
|
+
isLoading.value = true;
|
|
38
|
+
errorMessage.value = '';
|
|
39
|
+
iframeSrc.value = '';
|
|
40
|
+
|
|
41
|
+
const kkFileViewUrl = storageConfigStore.globalConfig.kkFileViewUrl;
|
|
42
|
+
const fileUrl = props.url;
|
|
43
|
+
const originalFileName = props.name;
|
|
44
|
+
|
|
45
|
+
if (!kkFileViewUrl) {
|
|
46
|
+
errorMessage.value = "预览服务地址未配置。";
|
|
47
|
+
isLoading.value = false;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!fileUrl) {
|
|
52
|
+
errorMessage.value = "文件URL无效,无法预览。";
|
|
53
|
+
isLoading.value = false;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!originalFileName) {
|
|
58
|
+
errorMessage.value = "文件名无效,无法预览。";
|
|
59
|
+
isLoading.value = false;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const file = { name: originalFileName, url: fileUrl };
|
|
64
|
+
|
|
65
|
+
iframeSrc.value = buildKkFileViewUrl(file, kkFileViewUrl);
|
|
66
|
+
isLoading.value = false;
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<style scoped>
|
|
71
|
+
.zfile-kkfile-viewer {
|
|
72
|
+
height: 100%;
|
|
73
|
+
width: 100%;
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: center;
|
|
77
|
+
background-color: #f7f7f7;
|
|
78
|
+
}
|
|
79
|
+
.viewer-status {
|
|
80
|
+
color: #888;
|
|
81
|
+
font-size: 16px;
|
|
82
|
+
}
|
|
83
|
+
.viewer-status.error {
|
|
84
|
+
color: #f56c6c;
|
|
85
|
+
}
|
|
86
|
+
</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<z-dialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
draggable
|
|
5
|
+
top="5vh"
|
|
6
|
+
width="90%"
|
|
7
|
+
class="zfile-kkfile-viewer-dialog"
|
|
8
|
+
:title="name"
|
|
9
|
+
:showFooter="false"
|
|
10
|
+
>
|
|
11
|
+
<kkfileview-viewer v-if="visible" :url="url" :name="name" />
|
|
12
|
+
</z-dialog>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup>
|
|
16
|
+
import { defineAsyncComponent } from 'vue';
|
|
17
|
+
import ZDialog from "~/components/common/dialog/ZDialog.vue";
|
|
18
|
+
import MarkdownViewerDialogAsyncLoading from "~/components/file/preview/MarkdownViewerDialogAsyncLoading.vue";
|
|
19
|
+
import useKkFileViewDialog from "~/composables/file/useKkFileViewDialog";
|
|
20
|
+
|
|
21
|
+
// 使用异步组件加载,提升性能
|
|
22
|
+
const KkfileviewViewer = defineAsyncComponent({
|
|
23
|
+
loader: () => import("~/components/file/preview/KkFileViewer.vue"),
|
|
24
|
+
loadingComponent: MarkdownViewerDialogAsyncLoading
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { visible, name, url } = useKkFileViewDialog();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<style scoped lang="scss">
|
|
31
|
+
/* 样式可以复用 OfficeViewerDialog 的 */
|
|
32
|
+
:deep(.el-dialog) {
|
|
33
|
+
@apply p-0 h-[80vh];
|
|
34
|
+
.z-dialog-content { @apply h-[80vh]; }
|
|
35
|
+
.el-dialog__header { @apply p-2; }
|
|
36
|
+
&.is-fullscreen {
|
|
37
|
+
height: 100%;
|
|
38
|
+
.z-dialog-content { height: calc(100vh - 41px); }
|
|
39
|
+
}
|
|
40
|
+
.el-dialog__footer { display: none; }
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="content">
|
|
3
|
+
<div class="dialog-scroll markdown-body" v-html="markdownHtml"></div>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
import {marked} from 'marked';
|
|
9
|
+
import { computed, onMounted, onUpdated, ref } from "vue";
|
|
10
|
+
import hljs from "highlight.js/lib/core";
|
|
11
|
+
import 'highlight.js/styles/github.css';
|
|
12
|
+
import 'github-markdown-css';
|
|
13
|
+
import { ElMessage } from 'element-plus';
|
|
14
|
+
import { getFileTextReq } from "~/api/home/common";
|
|
15
|
+
|
|
16
|
+
let props = defineProps({
|
|
17
|
+
fileUrl: String,
|
|
18
|
+
fileName: String
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const fileContent = ref('');
|
|
22
|
+
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
let fileUrl = props.fileUrl;
|
|
25
|
+
getFileTextReq(fileUrl, 'text').then((res) => {
|
|
26
|
+
fileContent.value = res.data;
|
|
27
|
+
}).catch((e) => {
|
|
28
|
+
ElMessage({
|
|
29
|
+
message: `加载文本文件失败. 请检查此地址是否有效或是否限制了跨域访问.`,
|
|
30
|
+
type: 'error',
|
|
31
|
+
duration: 0,
|
|
32
|
+
showClose: true,
|
|
33
|
+
grouping: true
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
let markdownHtml = computed(() => {
|
|
39
|
+
// url 新窗口打开.
|
|
40
|
+
let renderer = new marked.Renderer();
|
|
41
|
+
renderer.link = function() {
|
|
42
|
+
let link = marked.Renderer.prototype.link.apply(this, arguments);
|
|
43
|
+
return link.replace("<a","<a target='_blank'");
|
|
44
|
+
};
|
|
45
|
+
marked.setOptions({
|
|
46
|
+
renderer: renderer
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return marked(fileContent.value, {
|
|
50
|
+
highlight: function(code) {
|
|
51
|
+
return hljs.highlightAuto(code).value;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
import CodeCopy from '~/components/file/preview/CopyCode.vue';
|
|
57
|
+
import { createVNode, render } from "vue";
|
|
58
|
+
|
|
59
|
+
onUpdated(() => {
|
|
60
|
+
document.querySelectorAll('pre').forEach(el => {
|
|
61
|
+
if (el.classList.contains('code-copy-added')) return
|
|
62
|
+
// https://cn.vuejs.org/v2/api/index.html#Vue-extend
|
|
63
|
+
/* 使用基础 Vue 构造器,创建一个“子类”。参数是一个包含组件选项的对象 */
|
|
64
|
+
|
|
65
|
+
let codeCopyVNode = createVNode(CodeCopy, {
|
|
66
|
+
code: el.innerText,
|
|
67
|
+
});
|
|
68
|
+
let mountNode = document.createElement("div");
|
|
69
|
+
render(codeCopyVNode, mountNode);
|
|
70
|
+
el.classList.add('code-copy-added')
|
|
71
|
+
el.classList.add('hljs')
|
|
72
|
+
el.appendChild(mountNode)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<style scoped>
|
|
79
|
+
.content {
|
|
80
|
+
padding: 10px 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.content .markdown-body >>> pre {
|
|
84
|
+
margin-right: 20px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
.content .markdown-body >>> pre:hover .copy-btn {
|
|
89
|
+
opacity: 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.dialog-scroll {
|
|
93
|
+
height: 80vh;
|
|
94
|
+
overflow-y: auto;
|
|
95
|
+
overflow-x: hidden;
|
|
96
|
+
margin: 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.content >>> .code-copy-added {
|
|
100
|
+
position: relative;
|
|
101
|
+
}
|
|
102
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="w-full h-full">
|
|
3
|
+
<el-skeleton animated>
|
|
4
|
+
<template #template>
|
|
5
|
+
<el-skeleton-item variant="p" class="!w-1/4"></el-skeleton-item>
|
|
6
|
+
<br>
|
|
7
|
+
<el-skeleton-item variant="p" class="!w-1/2"></el-skeleton-item>
|
|
8
|
+
</template>
|
|
9
|
+
</el-skeleton>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup>
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<style lang="scss" scoped>
|
|
17
|
+
</style>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zfile-office-viewer">
|
|
3
|
+
<div id="office-body"></div>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
|
|
9
|
+
import { onMounted } from "vue";
|
|
10
|
+
import useStorageConfigStore from "~/stores/storage-config";
|
|
11
|
+
import { getOnlyOfficeConfigTokenReq } from "~/api/home/only-office.js";
|
|
12
|
+
import useRouterData from "~/composables/useRouterData";
|
|
13
|
+
import { concatPath } from "~/utils";
|
|
14
|
+
import useFilePwd from "~/composables/file/useFilePwd";
|
|
15
|
+
import { ElMessage } from "element-plus";
|
|
16
|
+
let { getPathPwd } = useFilePwd();
|
|
17
|
+
let storageConfigStore = useStorageConfigStore();
|
|
18
|
+
|
|
19
|
+
let { storageKey, currentPath } = useRouterData();
|
|
20
|
+
|
|
21
|
+
// 组件接收的属性:
|
|
22
|
+
// fileName: 文件名
|
|
23
|
+
const props = defineProps({
|
|
24
|
+
fileName: String
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
onMounted(() => {
|
|
28
|
+
loadScript(`${storageConfigStore.globalConfig.onlyOfficeUrl}/web-apps/apps/api/documents/api.js`, () => {
|
|
29
|
+
let filePathAndName = concatPath(currentPath.value, props.fileName);
|
|
30
|
+
|
|
31
|
+
let fileInfo = {
|
|
32
|
+
storageKey: storageKey.value,
|
|
33
|
+
path: filePathAndName,
|
|
34
|
+
password: getPathPwd()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getOnlyOfficeConfigTokenReq(fileInfo).then(res => {
|
|
38
|
+
let jsonObj = res.data;
|
|
39
|
+
const docEditor = new DocsAPI.DocEditor("office-body", jsonObj);
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function loadScript(src, callback) {
|
|
46
|
+
let script = document.createElement('script'),
|
|
47
|
+
head = document.getElementsByTagName('head')[0];
|
|
48
|
+
script.type = 'text/javascript';
|
|
49
|
+
script.charset = 'UTF-8';
|
|
50
|
+
script.src = src;
|
|
51
|
+
if (script.addEventListener) {
|
|
52
|
+
script.addEventListener('load', function () {
|
|
53
|
+
callback();
|
|
54
|
+
}, false);
|
|
55
|
+
script.addEventListener('error', function () {
|
|
56
|
+
ElMessage.warning("调用在线文档服务失败,请检查在线文档服务是否正常");
|
|
57
|
+
}, false);
|
|
58
|
+
} else if (script.attachEvent) {
|
|
59
|
+
script.attachEvent('onreadystatechange', function () {
|
|
60
|
+
var target = window.event.srcElement;
|
|
61
|
+
if (target.readyState === 'loaded') {
|
|
62
|
+
callback();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
head.appendChild(script);
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<style scoped>
|
|
71
|
+
|
|
72
|
+
.zfile-office-viewer, #office-body {
|
|
73
|
+
height: 100%;
|
|
74
|
+
width: 100%;
|
|
75
|
+
}
|
|
76
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<z-dialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
draggable
|
|
5
|
+
top="5vh"
|
|
6
|
+
width="90%"
|
|
7
|
+
class="zfile-office-viewer-dialog"
|
|
8
|
+
:title="name"
|
|
9
|
+
:showFooter="false"
|
|
10
|
+
>
|
|
11
|
+
<office-viewer v-if="visible" :file-name="name" />
|
|
12
|
+
</z-dialog>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup>
|
|
16
|
+
import ZDialog from "~/components/common/dialog/ZDialog.vue";
|
|
17
|
+
import MarkdownViewerDialogAsyncLoading from "~/components/file/preview/MarkdownViewerDialogAsyncLoading.vue";
|
|
18
|
+
|
|
19
|
+
const OfficeViewer = defineAsyncComponent({
|
|
20
|
+
loader: () => import("~/components/file/preview/OfficeViewer.vue"),
|
|
21
|
+
loadingComponent: MarkdownViewerDialogAsyncLoading
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
import useOfficeViewerDialog from "~/composables/file/useOfficeViewerDialog";
|
|
25
|
+
const { visible, name } = useOfficeViewerDialog();
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<style scoped lang="scss">
|
|
29
|
+
:deep(.el-dialog) {
|
|
30
|
+
// 内容无边框
|
|
31
|
+
@apply p-0 h-[80vh];
|
|
32
|
+
|
|
33
|
+
.z-dialog-content {
|
|
34
|
+
@apply h-[80vh];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 标题有边框
|
|
38
|
+
.el-dialog__header {
|
|
39
|
+
@apply p-2;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 全屏时,内容高度自适应
|
|
43
|
+
&.is-fullscreen {
|
|
44
|
+
height: 100%;
|
|
45
|
+
.z-dialog-content {
|
|
46
|
+
height: calc(100vh - 41px);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 隐藏底部按钮
|
|
51
|
+
.el-dialog__footer {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zfile-pdf-viewer">
|
|
3
|
+
<div class="app-header">
|
|
4
|
+
<div v-if="isLoading">
|
|
5
|
+
<span v-if="loadingProgress < 100">
|
|
6
|
+
加载 {{ loadingProgress }}%
|
|
7
|
+
</span>
|
|
8
|
+
<span v-else>
|
|
9
|
+
渲染所有页面中...
|
|
10
|
+
</span>
|
|
11
|
+
</div>
|
|
12
|
+
<div v-else>
|
|
13
|
+
<span v-if="showAllPages">
|
|
14
|
+
共 {{ pageCount }} 页
|
|
15
|
+
</span>
|
|
16
|
+
|
|
17
|
+
<span v-else>
|
|
18
|
+
<button :disabled="page <= 1" @click="page--">❮</button>
|
|
19
|
+
{{ page }} / {{ pageCount }}
|
|
20
|
+
<button :disabled="page >= pageCount" @click="page++">❯</button>
|
|
21
|
+
</span>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<span v-show="!isLoading">
|
|
25
|
+
<button class="px-1 sm:px-4" @click="pdfViewCanvasWidthNum-=5">-</button>
|
|
26
|
+
<span>
|
|
27
|
+
<span class="hidden sm:inline">缩放比例</span>
|
|
28
|
+
{{pdfViewCanvasWidthNum}} %
|
|
29
|
+
</span>
|
|
30
|
+
<button class="px-1 sm:px-4" @click="pdfViewCanvasWidthNum+=5">+</button>
|
|
31
|
+
</span>
|
|
32
|
+
|
|
33
|
+
<label :class="isLoading ? 'invisible' : 'visible'">
|
|
34
|
+
<input v-model="showAllPages" type="checkbox">
|
|
35
|
+
显示所有页
|
|
36
|
+
</label>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<div class="app-content">
|
|
40
|
+
<vue-pdf-embed
|
|
41
|
+
annotationLayer
|
|
42
|
+
textLayer
|
|
43
|
+
ref="pdfRef"
|
|
44
|
+
:source="doc"
|
|
45
|
+
:page="page"
|
|
46
|
+
@rendered="handleDocumentRender"
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<script setup>
|
|
53
|
+
import { computed, watch, ref } from 'vue'
|
|
54
|
+
import VuePdfEmbed, { useVuePdfEmbed } from 'vue-pdf-embed'
|
|
55
|
+
import { useMagicKeys } from '@vueuse/core'
|
|
56
|
+
const { ArrowLeft, ArrowRight, NumpadAdd, NumpadSubtract } = useMagicKeys()
|
|
57
|
+
import { ElMessage } from 'element-plus'
|
|
58
|
+
// optional styles
|
|
59
|
+
import 'vue-pdf-embed/dist/styles/annotationLayer.css'
|
|
60
|
+
import 'vue-pdf-embed/dist/styles/textLayer.css'
|
|
61
|
+
|
|
62
|
+
// 组件接收的属性:
|
|
63
|
+
// fileUrl: 文件下载路径
|
|
64
|
+
// fileName: 文件名
|
|
65
|
+
const props = defineProps({
|
|
66
|
+
fileUrl: String,
|
|
67
|
+
fileName: String
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const pdfRef = ref();
|
|
71
|
+
|
|
72
|
+
const pdfViewCanvasWidthNum = ref(100);
|
|
73
|
+
// 图片外部容器宽度, 100 / 图片列数
|
|
74
|
+
let pdfViewCanvasWidth = computed(() => {
|
|
75
|
+
return `${pdfViewCanvasWidthNum.value}%`;
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
let isLoading = ref(true);
|
|
79
|
+
let page = ref(null);
|
|
80
|
+
let pageCount = ref(1);
|
|
81
|
+
let showAllPages = ref(true);
|
|
82
|
+
|
|
83
|
+
watch(() => showAllPages.value, () => {
|
|
84
|
+
page.value = showAllPages.value ? null : 1;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const handleDocumentRender = (a) => {
|
|
88
|
+
pageCount.value = pdfRef.value.doc.numPages;
|
|
89
|
+
isLoading.value = false;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handlerDocumentError = (error) => {
|
|
93
|
+
isLoading.value = false;
|
|
94
|
+
ElMessage.error("PDF 加载失败");
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const loadingProgress = ref(0);
|
|
98
|
+
const handleDocumentLoadProgress = (progressData) => {
|
|
99
|
+
// 保留2位小数
|
|
100
|
+
loadingProgress.value = (progressData.loaded / progressData.total * 100).toFixed(2);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 支持按键翻页
|
|
104
|
+
watch(() => [ArrowLeft.value, ArrowRight.value], (value) => {
|
|
105
|
+
if (isLoading.value) return;
|
|
106
|
+
if (showAllPages.value) return;
|
|
107
|
+
if (value[0] && page.value > 1) {
|
|
108
|
+
page.value--;
|
|
109
|
+
}
|
|
110
|
+
if (value[1] && page.value < pageCount.value) {
|
|
111
|
+
page.value++;
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 支持按键缩放
|
|
116
|
+
watch(() => [NumpadSubtract.value, NumpadAdd.value], (value) => {
|
|
117
|
+
if (value[0]) {
|
|
118
|
+
pdfViewCanvasWidthNum.value -= 5;
|
|
119
|
+
}
|
|
120
|
+
if (value[1]) {
|
|
121
|
+
pdfViewCanvasWidthNum.value += 5;
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const { doc } = useVuePdfEmbed( {
|
|
126
|
+
source: props.fileUrl,
|
|
127
|
+
onProgress: handleDocumentLoadProgress,
|
|
128
|
+
onError: handlerDocumentError,
|
|
129
|
+
})
|
|
130
|
+
</script>
|
|
131
|
+
|
|
132
|
+
<style scoped lang="scss">
|
|
133
|
+
.vue-pdf-embed {
|
|
134
|
+
:deep(> div) {
|
|
135
|
+
box-shadow: 0 2px 8px 4px rgba(0, 0, 0, 0.1);
|
|
136
|
+
@apply w-full h-full mt-2;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
:deep(canvas) {
|
|
140
|
+
width: v-bind('pdfViewCanvasWidth') !important;
|
|
141
|
+
height: 100% !important;
|
|
142
|
+
margin: 0 auto;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.app-header {
|
|
147
|
+
box-shadow: 0 2px 8px 4px rgba(0, 0, 0, 0.1);
|
|
148
|
+
background-color: #555;
|
|
149
|
+
color: #ddd;
|
|
150
|
+
@apply flex content-between justify-between p-2 sm:p-4 bg-gray-600;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.app-content {
|
|
155
|
+
padding: 24px 0;
|
|
156
|
+
}
|
|
157
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<z-dialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
draggable
|
|
5
|
+
top="5vh"
|
|
6
|
+
class="zfile-pdf-viewer-dialog"
|
|
7
|
+
:title="name"
|
|
8
|
+
:showFooter="false"
|
|
9
|
+
>
|
|
10
|
+
<pdf-viewer v-if="visible" :file-name="name" :file-url="url" />
|
|
11
|
+
</z-dialog>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup>
|
|
15
|
+
import ZDialog from "~/components/common/dialog/ZDialog.vue";
|
|
16
|
+
import MarkdownViewerDialogAsyncLoading from "~/components/file/preview/MarkdownViewerDialogAsyncLoading.vue";
|
|
17
|
+
|
|
18
|
+
const PdfViewer = defineAsyncComponent({
|
|
19
|
+
loader: () => import("~/components/file/preview/PdfViewer.vue"),
|
|
20
|
+
loadingComponent: MarkdownViewerDialogAsyncLoading
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
import usePdfViewerDialog from "~/composables/file/usePdfViewerDialog";
|
|
24
|
+
const { visible, name, url } = usePdfViewerDialog();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<style scoped lang="scss">
|
|
28
|
+
:deep(.zfile-pdf-viewer-dialog) {
|
|
29
|
+
@apply min-w-[90%] sm:min-w-[80%] md:min-w-[70%] lg:min-w-[60%] xl:min-w-[50%];
|
|
30
|
+
|
|
31
|
+
.el-dialog__body {
|
|
32
|
+
@apply h-[80vh] overflow-auto;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.is-fullscreen {
|
|
36
|
+
.el-dialog__body {
|
|
37
|
+
height: calc(100vh - 49px - 16px);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
</style>
|