张延森 5 jaren geleden
bovenliggende
commit
92cc6bc8b5
4 gewijzigde bestanden met toevoegingen van 49 en 10 verwijderingen
  1. 2
    4
      src/pages/project/index.js
  2. 21
    5
      src/reducers/user.js
  3. 1
    1
      src/utils/login.js
  4. 25
    0
      src/utils/tools.js

+ 2
- 4
src/pages/project/index.js Bestand weergeven

@@ -17,7 +17,6 @@ import { ROLE_CODE, DECREASE_UNREADNUM } from '@constants/user'
17 17
 import { getStore, connect } from '@tarojs/redux'
18 18
 import * as actions from '@actions/project'
19 19
 import { transferImage } from '@utils/tools'
20
-import QQMapWX from '@lib/qqmap-wx-jssdk.min'
21 20
 import Notice from '@components/Notice'
22 21
 import Authorize from '@components/authorize'
23 22
 
@@ -51,9 +50,6 @@ export default class Index extends Component {
51 50
   }
52 51
 
53 52
   componentWillMount() {
54
-    this.qqmapsdk = new QQMapWX({
55
-      key: 'TIIBZ-ZJG33-52T3L-Y3X4Q-NWKLV-KUB3B'
56
-    })
57 53
     ready.queue(() => {
58 54
       this.getLocation()
59 55
 
@@ -97,6 +93,8 @@ export default class Index extends Component {
97 93
   }
98 94
 
99 95
   getLocation() {
96
+    debugger
97
+    console.log('-----this.props-->', this.props)
100 98
     const { cityList, userInfo: { person: { org } } } = this.props
101 99
     let defaultCity = cityList.filter(item => {
102 100
       return item.id == org.defaultCityId

+ 21
- 5
src/reducers/user.js Bestand weergeven

@@ -1,3 +1,5 @@
1
+import { mergeNotNull } from '@utils/tools'
2
+
1 3
 import {
2 4
   USER_INFO,
3 5
   // USER_QUERY_INFO,
@@ -20,10 +22,23 @@ const INITIAL_STATE = {
20 22
 export default function user(state = INITIAL_STATE, action) {
21 23
   switch (action.type) {
22 24
     case USER_INFO: {
23
-      return {
24
-        ...state,
25
-        userInfo: {
26
-          ...action.payload
25
+      if (!(state.userInfo || {}).person) {
26
+        return {
27
+          ...state,
28
+          userInfo: {
29
+            ...action.payload
30
+          }
31
+        }
32
+      } else {
33
+        const { person } = action.payload || {}
34
+        const newPerson = mergeNotNull(state.userInfo.person, person)
35
+        return {
36
+          ...state,
37
+          userInfo: {
38
+            ...state.userInfo,
39
+            ...action.payload,
40
+            person: newPerson,
41
+          }
27 42
         }
28 43
       }
29 44
     }
@@ -41,8 +56,9 @@ export default function user(state = INITIAL_STATE, action) {
41 56
     //   }
42 57
     // }
43 58
     case UPDATE_USER_INFO: {
44
-      const { person, extraInfo, miniApp = {} } = state.userInfo
45 59
       // debugger
60
+      const { person, extraInfo, miniApp = {} } = state.userInfo
61
+      
46 62
       return {
47 63
         ...state,
48 64
         userInfo: {

+ 1
- 1
src/utils/login.js Bestand weergeven

@@ -27,7 +27,6 @@ export default function (payload, callback) {
27 27
         const { dispatch } = getStore()
28 28
         Taro.setStorageSync('token', token)
29 29
         Taro.setStorageSync('sessionKey', sessionKey)
30
-
31 30
         dispatch({ type: USER_INFO, payload: { extraInfo, person, miniApp } })
32 31
 
33 32
         // 用户信息已授权获取成功
@@ -52,6 +51,7 @@ export default function (payload, callback) {
52 51
             })
53 52
           }
54 53
         }
54
+
55 55
         ready.open()
56 56
 
57 57
         console.info('ready status2', ready)

+ 25
- 0
src/utils/tools.js Bestand weergeven

@@ -16,6 +16,31 @@ export function times(n) {
16 16
   return n > 0 ? '*'.repeat(n - 1).split('*') : []
17 17
 }
18 18
 
19
+/**
20
+ * 将 b 中不为 null 或者 undefined 的值合并到 a 中
21
+ * @param {*} a 
22
+ * @param {*} b 
23
+ */
24
+export function mergeNotNull(a, b) {
25
+  const bKeys = Object.keys(b || {})
26
+  if (!bKeys.length) {
27
+    return a
28
+  }
29
+
30
+  let res = { ...(a || {}) }
31
+
32
+  bKeys.forEach(k => {
33
+    const v = b[k]
34
+    if (v === null || v === undefined) {
35
+      return
36
+    }
37
+
38
+    res[k] = v
39
+  })
40
+
41
+  return res
42
+}
43
+
19 44
 /**
20 45
  * 
21 46
  * @param {*} img