فهرست منبع

增加PDF文件查阅权限控制

cfort 1 سال پیش
والد
کامیت
0aeebe7c23

+ 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

+ 3 - 3
src/business/platform/bpmn/form/dialog.vue

@@ -66,8 +66,8 @@ export default {
             type: String
         },
         previousDataTemplate: {
-          type: Object
-        }
+            type: Object
+        }
     },
     data () {
         return {
@@ -101,7 +101,7 @@ export default {
         },
         // 关闭当前窗口
         closeDialog () {
-            this.$emit('close', false , this.previousDataTemplate)
+            this.$emit('close', false, this.previousDataTemplate)
         }
     }
 }

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

@@ -513,6 +513,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)
@@ -526,7 +527,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)) {

+ 2 - 1
src/components/ibps-file-viewer/index.vue

@@ -136,6 +136,7 @@ export default {
                 this.fileType = 'image'
             } else if (flag && pdfType.includes(this.fileExt)) {
                 // this.fileType = 'pdf'
+                const hasRole = localStorage.getItem('hasHighRole') || 0
                 this.$nextTick(() => {
                     // this.$refs.viewer.load(this.url)
                     const newTab = window.open()
@@ -147,7 +148,7 @@ export default {
                     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";>`)
+                    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 {

+ 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()

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

@@ -73,6 +73,16 @@ export default {
                             reject(response)
                         }
                         const info = response.data
+                        /**
+                         * store 统一存储高权限角色,用于各模块校验附件下载权限
+                         * 初定角色为:系统管理角色、主任、质量负责人、文件管理负责人、文件管理员
+                         */
+                        info.highRoles = ['xtgljs', 'syszr', 'zlfzr', 'wjglzzc', 'wjgly']
+                        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

+ 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}`

+ 4 - 3
src/views/viewFile/index.vue

@@ -18,7 +18,8 @@ export default {
             newId: '',
             timer: '',
             configKey: '',
-            option: {}
+            option: {},
+            hasRole: localStorage.getItem('hasHighRole') === '1'
         }
     },
     watch: {
@@ -50,10 +51,10 @@ export default {
                     permissions: {
                         comment: true,
                         copy: true,
-                        download: false,
+                        download: this.hasRole,
                         modifyContentControl: true,
                         modifyFilter: true,
-                        print: false,
+                        print: this.hasRole,
                         edit: true,
                         fillForms: true,
                         review: true