Преглед изворни кода

增加全局变量用于控制onlyoffice相关api,仅生产环境使用内网URL

cfort пре 1 година
родитељ
комит
7c188d061d

+ 1 - 1
public/config.js

@@ -1,6 +1,6 @@
 (function (global) {
     // 是否启用动态API,启用后,将根据访问IP的origin获取API地址
-    const ENABLE_DYNAMIC_API = true
+    const ENABLE_DYNAMIC_API = false
     const HOST_URL = `${location.origin}${location.pathname}`
     const BASE_URL = ENABLE_DYNAMIC_API ? HOST_URL : 'http://dev1.local/'
     global.__IBPS_CONFIG__ = {

+ 1 - 1
public/index.html

@@ -36,7 +36,7 @@
     <script src="lib/luckysheet/luckysheet.umd.js"></script>
 
     <title><%= VUE_APP_TITLE %></title>
-	<script type="text/javascript" src="http://dev1.local/word/web-apps/apps/api/documents/api.js"></script>
+	<script type="text/javascript" src="/word/web-apps/apps/api/documents/api.js"></script>
     <style>
      html,body,#app{height:100%;margin:0;padding:0}
      .ibps-home{background-color:#303133;height:100%;display:flex;flex-direction:column}

+ 2 - 5
src/api/baseUrl.js

@@ -1,7 +1,6 @@
 import store from '@/store'
 import {
     BASE_API as baseApi,
-    INTRANET_URL,
     BASE_GATEWAY_API as gatewayApi,
     BASE_WEBSOCKET as baseWebsocket,
     SINGLE, MULTIPLE_DOMAIN, API_DOMAIN_NAMES
@@ -22,11 +21,9 @@ const getApi = (api, i) => {
 
     return api.replace('{DOMAIN}', domainName)
 }
-
 // 默认url
-export const BASE_API = function (i, type = '') {
-    const base = type === 'intranet' ? `${INTRANET_URL}ibps` : baseApi
-    const api = store && store.getters.baseApi ? store.getters.baseApi : base
+export const BASE_API = function (i) {
+    const api = store && store.getters.baseApi ? store.getters.baseApi : baseApi
     return MULTIPLE_DOMAIN ? getApi(api, i) : api
 }
 // 网关API 解决上传乱码问题

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

@@ -474,9 +474,8 @@ export default {
         // 处理编辑文件
         handleEdit (index, data, type) {
             // 1、获取文件数据 及下载流接口
-            const api = BASE_API('', 'intranet') + SYSTEM_URL()
-            this.optionFile.url = api + '/file/download?attachmentId=' + data.id
-            this.optionFile.editUrl = api + '/file/editCallback?fileName=' + data.fileName + '&fileType=' + data.ext + '&type=' + type + '&id=' + data.id
+            this.optionFile.url = this.$onlyofficeApi + '/file/download?attachmentId=' + data.id
+            this.optionFile.editUrl = this.$onlyofficeApi + '/file/editCallback?fileName=' + data.fileName + '&fileType=' + data.ext + '&type=' + type + '&id=' + data.id
             this.optionFile.title = data.fileName // 文件名称
             this.optionFile.fileType = data.ext // 类型
             this.optionFile.data = data // 记录编制的位置,需要替换。

+ 6 - 5
src/business/platform/file/attachment/template-selector.vue

@@ -495,8 +495,10 @@ export default {
             this.templateOption.editorConfig.mode = mode
             // 新标签页打开
             if (openType === '_blank') {
-                localStorage.setItem('templateOption', JSON.stringify(this.templateOption))
-                window.open('#/templateView', '_blank')
+                const path = this.templateOption.document.title
+                // localStorage.setItem('templateOption', JSON.stringify(this.templateOption))
+                sessionStorage.setItem(path, JSON.stringify(this.templateOption))
+                window.open(`#/templateView?path=${encodeURIComponent(path)}`, '_blank')
             } else {
                 // 表单内打开
                 this.showFile = true
@@ -552,11 +554,10 @@ export default {
          */
         getPreview (index) {
             // 1、获取文件数据 及下载流接口
-            const api = BASE_API('', 'intranet') + SYSTEM_URL()
             // 下载地址
-            this.optionFileView.url = api + '/file/download?attachmentId=' + this.attachment.id
+            this.optionFileView.url = this.$onlyofficeApi + '/file/download?attachmentId=' + this.attachment.id
             // 回调接口url
-            this.optionFileView.editUrl = api + '/file/editCallback?fileName=' + this.attachment.fileName + '&fileType=' + this.attachment.ext
+            this.optionFileView.editUrl = this.$onlyofficeApi + '/file/editCallback?fileName=' + this.attachment.fileName + '&fileType=' + this.attachment.ext
             this.optionFileView.title = this.attachment.fileName // 文件名称
             this.optionFileView.fileType = this.attachment.ext // 类型
             this.optionFileView.data = this.attachment // 记录编制的位置,需要替换。

+ 4 - 1
src/plugins/ibps/index.js

@@ -38,8 +38,9 @@ import pluginLog from '@/plugins/log'
 import pluginOpen from '@/plugins/open'
 // 平台配置文件
 import setting from '@/setting.js'
-import { BASE_URL, BASE_SEAL_API, REPORT_PATH } from '@/constant'
+import { BASE_URL, BASE_SEAL_API, REPORT_PATH, INTRANET_URL } from '@/constant'
 import env from '@/env'
+import { BASE_API, SYSTEM_URL } from '@/api/baseUrl'
 
 export default {
     async install (Vue, options) {
@@ -50,6 +51,8 @@ export default {
         Vue.prototype.$nodeEnv = env.NODE_ENV
         // 当前环境变量
         Vue.prototype.$env = env
+        // onlyofficeUrl,开发环境使用当前环境api,生产环境固定使用INTRANET_URL
+        Vue.prototype.$onlyofficeApi = env.NODE_ENV === 'development' ? BASE_API() : `${INTRANET_URL}ibps` + SYSTEM_URL()
 
         // 当前的 baseUrl   简化代码中 env.VUE_APP_PUBLIC_PATH 取值
         Vue.prototype.$baseUrl = env.VUE_APP_PUBLIC_PATH || '/'

+ 2 - 3
src/views/component/fileTraining/index.vue

@@ -502,9 +502,8 @@ export default {
                             totalBytes: val.fileInfos.TOTAL_BYTES_
                         }
 
-                        const api = BASE_API('', 'intranet') + SYSTEM_URL()
-                        this.optionFile.url = `${api}/file/download?attachmentId=${data.id}`
-                        this.optionFile.editUrl = `${api}/file/editCallback?fileName=${data.fileName}&fileType=${data.ext}&type=fileTraining&id=${data.id}`
+                        this.optionFile.url = `${this.$onlyofficeApi}/file/download?attachmentId=${data.id}`
+                        this.optionFile.editUrl = `${this.$onlyofficeApi}/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 // 记录编制的位置,需要替换。

+ 2 - 3
src/views/platform/file/attachment/detail.vue

@@ -162,11 +162,10 @@ export default {
                 this.$message.warning('图片附件请直接在列表预览!')
                 return
             }
-            const api = BASE_API('', 'intranet') + SYSTEM_URL()
             this.fileOption.user.id = this.$store.getters.userId
             this.fileOption.user.name = this.$store.getters.name
-            this.fileOption.url = api + `/file/download?attachmentId=${id}`
-            this.fileOption.editUrl = api + `/file/editCallback?fileName=${fileName}&fileType=${ext}&id=${id}`
+            this.fileOption.url = this.$onlyofficeApi + `/file/download?attachmentId=${id}`
+            this.fileOption.editUrl = this.$onlyofficeApi + `/file/editCallback?fileName=${fileName}&fileType=${ext}&id=${id}`
             this.fileOption.title = fileName
             this.fileOption.fileType = ext
             // console.log(this.fileOption)

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

@@ -284,9 +284,8 @@ export default {
                             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 {
-                        const api = BASE_API('', 'intranet') + SYSTEM_URL()
-                        this.file.url = `${api}/file/download?attachmentId=${data.id}`
-                        this.file.editUrl = `${api}/file/editCallback?fileName=${data.fileName}&fileType=${data.ext}&id=${data.id}`
+                        this.file.url = `${this.$onlyofficeApi}/file/download?attachmentId=${data.id}`
+                        this.file.editUrl = `${this.$onlyofficeApi}/file/editCallback?fileName=${data.fileName}&fileType=${data.ext}&id=${data.id}`
                         this.file.title = data.fileName // 文件名称
                         this.file.fileType = data.ext // 类型
                         this.filePreviewVisible = false