瀏覽代碼

修改文件在线编辑轮询逻辑

cfort 3 年之前
父節點
當前提交
f1963607c7
共有 1 個文件被更改,包括 22 次插入6 次删除
  1. 22 6
      src/business/platform/file/attachment/editFile/editor.vue

+ 22 - 6
src/business/platform/file/attachment/editFile/editor.vue

@@ -32,6 +32,21 @@
             if (this.option.url) {
                 this.setEditor(this.option)
             }
+            if(this.option.mode == 'edit'){
+                // 编辑模式下轮询获取文件id
+                this.timer = setInterval(() => {
+                    if (this.configKey) {
+                        showView({ key: this.configKey }).then((response) => {
+                            if (response.variables.data !== '0' && this.newId !== response.variables.data) {
+                                // 记录当前id,与返回的文件id比对,有变化证明有做修改,提示并替换
+                                this.newId = response.variables.data 
+                                this.$message.success('文件编辑保存成功,稍后请提交表单!')
+                                this.$emit('updateFile', this.newId)
+                            }
+                        })
+                    }
+                }, 2000)
+            }
         },
         beforeDestroy() {
             // 页面关闭清除定时任务
@@ -92,12 +107,13 @@
                         onRequestSaveAs: () => {
                             console.log('另存为')
                         },
-                        onDocumentStateChange: e => {
-                            if (!e.data) {
-                                console.log('文件修改', e)
-                                this.handlerFileSave()
-                            }
-                        },
+                        // 监听文件修改开启轮询,有几率同时触发N个,导致页面卡死
+                        // onDocumentStateChange: e => {
+                        //     if (!e.data) {
+                        //         console.log('文件修改', e)
+                        //         this.handlerFileSave()
+                        //     }
+                        // },
                         onDocumentReady: () => {
                             console.log('文件加载完成~')
                         }