Просмотр исходного кода

fix:POCT文件培训组件,结合数据模板脚本使用

liujiayin 2 лет назад
Родитель
Сommit
9f3e595d17

+ 6 - 2
src/business/platform/file/attachment/editFile/fView.vue

@@ -4,11 +4,11 @@
  * @Author: Liu_jiaYin
  * @Date: 2023-11-17 16:40:46
  * @LastEditors: Do not edit
- * @LastEditTime: 2024-03-01 16:39:32
+ * @LastEditTime: 2024-03-07 08:51:52
 -->
 <template>
     <div>
-        <editor :option="option" :operation_status="operation_status" @updateFile="updateFile" @hadLoadedFile="hadLoadedFile" />
+        <editor ref="editor" :option="option" :operation_status="operation_status" @updateFile="updateFile" @hadLoadedFile="hadLoadedFile" />
     </div>
 </template>
 
@@ -65,6 +65,10 @@ export default {
         },
         hadLoadedFile (v) {
             this.$emit('hadLoadedFile', v)
+        },
+        destoryZiComponent () {
+            const editor = this.$refs.editor
+            editor.clearTimer()
         }
     }
 }

+ 162 - 162
src/components/ibps-file-viewer/index.vue

@@ -15,7 +15,7 @@
                 custom-class="ibps-file-preview-dialog"
                 @close="closeDialog"
             >
-                <editor :option="option" v-if="dialogVisible" />
+                <editor v-if="dialogVisible" :option="option" />
                 <pdf-viewer v-if="fileType === 'pdf'" ref="viewer" />
 
                 <txt-viewer
@@ -29,7 +29,7 @@
     </div>
 </template>
 <script>
-    /**
+/**
      * 文件预览
      * 1、'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'  类型支持
      * 2、图片支持缩放
@@ -40,177 +40,177 @@
      * 2、音频,语音多格式支持
      * 3、压缩包支持
      */
