Explorar el Código

黏贴样式2255

zhouna hace 5 años
padre
commit
98b59de692

+ 2 - 28
src/common/components/EditableSpan/index.jsx

@@ -1,7 +1,7 @@
 import React,{Component} from 'react';
 import style from './index.less';
 import config from "@config/index";
-import {filterArr,isIE,getPageCoordinate,filterDataArr,preventDefault,setFontColorSize} from '@utils/tools.js';
+import {filterArr,isIE,getPageCoordinate,filterDataArr,preventDefault,setFontColorSize,moveEnd} from '@utils/tools.js';
 import Notify from '../Notify/index.js';
 import classNames from 'classnames';
 
@@ -37,7 +37,6 @@ class EditableSpan extends Component{
     this.handleBlur = this.handleBlur.bind(this);
     this.handleKeydown = this.handleKeydown.bind(this);
     this.handleKeyup = this.handleKeyup.bind(this);
-    this.moveEnd = this.moveEnd.bind(this);
     this.handleClick = this.handleClick.bind(this);
   }
   handleFocus(e){
@@ -49,7 +48,7 @@ class EditableSpan extends Component{
       setTimeout(function(){
         txt = that.$span.current.innerText||that.$span.current.innerHTML;
         that.$span.current.innerHTML = txt;
-        that.moveEnd($(that.$span.current)[0]);     //光标落到最后去
+        moveEnd($(that.$span.current)[0]);     //光标落到最后去
       });
     })
     
@@ -138,31 +137,6 @@ class EditableSpan extends Component{
     $(this.$span.current).off("paste");
   }
 
-  moveEnd(obj,flg) {
-    if(window.getSelection){//ie11 10 9 ff safari
-      setTimeout(() => {
-        obj.focus(); //解决ff不获取焦点无法定位问题
-        var range = window.getSelection();//创建range
-        range.selectAllChildren(obj);//range 选择obj下所有子内容
-        if(flg){
-          range.collapseToStart();//光标移至开头
-        }else{
-          range.collapseToEnd();//光标移至最后
-        }
-      }, 0);
-    }
-    else if (document.selection) {//ie10 9 8 7 6 5
-      var range = document.selection.createRange();//创建选择对象
-      range.moveToElementText(obj);//range定位到obj
-      if(flg){
-        range.collapse(true);//光标移至开头
-      }else{
-        range.collapse(false);//光标移至最后
-      }
-      range.select();
-    }
-  }
-
   handleKeydown(e){
     const ev = e||window.event;
     const {i} = this.props;

+ 14 - 1
src/components/AddAssistCheck/Textarea/index.jsx

@@ -2,7 +2,7 @@ import React, { Component } from "react";
 import style from "./index.less";
 import config from '@config/index';
 import $ from 'jquery';
-import { setFontColorSize} from '@utils/tools';
+import { setFontColorSize,moveEnd} from '@utils/tools';
 
 class Textarea extends Component {
   constructor(props) {
@@ -66,6 +66,19 @@ class Textarea extends Component {
     }else{
       this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = '报告描述或意见'):(this.$dom.current.nextSibling.innerHTML = '报告描述或意见')
     }
+    const that = this;
+    let txt = '';
+    //黏贴时去掉html格式
+    $(this.$dom.current).on("paste",function(e){
+      setTimeout(function(){
+        txt = that.$dom.current.innerText||that.$dom.current.innerHTML;
+        that.$dom.current.innerHTML = txt;
+        moveEnd($(that.$dom.current)[0]);     //光标落到最后去
+      });
+    })
+  }
+  componentWillUnmount(){
+    $(this.$dom.current).off("paste");
   }
   handleFocus(){     //ie8下提示语挡住输入框,导致输入框无法聚焦
     this.textInput.current.previousSibling.focus();

+ 16 - 8
src/components/Advice/Textarea/index.jsx

@@ -1,7 +1,7 @@
 import React, { Component } from "react";
 import style from "./index.less";
 import config from '@config/index';
-import {setFontColorSize} from '@utils/tools';
+import {setFontColorSize,moveEnd} from '@utils/tools';
 import $ from 'jquery';
 
 class Textarea extends Component {
@@ -20,7 +20,6 @@ class Textarea extends Component {
     e.stopPropagation();
     const {handleChangeAssistValue,idx,handlePush} = this.props;
     const text =  e.target.textContent.trim() ? e.target.innerHTML : ''
-    const stimer = this.state.timer;
     handleChangeAssistValue&&handleChangeAssistValue(text);
    
   }
@@ -32,13 +31,8 @@ class Textarea extends Component {
   }
   componentWillReceiveProps(next){
     const {isRead, typeConfig} = this.props;
-    // if(next.isRead != isRead && next.value!=this.props.value){      //value对比解决复诊不显示bug
-    //   next.value ? this.$dom.current.innerText = next.value :  this.$dom.current.innerText = next.value 
-    //   // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
-    // }
     if(next.isRead != isRead && next.value || next.isRead != isRead && next.value!=this.props.value){      //value对比解决复诊不显示bug
       next.value ? this.$dom.current.innerHTML = next.value :  this.$dom.current.innerHTML = '' 
-      // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
     }
     if(next.typeConfig != typeConfig) {
       this.$dom.current.innerText = '' 
@@ -52,8 +46,22 @@ class Textarea extends Component {
       // this.$dom.current.innerText ? (this.$dom.current.innerText = value) : (this.$dom.current.innerHTML = value)
     //   this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = ''):(this.$dom.current.nextSibling.innerHTML = '')
     }
+    const that = this;
+    let txt = '';
+    //黏贴时去掉html格式
+    $(this.$dom.current).on("paste",function(e){
+      setTimeout(function(){
+        txt = that.$dom.current.innerText||that.$dom.current.innerHTML;
+        that.$dom.current.innerHTML = txt;
+      });
+      setTimeout(function(){
+        moveEnd($(that.$dom.current)[0]);     //光标落到最后去
+      },200)
+    })
+  }
+  componentWillUnmount(){
+    $(this.$dom.current).off("paste");
   }
- 
   render() {
     return (
       <div>

+ 27 - 1
src/utils/tools.js

@@ -1331,6 +1331,31 @@ function setPosition (e,dom,setHighter){
     // $(e.target)[0].scrollIntoView(true);
   },10);
 }
+
+function moveEnd(obj,flg) {
+  if(window.getSelection){//ie11 10 9 ff safari
+    setTimeout(() => {
+      obj.focus(); //解决ff不获取焦点无法定位问题
+      var range = window.getSelection();//创建range
+      range.selectAllChildren(obj);//range 选择obj下所有子内容
+      if(flg){
+        range.collapseToStart();//光标移至开头
+      }else{
+        range.collapseToEnd();//光标移至最后
+      }
+    }, 0);
+  }
+  else if (document.selection) {//ie10 9 8 7 6 5
+    var range = document.selection.createRange();//创建选择对象
+    range.moveToElementText(obj);//range定位到obj
+    if(flg){
+      range.collapse(true);//光标移至开头
+    }else{
+      range.collapse(false);//光标移至最后
+    }
+    range.select();
+  }
+}
 /**
  * 获取样式类名
  * largeFontSize 18px      middleFontSize 16px(暂无)       simpleFontSize 14px
@@ -1460,5 +1485,6 @@ module.exports = {
     setPosition,
     isAllPartClear,
     getDomUpDown,
-    setFontColorSize
+    setFontColorSize,
+    moveEnd
 };