Pārlūkot izejas kodu

Merge branch 'dev' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into dev

xujing 5 gadus atpakaļ
vecāks
revīzija
c268269255
1 mainītis faili ar 166 papildinājumiem un 162 dzēšanām
  1. 166
    162
      src/app.js

+ 166
- 162
src/app.js Parādīt failu

@@ -1,49 +1,42 @@
1
-import '@tarojs/async-await'
2
-import Taro, { Component } from '@tarojs/taro'
3
-import './app.scss'
1
+import "@tarojs/async-await";
2
+import Taro, { Component } from "@tarojs/taro";
3
+import "./app.scss";
4 4
 import "@/styles/icon.scss";
5 5
 import "@/components/wxParse/wxParse.scss";
6
-import Index from './pages/auth/index'
7
-import { Provider } from '@tarojs/redux'
8
-import { parseQueryString } from '@/utils/tools'
9
-import { trackUserSource } from '@/utils/track'
10
-import { getCardDetail } from '@/services/card'
6
+import Index from "./pages/auth/index";
7
+import { Provider } from "@tarojs/redux";
8
+import { parseQueryString } from "@/utils/tools";
9
+import { trackUserSource } from "@/utils/track";
10
+import { getCardDetail } from "@/services/card";
11 11
 
12 12
 import {
13 13
   getCodeScene,
14 14
   savePoint,
15 15
   queryCityList,
16
-  getPreloadData,
17
-} from '@/services/common'
16
+  getPreloadData
17
+} from "@/services/common";
18 18
 
19
-import {
20
-  queryUserInfo
21
-} from '@/services/user'
19
+import { queryUserInfo } from "@/services/user";
22 20
 
23
-import {
24
-  CITY_LIST
25
-} from '@/constants/city'
26
-import {
27
-  ASSIGN_UNREADNUM,
28
-  INCREASE_UNREADNUM
29
-} from '@/constants/user'
30
-import { UPDATE_PRELOAD, SYNC_SYSTEMINFO } from '@/constants/common'
31
-import ready from '@/utils/ready'
32
-import login from '@/utils/login'
33
-import store from './store'
34
-import socket from '@/utils/im'
21
+import { CITY_LIST } from "@/constants/city";
22
+import { ASSIGN_UNREADNUM, INCREASE_UNREADNUM } from "@/constants/user";
23
+import { UPDATE_PRELOAD, SYNC_SYSTEMINFO } from "@/constants/common";
24
+import ready from "@/utils/ready";
25
+import login from "@/utils/login";
26
+import store from "./store";
27
+import socket from "@/utils/im";
35 28
 
36 29
 // const store = configStore()
37 30
 
38 31
 // for dev
39
-global.store = store
32
+global.store = store;
40 33
 
