From ea406e0b3aed9cd0b57a37e4ffa5b55892fa1434 Mon Sep 17 00:00:00 2001
From: Crunchy <3114200645@qq.com>
Date: 星期四, 16 五月 2024 14:55:21 +0800
Subject: [PATCH] 2024-5-16 在线编辑完成

---
 src/components/view/b1-report-preparation.vue |   70 ++++++++-----
 index.html                                    |    1 
 src/components/view/system-log.vue            |    2 
 src/components/tool/onlyoffice.vue            |  193 ++++++++++++++++++++++++++++++++++++++
 src/router/index.js                           |    5 
 5 files changed, 242 insertions(+), 29 deletions(-)

diff --git a/index.html b/index.html
index ba5e1c3..93c7f79 100644
--- a/index.html
+++ b/index.html
@@ -21,6 +21,7 @@
 	</head>
 	<body>
 		<div id="app"></div>
+		<script type='text/javascript' src='http://192.168.73.130:9001/web-apps/apps/api/documents/api.js'></script>
 		<script src="<%= htmlWebpackPlugin.options.url %>/static/luckysheet/plugins/js/plugin.js"></script>
 		<script src="<%= htmlWebpackPlugin.options.url %>/static/luckysheet/luckysheet.umd.js"></script>
 	</body>
