|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div style="width: 100%; height: 100%">
|
|
|
3
|
+ <div id="placeholder"></div>
|
|
|
4
|
+ </div>
|
|
|
5
|
+</template>
|
|
|
6
|
+
|
|
|
7
|
+<script>
|
|
|
8
|
+import { getOnlyoffice, saveOnlyOfficeFile } from "@/api/onlyoffice/onlyoffice";
|
|
|
9
|
+import { setToken } from "@/utils/auth";
|
|
|
10
|
+import store from "@/store";
|
|
|
11
|
+import axios from "axios";
|
|
|
12
|
+export default {
|
|
|
13
|
+ props: [],
|
|
|
14
|
+ data() {
|
|
|
15
|
+ return {
|
|
|
16
|
+ config: {},
|
|
|
17
|
+ flag: 0,
|
|
|
18
|
+ userId: store.getters.userId,
|
|
|
19
|
+ websock: null,
|
|
|
20
|
+ };
|
|
|
21
|
+ },
|
|
|
22
|
+ destroyed() {
|
|
|
23
|
+ //页面销毁时关闭ws连接
|
|
|
24
|
+ if (this.websock) {
|
|
|
25
|
+ this.websock.close(); // 关闭websocket
|
|
|
26
|
+ }
|
|
|
27
|
+ },
|
|
|
28
|
+ methods: {
|
|
|
29
|
+ getConfig(id) {
|
|
|
30
|
+ let edit = "edit";
|
|
|
31
|
+ if (this.flag == 0) {
|
|
|
32
|
+ edit = "view";
|
|
|
33
|
+ } else {
|
|
|
34
|
+ edit = "edit";
|
|
|
35
|
+ }
|
|
|
36
|
+ axios
|
|
|
37
|
+ .get(
|
|
|
38
|
+ `http://121.40.189.20:9090/onlyOfficeConfig/${edit}/${id}/${this.userId}/desktop/true/zhongcai`
|
|
|
39
|
+ )
|
|
|
40
|
+ .then((res) => {
|
|
|
41
|
+ this.config = res.data;
|
|
|
42
|
+ this.config.editorConfig.callbackUrl = this.config.editorConfig.callbackUrl + "/" + id;
|
|
|
43
|
+ console.log(this.config,"OOOOOOOOOOOOOOOOOOOOOOOOOOO");
|
|
|
44
|
+
|
|
|
45
|
+ // this.config.callbackUrl = this.config.callbackUrl + `/${this.userId}`;
|
|
|
46
|
+ var docEditor = new DocsAPI.DocEditor("placeholder", this.config);
|
|
|
47
|
+ });
|
|
|
48
|
+ },
|
|
|
49
|
+ //初始化weosocket
|
|
|
50
|
+ initWebSocket() {
|
|
|
51
|
+ if (typeof WebSocket === "undefined") {
|
|
|
52
|
+ alert("您的浏览器不支持WebSocket");
|
|
|
53
|
+ return false;
|
|
|
54
|
+ }
|
|
|
55
|
+ const wsuri = `ws://121.40.189.20:9090/api/websocket/${this.userId}`; // websocket地址
|
|
|
56
|
+ this.websock = new WebSocket(wsuri);
|
|
|
57
|
+ this.websock.onopen = this.websocketonopen;
|
|
|
58
|
+ this.websock.onmessage = this.websocketonmessage;
|
|
|
59
|
+ this.websock.onerror = this.websocketonerror;
|
|
|
60
|
+ this.websock.onclose = this.websocketclose;
|
|
|
61
|
+ },
|
|
|
62
|
+ //连接成功
|
|
|
63
|
+ websocketonopen() {
|
|
|
64
|
+ console.log("WebSocket连接成功");
|
|
|
65
|
+ },
|
|
|
66
|
+ //接收后端返回的数据
|
|
|
67
|
+ websocketonmessage(e) {
|
|
|
68
|
+ let dataJson = e.data;
|
|
|
69
|
+ if (dataJson != "conn_success") {
|
|
|
70
|
+ dataJson = JSON.parse(dataJson);
|
|
|
71
|
+ }
|
|
|
72
|
+ if (dataJson.caseId) {
|
|
|
73
|
+ saveOnlyOfficeFile({
|
|
|
74
|
+ caseAppliId: Number(dataJson.caseId),
|
|
|
75
|
+ annexName: dataJson.fileName,
|
|
|
76
|
+ annexPath: dataJson.filePath,
|
|
|
77
|
+ onlyOfficeFileId: dataJson.fileId,
|
|
|
78
|
+ }).then((res) => {
|
|
|
79
|
+ this.websock.send();
|
|
|
80
|
+ });
|
|
|
81
|
+ }
|
|
|
82
|
+ // 在这里使用后端返回的数据,对数据进行处理渲染
|
|
|
83
|
+ },
|
|
|
84
|
+ //连接建立失败重连
|
|
|
85
|
+ websocketonerror(e) {
|
|
|
86
|
+ console.log(`连接失败的信息:`, e);
|
|
|
87
|
+ this.initWebSocket(); // 连接失败后尝试重新连接
|
|
|
88
|
+ },
|
|
|
89
|
+ //关闭连接
|
|
|
90
|
+ websocketclose(e) {
|
|
|
91
|
+ console.log("断开连接", e);
|
|
|
92
|
+ },
|
|
|
93
|
+ /**是否从视频会议跳转,是处理token */
|
|
|
94
|
+ async getToken() {
|
|
|
95
|
+ setToken(this.$route.query.token);
|
|
|
96
|
+ },
|
|
|
97
|
+ },
|
|
|
98
|
+ async mounted() {
|
|
|
99
|
+ if (this.$route.query.token) {
|
|
|
100
|
+ await this.getToken();
|
|
|
101
|
+ }
|
|
|
102
|
+ let id = this.$route.query.id;
|
|
|
103
|
+ this.flag = this.$route.query.flag;
|
|
|
104
|
+ this.getConfig(id);
|
|
|
105
|
+ this.initWebSocket();
|
|
|
106
|
+ },
|
|
|
107
|
+ watch: {},
|
|
|
108
|
+};
|
|
|
109
|
+</script>
|
|
|
110
|
+<style lang="scss" scoped></style>
|