41 34
 class App extends Component {
42 35
   config = {
43
-    debug: process.env.NODE_ENV === 'development',
36
+    debug: process.env.NODE_ENV === "development",
44 37
     permission: {
45 38
       "scope.userLocation": {
46
-        "desc": "你的位置信息将用于显示当前区域信息"
39
+        desc: "你的位置信息将用于显示当前区域信息"
47 40
       }
48 41
     },
49 42
     navigateToMiniProgramAppIdList: [
@@ -52,7 +45,7 @@ class App extends Component {
52 45
       "wx74767bf0b684f7d3",
53 46
       "wx6fa58869f7b65e7f",
54 47
       "wxc4f812079fc9ff0d",
55
-      "wx60d176f873ca2d67",
48
+      "wx60d176f873ca2d67"
56 49
     ],
57 50
     // eslint-disable-next-line no-undef
58 51
     pages: preval`
@@ -65,82 +58,82 @@ class App extends Component {
65 58
       module.exports = getPages().subPackages
66 59
     `,
67 60
     window: {
68
-      backgroundTextStyle: 'light',
69
-      navigationBarBackgroundColor: '#BB9C79',
70
-      navigationBarTitleText: '',
71
-      navigationBarTextStyle: 'white',
61
+      backgroundTextStyle: "light",
62
+      navigationBarBackgroundColor: "#BB9C79",
63
+      navigationBarTitleText: "",
64
+      navigationBarTextStyle: "white"
72 65
       // navigationStyle:'custom'
73 66
     },
74 67
     tabBar: {
75
-      color: '#666',
76
-      selectedColor: '#BB9C79',
68
+      color: "#666",
69
+      selectedColor: "#BB9C79",
77 70
 
78 71
       list: [
79 72
         {
80 73
           pagePath: "pages/project/index",
81 74
           text: "首页",
82
-          iconPath: './assets/tabbar/index1.png',
83
-          selectedIconPath: './assets/tabbar/index2.png',
75
+          iconPath: "./assets/tabbar/index1.png",
76
+          selectedIconPath: "./assets/tabbar/index2.png"
84 77
         },
85 78
         {
86 79
           pagePath: "pages/shop/index",
87 80
           text: "赚好礼",
88
-          iconPath: './assets/tabbar/shop1.png',
89
-          selectedIconPath: './assets/tabbar/shop2.png',
81
+          iconPath: "./assets/tabbar/shop1.png",
82
+          selectedIconPath: "./assets/tabbar/shop2.png"
90 83
         },
91 84
         {
92 85
           pagePath: "pages/activity/activity",
93 86
           text: "活动资讯",
94
-          iconPath: './assets/tabbar/activity1.png',
95
-          selectedIconPath: './assets/tabbar/activity2.png',
87
+          iconPath: "./assets/tabbar/activity1.png",
88
+          selectedIconPath: "./assets/tabbar/activity2.png"
96 89
         },
97 90
         {
98 91
           pagePath: "pages/person/index",
99 92
           text: "我的地盘",
100
-          iconPath: './assets/tabbar/mine1.png',
101
-          selectedIconPath: './assets/tabbar/mine2.png',
93
+          iconPath: "./assets/tabbar/mine1.png",
94
+          selectedIconPath: "./assets/tabbar/mine2.png"
102 95
         }
103 96
       ]
104 97
     },
105
-  }
98
+    restartStrategy: "homePageAndLatestPage"
99
+  };
106 100
 
107 101
   // 更新埋点时长
108 102
   updateTrack;
109 103
 
110 104
   componentDidHide() {
111 105
     if (this.updateTrack) {
112
-      this.updateTrack()
113
-      this.updateTrack = undefined
106
+      this.updateTrack();
107
+      this.updateTrack = undefined;
114 108
     }
115 109
 
116 110
     // ready.close()
117
-    socket.closeSocket()
111
+    socket.closeSocket();
118 112
   }
119 113
 
120 114
   componentDidShow() {
121
-
122
-    const updateManager = wx.getUpdateManager()
123
-    updateManager.onCheckForUpdate(function (res) {
115
+    const updateManager = wx.getUpdateManager();
116
+    updateManager.onCheckForUpdate(function(res) {
124 117
       // 请求完新版本信息的回调
125
-      console.info('新版本是否更新:', res.hasUpdate)
126
-    })
118
+      console.info("新版本是否更新:", res.hasUpdate);
119
+    });
127 120
 
128
-    updateManager.onUpdateReady(function () {
121
+    updateManager.onUpdateReady(function() {
129 122
       wx.showModal({
130
-        title: '更新提示',
131
-        content: '新版本已经准备好,是否重启应用?',
123
+        title: "更新提示",
124
+        content: "新版本已经准备好,是否重启应用?",
132 125
         success(res) {
133 126
           if (res.confirm) {
134 127
             // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
135
-            updateManager.applyUpdate()
128
+            updateManager.applyUpdate();
136 129
           }
137 130
         }
138
-      })
139
-    })
131
+      });
132
+    });
140 133
 
141
-    socket.reconnect()
134
+    socket.reconnect();
142 135
 
