xcx před 4 roky
rodič
revize
ba07948e84
2 změnil soubory, kde provedl 22 přidání a 11 odebrání
  1. 11
    10
      src/app.js
  2. 11
    1
      src/utils/request.js

+ 11
- 10
src/app.js Zobrazit soubor

@@ -18,18 +18,19 @@ class App extends Component {
18 18
     // 此处获取不到 state, 因为 app 不会刷新
19 19
     const { setSysInfo } = store.getModel('sys').getState()
20 20
 
21
-    // 预拉取数据
22
-    Taro.getBackgroundFetchData({
23
-      fetchType: 'pre',
24
-      success (res) {
25
-        if (res.errMsg === 'getBackgroundFetchData:ok') {
26
-          const data = JSON.parse(res.fetchedData)
27
-          if (data.code === 1000) {
28
-            setSysInfo(data.data)
21
+    if (Taro.getBackgroundFetchData) { // 预拉取数据
22
+      Taro.getBackgroundFetchData({
23
+        fetchType: 'pre',
24
+        success (res) {
25
+          if (res.errMsg === 'getBackgroundFetchData:ok') {
26
+            const data = JSON.parse(res.fetchedData)
27
+            if (data.code === 1000) {
28
+              setSysInfo(data.data)
29
+            }
29 30
           }
30 31
         }
31
-      }
32
-    })
32
+      })
33
+    }
33 34
   }
34 35
 
35 36
   onError (err) {

+ 11
- 1
src/utils/request.js Zobrazit soubor

@@ -5,8 +5,18 @@ import $api from './api'
5 5
 const accountInfo = Taro.getAccountInfoSync()
6 6
 const appId = accountInfo.miniProgram.appId
7 7
 
8
+const entries = obj => {
9
+  const ownProps = Object.keys( obj )
10
+  let i = ownProps.length
11
+  const resArray = new Array(i)
12
+  while (i--)
13
+    resArray[i] = [ownProps[i], obj[ownProps[i]]]
14
+
15
+  return resArray
16
+}
17
+
8 18
 const query2String = query => {
9
-  return Object.entries(query || {}).map(pair => `${encodeURIComponent(pair[0])}=${encodeURIComponent(pair[1])}`).join('&')
19
+  return entries(query || {}).map(pair => `${encodeURIComponent(pair[0])}=${encodeURIComponent(pair[1])}`).join('&')
10 20
 }
11 21
 
12 22
 const transPathArgs = (path, args) => {