张延森 5 vuotta sitten
vanhempi
commit
39f49f91db

+ 4
- 4
config/dev.js Näytä tiedosto

@@ -5,12 +5,12 @@ module.exports = {
5 5
   defineConstants: {
6 6
     // HOST: '"http://47.101.36.130:8085"',//测试
7 7
     // WSS_HOST: '"wss://47.101.36.130:8085"',
8
-    HOST: '"https://dev.jinchengjiaye.com"',//测试
9
-    WSS_HOST: '"wss://dev.jinchengjiaye.com"',
8
+    // HOST: '"https://dev.jinchengjiaye.com"',//测试
9
+    // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10 10
     // HOST: '"https://lt.pawoma.cn"',
11 11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
12
-    // HOST: '"http://192.168.2.51:8080"',
13
-    // WSS_HOST: '"ws://192.168.2.51:8080"',
12
+    HOST: '"http://127.0.0.1:8080"',
13
+    WSS_HOST: '"ws://127.0.0.1:8080"',
14 14
     Version: 'V3.5.6'
15 15
   },
16 16
   weapp: {},

+ 2
- 2
project.config.json Näytä tiedosto

@@ -1,8 +1,8 @@
1 1
 {
2 2
 	"miniprogramRoot": "dist/",
3 3
 	"projectname": "mini-chengjiao",
4
-	"description": "知与行联调",
5
-	"appid": "wxd9ee3a9480a4e544",
4
+	"description": "知与行互动",
5
+	"appid": "wxd6f47a9bb3052175",
6 6
 	"setting": {
7 7
 		"urlCheck": false,
8 8
 		"es6": false,

+ 12
- 1
src/actions/project.js Näytä tiedosto

@@ -7,7 +7,8 @@ import {
7 7
 import {
8 8
   API_ITEMS_DETAIL,
9 9
   API_ITEMS_LIST,
10
-  API_BANNER_LIST
10
+  API_BANNER_LIST,
11
+  API_INDEX_PROJECTS,
11 12
 } from '@/constants/api'
12 13
 
13 14
 import { createAction } from '@/utils/redux'
@@ -23,6 +24,16 @@ export const dispatchProjectList = payload => createAction({
23 24
   payload
24 25
 })
25 26
 
27
+/**
28
+ * 获取楼盘列表
29
+ * @param {*} payload 
30
+ */
31
+export const dispatchIndexProjects = payload => createAction({
32
+  url: `${API_INDEX_PROJECTS}`,
33
+  type: PROJECT_LIST,
34
+  payload
35
+})
36
+
26 37
 
27 38
 /**
28 39
  * 获取项目信息

+ 96
- 44
src/app.js Näytä tiedosto

@@ -11,7 +11,8 @@ import { trackUserSource } from '@/utils/track'
11 11
 import {
12 12
   getCodeScene,
13 13
   savePoint,
14
-  queryCityList
14
+  queryCityList,
15
+  getPreloadData,
15 16
 } from '@/services/common'
16 17
 
17 18
 import {
@@ -158,6 +159,7 @@ class App extends Component {
158 159
   componentDidHide() {
159 160
     if (this.updateTrack) {
160 161
       this.updateTrack()
162
+      this.updateTrack = undefined
161 163
     }
162 164
 
163 165
     // ready.close()
@@ -166,7 +168,10 @@ class App extends Component {
166 168
 
167 169
   componentDidShow() {
168 170
     // 埋点
169
-    trackUserSource(this.$router.params).then(res => this.updateTrack = res)
171
+    const t = setTimeout(() => {
172
+      trackUserSource(this.$router.params).then(res => this.updateTrack = res)
173
+      clearTimeout(t)
174
+    }, 1000)
170 175
 
171 176
     const updateManager = wx.getUpdateManager()
172 177
     updateManager.onCheckForUpdate(function (res) {
@@ -189,7 +194,7 @@ class App extends Component {
189 194
 
190 195
     socket.reconnect()
191 196
   }
192
-  
197
+
193 198
   componentDidMount() {
194 199
     // console.info('app componentDidMount')
195 200
   }
@@ -202,18 +207,35 @@ class App extends Component {
202 207
     this.initData()
203 208
   }
204 209
 
210
+  componentWillUnmount() {
211
+    if (this.updateTrack) {
212
+      this.updateTrack()
213
+      this.updateTrack = undefined
214
+    }
215
+  }
216
+
205 217
   wxPreloadData () {
206
-    wx.setBackgroundFetchToken()
207
-    wx.getBackgroundFetchData({
208
-      fetchType: 'pre',
209
-      success: (res) => {
210
-        console.log('[preload]: ', res)
211
-        store.dispatch({
212
-          type: UPDATE_PRELOAD,
213
-          payload: res.fetchedData,
214
-        })
215
-      }
216
-    })
218
+    // getPreloadData({
219
+    //   appid: wx.getAccountInfoSync().miniProgram.appId,
220
+    //   timestamp: (new Date).valueOf(),
221
+    // }).then((res) => {
222
+    //   console.log('[preload]: ', res)
223
+    //   store.dispatch({
224
+    //     type: UPDATE_PRELOAD,
225
+    //     payload: res,
226
+    //   })
227
+    // })
228
+    // wx.setBackgroundFetchToken()
229
+    // wx.getBackgroundFetchData({
230
+    //   fetchType: 'pre',
231
+    //   success: (res) => {
232
+    //     console.log('[preload]: ', res)
233
+    //     store.dispatch({
234
+    //       type: UPDATE_PRELOAD,
235
+    //       payload: res.fetchedData,
236
+    //     })
237
+    //   }
238
+    // })
217 239
   }
218 240
 
219 241
   initData () {
@@ -222,39 +244,40 @@ class App extends Component {
222 244
     console.info('ready status1', ready)
223 245
 
224 246
     // 获取城市列表
225
-    queryCityList().then(payload => {
226
-      store.dispatch({ type: CITY_LIST, payload })
227
-    })
247
+    // queryCityList().then(payload => {
248
+    //   store.dispatch({ type: CITY_LIST, payload })
249
+    // })
250
+
251
+    this.getLocation().then((loc) => {
252
+      // 获取router参数
253
+      this.getRouterParams().then(router => {
254
+        Taro.setStorageSync('router', router)
255
+        console.info('router2:', router)
256
+        console.info('-----------')
257
+        const { query: payload } = router
258
+
259
+        payload.path = router.path
260
+        payload.scene = router.scene
261
+
262
+        if (loc) {
263
+          payload.lon = loc.lon
264
+          payload.lat = loc.lat
265
+        }
228 266
 
229
-    // 获取router参数
230
-    this.getRouterParams().then(router => {
231
-      Taro.setStorageSync('router', router)
232
-      console.info('router2:', router)
233
-      console.info('-----------')
234
-      const { query: payload } = router
235
-
236
-      payload.path = router.path
237
-      payload.scene = router.scene
238
-
239
-      // login
240
-      login(payload, res => {
241
-        // 获取未读消息
242
-        const { person: { personId } } = res
243
-        queryUserInfo(personId).then(info => {
244
-          const { unReadNum } = info
245
-          store.dispatch({ type: ASSIGN_UNREADNUM, payload: { unReadNum } });
246
-          socket.createSocket({ id: personId });
247
-          socket.wss.onMessage(data => {
248
-            store.dispatch({ type: INCREASE_UNREADNUM })
267
+        // login
268
+        login(payload, res => {
269
+          // 获取未读消息
270
+          const { person: { personId } } = res
271
+
272
+          queryUserInfo(personId).then(info => {
273
+            const { unReadNum } = info
274
+            store.dispatch({ type: ASSIGN_UNREADNUM, payload: { unReadNum } });
275
+            socket.createSocket({ id: personId });
276
+            socket.wss.onMessage(data => {
277
+              store.dispatch({ type: INCREASE_UNREADNUM })
278
+            })
249 279
           })
250 280
         })
251
-
252
-        const data = Object.assign({}, payload, {
253
-          event: 'start',
254
-          propertyName: '进入小程序',
255
-          data: ''
256
-        })
257
-        savePoint(data)
258 281
       })
259 282
     })
260 283
   }
@@ -303,6 +326,35 @@ class App extends Component {
303 326
       
304 327
     })
305 328
   }
329
+
330
+  getLocation() {
331
+    return new Promise((resolve) => {
332
+      Taro.getLocation().then(location => {
333
+        Taro.setStorageSync('lat', location.latitude)
334
+        Taro.setStorageSync('lon', location.longitude)
335
+
336
+        resolve({lon: location.longitude, lat: location.latitude})
337
+      }).catch(err => {
338
+        if (err.errMsg === 'getLocation:fail auth deny') {
339
+          Taro.showModal({
340
+            content: '请同意授权您的定位功能',
341
+            showCancel: false,
342
+            duration: 3000,
343
+          })
344
+        } else {
345
+          Taro.showToast({
346
+            title: `定位失败, 请手动选择城市: ${err.errMsg}`,
347
+            icon: 'none',
348
+            duration: 3000,
349
+          })
350
+        }
351
+
352
+        console.error(err)
353
+        resolve()
354
+      })
355
+    })
356
+  }
357
+
306 358
   // 在 App 类中的 render() 函数没有实际作用
307 359
   // 请勿修改此函数
308 360
   render() {

+ 2
- 0
src/constants/api.js Näytä tiedosto

@@ -13,6 +13,7 @@ export const pathname = '/api/wx'
13 13
 const resolvePath = api => `${host + pathname}/${api}`
14 14
 
15 15
 // common
16
+export const API_PRELOAD = resolvePath('preload')
16 17
 export const API_QRCODE = resolvePath('qrcode')
17 18
 export const API_BANNER_LIST = resolvePath('extendContent')
18 19
 export const API_QUERY_CODE_SCENE = resolvePath('qrcode/scene')
@@ -51,6 +52,7 @@ export const API_ITEMS_TYPE = resolvePath('tdBuildingType')
51 52
 export const API_ACTIVITY_GROUP = resolvePath('helpActivityAndGroup')
52 53
 export const API_LOCATION_CITYP = resolvePath('location/city')
53 54
 export const API_TACUSTOMIMG = resolvePath('taCustomImg')
55
+export const API_INDEX_PROJECTS = resolvePath('building/main')
54 56
 // /wx/location/city?location=lon,lat
55 57
 
56 58
 

+ 19
- 17
src/pages/city/index.js Näytä tiedosto

@@ -3,8 +3,8 @@ import { connect } from '@tarojs/redux'
3 3
 import * as actions from '@/actions/city'
4 4
 import { ScrollView } from '@tarojs/components';
5 5
 import './index.scss'
6
-
7 6
 import Search from '@/components/search'
7
+import { queryCityList } from '@/services/common'
8 8
 
9 9
 @connect(state => state.city, { ...actions })
10 10
 export default class Index extends Component {
@@ -20,24 +20,26 @@ export default class Index extends Component {
20 20
   }
21 21
 
22 22
   componentWillMount() {
23
+
23 24
     this.initData()
24 25
     console.log(this.props,"this.props.citylist")
25 26
   }
26 27
 
27 28
   initData() {
28
-    const { cityList } = this.props
29
-    const list = cityList.reduce((prev, cur) => {
30
-      if (prev[cur.initial]) {
31
-        prev[cur.initial].push(cur)
32
-      } else {
33
-        prev[cur.initial] = [cur]
34
-      }
35
-
36
-      return prev
37
-    }, {})
38
-
39
-    this.setState({
40
-      list
29
+    queryCityList().then(cityList => {
30
+      const list = cityList.reduce((prev, cur) => {
31
+        if (prev[cur.initial]) {
32
+          prev[cur.initial].push(cur)
33
+        } else {
34
+          prev[cur.initial] = [cur]
35
+        }
36
+  
37
+        return prev
38
+      }, {})
39
+  
40
+      this.setState({
41
+        list
42
+      })
41 43
     })
42 44
   }
43 45
  
@@ -50,10 +52,10 @@ export default class Index extends Component {
50 52
   }
51 53
 
52 54
   handleSearch = (keywords) => {
53
-    const { cityList } = this.props
55
+    const { list } = this.state
56
+
57
+    const searchList = list.filter(item => (item.name.includes(keywords)))
54 58
 
55
-    const searchList = cityList.filter(item => (item.name.includes(keywords)))
56
-    console.log(searchList, "-----------searchList----------")
57 59
     this.setState({
58 60
       searchList,
59 61
       keywords

+ 101
- 128
src/pages/project/index.js Näytä tiedosto

@@ -8,7 +8,7 @@ import BannerTwo from './swiper'
8 8
 // import ActivityItem from '../activity/item'
9 9
 import ready from '@/utils/ready'
10 10
 import { getLocationCity } from '@/services/map'
11
-import { queryBanners, savePoint, updatePoint } from '@/services/common'
11
+import { queryBanners, savePoint, updatePoint, queryExtContents } from '@/services/common'
12 12
 import { queryHelpGroup } from '@/services/news'
13 13
 import { getIndexShare } from '@/services/user'
14 14
 // import { queryActivityList } from '@/services/activity'
@@ -19,11 +19,11 @@ import { getStore, connect } from '@tarojs/redux'
19 19
 import * as actions from '@/actions/project'
20 20
 import { transferImage } from '@/utils/tools'
21 21
 import Notice from '@/components/Notice'
22
-import { getIndexPreloadData } from '@/utils/preload'
22
+// import { getIndexPreloadData } from '@/utils/preload'
23 23
 // import Authorize from '@/components/authorize'
24 24
 // import * as noticeType from '@/constants/common.js'
25 25
 
26
-const { miniProgram: { appId } } = wx.getAccountInfoSync();
26
+// const { miniProgram: { appId } } = wx.getAccountInfoSync();
27 27
 
28 28
 @connect(
29 29
   state => ({ ...state.project, ...state.city, ...state.user, system: state.system }),
@@ -52,16 +52,18 @@ export default class Index extends Component {
52 52
     achieve: false,
53 53
     propagandaBanner: [],
54 54
     newsShow: false,
55
+    city: null,
55 56
   }
56 57
 
57 58
   componentWillMount() {
59
+    Taro.hideTabBar()
60
+
58 61
     ready.queue(() => {
59 62
 
60
-      Taro.hideTabBar()
61
-      this.getLocation()
62
-      this.getIndexShareInfo()
63
+      const city = this.state.city || this.props.curCity
64
+      this.loadData({ curCity: city })
63 65
 
64
-      Taro.setNavigationBarTitle({ title: this.props.userInfo.miniApp.name })
66
+      this.getIndexShareInfo()
65 67
 
66 68
       savePoint({
67 69
         event: 'index',
@@ -76,6 +78,11 @@ export default class Index extends Component {
76 78
       })
77 79
     })
78 80
   }
81
+
82
+  componentDidMount() {
83
+    // Taro.setNavigationBarTitle({ title: this.props.userInfo.miniApp.name })
84
+  }
85
+
79 86
   getIndexShareInfo() {
80 87
     getIndexShare().then(res => {
81 88
 
@@ -96,13 +103,13 @@ export default class Index extends Component {
96 103
     })
97 104
   }
98 105
   componentDidShow() {
106
+    // this.getIndexShareInfo()
99 107
 
100
-    this.getIndexShareInfo()
101
-    if (this.props.curCity.id) {
108
+    const city = this.state.city || this.props.curCity
109
+    if (city && city.id) {
102 110
       ready.queue(() => {
103 111
         // Taro.hideTabBar()
104
-        this.loadData()
105
-
112
+        this.loadData({ curCity: city })
106 113
       })
107 114
     }
108 115
   }
@@ -112,91 +119,93 @@ export default class Index extends Component {
112 119
     recordId && updatePoint(recordId)
113 120
   }
114 121
 
115
-  getLocation() {
116
-    const { cityList, userInfo: { person: { org } } } = this.props
117
-    let defaultCity = cityList.filter(item => {
118
-      return item.id == org.defaultCityId
119
-    })[0]
120
-    // console.log('-----defaultCity-->', defaultCity)
121
-
122
-    Taro.getLocation().then(location => {
123
-      Taro.setStorageSync('lat', location.latitude)
124
-      Taro.setStorageSync('lon', location.longitude)
125
-
126
-      const payload = { location: `${location.longitude},${location.latitude}` }
122
+  // getLocation() {
123
+  //   Taro.getLocation().then(location => {
124
+  //     Taro.setStorageSync('lat', location.latitude)
125
+  //     Taro.setStorageSync('lon', location.longitude)
126
+
127
+  //     const payload = { location: `${location.longitude},${location.latitude}` }
128
+
129
+  //     getLocationCity(payload).then(res => {
130
+  //       if (!res || !res.id) {
131
+  //         Taro.showToast({
132
+  //           title: '未查询到当前城市信息, 请手动选择',
133
+  //           icon: 'none',
134
+  //           duration: 3000,
135
+  //         })
136
+  //       } else {
137
+  //         this.setState({ city: res })
138
+  //         this.loadData({ curCity: res })
139
+  //         this.updateCity(res)
140
+  //       }
141
+  //     }).catch(err => {
142
+  //       console.error(err)
143
+
144
+  //       Taro.showToast({
145
+  //         title: '服务错误, 请手动选择城市',
146
+  //         icon: 'none',
147
+  //         duration: 3000,
148
+  //       })
149
+  //     })
150
+  //   }).catch(err => {
151
+  //     if (err.errMsg === 'getLocation:fail auth deny') {
152
+  //       Taro.showModal({
153
+  //         content: '请同意授权您的定位功能',
154
+  //         showCancel: false,
155
+  //         duration: 3000,
156
+  //       })
157
+  //     } else {
158
+  //       Taro.showToast({
159
+  //         title: `定位失败, 请手动选择城市: ${err.errMsg}`,
160
+  //         icon: 'none',
161
+  //         duration: 3000,
162
+  //       })
163
+  //     }
164
+
165
+  //     console.error(err)
166
+  //   })
167
+  // }
168
+
169
+  // updateCity(payload) {
170
+  //   this.props.dispatchCitySelected(payload)
171
+  // }
172
+
173
+  loadData(props = {}) {
174
+    this.loadHelpGroupList(props)
175
+    this.loadList(props)
176
+    this.loadExtContents(props)
177
+  }
178
+
179
+  loadExtContents(props) {
180
+    const curCity = this.state.city || props.curCity
127 181
 
128
-      getLocationCity(payload).then(res => {
129
-
130
-        let curCity = cityList.filter(item => {
131
-          return item.name == res.name || ''
132
-        })
133
-        // console.log('-----curCity-->', curCity)
134
-        this.updateCity(curCity[0] || defaultCity)
135
-      }).catch(err => {
136
-        Taro.showToast({
137
-          title: `定位错误: ${err.message}`,
138
-          icon: 'none',
139
-        })
140
-        console.error(err)
141
-        this.updateCity(defaultCity)
142
-      })
143
-    }).catch(err => {
144
-      if (err.errMsg === 'getLocation:fail auth deny') {
145
-        Taro.showModal({
146
-          content: '请同意授权您的定位功能',
147
-          showCancel: false,
148
-        })
149
-      } else {
150
-        Taro.showToast({
151
-          title: `定位失败: ${err.errMsg}`,
152
-          icon: 'none',
153
-        })
154
-      }
155
-      console.error(err)
156
-      this.updateCity(defaultCity)
157
-    })
158
-  }
159
-  updateCity(payload) {
160
-    this.props.dispatchCitySelected(payload).then(res => {
161
-      this.loadData()
182
+    this.setState({
183
+      visBanner: false,
184
+      visPropagandaBanner: false
162 185
     })
163
-  }
164
-
165
-  loadData() {
166
-    this.loadBannerList()
167
-    this.loadHelpGroupList()
168
-    this.loadOpenScreenBanner()
169
-    // this.loadActivityList()
170
-    this.loadList()
171 186
 
172
-  }
173
-  loadOpenScreenBanner() {
174
-    const { curCity } = this.props
175
-
176
-    const payload = {}
177
-    if (curCity.id) {
178
-      payload.cityId = curCity.id
179
-    }
187
+    queryExtContents({ cityId: curCity.id }).then(res => {
188
+      // 开屏广告
189
+      const maskBanner = (res || []).filter(x => x.showType === 'screen')[0] || {}
190
+      const maskVisible = maskBanner.contentId && this.props.screenShow !== maskBanner.contentId
191
+      
192
+      // 首页 banner
193
+      const bannerList = (res || []).filter(x => x.showType === 'banner' && x.showPosition === 'index')
180 194
 
181
-    // 获取开屏广告图
182
-    this.props.dispatchProjectScreen(payload).then(res => {
183
-      const banner = res[0]
184
-
185
-      const maskVisible = banner && this.props.screenShow !== (banner || {}).contentId
186
-      if (maskVisible) {
187
-        Taro.hideTabBar()
188
-      } else {
189
-        Taro.showTabBar()
190
-      }
195
+      // 首页 宣传位
196
+      const propagandaBanner = (res || []).filter(x => x.showType === 'propaganda')
191 197
 
192 198
       this.setState({
193 199
         maskVisible,
194
-        maskBanner: banner || {}
200
+        visBanner: true,
201
+        visPropagandaBanner: true,
202
+        maskBanner,
203
+        bannerList,
204
+        propagandaBanner,
195 205
       }, () => {
196 206
         if (Taro.getStorageSync('firstLoading') != '8') {
197 207
           const { dispatch } = getStore()
198
-          dispatch({ type: SET_SCREEN_SHOWED, payload: (banner || {}).contentId })
199
-
208
+          dispatch({ type: SET_SCREEN_SHOWED, payload: maskBanner.contentId })
200 209
         } else {
201 210
           Taro.setStorageSync('firstLoading', '6')
202 211
         }
@@ -204,46 +213,9 @@ export default class Index extends Component {
204 213
     })
205 214
   }
206 215
 
207
-  loadBannerList() {
208
-    const { curCity } = this.props
209
-    // 获取首页banner
210
-    const payload = {
211
-      showPosition: 'index'
212
-    }
213
-    if (curCity.id) {
214
-      payload.cityId = curCity.id
215
-
216
-      var propagandaParams = {
217
-        cityId: curCity.id
218
-      }
219
-
220
-    }
221
-    this.setState({
222
-      visBanner: false,
223
-      visPropagandaBanner: false
224
-    })
225
-
226
-
227
-    queryBanners('banner', payload).then(res => {
228
-      this.setState({
229
-        visBanner: true,
230
-        bannerList: res || [],
231
-      })
232
-    })
233
-    queryBanners('propaganda', propagandaParams).then(res => {
234
-      this.setState({
235
-        visPropagandaBanner: true,
236
-        propagandaBanner: res || [],
237
-
238
-      })
239
-      console.log(this.state.visPropagandaBanner, "visPropagandaBanner")
240
-    })
241
-
216
+  loadHelpGroupList(props) {
217
+    const curCity = this.state.city || props.curCity
242 218
 
243
-  }
244
-
245
-  loadHelpGroupList() {
246
-    const { curCity } = this.props
247 219
     queryHelpGroup({ cityId: curCity.id, buildingId: '' }).then(res => {
248 220
       this.setState({
249 221
         helpGroupList: res || []
@@ -252,9 +224,9 @@ export default class Index extends Component {
252 224
   }
253 225
 
254 226
 
255
-  loadList() {
227
+  loadList(props) {
256 228
     const { keywords } = this.state
257
-    const { curCity } = this.props
229
+    const curCity = this.state.city || props.curCity
258 230
 
259 231
     const payload = {
260 232
       name: keywords,
@@ -264,7 +236,8 @@ export default class Index extends Component {
264 236
       payload.cityId = curCity.id
265 237
     }
266 238
     Taro.showLoading()
267
-    this.props.dispatchProjectList(payload).then(res => {
239
+ 
240
+    this.props.dispatchIndexProjects(payload).then(res => {
268 241
       if (!this.state.loaded && res.records.length <= 0) {
269 242
         // let city = {
270 243
         //   name: '南京市',

+ 2
- 1
src/services/activity.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_ACTIVITY_LIST,
4 5
   API_ACTIVITY_DETAIL,

+ 2
- 1
src/services/agent.js Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 
2
-import { fetch } from '@/utils/request'
2
+// import { fetch } from '@/utils/request'
3
+import { fetchQ as fetch } from '@/utils/requestQueue'
3 4
 import {
4 5
   API_AGENT_LIST,
5 6
   API_REGISTER_AGENT,

+ 2
- 1
src/services/card.js Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 
2
-import { fetch } from '@/utils/request'
2
+// import { fetch } from '@/utils/request'
3
+import { fetchQ as fetch } from '@/utils/requestQueue'
3 4
 import {
4 5
   API_CARDS_LIST,
5 6
   API_CARDS_APPLY,

+ 2
- 1
src/services/chat.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_CHAT_SEND,
4 5
   API_CHAT_HISTORY,

+ 2
- 1
src/services/checkin.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_CHECKIN_DETAILS,
4 5
   API_CHECKIN_ACTIVE

+ 2
- 1
src/services/client.js Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 
2
-import { fetch } from '@/utils/request'
2
+// import { fetch } from '@/utils/request'
3
+import { fetchQ as fetch } from '@/utils/requestQueue'
3 4
 import {
4 5
   API_CLIENT_LIST,
5 6
   API_RECOMENT_CLIENT,

+ 18
- 5
src/services/common.js Näytä tiedosto

@@ -1,7 +1,7 @@
1
-
2
-
3
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
4 3
 import {
4
+  API_PRELOAD,
5 5
   API_QRCODE,
6 6
   API_BANNER_LIST,
7 7
   API_QUERY_CODE_SCENE,
@@ -10,6 +10,13 @@ import {
10 10
   API_TEMPLATE_TYPE,
11 11
 } from '@/constants/api'
12 12
 
13
+/**
14
+ * 预加载数据
15
+ *  @param {*} payload
16
+ * 
17
+*/
18
+export const getPreloadData = payload => fetch({ url: API_PRELOAD, payload, method: 'GET' })
19
+
13 20
 /**
14 21
  * 获取二维码
15 22
  *  @param {*} payload
@@ -34,11 +41,17 @@ export const getCodeScene = scene => fetch({ url: `${API_QUERY_CODE_SCENE}/${sce
34 41
 */
35 42
 export const queryBanners = (type, payload) => fetch({ url: `${API_BANNER_LIST}/${type}`, payload })
36 43
 
44
+/**
45
+ * 获取 banner , 首屏等一些信息
46
+ * @param {*} payload 
47
+ */
48
+export const queryExtContents = payload => fetch({ url: API_BANNER_LIST, payload })
49
+
37 50
 /**
38 51
  * 新增埋点
39 52
  * @param {*} payload 
40 53
  */
41
-export const savePoint = (payload) => fetch({ url: API_BURIED_POINT, payload, method: 'POST' })
54
+export const savePoint = (payload) => fetch({ url: API_BURIED_POINT, payload, method: 'POST' }, 2)
42 55
 
43 56
 
44 57
 /**
@@ -46,7 +59,7 @@ export const savePoint = (payload) => fetch({ url: API_BURIED_POINT, payload, me
46 59
  * @param {*} id 
47 60
  * @param {*} payload
48 61
  */
49
-export const updatePoint = (id, payload) => fetch({ url: `${API_BURIED_POINT}/${id}`, payload, method: 'PUT' })
62
+export const updatePoint = (id, payload) => fetch({ url: `${API_BURIED_POINT}/${id}`, payload, method: 'PUT' }, 2)
50 63
 
51 64
 
52 65
 /**

+ 2
- 1
src/services/feedback.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_FEEDBACK_SUBMIT
4 5
 } from '@/constants/api'

+ 2
- 1
src/services/getCode.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_GET_CODE,
4 5
   API_PUT_REGISTER,

+ 2
- 1
src/services/item.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_ITEMS_LIST,
4 5
   API_ITEMS_DETAIL,

+ 2
- 1
src/services/login.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import Qs from 'qs'
3 4
 import {
4 5
   API_USER_LOGIN

+ 2
- 3
src/services/map.js Näytä tiedosto

@@ -1,6 +1,5 @@
1
-
2
-
3
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
4 3
 import {
5 4
   API_LOCATION_CITYP
6 5
 

+ 2
- 1
src/services/news.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_NEWS_LIST,
4 5
   API_NEWS_FAVOR,

+ 2
- 1
src/services/person.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_MY_CUSTOMER,
4 5
   API_CUSTOMER_LIST,

+ 2
- 1
src/services/policy.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_POLICY_LIST,
4 5
 } from '@/constants/api'

+ 2
- 1
src/services/report.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_REPORT_LIST,
4 5
   API_REPORT_CLIENT,

+ 2
- 1
src/services/user.js Näytä tiedosto

@@ -1,4 +1,5 @@
1
-import { fetch } from '@/utils/request'
1
+// import { fetch } from '@/utils/request'
2
+import { fetchQ as fetch } from '@/utils/requestQueue'
2 3
 import {
3 4
   API_USER_INFO,
4 5
   API_USER_PHONE,

+ 8
- 2
src/utils/login.js Näytä tiedosto

@@ -4,6 +4,8 @@ import { USER_INFO } from '@/constants/user'
4 4
 import { wxLogin } from '@/services/login'
5 5
 import { sceneInShare } from '@/utils/tools'
6 6
 import ready from '@/utils/ready'
7
+import { dispatchCitySelected } from '@/actions/city'
8
+
7 9
 let loading = false
8 10
 export default function (payload, callback) {
9 11
   const { path, scene, ...params } = payload
@@ -22,20 +24,24 @@ export default function (payload, callback) {
22 24
 
23 25
         loading = false
24 26
 
25
-        const { extraInfo, miniApp, person, miniAuthorized, avatarAuth } = data
27
+        const { extraInfo, miniApp, person, miniAuthorized, avatarAuth, city } = data
26 28
         const { token, sessionKey } = miniApp
27 29
         const { dispatch } = getStore()
28 30
         Taro.setStorageSync('token', token)
29 31
         Taro.setStorageSync('sessionKey', sessionKey)
32
+        
30 33
         dispatch({ type: USER_INFO, payload: { extraInfo, person, miniApp } })
31 34
 
35
+        if (city) {
36
+          dispatchCitySelected(city)(dispatch)
37
+        }
32 38
 
33 39
         // // 用户信息已授权获取成功
34 40
         // if (miniAuthorized || avatarAuth) {
35 41
 
36 42
         //   // 保存用户信息
37 43
         //   // dispatch({ type: USER_INFO, payload: { extraInfo, person, miniApp } })
38
-        //   callback && callback(data)
44
+          callback && callback(data)
39 45
 
40 46
         // } else {
41 47
 

+ 106
- 81
src/utils/request.js Näytä tiedosto

@@ -29,88 +29,12 @@ export const setStorage = function (key, data) {
29 29
  * @param {*} options
30 30
  */
31 31
 export const fetch = async (options) => {
32
-  const { url, payload = {}, method = 'GET', showToast = true, autoLogin = true } = options
33
-  const showMessage = Object.prototype.hasOwnProperty.call(payload, 'showToast') ? payload.showToast : showToast
34
-  // debugger
35
-  return Taro.request({
36
-    url,
37
-    method,
38
-    data: payload,
39
-    header: {
40
-      'content-type': 'application/json',
41
-      'authorization': `Bearer ${Taro.getStorageSync('token')}`,
42
-      'appId': appId,
43
-      'x-action': 'miniapp',
44
-      'x-version': Version,
45
-    }
46
-  }).then(async (res) => {
47
-    if (res.statusCode === 500) {
48
-      Taro.showToast({
49
-        title: "请检查网络",
50
-        icon: 'none'
51
-      })
52
-      console.error(res)
53
-      throw new Error('请检查网络')
54
-    }
55
-
56
-    const { data, code, message } = res.data
57
-    if (code === CODE_SUCCESS) {
58
-      return data
59
-    } else {
60
-      const isExpired = (code === CODE_AUTH_EXPIRED || code === CODE_UNLOGIN)
61
-      const defaultMsg = isExpired ? '登录失效' : message
62
-      if (isExpired && autoLogin) {
63
-        // token失效,重新登录后,跳转到首页
64
-        login({}, () => {
65
-          Taro.switchTab({
66
-            url: '/pages/project/index'
67
-          })
68
-        })
69
-      } else {
70
-        if (showMessage) {
71
-          Taro.showToast({
72
-            title: defaultMsg,
73
-            icon: 'none'
74
-          })
75
-        }
76
-      }
77
-      if (showMessage) {
78
-
79
-        Taro.showToast({
80
-          title: message,
81
-          icon: 'none'
82
-        })
83
-      }
84
-
85
-      throw res.data
86
-    }
87
-  }).catch((err) => {
88
-    rtLog.error('[request]', "==================================")
89
-    rtLog.error('[request]', err)
90
-    rtLog.error('[request]', url)
91
-    rtLog.error('[request]', wx.getLaunchOptionsSync())
92
-    rtLog.error('[request]', "==================================")
93
-
94
-    let errMessage = `请求失败: ${err.errMsg}`
95
-    if (err.errMsg) {
96
-      errMessage = '请检查网络'
97
-    }
98
-
99
-    if (err.message) {
100
-      console.error('请求失败', err.message)
101
-      errMessage = err.message.indexOf('java') > -1 ? '服务内部错误' : err.message
102
-    }
103
-
104
-    if (showMessage) {
105
-      Taro.showToast({
106
-        title: errMessage,
107
-        icon: 'none',
108
-        duration: 3000
109
-      })
110
-    }
32
+  const opts = optionBuilder(options)
111 33
 
112
-    throw new Error(errMessage)
113
-  })
34
+  // debugger
35
+  return Taro.request(opts[0])
36
+    .then((res) => reqSuccess(res, opts))
37
+    .catch((err) => reqFail(err, opts))
114 38
 }
115 39
 
116 40
 export const uploadFiles = async (files) => {
@@ -146,3 +70,104 @@ export const uploadFiles = async (files) => {
146 70
 
147 71
   return Promise.all(uploads)
148 72
 }
73
+
74
+export function optionBuilder(options) {
75
+  const { url, payload = {}, method = 'GET', showToast = true, autoLogin = true } = options
76
+  const showMessage = Object.prototype.hasOwnProperty.call(payload, 'showToast') ? payload.showToast : showToast
77
+
78
+  return [
79
+    {
80
+      url,
81
+      method,
82
+      data: payload,
83
+      header: {
84
+        'content-type': 'application/json',
85
+        'authorization': `Bearer ${Taro.getStorageSync('token')}`,
86
+        'appId': appId,
87
+        'x-action': 'miniapp',
88
+        'x-version': Version,
89
+      }
90
+    },
91
+    {
92
+      showMessage,
93
+      autoLogin
94
+    }
95
+  ]
96
+}
97
+
98
+export function reqSuccess (res, opts) {
99
+  const [, settings] = opts || []
100
+  const { showMessage, autoLogin = true } = settings || {}
101
+
102
+  if (res.statusCode === 500) {
103
+    Taro.showToast({
104
+      title: "请检查网络",
105
+      icon: 'none'
106
+    })
107
+    console.error(res)
108
+    throw new Error('请检查网络')
109
+  }
110
+
111
+  const { data, code, message } = res.data
112
+  if (code === CODE_SUCCESS) {
113
+    return data
114
+  } else {
115
+    const isExpired = (code === CODE_AUTH_EXPIRED || code === CODE_UNLOGIN)
116
+    const defaultMsg = isExpired ? '登录失效' : message
117
+    if (isExpired && autoLogin) {
118
+      // token失效,重新登录后,跳转到首页
119
+      login({}, () => {
120
+        Taro.switchTab({
121
+          url: '/pages/project/index'
122
+        })
123
+      })
124
+    } else {
125
+      if (showMessage) {
126
+        Taro.showToast({
127
+          title: defaultMsg,
128
+          icon: 'none'
129
+        })
130
+      }
131
+    }
132
+    if (showMessage) {
133
+
134
+      Taro.showToast({
135
+        title: message,
136
+        icon: 'none'
137
+      })
138
+    }
139
+
140
+    throw res.data
141
+  }
142
+}
143
+
144
+export function reqFail (err, opts) {
145
+  const [reqParams, settings] = opts || []
146
+  const { showMessage } = settings || {}
147
+
148
+  rtLog.error('[request]', "==================================")
149
+  rtLog.error('[request]', err)
150
+  rtLog.error('[request]', reqParams.url)
151
+  rtLog.error('[request]', wx.getLaunchOptionsSync())
152
+  rtLog.error('[request]', "==================================")
153
+
154
+  let errMessage = `请求失败: ${err.errMsg}`
155
+  if (err.errMsg) {
156
+    errMessage = '请检查网络'
157
+  }
158
+
159
+  if (err.message) {
160
+    console.error('请求失败', err.message)
161
+    errMessage = err.message.indexOf('java') > -1 ? '服务内部错误' : err.message
162
+  }
163
+
164
+  if (showMessage) {
165
+    Taro.showToast({
166
+      title: errMessage,
167
+      icon: 'none',
168
+      duration: 3000
169
+    })
170
+  }
171
+
172
+  throw new Error(errMessage)
173
+}

+ 80
- 0
src/utils/requestQueue.js Näytä tiedosto

@@ -0,0 +1,80 @@
1
+import { fetch } from './request'
2
+import { times } from './tools'
3
+
4
+// 高级队列, 先执行高级队列
5
+// 高级队列一般放置, 影响页面显示及交互的请求
6
+const tq = [];
7
+
8
+// 再执行中级队列
9
+// 中级队列一般放置, 与页面及交互无关的请求, 比如数据更新之类的
10
+const mq = [];
11
+
12
+// 最后执行低级队列
13
+// 低级队列一般放置, 与业务无关的请求, 比如埋点之类的
14
+const lq = [];
15
+
16
+// 汇总队列
17
+const qs = [tq, mq, lq];
18
+
19
+// 当前 request loop 是否执行中
20
+let isProcessing = false
21
+
22
+// 执行一个队列
23
+function execQ(qt) {
24
+  const qLen = qs[qt].length
25
+  if (process.env.NODE_ENV === 'development') {
26
+    console.log(`[request-queue] [${qt}]: 当前队列长度 ${qLen}`, qs[qt])
27
+  }
28
+
29
+  if (qLen === 0) {
30
+    return Promise.resolve()
31
+  }
32
+
33
+  return new Promise((resolve) => {
34
+    times(qLen).forEach(() => {
35
+
36
+      const current = qs[qt].shift()
37
+      const [options, success, fail] = current
38
+
39
+      fetch(options).then((res) => {
40
+        success(res)
41
+      }).catch((err) => {
42
+        fail(err)
43
+      })
44
+
45
+    })
46
+
47
+    resolve()
48
+  })
49
+}
50
+
51
+// 添加任务队列, 如果空闲状态则立即执行
52
+function addToQs(qt, job) {
53
+  qs[qt].push(job)
54
+
55
+  if (!isProcessing) {
56
+    startQs()
57
+  }
58
+}
59
+
60
+async function startQs() {
61
+  isProcessing = true
62
+
63
+  await execQ(0)
64
+  await execQ(1)
65
+  await execQ(2)
66
+
67
+  if (qs.reduce((s,q) => s + q.length, 0) > 0) {
68
+    await startQs()
69
+  }
70
+
71
+  isProcessing = false
72
+}
73
+
74
+export function fetchQ(options, queueType) {
75
+  return new Promise((resolve, reject) => {
76
+    // 默认放置高级队列
77
+    const qt = queueType || 0
78
+    addToQs(qt, [options, resolve, reject])
79
+  })
80
+}