143
-    this.initData()
136
+    this.initData();
144 137
   }
145 138
 
146 139
   componentDidMount() {
@@ -149,17 +142,17 @@ class App extends Component {
149 142
 
150 143
   componentWillMount() {
151 144
     // 预加载数据
152
-    this.wxPreloadData()
145
+    this.wxPreloadData();
153 146
 
154 147
     // 获取系统信息
155 148
     wx.getSystemInfo({
156
-      success: (res) => {
149
+      success: res => {
157 150
         store.dispatch({
158 151
           type: SYNC_SYSTEMINFO,
159
-          payload: res,
160
-        })
152
+          payload: res
153
+        });
161 154
       }
162
-    })
155
+    });
163 156
 
164 157
     // console.info('app componentWillMount', params)
165 158
     // this.initData()
@@ -167,8 +160,8 @@ class App extends Component {
167 160
 
168 161
   componentWillUnmount() {
169 162
     if (this.updateTrack) {
170
-      this.updateTrack()
171
-      this.updateTrack = undefined
163
+      this.updateTrack();
164
+      this.updateTrack = undefined;
172 165
     }
173 166
     // this.initData()
174 167
   }
@@ -186,112 +179,124 @@ class App extends Component {
186 179
     // })
187 180
     // wx.setBackgroundFetchToken()
188 181
     wx.getBackgroundFetchData({
189
-      fetchType: 'pre',
190
-      success: (res) => {
191
-        console.log('[preload]: ', res)
182
+      fetchType: "pre",
183
+      success: res => {
184
+        console.log("[preload]: ", res);
192 185
         // store.dispatch({
193 186
         //   type: UPDATE_PRELOAD,
194 187
         //   payload: res.fetchedData,
195 188
         // })
196 189
       }
197
-    })
190
+    });
198 191
   }
199 192
 
200
-  _mounted = false
193
+  _mounted = false;
201 194
 
