xcx 4 年 前
コミット
3f04ec16d7
共有1 個のファイルを変更した17 個の追加9 個の削除を含む
  1. 17
    9
      src/pages/ShouYe/index.jsx

+ 17
- 9
src/pages/ShouYe/index.jsx ファイルの表示

@@ -47,9 +47,17 @@ export default function Index (props) {
47 47
 
48 48
   useEffect(() => {
49 49
     if (NoticeInfo !== null) {
50
-      window.setTimeout(() => {
51
-        let QueryParent = Taro.createSelectorQuery()
52
-        let QueryChild = Taro.createSelectorQuery()
50
+      let WidthTimer = null
51
+      CalcWidth(WidthTimer)
52
+    }
53
+  }, [NoticeInfo])
54
+
55
+  const CalcWidth = (timer = null) => {
56
+    timer = setTimeout(() => {
57
+      let QueryParent = Taro.createSelectorQuery()
58
+      let QueryChild = Taro.createSelectorQuery()
59
+      if (QueryParent.select('#NoticeParent')) {
60
+        clearTimeout(timer)
53 61
         QueryParent.select('#NoticeParent').boundingClientRect()
54 62
         QueryChild.select('#NoticeText').boundingClientRect()
55 63
         QueryParent.exec((res) => {
@@ -58,11 +66,11 @@ export default function Index (props) {
58 66
             setNoticeWidth(cres[0].width)
59 67
           })
60 68
         })
61
-      }, 100)
62
-      // let NoticeText = document.getElementById('NoticeText')
63
-      // console.log(NoticeText.boundingClientRect[0].width)
64
-    }
65
-  }, [NoticeInfo])
69
+      } else {
70
+        CalcWidth(timer)
71
+      }
72
+    }, 100)
73
+  }
66 74
 
67 75
   const Init = (done = () => { }) => { // 初始化
68 76
     GetNotice() // 获取通知
@@ -203,7 +211,7 @@ export default function Index (props) {
203 211
                 <view>
204 212
 
205 213
                   {/* 通知栏 */}
206
-                  <view className='NoticeContent' style={{display: ShowNotice ? 'block' : 'none'}}>
214
+                  <view className='NoticeContent' style={{ display: ShowNotice ? 'block' : 'none' }}>
207 215
                     <view className='flex-h'>
208 216
                       <text className='iconfont icontongzhi1'></text>
209 217
                       <view id='NoticeParent' className='flex-item' onClick={() => { Taro.navigateTo({ url: `/pages/WuYe/GongGaoDetail/index?id=${NoticeInfo.id}` }) }}>