-    import ImageViewer from './image'
-    // import AudioViewer from './audio' //xianyifan
-    // import VideoViewer from './video' //xianyifan
-    import TxtViewer from './txt'
-    import pdfViewer from './pdf/index'
-    import { officeType, pdfType, txtType, imageType, audioType, videoType } from './constants'
-    import PopupManager from '@/utils/popup'
-    import editor from '@/business/platform/file/attachment/editFile/editor.vue'
-    export default {
-        components: {
-            ImageViewer,
-            // AudioViewer,
-            // VideoViewer,
-            TxtViewer,
-            editor,
-            pdfViewer
+import ImageViewer from './image'
+// import AudioViewer from './audio' //xianyifan
+// import VideoViewer from './video' //xianyifan
+import TxtViewer from './txt'
+import pdfViewer from './pdf/index'
+import { officeType, pdfType, txtType, imageType, audioType, videoType } from './constants'
+import PopupManager from '@/utils/popup'
+import editor from '@/business/platform/file/attachment/editFile/editor.vue'
+export default {
+    components: {
+        ImageViewer,
+        // AudioViewer,
+        // VideoViewer,
+        TxtViewer,
+        editor,
+        pdfViewer
+    },
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
         },
-        props: {
-            visible: {
-                type: Boolean,
-                default: false
-            },
-            title: {
-                type: String
-            },
-            fileExt: {
-                type: String
-            },
-            url: {
-                type: String,
-                require: true
-            },
-            optionFile: {
-                type: Object,
-                default: () => {}
-            },
-            file:{
-                type: String,
-                require: ''
-            }
+        title: {
+            type: String
         },
-        data() {
-            return {
-                dialogVisible: false,
-                fileType: '',
-                zIndex: 2000,
-                // openedLoaded: false,
-                fileUrl: '',
-                option: {
-                    url: '',
-                    isEdit: true,
-                    fileType: '',
-                    title: '',
-                    user: {
-                        id: '',
-                        name: ''
-                    },
-                    mode: 'view',
-                    editUrl: '',
-                    key: ''
-                }
-            }
+        fileExt: {
+            type: String
         },
-        watch: {
-            optionFile: {
-                handler: function (val, oldVal) {
-                    this.dialogVisible = this.visible
-                    this.loadViewer()
-                },
-                immediate: true
-            }
+        url: {
+            type: String,
+            require: true
         },
-        beforeDestroy() {
-            this.fileType = ''
-            // this.openedLoaded = false
-            this.option = {}
+        optionFile: {
+            type: Object,
+            default: () => {}
         },
-        methods: {
-            /**
+        file: {
+            type: String,
+            require: ''
+        }
+    },
+    data () {
+        return {
+            dialogVisible: false,
+            fileType: '',
+            zIndex: 2000,
+            // openedLoaded: false,
+            fileUrl: '',
+            option: {
+                url: '',
+                isEdit: true,
+                fileType: '',
+                title: '',
+                user: {
+                    id: '',
+                    name: ''
+                },
+                mode: 'view',
+                editUrl: '',
+                key: ''
+            }
+        }
+    },
+    watch: {
+        optionFile: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+                this.loadViewer()
+            },
+            immediate: true
+        }
+    },
+    beforeDestroy () {
+        this.fileType = ''
+        // this.openedLoaded = false
+        this.option = {}
+    },
+    methods: {
+        /**
              * zxh 修复zindex 不是最高的被遮住
              */
-            fixZIndex() {
-                return PopupManager.getZIndex()
-            },
-            loadViewer() {
-                var flag = true
-                if (/Mobi|Android|iPhone|iPad/i.test(navigator.userAgent)) {
-                    flag = false
-                }
-                if (imageType.includes(this.fileExt)) {
-                    this.dialogVisible = false
-                    this.zIndex = this.fixZIndex()
-                    this.fileUrl = this.url
-                    this.fileType = 'image'
-                } else if(flag && pdfType.includes(this.fileExt)){
-                    // this.fileType = 'pdf'
-                    this.$nextTick(() => {
-                        // this.$refs.viewer.load(this.url)
-                        const newTab = window.open()
-                        const link = newTab.document.createElement('link')
-                        link.rel = 'shortcut icon'
-                        link.type = 'image/x-icon'
-                        link.href = 'favicon.ico'
-                        // newTab.document.write('<link rel="icon" type="image/x-icon" href="favicon.ico">')
-                        newTab.document.write(`<title>文件预览页-${this.title}</title>`)
-                        newTab.document.write('<style>body { margin: 0px; }</style>')
-                        newTab.document.head.appendChild(link)
-                        newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(this.url)}" style="width:100%; height:100%;" frameborder="0";>`)
-                        this.closeDialog()
-                    })
-
-                } else {
-                    this.openDialog() // 先初始化调用参数
-                    this.openWindow() // 打开外部预览页面
-                    this.closeDialog() // 关闭当前
-                    // this.fileType = 'FILE'
-                }
-                // else if (
-                //     officeType.includes(this.fileExt) ||
-                //     pdfType.includes(this.fileExt)
-                // ) {
-                //     this.fileType = 'pdf'
-                // } else if (audioType.includes(this.fileExt)) {
-                //     this.fileType = 'audio'
-                // } else if (videoType.includes(this.fileExt)) {
-                //     this.fileType = 'video'
-                // } else if (txtType.includes(this.fileExt)) {
-                //     this.fileType = 'txt'
-                // }
-            },
-            openWindow(data) {
-                let routeData = this.$router.resolve({
-                    path: '/fileView',
-                    query: this.option
+        fixZIndex () {
+            return PopupManager.getZIndex()
+        },
+        loadViewer () {
+            var flag = true
+            if (/Mobi|Android|iPhone|iPad/i.test(navigator.userAgent)) {
+                flag = false
+            }
+            if (imageType.includes(this.fileExt)) {
+                this.dialogVisible = false
+                this.zIndex = this.fixZIndex()
+                this.fileUrl = this.url
+                this.fileType = 'image'
+            } else if (flag && pdfType.includes(this.fileExt)) {
+                // this.fileType = 'pdf'
+                this.$nextTick(() => {
+                    // this.$refs.viewer.load(this.url)
+                    const newTab = window.open()
+                    const link = newTab.document.createElement('link')
+                    link.rel = 'shortcut icon'
+                    link.type = 'image/x-icon'
+                    link.href = 'favicon.ico'
+                    // newTab.document.write('<link rel="icon" type="image/x-icon" href="favicon.ico">')
+                    newTab.document.write(`<title>文件预览页-${this.title}</title>`)
+                    newTab.document.write('<style>body { margin: 0px; }</style>')
+                    newTab.document.head.appendChild(link)
+                    newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(this.url)}" style="width:100%; height:100%;" frameborder="0";>`)
+                    this.closeDialog()
                 })
-                window.open(routeData.href)
-            },
-            openDialog() {
-                this.option.user.id = this.$store.getters.userId
-                this.option.user.name = this.$store.getters.name
-                this.getFile()
-            },
-            getFile() {
-                this.option.url = this.optionFile.url // 下载地址
-                this.option.editUrl = this.optionFile.editUrl // 回调接口url
-                this.option.title = this.optionFile.title // 文件名称
-                this.option.fileType = this.optionFile.fileType // 类型
-            },
-            // openDialog() {
-            //     if (this.fileType === 'pdf') {
-            //         this.$nextTick(() => {
-            //             const timer = setInterval(() => {
-            //                 if (this.openedLoaded) {
-            //                     clearInterval(timer)
-            //                 } else {
-            //                     if (this.$refs.viewer) {
-            //                         this.$refs.viewer.load(this.url)
-            //                         this.openedLoaded = true
-            //                     }
-            //                 }
-            //             }, 50)
-            //         })
-            //     }
-            // },
-            closeDialog() {
-                this.fileType = ''
-                // this.openedLoaded = false
-                this.$emit('close', false)
+            } else {
+                this.openDialog() // 先初始化调用参数
+                this.openWindow() // 打开外部预览页面
+                this.closeDialog() // 关闭当前
+                // this.fileType = 'FILE'
             }
+            // else if (
+            //     officeType.includes(this.fileExt) ||
+            //     pdfType.includes(this.fileExt)
+            // ) {
+            //     this.fileType = 'pdf'
+            // } else if (audioType.includes(this.fileExt)) {
+            //     this.fileType = 'audio'
+            // } else if (videoType.includes(this.fileExt)) {
+            //     this.fileType = 'video'
+            // } else if (txtType.includes(this.fileExt)) {
+            //     this.fileType = 'txt'
+            // }
+        },
+        openWindow (data) {
+            const routeData = this.$router.resolve({
+                path: '/fileView',
+                query: this.option
+            })
+            console.log('178 routeData', routeData)
+            window.open(routeData.href)
+        },
+        openDialog () {
+            this.option.user.id = this.$store.getters.userId
+            this.option.user.name = this.$store.getters.name
+            this.getFile()
+        },
+        getFile () {
+            this.option.url = this.optionFile.url // 下载地址
+            this.option.editUrl = this.optionFile.editUrl // 回调接口url
+            this.option.title = this.optionFile.title // 文件名称
+            this.option.fileType = this.optionFile.fileType // 类型
+        },
+        // openDialog() {
+        //     if (this.fileType === 'pdf') {
+        //         this.$nextTick(() => {
+        //             const timer = setInterval(() => {
+        //                 if (this.openedLoaded) {
+        //                     clearInterval(timer)
+        //                 } else {
+        //                     if (this.$refs.viewer) {
+        //                         this.$refs.viewer.load(this.url)
+        //                         this.openedLoaded = true
+        //                     }
+        //                 }
+        //             }, 50)
+        //         })
+        //     }
+        // },
+        closeDialog () {
+            this.fileType = ''
+            // this.openedLoaded = false
+            this.$emit('close', false)
         }
     }
+}
 </script>
 <style lang="scss">
     .ibps-file-preview-dialog {

+ 146 - 0
src/views/component/fileTraining/index.vue

@@ -0,0 +1,146 @@
+<!--
+ * @Descripttion: POCT文件培训
+ * @version: 1.0
+ * @Author: Liu_jiaYin
+ * @Date: 2024-03-01 13:47:32
+ * @LastEditors: Do not edit
+ * @LastEditTime: 2024-03-07 11:24:29
+-->
+<template>
+    <el-dialog
+        :visible.sync="dialogVisible"
+        :title="title"
+        fullscreen
+        append-to-body
+        custom-class="ibps-file-preview-dialog"
+        @close="closeDialog"
+    >
+        <fView ref="fvView" :option-file="optionFile" :operation_status="operation_status" @hadLoadedFile="hadLoadedFile" />
+    </el-dialog>
+</template>
+<script>
+/**
+     * 文件预览
+     * 1、'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'  类型支持
+     * 2、图片支持缩放
+     * 3、音频,语音支持
+     * ==================
+     * 下一版本支持
+     * 1、pdf支持缩放
+     * 2、音频,语音多格式支持
+     * 3、压缩包支持
+     */
+import fView from '@/business/platform/file/attachment/editFile/fView.vue'
+import { SYSTEM_URL, BASE_API } from '@/api/baseUrl'
+import ViewFile from '@/views/viewFile/index.vue'
+
+export default {
+    name: 'file-training',
+    components: {
+        fView,
+        ViewFile
+    },
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        fileInfos: {
+            type: Object,
+            default: () => {}
+        },
+        template: {
+            type: Object,
+            default: () => {}
+        }
+    },
+    data () {
+        return {
+            dialogVisible: false,
+            operation_status: 'fileTraining',
+            title: '',
+            browseTime: 0, // 浏览时长初始值为 0
+            clearTimeSet: null,
+            optionFile: {},
+            tmpId: '',
+            upFunc: () => {},
+            height: 0
+        }
+    },
+    watch: {
+        fileInfos: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+                this.title = `《${val.FILE_NAME_}》文件培训`
+                this.tmpId = val.id
+                this.upFunc = val.func
+                const data = {
+                    ext: val.fileInfos.EXT_,
+                    fileName: val.fileInfos.FILE_NAME_,
+                    id: val.fileInfos.ID_,
+                    index: 0,
+                    totalBytes: val.fileInfos.TOTAL_BYTES_
+                }
+                // 1、获取文件数据 及下载流接口
+                this.optionFile.url = BASE_API() + SYSTEM_URL() + '/file/download?attachmentId=' + data.id
+                this.optionFile.editUrl = BASE_API() + SYSTEM_URL() + '/file/editCallback?fileName=' + data.fileName + '&fileType=' + data.ext + '&type="fileTraining"&id=' + data.id
+                this.optionFile.title = data.fileName // 文件名称
+                this.optionFile.fileType = data.ext // 类型
+                this.optionFile.data = data // 记录编制的位置,需要替换。
+                this.optionFile.data.index = data.index
+            },
+            immediate: true
+        },
+        browseTime: {
+            handler: function (val, oldVal) {
+                this.title = `《${this.optionFile.title}》文件培训,查阅时长:${val}秒`
+            },
+            immediate: true
+        }
+    },
+    beforeDestroy () {
+        this.fileType = ''
+        this.option = {}
+    },
+    mounted () {
+        this.height = this.getDialogHeightHeight()
+    },
+    methods: {
+        closeDialog () {
+            const fvView = this.$refs.fvView
+            // 销毁子组件方法
+            fvView.destoryZiComponent()
+            this.upFunc(this.template, this.tmpId, this.browseTime)
+            // 针对关闭窗口或者浏览器的
+            if (this.clearTimeSet != null) {
+                clearInterval(this.clearTimeSet)
+            }
+        },
+        hadLoadedFile (v) {
+            this.setBrowseTime()
+        },
+        setBrowseTime () {
+            // 设置定时器
+            this.clearTimeSet = setInterval(() => {
+                this.browseTime++
+            }, 1000)
+        },
+        getDialogHeightHeight () {
+            return ((document.documentElement.clientHeight || document.body.clientHeight) - 60) + 'px'
+        }
+    }
+}
+</script>
+<style lang="scss">
+    .ibps-file-preview-dialog {
+      width: 80%;
+      z-index:99999;
+        .el-dialog__body {
+            padding: 0;
+
+        }
+        .file-type-txt {
+            height: calc(88vh) !important;
+        }
+    }
+</style>