202 195
   initData() {
203
-    console.info('router1', this.$router)
204
-    console.info('ready status1', ready)
205
-    const enterOptions = wx.getEnterOptionsSync()
206
-    console.log(enterOptions, "enterOptionsenterOptionsenterOptionsenterOptionsenterOptions")
207
-
208
-    if (Object.keys(enterOptions.query).indexOf('recommender') > -1) {
209
-      Taro.setStorageSync('recommender', enterOptions.query.recommender)
210
-      Taro.setStorageSync('consultantId', enterOptions.query.consultant)
211
-    }
196
+    console.info("router1", this.$router);
197
+    console.info("ready status1", ready);
198
+    // 清空全局置业顾问Id
199
+    Taro.removeStorageSync("consultantId");
200
+
212 201
     // 获取城市列表
213 202
     // queryCityList().then(payload => {
214 203
     //   store.dispatch({ type: CITY_LIST, payload })
215 204
     // })
216 205
 
217
-    this.getLocation().then((loc) => {
206
+    this.getLocation().then(loc => {
218 207
       // 获取router参数
219 208
       this.getRouterParams().then(router => {
220
-        Taro.setStorageSync('router', router)
221
-        console.info('router2:', JSON.stringify(router))
222
-        console.info('-----------')
223
-        const { query: payload } = router
209
+        Taro.setStorageSync("router", router);
210
+        console.info("router2:", router);
211
+        console.info("-----------");
212
+        const { query: payload } = router;
224 213
 
225
-        payload.path = router.path
226
-        payload.scene = router.scene
214
+        payload.path = router.path;
215
+        payload.scene = router.scene;
227 216
 
228 217
         if (loc) {
229
-          payload.lon = loc.lon
230
-          payload.lat = loc.lat
218
+          payload.lon = loc.lon;
219
+          payload.lat = loc.lat;
231 220
         }
232 221
 
233 222
         // login
234 223
         login(payload, res => {
235 224
           // 清空本地缓存
236 225
           if (!this._mounted) {
237
-
238
-            Taro.removeStorageSync('activityPageIndex')
239
-            Taro.removeStorageSync('newsPageIndex')
240
-            Taro.removeStorageSync('buildingPageIndex')
241
-            Taro.removeStorageSync('followPageIndex')
242
-            Taro.removeStorageSync('clinchPageIndex')
226
+            Taro.removeStorageSync("activityPageIndex");
227
+            Taro.removeStorageSync("newsPageIndex");
228
+            Taro.removeStorageSync("buildingPageIndex");
229
+            Taro.removeStorageSync("followPageIndex");
230
+            Taro.removeStorageSync("clinchPageIndex");
243 231
             // Taro.removeStorageSync('extendContent')
244
-            Taro.setStorageSync('extendContent', [])
245
-            // Taro.setStorageSync('recommender', payload.recommender)
246
-            // Taro.setStorageSync('consultantId', payload.consultant)
232
+            Taro.setStorageSync("extendContent", []);
247 233
             // 获取分享人
248
-            this._mounted = true
234
+            this._mounted = true;
249 235
           }
250
-          console.log(payload, "payloadpayloadpayloadpayloadpayloadpayloadpayload啦啦啦啦啦")
251
-
252 236
 
237
+          console.log(
238
+            payload,
239
+            "payloadpayloadpayloadpayloadpayloadpayloadpayload啦啦啦啦啦"
240
+          );
241
+          Taro.setStorageSync("recommender", payload.recommender);
242
+          Taro.setStorageSync("consultantId", payload.consultant);
253 243
 
254 244
           // 获取未读消息
255
-          const { person: { personId } } = res
245
+          const {
246
+            person: { personId }
247
+          } = res;
256 248
 
257 249
           queryUserInfo(personId).then(info => {
258
-            const { unReadNum } = info
250
+            const { unReadNum } = info;
259 251
             store.dispatch({ type: ASSIGN_UNREADNUM, payload: { unReadNum } });
260 252
             socket.createSocket({ id: personId });
261 253
             socket.onMessage(data => {
262
-              store.dispatch({ type: INCREASE_UNREADNUM })
263
-            })
264
-          })
254
+              store.dispatch({ type: INCREASE_UNREADNUM });
255
+            });
256
+          });
265 257
           // 埋点
266 258
           // const t = setTimeout(() => {
267
-          trackUserSource(this.$router.params).then(res => this.updateTrack = res)
259
+          trackUserSource(this.$router.params).then(
260
+            res => (this.updateTrack = res)
261
+          );
268 262
 
269 263
           // }, 1000)
270
-        })
271
-      })
272
-    })
264
+        });
265
+      });
266
+    });
273 267
   }
274 268
 
