Преглед на файлове

PDF文件预览页下载打印权限控制

cfort преди 2 години
родител
ревизия
e442d63f76

+ 4 - 4
public/lib/pdfjs-dist/web/viewer.html

@@ -210,18 +210,18 @@ See https://github.com/adobe-type-tools/cmap-resources
                   <span data-l10n-id="presentation_mode_label">Presentation Mode</span>
                 </button>
 
-                <button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file" style="display: none;">
+                <button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
                   <span data-l10n-id="open_file_label">Open</span>
                 </button>
 
-                <button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print" style="display: none;">
+                <button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
                   <span data-l10n-id="print_label">Print</span>
                 </button>
 
-                <button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download" style="display: none;">
+                <button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
                   <span data-l10n-id="download_label">Download</span>
                 </button>
-                <a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark" style="display: none;">
+                <a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
                   <span data-l10n-id="bookmark_label">Current View</span>
                 </a>
 

+ 14 - 0
public/lib/pdfjs-dist/web/viewer.js

@@ -1764,9 +1764,11 @@ function loadAndEnablePDFBug(enabledTabs) {
 function webViewerInitialized() {
   const appConfig = PDFViewerApplication.appConfig;
   let file;
+  let hasRole;
   const queryString = document.location.search.substring(1);
   const params = (0, _ui_utils.parseQueryString)(queryString);
   file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
+  hasRole = "hasrole" in params ? params.hasrole : _app_options.AppOptions.get("hasRole");
   validateFileURL(file);
   const fileInput = document.createElement("input");
   fileInput.id = appConfig.openFileInputName;
@@ -1775,6 +1777,14 @@ function webViewerInitialized() {
   fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
   document.body.appendChild(fileInput);
 
+  if (hasRole !== '1') {
+    appConfig.toolbar.openFile.setAttribute("hidden", "true");
+    appConfig.toolbar.print.setAttribute("hidden", "true");
+    appConfig.toolbar.download.setAttribute("hidden", "true");
+    appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
+    appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
+  }
+
   if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
     appConfig.toolbar.openFile.setAttribute("hidden", "true");
     appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
@@ -3494,6 +3504,10 @@ const defaultOptions = {
     value: "compressed.tracemonkey-pldi-09.pdf",
     kind: OptionKind.VIEWER
   },
+  hasRole: {
+    value: '0',
+    kind: OptionKind.VIEWER
+  },
   defaultZoomValue: {
     value: "",
     kind: OptionKind.VIEWER + OptionKind.PREFERENCE

+ 2 - 1
src/business/platform/file/attachment/selector.vue

@@ -502,6 +502,7 @@ export default {
          */
         handlePreview (index) {
             this.attachment = this.multiple ? this.selectorValue[index] : this.selectorValue
+            const hasRole = localStorage.getItem('hasHighRole') || 0
             if (this.attachment.ext === 'pdf') {
                 this.$nextTick(() => {
                     // this.$refs.viewer.load(this.url)
@@ -515,7 +516,7 @@ export default {
                     newTab.document.write(`<title>文件预览页-${this.attachment.fileName}</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(url)}" style="width:100%; height:100%;" frameborder="0";>`)
+                    newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(url)}&hasRole=${hasRole}" style="width:100%; height:100%;" frameborder="0";>`)
                     // this.closeDialog()
                 })
             } else if (supportFileTypes.includes(this.attachment.ext)) {

+ 3 - 3
src/business/platform/form/formrender/dynamic-form/dynamic-form-field.vue

@@ -653,9 +653,9 @@
             }
         },
         data() {
-            const roleList = this.$store.getters.userInfo.role
-            // 系统管理角色、实验室主任、档案管理员、信息管理角色可下载
-            const limitDownload = roleList.some(item => ['xtgljs', 'syszr', 'dagly', 'xxgljs'].includes(item.alias))
+            const { role = [], highRoles = [] } = this.$store.getters.userInfo || {}
+            // 系统管理角色、实验室主任、档案管理员、信息管理角色可下载打印
+            const limitDownload = role.some(item => highRoles.includes(item.alias))
             return {
                 limitDownload,
                 dataModel: this.value,

+ 2 - 2
src/business/platform/form/utils/custom/pintText.js

@@ -36,9 +36,9 @@ const getPint = (tableForm, url) => {
             },
             (tpl) => {
                 tableForm.dialogTemplate = tpl
-                const { role } = store.getters.userInfo || {}
+                const { role = [], highRoles = [] } = store.getters.userInfo || {}
                 // 系统管理角色、实验室主任、档案管理员、信息管理角色可下载打印
-                const hasRole = role.some(item => ['xtgljs', 'syszr', 'dagly', 'xxgljs'].includes(item.alias))
+                const hasRole = role.some(item => highRoles.includes(item.alias))
                 if (hasRole) {
                     return
                 }

+ 173 - 173
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,189 +29,189 @@
     </div>
 </template>
 <script>
-    /**
-     * 文件预览
-     * 1、'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'  类型支持
-     * 2、图片支持缩放
-     * 3、音频,语音支持
-     * ==================
-     * 下一版本支持
-     * 1、pdf支持缩放
-     * 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
+/**
+ * 文件预览
+ * 1、'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'  类型支持
+ * 2、图片支持缩放
+ * 3、音频,语音支持
+ * ==================
+ * 下一版本支持
+ * 1、pdf支持缩放
+ * 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
+    },
+    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
+        },
+        fileExt: {
+            type: String
+        },
+        url: {
+            type: String,
+            require: true
         },
-        data() {
-            return {
-                dialogVisible: false,
+        optionFile: {
+            type: Object,
+            default: () => {}
+        },
+        file: {
+            type: String,
+            require: ''
+        }
+    },
+    data () {
+        return {
+            dialogVisible: false,
+            fileType: '',
+            zIndex: 2000,
+            // openedLoaded: false,
+            fileUrl: '',
+            option: {
+                url: '',
+                isEdit: true,
                 fileType: '',
-                zIndex: 2000,
-                // openedLoaded: false,
-                fileUrl: '',
-                option: {
-                    url: '',
-                    isEdit: true,
-                    fileType: '',
-                    title: '',
-                    user: {
-                        id: '',
-                        name: ''
-                    },
-                    mode: 'view',
-                    editUrl: '',
-                    key: ''
-                }
+                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()
         },
-        watch: {
-            optionFile: {
-                handler: function (val, oldVal) {
-                    this.dialogVisible = this.visible
-                    this.loadViewer()
-                },
-                immediate: true
+        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.optionFile.previewType === 'PDFH5') {
+                // 仅特定字段的PDF文件用PDFh5预览,其余PDF文件使用onlyoffice预览
+                // this.fileType = 'pdf'
+                const hasRole = localStorage.getItem('hasHighRole') || 0
+                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)}&hasRole=${hasRole}" 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) {
+            const routeData = this.$router.resolve({
+                path: '/fileView',
+                query: this.option
+            })
+            window.open(routeData.href)
+        },
+        openDialog () {
+            this.option.user.id = this.$store.getters.userId
+            this.option.user.name = this.$store.getters.name
+            this.getFile()
         },
-        beforeDestroy() {
+        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.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.optionFile.previewType === 'PDFH5'){
-                    // 仅特定字段的PDF文件用PDFh5预览,其余PDF文件使用onlyoffice预览
-                    // 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
-                })
-                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)
-            }
+            this.$emit('close', false)
         }
     }
+}
 </script>
 <style lang="scss">
     .ibps-file-preview-dialog {

+ 4 - 3
src/components/ibps-file-viewer/pdf/index.vue

@@ -8,7 +8,8 @@ export default {
     data () {
         return {
             pdfUrl: null,
-            height: '450px'
+            height: '450px',
+            hasRole: localStorage.getItem('hasHighRole') || 0
         }
     },
     mounted () {
@@ -19,11 +20,11 @@ export default {
         load (url) {
             this.pdfUrl = null
             url = encodeURIComponent(url)
-            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${url}&newWindow=true`
+            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${url}&&hasRole=${this.hasRole}`
         },
         loadData (data) {
             this.pdfUrl = null
-            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${data}`
+            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${data}&hasRole=${this.hasRole}`
         },
         handleDialogHeightResize () {
             this.height = this.getDialogHeightHeight()

+ 7 - 0
src/store/modules/ibps/modules/user.js

@@ -70,6 +70,13 @@ export default {
                             reject(response)
                         }
                         const info = response.data
+                        // store 统一存储高权限角色,用于各模块校验附件下载权限
+                        info.highRoles = ['xtgljs', 'syszr', 'dagly', 'xxgljs']
+                        const { role = [] } = info || {}
+                        const hasHighRole = role.some(item => info.highRoles.includes(item.alias))
+                        // 用于文件预览页判定是否开启下载权限
+                        localStorage.setItem('hasHighRole', hasHighRole ? 1 : 0)
+
                         // 设置当前
                         await dispatch('ibps/user/set', info, {
                             root: true

+ 3 - 4
src/views/platform/bpmn/bpmInstHis/list.vue

@@ -197,9 +197,8 @@ export default {
         }
     },
     data () {
-        const roleList = this.$store.getters.userInfo.role
-        // 系统管理角色、实验室主任、档案管理员具有高级权限
-        const hasRole = roleList.some(item => ['xtgljs', 'syszr', 'dagly', 'xxgljs'].includes(item.alias))
+        const { role = [], highRoles = [] } = this.$store.getters.userInfo || {}
+        const hasRole = role.some(item => highRoles.includes(item.alias))
         const { userList = [] } = this.$store.getters
         const selectOptions = [
             {
@@ -367,7 +366,7 @@ export default {
                     item.tYear = item.createTime.slice(0, 4)
                     item.tDept = temp.groupName
                     item.tUser = temp.userName
-                    if ((item.formKey == 'nsssjhbfj' || item.formKey == 'nsssjhx') && item.updateTime == item.endTime) {
+                    if ((item.formKey === 'nsssjhbfj' || item.formKey === 'nsssjhx') && item.updateTime === item.endTime) {
                         item.endTime = ''
                     }
                 })

+ 3 - 4
src/views/platform/bpmn/bpmInstHis/record/component/testingRecord.vue

@@ -248,9 +248,8 @@ export default {
         }
     },
     data () {
-        const roleList = this.$store.getters.userInfo.role
-        // 系统管理角色、实验室主任、档案管理员、信息管理角色具有高级权限
-        const hasRole = roleList.some(item => ['xtgljs', 'syszr', 'dagly', 'xxgljs'].includes(item.alias))
+        const { role = [], highRoles = [] } = this.$store.getters.userInfo || {}
+        const hasRole = role.some(item => highRoles.includes(item.alias))
         return {
             searchList,
             reportList,
@@ -444,7 +443,7 @@ export default {
                     newTab.document.write(`<title>文件预览页-${file.fileName}</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(url)}" style="width:100%; height:100%;" frameborder="0";>`)
+                    newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(url)}&hasRole=${this.hasRole ? 1 : 0}" style="width:100%; height:100%;" frameborder="0";>`)
                 })
             } else {
                 this.getOption(file)

+ 2 - 1
src/views/platform/file/attachment/list.vue

@@ -273,6 +273,7 @@ export default {
                             const newTab = window.open()
                             const link = newTab.document.createElement('link')
                             const url = BASE_API() + SYSTEM_URL() + '/file/download?attachmentId=' + data.id
+                            const hasRole = localStorage.getItem('hasHighRole') || 0
                             link.rel = 'shortcut icon'
                             link.type = 'image/x-icon'
                             link.href = 'favicon.ico'
@@ -280,7 +281,7 @@ export default {
                             newTab.document.write(`<title>文件预览页-${data.fileName}</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(url)}" style="width:100%; height:100%;" frameborder="0";>`)
+                            newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(url)}&hasRole=${hasRole}" style="width:100%; height:100%;" frameborder="0";>`)
                         })
                     } else {
                         this.file.url = BASE_API() + SYSTEM_URL() + `/file/download?attachmentId=${data.id}`