tianyun 1 år sedan
förälder
incheckning
3726b7c2d9
1 ändrade filer med 28 tillägg och 0 borttagningar
  1. 28 0
      simple-demo/edit_online.html

+ 28 - 0
simple-demo/edit_online.html

@@ -65,6 +65,7 @@
         if (res.code == 200) {
             if (res.res.length > 0) {
                 document.getElementById("editor").innerHTML = res.res[0].content;
+                showTextOnTopRight("✅");
             }
         }
     } else {
@@ -94,6 +95,7 @@
         });
         if (res.code == 200) {
             console.log("同步成功");
+            showTextOnTopRight("✅");
         }
     }
     let debounce1 = debounce(sysncContent, 1000);
@@ -105,10 +107,36 @@
 
         // 在这里执行你想要的操作,比如更新数据或执行其他逻辑
         console.log("内容发生变化");
+        showTextOnTopRight("待同步");
         // 防抖 1秒内同步一次
         debounce1();
     });
 
+    function showTextOnTopRight(text) {
+        let id1 = "showTextOnTopRight";
+        // 删除之前的
+        let oldDiv = document.getElementById(id1);
+        if (oldDiv) {
+            document.body.removeChild(oldDiv);
+        }
+        // 在屏幕右上角显示一个文本
+        let div = document.createElement("div");
+        // 设置id
+        div.id = id1;
+        div.style.position = "fixed";
+        div.style.top = "8px";
+        div.style.right = "8px";
+        div.style.padding = "5px";
+        div.style.backgroundColor = "#fff";
+        div.style.border = "1px solid #ccc";
+        div.style.borderRadius = "5px";
+        div.style.zIndex = "9999";
+        // 字体大小
+        div.style.fontSize = "12px";
+        div.innerHTML = text;
+        document.body.appendChild(div);
+    }
+
 </script>
 
 </body>