diff --git a/src/components/tool/onlyoffice.vue b/src/components/tool/onlyoffice.vue
new file mode 100644
index 0000000..f9865c6
--- /dev/null
+++ b/src/components/tool/onlyoffice.vue
@@ -0,0 +1,193 @@
+<!--onlyoffice 缂栬緫鍣�-->
+<template>
+  <div id="vabOnlyOffice"></div>
+</template>
+
+<script>
+export default {
+  name: "VabOnlyOffice",
+  data() {
+    return {
+      doctype: "",
+      docEditor: null,
+      //鍙傝�僾abOnlyOffice缁勪欢鍙傛暟閰嶇疆
+      option: {
+        url: "",
+        isEdit: false,
+        fileType: "",
+        title: "",
+        lang: "zh-CN",
+        isPrint: true,
+        user: {},
+        editUrl: ""
+      }
+    };
+  },
+  created() {
+    const option = this.$route.query
+    this.option.url = option.url
+    this.option.isEdit = option.isEdit === "true" ? true : false
+    this.option.fileType = option.fileType
+    this.option.title = option.title
+    this.option.lang = option.lang
+    this.option.isPrint = option.isPrint
+    this.option.user.id = option.user_id
+    this.option.user.name = option.user_name
+    this.option.editUrl = option.editUrl
+  },
+  beforeDestroy() {
+    if (this.docEditor !== null) {
+      this.docEditor.destroyEditor();
+      this.docEditor = null;
+    }
+  },
+  watch: {
+    option: {
+      handler: function(n) {
+        this.setEditor(n);
+        this.doctype = this.getFileType(n.fileType);
+      },
+      deep: true
+    }
+  },
+  mounted() {
+    if (this.option.url) {
+      this.setEditor(this.option);
+    }
+  },
+  methods: {
+    async setEditor(option) {
+      console.log(`output->option`,option)
+      if (this.docEditor !== null) {
+        this.docEditor.destroyEditor();
+        this.docEditor = null;
+      }
+      this.doctype = this.getFileType(option.fileType);
+      let config = {
+        document: {
+          //鍚庣紑
+          fileType: option.fileType,
+          key: option.key || "",
+          title: option.title,
+          permissions: {
+            edit: option.isEdit, //鏄惁鍙互缂栬緫: 鍙兘鏌ョ湅锛屼紶false
+            print: option.isPrint,
+            download: false
+            // "fillForms": true,//鏄惁鍙互濉啓琛ㄦ牸锛屽鏋滃皢mode鍙傛暟璁剧疆涓篹dit锛屽垯濉啓琛ㄥ崟浠呭鏂囨。缂栬緫鍣ㄥ彲鐢ㄣ�� 榛樿鍊间笌edit鎴杛eview鍙傛暟鐨勫�间竴鑷淬��
+            // "review": true //璺熻釜鍙樺寲
+          },
+          url: option.url
+        },
+        documentType: this.doctype,
+        editorConfig: {
+          callbackUrl: option.editUrl, //"缂栬緫word鍚庝繚瀛樻椂鍥炶皟鐨勫湴鍧�锛岃繖涓猘pi闇�瑕佽嚜宸卞啓浜嗭紝灏嗙紪杈戝悗鐨勬枃浠堕�氳繃杩欎釜api淇濆瓨鍒拌嚜宸辨兂瑕佺殑浣嶇疆
+          lang: option.lang, //璇█璁剧疆
+          //瀹氬埗
+          customization: {
+            autosave: false, //鏄惁鑷姩淇濆瓨
+            chat: true,
+            comments: false,
+            help: false,
+            // "hideRightMenu": false,//瀹氫箟鍦ㄧ涓�娆″姞杞芥椂鏄樉绀鸿繕鏄殣钘忓彸渚ц彍鍗曘�� 榛樿鍊间负false
+            //鏄惁鏄剧ず鎻掍欢
+            plugins: false
+          },
+          user: {
+            id: option.user.id,
+            name: option.user.name
+          },
+          mode: option.model ? option.model : "edit"
+        },
+        width: "100%",
+        height: "100%",
+        token: option.token || ""
+      };
+
+      // eslint-disable-next-line no-undef,no-unused-vars
+      this.docEditor = new DocsAPI.DocEditor("vabOnlyOffice", config);
+    },
+    getFileType(fileType) {
+      let docType = "";
+      let fileTypesDoc = [
+        "doc",
+        "docm",
+        "docx",
+        "dot",
+        "dotm",
+        "dotx",
+        "epub",
+        "fodt",
+        "htm",
+        "html",
+        "mht",
+        "odt",
+        "ott",
+        "pdf",
+        "rtf",
+        "txt",
+        "djvu",
+        "xps"
+      ];
+      let fileTypesCsv = [
+        "csv",
+        "fods",
+        "ods",
+        "ots",
+        "xls",
+        "xlsm",
+        "xlsx",
+        "xlt",
+        "xltm",
+        "xltx"
+      ];
+      let fileTypesPPt = [
+        "fodp",
+        "odp",
+        "otp",
+        "pot",
+        "potm",
+        "potx",
+        "pps",
+        "ppsm",
+        "ppsx",
+        "ppt",
+        "pptm",
+        "pptx"
+      ];
+      if (fileTypesDoc.includes(fileType)) {
+        docType = "text";
+      }
+      if (fileTypesCsv.includes(fileType)) {
+        docType = "spreadsheet";
+      }
+      if (fileTypesPPt.includes(fileType)) {
+        docType = "presentation";
+      }
+      return docType;
+    }
+  }
+};
+</script>
+
+<style>
+html,
+body {
+  height: 100%;
+}
+#app {
+  font-family: Avenir, Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  text-align: center;
+  color: #2c3e50;
+  height: 100%;
+}
+.qualityManual-container {
+  padding: 0 !important;
+  height: 100%;
+}
+.qualityManual-container-office {
+  width: 100%;
+  height: calc(100% - 55px);
+}
+</style>
diff --git a/src/components/view/b1-report-preparation.vue b/src/components/view/b1-report-preparation.vue
index 3a85cb3..97addd9 100644
--- a/src/components/view/b1-report-preparation.vue
+++ b/src/components/view/b1-report-preparation.vue
@@ -180,15 +180,15 @@
           showSelect: false,
           select: false,
           do: [
-            //   {
-            //   id: 'handleWeave',
-            //   font: '鍦ㄧ嚎缂栧埗',
-            //   type: 'text',
-            //   method: 'handleWeave',
-            //   disabFun: (row, index) => {
-            //     return row.isExamine != null
-            //   }
-            // },
+              {
+              id: 'handleWeave',
+              font: '鍦ㄧ嚎缂栧埗',
+              type: 'text',
+              method: 'handleWeave',
+              disabFun: (row, index) => {
+                return row.isExamine != null
+              }
+            },
             {
               id: 'download',
               font: '涓嬭浇',
@@ -242,9 +242,9 @@
             }
           ],
           linkEvent: {
-            // code: {
-            //   method: 'selectAllByOne'
-            // }
+            code: {
+              method: 'selectAllByOne'
+            }
           },
           tagField: {
             isRatify: {
@@ -343,22 +343,22 @@
         this.upIndex++
       },
       async handleWeave(row) {
-        // this.value = await file.convertFileToHtml(row.url)
-        // this.claimVisible = true;
-        this.$axios.post(this.$api.insReport.wordToHtml, {
-          path: row.urlS ? row.urlS : row.url
-        }).then(res => {
-          if (res.code === 200) {
-            // console.log(11111111,res.data)
-            this.value = res.data
-              .replace(/<a [^>]*>/g, "")
-              .replace(/<\/a>/g, "")
-              .replace(/&nbsp;/g, "&nbsp;&nbsp;");
-            this.claimVisible = true;
+        const userName = JSON.parse(localStorage.getItem("user")).name;
+        //鍙傝�僾abOnlyOffice缁勪欢鍙傛暟閰嶇疆
+        const { href } = this.$router.resolve({
+          path: `/wordEdit`,
+          query: {
+            url: this.javaApi + "/word/" + row.entrustCode + ".docx",
+            isEdit: true,
+            fileType: "docx",
+            title: row.entrustCode + ".docx",
+            lang: 'zh-CN',
+            isPrint: true,
+            user:  { id: 1, name: userName},
+            editUrl: this.javaApi + "/insReport/onlyOffice/save?fileName=" + row.entrustCode + ".docx"
           }
-        }).catch(error => {
-          console.error(error)
         })
+        window.open(href, '_blank');
       },
       // 鏉冮檺鍒嗛厤
       getPower(radio) {
@@ -406,7 +406,23 @@
         // console.log(this.$refs.Word.getValue())
       },
       async selectAllByOne(row) {
-        console.log(row, await file.convertFileToHtml(row.url));
+        const userName = JSON.parse(localStorage.getItem("user")).name;
+        //鍙傝�僾abOnlyOffice缁勪欢鍙傛暟閰嶇疆
+        const { href } = this.$router.resolve({
+          path: `/wordEdit`,
+          query: {
+            url: this.javaApi + "/word/" + row.entrustCode + ".docx",
+            isEdit: "false",
+            fileType: "docx",
+            title: row.entrustCode + ".docx",
+            lang: 'zh-CN',
+            isPrint: true,
+            user_id: 1,
+            user_name: userName
+          }
+        })
+        window.open(href, '_blank');
+        console.log(`output->row`,row)
       },
       download(row) {
         let url = row.urlS ? row.urlS : row.url;
diff --git a/src/components/view/system-log.vue b/src/components/view/system-log.vue
index a415609..519b37c 100644
--- a/src/components/view/system-log.vue
+++ b/src/components/view/system-log.vue
@@ -106,4 +106,4 @@
 			}
 		}
 	}
-</script>
+</script>
\ No newline at end of file
diff --git a/src/router/index.js b/src/router/index.js
index cdde777..2c7ef5b 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -26,5 +26,8 @@
   },{
 		path: "/test/excel",
 		component: () => import("../components/tool/excel.vue")
-	}]
+	},{
+    path: "/wordEdit",
+    component: () => import("../components/tool/onlyoffice.vue")
+  }]
 })

--
Gitblit v1.9.3