Forráskód Böngészése

叫号滚动优化

liudan 2 hónapja
szülő
commit
034c412132
2 módosított fájl, 15 hozzáadás és 6 törlés
  1. 12 6
      src/components/Scroll.jsx
  2. 3 0
      src/pages/home/Index.jsx

+ 12 - 6
src/components/Scroll.jsx

@@ -12,18 +12,24 @@ class Scroll extends React.Component {
   }
   componentDidMount() {
     if (ref.current) {
-      this.setState({
-        isScroll: ref.current.offsetWidth > ref.current.parentNode.offsetWidth,
-      });
+      this.initWidth();
     }
   }
   componentDidUpdate(prev) {
     if (prev.text !== this.props.text && ref.current) {
-      this.setState({
-        isScroll: ref.current.offsetWidth > ref.current.parentNode.offsetWidth,
-      });
+      this.initWidth();
     }   
   }
+  initWidth = () => {
+    const parentDom = ref.current.parentNode;
+    if (!parentDom) {
+      return;
+    }
+    const parentW = parentDom.offsetWidth - 0.8 * 2 * document.body.clientWidth / 100;
+    this.setState({
+      isScroll: ref.current.offsetWidth > parentW,
+    });
+  };
   render() {
     return (
       <div ref={ ref }>

+ 3 - 0
src/pages/home/Index.jsx

@@ -104,6 +104,9 @@ class Home extends React.Component {
             'callPat': [{ 'patCallNo': '1号', 'patName': '患*者' }],
             'waitPat': [
               { 'patCallNo': '复01', 'patName': '患*者1' },
+              { 'patCallNo': '复1', 'patName': '患*者2' },
+              { 'patCallNo': '01', 'patName': '患*者3' },
+              { 'patCallNo': '复1', 'patName': '患*者4' },
             ],
             'reWaitPat': [
               { 'patCallNo': '复01', 'patName': '患*者1' },