Yansen 5 lat temu
rodzic
commit
94badb463c
1 zmienionych plików z 163 dodań i 154 usunięć
  1. 163
    154
      src/app.js

+ 163
- 154
src/app.js Wyświetl plik

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