zhuliu 1 year ago
parent
commit
bfc446b819
1 changed files with 14 additions and 6 deletions
  1. 14 6
      src/utils/model/RichText/index.vue

+ 14 - 6
src/utils/model/RichText/index.vue

@@ -76,6 +76,11 @@ export default {
     value(val){
       this.content = val
     },
+    show(val){
+      if(!val){
+        this.$refs.myEditBox.focus()
+      }
+    }
   },
   computed: {},
   created() {},
@@ -88,10 +93,12 @@ export default {
     this.setFocus()
     // 当点击任意地方或者按下ESC键时,隐藏菜单
     // window.onclick = this.hideCustomMenu
+    var that = this
     window.addEventListener('click',function(event){
       var customMenu = that.$refs.customMenu
       if (customMenu && event.target != customMenu && !customMenu.contains(event.target)) {
           customMenu.style.display = "none";
+          that.show = false
       }
       
     })
@@ -117,7 +124,7 @@ export default {
       //  var html = this.addTag(SplitHtmls,method)
       this.content = html
       this.show = false
-      this.$refs.myEditBox.focus()
+      
       this.$emit('input',html)
       // this.$emit('blur',html)
       this.$emit('change',html)
@@ -172,8 +179,8 @@ export default {
       this.$nextTick(()=>{
         this.show = true
         var customMenu = this.$refs.customMenu
-        var xPos = event.layerX + "px";
-        var yPos = event.layerY + "px";
+        var xPos = event.clientX + "px";
+        var yPos = event.clientY + "px";
         customMenu.style.display = "block";
         customMenu.style.left = xPos;
         customMenu.style.top = yPos;
@@ -195,9 +202,10 @@ export default {
       e = e || window.event;
       if (e.keyCode == 27) { // ESC键的keycode值为27
           customMenu.style.display = "none";
+          this.show = false
       }
       if (e.keyCode === 13) {
-        return
+        // return
           e.preventDefault(); // 阻止默认操作
           document.execCommand("insertHTML", false, "<br><br>"); // 插入换行
       }
@@ -438,9 +446,9 @@ async urlToBase64(imageUrl) {
   box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.2);
   min-width: 100px;
   text-align: center;
-  z-index: 999;
+  z-index: 9999;
    display: none; /* 初始状态下不显示 */
-   position: absolute;
+   position: fixed;
    &>div{
     padding:10px;
     line-height: 25px;