Browse Source

修改excel用户选择

wukai 1 year ago
parent
commit
0edd217e02
2 changed files with 209 additions and 135 deletions
  1. 7 0
      src/api/biz/info.js
  2. 202 135
      src/components/OnlyOffice/index.vue

+ 7 - 0
src/api/biz/info.js

@@ -16,6 +16,13 @@ export function getInfo(docId) {
     method: 'get'
   })
 }
+// 查询文件允许使用的用户
+export function users(docId) {
+  return request({
+    url: '/biz/info/users/' + docId,
+    method: 'get'
+  })
+}
 
 // 根据目录id查询文件列表
 export function getInfoByDirId(dirId) {

+ 202 - 135
src/components/OnlyOffice/index.vue

@@ -1,148 +1,215 @@
 <!--onlyoffice 编辑器-->
 <template>
-	<div id='jjtOnlyOffice'></div>
+  <div id="jjtOnlyOffice"></div>
 </template>
 
 <script>
-	export default {
-		name: 'jjtOnlyOffice',
-		props: {
-			option: {
-				type: Object,
-				default: () => {
-					return {}
-				},
-			},
-		},
-		data() {
-			return {
-				doctype: '',
-				docEditor: null,
-			}
-		},
-		beforeDestroy() {
-			if (this.docEditor !== null) {
-				this.docEditor.destroyEditor();
-				this.docEditor = null;
-			}
-		},
-		watch: {
-			option: {
-				handler: function(n) {
-					this.setEditor(n)
-					this.doctype = this.getDocType(n.fileType)
-				},
-				deep: true,
-			},
+import { listVersion } from "@/api/biz/version";
+import { users } from "@/api/biz/info";
+export default {
+  name: 'jjtOnlyOffice',
+  props: {
+    option: {
+      type: Object,
+      default: () => {
+        return {}
+      }
+    }
+  },
+  data() {
+    return {
+      doctype: '',
+      docEditor: null,
+      docId: null,
+			basePath:null
+    }
+  },
+  beforeDestroy() {
+    if (this.docEditor !== null) {
+      this.docEditor.destroyEditor()
+      this.docEditor = null
+    }
+  },
+  watch: {
+    option: {
+      handler: function (n) {
+        this.docId = n.docId
+        this.setEditor(n)
+        this.doctype = this.getDocType(n.fileType)
+      },
+      deep: true
+    }
+  },
+  mounted() {
+    // let script = document.createElement("script");
+    // script.type = "text/javascript";
+    // script.src = `${window.location.origin}:19531/web-apps/apps/api/documents/api.js`;
+    // document.body.appendChild(script);
+    // if (this.option.url) {
+    // 	this.setEditor(this.option)
+    // }
+  },
+  methods: {
+    onRequestUsers(event) {
+			users(this.docId).then(response => {
+				const users=new Array();
+				response.data.forEach((item,index)=>{
+					users.push({
+							email:item.deptName,
+							id: item.userId,
+							name: item.userName
+						})
+				})
+				
+				this.docEditor.setUsers({
+				  c: event.data.c,
+				  users: users
+				})
+			})
+    },
+		
+    onRequestHistory() {
+			listVersion({ pageNum: 1, pageSize: 10000, docId: this.docId }).then(response => {
+				const his=new Array();
+				response.rows.forEach((item,index)=>{
+					his.push({
+							created: item.createTime,
+							key: item.fileId,
+							user: {
+								name: item.createBy
+							},
+							version: item.fileId
+						})
+				})
+				this.docEditor.refreshHistory({
+					currentVersion: 1,
+					history: his
+				})
+			})	
 		},
-		mounted() {
-			// let script = document.createElement("script");
-			// script.type = "text/javascript";
-			// script.src = `${window.location.origin}:19531/web-apps/apps/api/documents/api.js`;
-			// document.body.appendChild(script);
-			// if (this.option.url) {
-			// 	this.setEditor(this.option)
-			// }
+    onRequestHistoryData(event) {
+			console.log(event);
+      var key = event.data
+      this.docEditor.setHistoryData({
+        key: key,
+        url: `${window.location.origin}${import.meta.env.VITE_APP_BASE_API}/api/history/${key}`,
+        version: key
+      })
+    },
+		onRequestHistoryClose() {
+		    document.location.reload();
 		},
-		methods: {
-			async setEditor(option) {
-				if (this.docEditor !== null) {
-					this.docEditor.destroyEditor();
-					this.docEditor = null;
-				}
+    async setEditor(option) {
+      if (this.docEditor !== null) {
+        this.docEditor.destroyEditor()
+        this.docEditor = null
+      }
 
-				this.doctype = this.getDocType(option.fileType);
-				// console.log(option);
-				const isCopy = option.isCopy ? option.isCopy : true;
-				// console.log(option.key);
-				let config = {
-					document: {
-						fileType: option.fileType, //后缀
-						key: option.key || '',
-						title: option.title,
-						permissions: {
-							edit: option.isEdit, //是否可以编辑: 只能查看,传false
-							print: false, //是否可以打印
-							download: false, //是否可以下载
-							copy: option.isCopy,
-							// "fillForms": true,//是否可以填写表格,如果将mode参数设置为edit,则填写表单仅对文档编辑器可用。 默认值与edit或review参数的值一致。
-							// "review": true //跟踪变化
-						},
-						url: option.url,
-					},
-					documentType: this.doctype,
-					editorConfig: {
-						callbackUrl: option.editUrl, //"编辑word后保存时回调的地址,这个api需要自己写了,将编辑后的文件通过这个api保存到自己想要的位置
-						lang: 'zh-CN', //语言设置
-						//定制
-						customization: {
-							autosave: false, //是否自动保存
-							chat: true,
-							comments: true,
-							help: false,
-							// "hideRightMenu": false,//定义在第一次加载时是显示还是隐藏右侧菜单。 默认值为false
-							//是否显示插件
-							plugins: false,
-							spellcheck: false, //定义在加载编辑器时是否自动打开或关闭拼写检查器。拼写检查器仅适用于文档编辑器和演示文稿编辑器。默认值为true。
-							customer: {
-								//开源版无效,商业版才行
-								address: "My City, 123a-45",
-								info: "Some additional information",
-								logo: "https://example.com/logo-big.png",
-								logoDark: "https://example.com/dark-logo-big.png",
-								mail: "john@example.com",
-								name: "John Smith and Co.",
-								phone: "123456789",
-								www: "example.com"
-							},
-						},
-						user: {
-							id: option.user.id + '',
-							name: option.user.name
-						},
-						mode: option.model ? option.model : 'edit',
-						// 定义共享编辑模式(快速fast/严格strict), change为控制是否允许修改
-						coEditing: {
-							mode: 'fast',
-							change: true
-						}
-					},
-					width: document.body.clientWidth - 100,
-					height: document.body.clientHeight - 100,
-					token: option.token || ''
-				}
-				// eslint-disable-next-line no-undef,no-unused-vars
-				this.docEditor = new DocsAPI.DocEditor('jjtOnlyOffice', config)
+      this.doctype = this.getDocType(option.fileType)
+      const isCopy = option.isCopy ? option.isCopy : true
 
-			},
-			/*
-			 * 通过扩展名获取文档类型
-			 * text对应各种文档类型(.doc, .docm, .docx, .dot, .dotm, .dotx, .epub, .fodt, .htm, .html, .mht, .odt, .ott, .pdf, .rtf, .txt, .djvu, .xps)
-			 * spreadsheet对应表格类型(.csv, .fods, .ods, .ots, .xls, .xlsm, .xlsx, .xlt, .xltm, .xltx)
-			 * presentation对应PPT类型(.fodp, .odp, .otp, .pot, .potm, .potx, .pps, .ppsm, .ppsx, .ppt, .pptm, .pptx)
-			 */
-			getDocType(fileType) {
-				let docType = '';
-				for (const type in fileTypeMap) {
-					if (fileTypeMap[type].includes(fileType)) {
-						docType = type;
-						break;
-					}
-				}
-				return docType;
-			}
-		},
-	}
+      let config = {
+        events: {
+          onRequestHistory: this.onRequestHistory,
+          onRequestHistoryData: this.onRequestHistoryData,
+          onRequestUsers: this.onRequestUsers,
+					onRequestHistoryClose:this.onRequestHistoryClose
+        },
+        document: {
+          fileType: option.fileType, //后缀
+          key: option.key || '',
+          title: option.title,
+          permissions: {
+            edit: option.isEdit, //是否可以编辑: 只能查看,传false
+            print: false, //是否可以打印
+            download: false, //是否可以下载
+            copy: option.isCopy
+            // "fillForms": true,//是否可以填写表格,如果将mode参数设置为edit,则填写表单仅对文档编辑器可用。 默认值与edit或review参数的值一致。
+            // "review": true //跟踪变化
+          },
+          url: option.url
+        },
+        documentType: this.doctype,
+        editorConfig: {
+          callbackUrl: option.editUrl, //"编辑word后保存时回调的地址,这个api需要自己写了,将编辑后的文件通过这个api保存到自己想要的位置
+          canUseHistory: true,
+          lang: 'zh-CN', //语言设置
+          //定制
+          customization: {
+            autosave: false, //是否自动保存
+            chat: true,
+            comments: true,
+            help: false,
+            // "hideRightMenu": false,//定义在第一次加载时是显示还是隐藏右侧菜单。 默认值为false
+            //是否显示插件
+            plugins: false,
+            spellcheck: false //定义在加载编辑器时是否自动打开或关闭拼写检查器。拼写检查器仅适用于文档编辑器和演示文稿编辑器。默认值为true。
+          },
+          user: {
+            id: option.user.id + '',
+            name: option.user.name
+          },
+          mode: option.model ? option.model : 'edit',
+          // 定义共享编辑模式(快速fast/严格strict), change为控制是否允许修改
+          coEditing: {
+            mode: 'fast',
+            change: true
+          }
+        },
+        width: document.body.clientWidth - 100,
+        height: document.body.clientHeight - 100,
+        token: option.token || ''
+      }
 
-	const fileTypeMap = {
-		'word': ['doc', 'docm', 'docx', 'dot', 'dotm', 'dotx', 'epub', 'fodt', 'htm', 'html', 'mht', 'odt', 'ott',
-			'pdf', 'rtf', 'txt', 'djvu', 'xps', 'wps'
-		],
-		'cell': ['csv', 'fods', 'ods', 'ots', 'xls', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx'],
-		'slide': ['fodp', 'odp', 'otp', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx']
-	}
-</script>
+      // eslint-disable-next-line no-undef,no-unused-vars
+      this.docEditor = new DocsAPI.DocEditor('jjtOnlyOffice', config)
+    },
+
+    /*
+     * 通过扩展名获取文档类型
+     * text对应各种文档类型(.doc, .docm, .docx, .dot, .dotm, .dotx, .epub, .fodt, .htm, .html, .mht, .odt, .ott, .pdf, .rtf, .txt, .djvu, .xps)
+     * spreadsheet对应表格类型(.csv, .fods, .ods, .ots, .xls, .xlsm, .xlsx, .xlt, .xltm, .xltx)
+     * presentation对应PPT类型(.fodp, .odp, .otp, .pot, .potm, .potx, .pps, .ppsm, .ppsx, .ppt, .pptm, .pptx)
+     */
+    getDocType(fileType) {
+      let docType = ''
+      for (const type in fileTypeMap) {
+        if (fileTypeMap[type].includes(fileType)) {
+          docType = type
+          break
+        }
+      }
+      return docType
+    }
+  }
+}
 
+const fileTypeMap = {
+  word: [
+    'doc',
+    'docm',
+    'docx',
+    'dot',
+    'dotm',
+    'dotx',
+    'epub',
+    'fodt',
+    'htm',
+    'html',
+    'mht',
+    'odt',
+    'ott',
+    'pdf',
+    'rtf',
+    'txt',
+    'djvu',
+    'xps',
+    'wps'
+  ],
+  cell: ['csv', 'fods', 'ods', 'ots', 'xls', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx'],
+  slide: ['fodp', 'odp', 'otp', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx']
+}
+</script>
 
 <!-- let config = {
       "document": {
@@ -276,4 +343,4 @@
           //"onDocumentReady" : onDocumentReady, //文档初始化准备好后的回调
       },
   };
-  var docEditor = new DocsAPI.DocEditor("placeholder", config); -->
+  var docEditor = new DocsAPI.DocEditor("placeholder", config); -->