Browse Source

Merge branch 'master' of http://git.ycjcjy.com/xiangsong/miniapp

张延森 4 years ago
parent
commit
0fbd506dae
2 changed files with 26 additions and 14 deletions
  1. 9
    5
      src/app.js
  2. 17
    9
      src/pages/ShouYe/index.jsx

+ 9
- 5
src/app.js View File

@@ -1,7 +1,7 @@
1 1
 import React, { Component } from 'react'
2 2
 import Taro, { getCurrentInstance } from '@tarojs/taro'
3 3
 import { StoreRoot, store } from './store'
4
-import { deepCopy } from './utils'
4
+// import { deepCopy } from './utils'
5 5
 import request, { apis } from './utils/request'
6 6
 import { trackUserSource } from './utils/track'
7 7
 import * as log from './utils/rtLog'
@@ -10,12 +10,16 @@ import './app.less'
10 10
 class App extends Component {
11 11
   updateTracing;
12 12
 
13
-  onLaunch (options) {
13
+  onLaunch () {
14
+
15
+    Taro.setEnableDebug({
16
+      enableDebug: true
17
+    })
14 18
     // 此处获取不到 state, 因为 app 不会刷新
15 19
     const { setSysInfo } = store.getModel('sys').getState()
16 20
 
17 21
     // 预拉取数据
18
-    wx.getBackgroundFetchData({
22
+    Taro.getBackgroundFetchData({
19 23
       fetchType: 'pre',
20 24
       success (res) {
21 25
         if (res.errMsg === 'getBackgroundFetchData:ok') {
@@ -44,14 +48,14 @@ class App extends Component {
44 48
     // scene 与其它参数时互斥的. 有 scene 说明时扫码进来的
45 49
     const params = router.params || {}
46 50
     const { from = '', recommender = '', scene = '', mpOpenId = '' } = params
47
-    setAppParams({...params})
51
+    setAppParams({ ...params })
48 52
 
49 53
     // 登录
50 54
     Taro.login({
51 55
       success: res => {
52 56
         if (res.errMsg === 'login:ok') {
53 57
           request({ ...apis.login, params: { code: res.code, from, recommender, scene, mpOpenId } }).then(x => {
54
-            setUser({...x.person, ShowIndexAdv: false, FirstComing: true})
58
+            setUser({ ...x.person, ShowIndexAdv: false, FirstComing: true })
55 59
             Taro.setStorage({ key: 'token', data: x.token })
56 60
             Taro.setStorage({ key: 'sessionKey', data: x.sessionKey })
57 61
 

+ 17
- 9
src/pages/ShouYe/index.jsx View File

@@ -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}` }) }}>