275
-
276 269
   getRouterParams() {
277 270
     return new Promise(resolve => {
278
-      console.log('------getRouterParams------>', this.$router)
279
-      const router = this.$router.params
271
+      console.log("------getRouterParams------>", this.$router);
272
+      const router = this.$router.params;
280 273
       const originQuery = { ...router.query };
281
-      let { query: { scene: paramsId, consultant }, scene } = router
274
+      let {
275
+        query: { scene: paramsId, consultant },
276
+        scene
277
+      } = router;
282 278
 
283 279
       // query 里面如果跟同级场景一样, 说明是小程序原生场景值
284 280
       if (paramsId === scene) {
285
-        paramsId = undefined
281
+        paramsId = undefined;
286 282
       }
287 283
 
288 284
       if (paramsId) {
289 285
         // 扫码进入
290 286
         getCodeScene(paramsId).then(res => {
291
-          let params = JSON.parse(res).scene
292
-          console.log(params, "paramsparamsparamsparamsparamsparamsparamsparamsparamsparams")
287
+          let params = JSON.parse(res).scene;
288
+          console.log(
289
+            params,
290
+            "paramsparamsparamsparamsparamsparamsparamsparamsparamsparams"
291
+          );
293 292
 
294
-          let { from: _from, recommender: _recommender, consultant, id, ...left } = parseQueryString(params) || {}
293
+          let {
294
+            from: _from,
295
+            recommender: _recommender,
296
+            consultant,
297
+            id,
298
+            ...left
299
+          } = parseQueryString(params) || {};
295 300
 
296 301
           router.query = Object.assign(router.query, {
297 302
             originQuery,
@@ -302,55 +307,54 @@ class App extends Component {
302 307
             consultant,
303 308
             params,
304 309
             targetId: id,
305
-            ...left,
306
-          })
307
-          Taro.setStorageSync('recommender', router.query.recommender)
308
-          Taro.setStorageSync('consultantId', router.query.consultant)
309
-          resolve(router)
310
-        })
311
-      } else {
310
+            ...left
311
+          });
312 312
 
313
+          resolve(router);
314
+        });
315
+      } else {
313 316
         router.query = Object.assign(router.query, {
314 317
           originQuery,
315
-          paramsId: router.query.id || '',
316
-          from: router.query.from || 'search',
317
-          recommender: router.query.recommender || '',
318
-          targetId: router.query.id || '',
319
-          consultant: router.query.consultant || '',
320
-        })
321
-
322
-        resolve(router)
318
+          paramsId: router.query.id || "",
319
+          from: router.query.from || "search",
320
+          recommender: router.query.recommender || "",
321
+          targetId: router.query.id || "",
322
+          consultant: router.query.consultant || ""
323
+        });
324
+
325
+        resolve(router);
323 326
       }
324
-
325
-    })
327
+    });
326 328
   }
327 329
 
328 330
   getLocation() {
329
-    return new Promise((resolve) => {
330
-      Taro.getLocation().then(location => {
331
-        Taro.setStorageSync('lat', location.latitude)
332
-        Taro.setStorageSync('lon', location.longitude)
333
-
334
-        resolve({ lon: location.longitude, lat: location.latitude })
335
-      }).catch(err => {
336
-        if (err.errMsg === 'getLocation:fail auth deny') {
337
-          Taro.showModal({
338
-            content: '请同意授权您的定位功能',
339
-            showCancel: false,
340
-            duration: 3000,
341
-          })
342
-        } else {
343
-          Taro.showToast({
344
-            title: `定位失败, 请手动选择城市: ${err.errMsg}`,
345
-            icon: 'none',
346
-            duration: 3000,
347
-          })
348
-        }
331
+    return new Promise(resolve => {
332
+      Taro.getLocation()
333
+        .then(location => {
334
+          Taro.setStorageSync("lat", location.latitude);
335
+          Taro.setStorageSync("lon", location.longitude);
336
+
337
+          resolve({ lon: location.longitude, lat: location.latitude });
338
+        })
339
+        .catch(err => {
340
+          if (err.errMsg === "getLocation:fail auth deny") {
341
+            Taro.showModal({
342
+              content: "请同意授权您的定位功能",
343
+              showCancel: false,
344
+              duration: 3000
345
+            });
346
+          } else {
347
+            Taro.showToast({
348
+              title: `定位失败, 请手动选择城市: ${err.errMsg}`,
349
+              icon: "none",
350
+              duration: 3000
351
+            });
352
+          }
349 353
 
350
-        console.error(err)
351
-        resolve()
352
-      })
353
-    })
354
+          console.error(err);
355
+          resolve();
356
+        });
357
+    });
354 358
   }
355 359
 
356 360
   // 在 App 类中的 render() 函数没有实际作用
@@ -360,8 +364,8 @@ class App extends Component {
360 364
       <Provider store={store}>
361 365
         <Index />
362 366
       </Provider>
363
-    )
367
+    );
364 368
   }
365 369
 }
366 370
 
367
-Taro.render(<App />, document.getElementById('app'))
371
+Taro.render(<App />, document.getElementById("app"));