张延森 3 vuotta sitten
vanhempi
commit
7d787be4d5

+ 5
- 6
src/app.js Näytä tiedosto

@@ -7,15 +7,14 @@ import './app.less'
7 7
 class App extends Component {
8 8
 
9 9
   onLaunch(options) {
10
-    const {setPerson, login} = store.getModel('person').getState()
10
+    console.group('APP Launch')
11
+    console.debug(options)
12
+    console.groupEnd()
13
+
14
+    const { login} = store.getModel('person').getState()
11 15
 
12 16
     // 预拉取数据
13 17
     preFetchData().then((fetchData) => {
14
-      setPerson({
15
-        personId: fetchData.personId,
16
-        openid: fetchData.openid,
17
-      })
18
-
19 18
       const { fromType, recommender, scene : qrCodeId } = options.query
20 19
 
21 20
       // 登录获取人员信息

+ 1
- 3
src/components/AuthPage/index.jsx Näytä tiedosto

@@ -1,5 +1,4 @@
1 1
 import React, { useState } from 'react'
2
-import Taro from '@tarojs/taro'
3 2
 import { useModel } from '@/store'
4 3
 import { Label, RadioGroup, Radio } from '@tarojs/components'
5 4
 import index from '@/assets/icons/login/LOGO.png'
@@ -7,7 +6,7 @@ import './login.less'
7 6
 
8 7
 
9 8
 export default (props) => {
10
-  const { getPhone } = useModel('person')
9
+  const { getPhone, sessionKey } = useModel('person')
11 10
 
12 11
   const [loading, setLoading] = useState(false)
13 12
   const [checked, setChecked] = useState(false)
@@ -19,7 +18,6 @@ export default (props) => {
19 18
   const handlePhoneNumber = (e) => {
20 19
     const { errMsg, ...data } = e.detail || {}
21 20
     if (errMsg === 'getPhoneNumber:ok') {
22
-      const sessionKey = Taro.getStorageSync('sessionKey')
23 21
       getPhone({ ...data, sessionKey }).then(() => {
24 22
         setLoading(false)
25 23
       }).catch(() => setLoading(false))

+ 3
- 1
src/components/CustomNav/index.jsx Näytä tiedosto

@@ -71,7 +71,9 @@ export default (props) => {
71 71
   }
72 72
 
73 73
   useEffect(() => {
74
-    Taro.setNavigationBarTitle(title)
74
+    if (title) {
75
+      Taro.setNavigationBarTitle({title})
76
+    }
75 77
   }, [title])
76 78
 
77 79
   return (

+ 4
- 6
src/layouts/index.jsx Näytä tiedosto

@@ -33,12 +33,10 @@ export default (Child) => (props) => {
33 33
     const isNormalPerson = personRole === 'normal'
34 34
 
35 35
     const currentPage = getPageBy(router.path)
36
-    let indexPage = getIndexPageOf(personRole)
36
+    let indexPage = `pages/index/index`
37 37
     if (!isNormalPerson) {
38
-      indexPage = `${personRole}/${indexPage.page}`
39
-
40
-    } else {
41
-      indexPage = `pages/index/index`
38
+      const { page } = getIndexPageOf(personRole);
39
+      indexPage = `${personRole}/${page}`
42 40
     }
43 41
 
44 42
     const isMatched = isNormalPerson ?
@@ -49,7 +47,7 @@ export default (Child) => (props) => {
49 47
 
50 48
 
51 49
     // 如果对应上, 就不跳转
52
-    return isMatched ? personRole : indexPage
50
+    return isMatched ? undefined : indexPage
53 51
 
54 52
   }, [router.path, person?.personRole])
55 53
 

+ 22
- 23
src/pages/details/mjDetails/sceneryDetails.jsx Näytä tiedosto

@@ -16,12 +16,9 @@ import useSave from "@/utils/hooks/useSave"
16 16
 import useLike from "@/utils/hooks/useLike"
17 17
 import Cards from '@/components/foodCards/foodCards.jsx'
18 18
 import Taro, { useShareAppMessage } from '@tarojs/taro'
19
-import { getTouristDistance } from '@/services/home'
20 19
 import Extend from '../components/Extend/extend'
21 20
 import './sceneryDetails.less'
22 21
 
23
-
24
-
25 22
 export default withLayout((props) => {
26 23
   const { router, person, location } = props
27 24
   const { id } = props.router.params
@@ -56,35 +53,37 @@ export default withLayout((props) => {
56 53
   const [recommend, setRecommend] = useState([])
57 54
 
58 55
   const openMap = () => {
56
+    const [lng, lat] = detail.location.split(',')
57
+
59 58
     Taro.openLocation({
60
-      longitude: log.current - 0,
61
-      latitude: lat.current - 0,
59
+      longitude: lng - 0,
60
+      latitude: lat - 0,
62 61
       name: detail.touristName,
63 62
       address: detail.address,
64 63
       scale: 12,
65 64
     })
66 65
   }
67
-  const log = useRef('')
68
-  const lat = useRef('')
66
+
69 67
   useEffect(() => {
70
-    getTouristDetail(id).then((res) => {
71
-      log.current = (res.locaton).toString().split(',')[0]
72
-      lat.current = (res.locaton).toString().split(',')[1]
73
-      setDetail(res)
74
-      setimglist(res.imageList || [])
75
-    })
76
-    getExtendContent('tourist', id).then((res) => {
77
-      setExtend(res.records || [])
78
-      setAllextNum(res.total)
79
-      setNewextNum(res.records.length)
80
-    })
81
-    getTouristDistance('tourist', id, { location: location }).then((res) => {
82
-      setDistance((res.distance / 1000).toFixed(2))
83
-      getRecommendList({ location: res.lng + ',' + res.lat }).then((res2) => {
68
+    if (id) {
69
+      getTouristDetail(id).then((res) => {
70
+        setDetail(res)
71
+        setimglist(res.imageList || [])
72
+        getRecommendList({ location: res.locaton }).then((res2) => {
73
+          setRecommend(res2 || [])
74
+        })
75
+      })
76
+      getExtendContent('tourist', id).then((res) => {
77
+        setExtend(res.records || [])
78
+        setAllextNum(res.total)
79
+        setNewextNum(res.records.length)
80
+      })
81
+    } else {
82
+      getRecommendList({ location }).then((res2) => {
84 83
         setRecommend(res2 || [])
85 84
       })
86
-    })
87
-  }, [])
85
+    }
86
+  }, [id, location])
88 87
   // 分享
89 88
   useShareAppMessage(() => {
90 89
     return {

+ 0
- 6
src/services/home.js Näytä tiedosto

@@ -103,12 +103,6 @@ export const getExtendContent = (type, id, params) => request(`/${type}/${id}/co
103 103
  */
104 104
 export const getTouristDetail = (id) => request(`/tourist/${id}`)
105 105
 
106
-/**
107
- * 获取景点距离定位 用于通过景点分享功能进入景点详情页的客户
108
- * @param {*} id 
109
- * @returns 
110
- */
111
- export const getTouristDistance = (targetType,targetId,params) => request(`/resource/${targetType}/${targetId}`,{params})
112 106
 
113 107
 /**
114 108
  * 获取推荐套餐列表

+ 7
- 8
src/store/models/person.js Näytä tiedosto

@@ -4,22 +4,19 @@ import { signIn, authPhone, authAvatar,toggleRole } from '@/services/person'
4 4
 
5 5
 export default () => {
6 6
   const [person, setPerson] = useState()
7
+  const [qrCode, setQrCode] = useState()
7 8
   const [peronRoles, setPersonRoles] = useState([])
9
+  const [sessionKey, setSessionKey] = useState()
8 10
 
9 11
   const login = (params) => {
10 12
     signIn(params).then((res) => {
11
-      const { person: taPerson, personRoleList, sessionKey, qrcode, token } = res;
13
+      const { person: taPerson, personRoleList, sessionKey : skey, qrcode, token } = res;
12 14
       setPerson(taPerson);
13 15
       setPersonRoles(personRoleList);
16
+      setQrCode(qrcode);
17
+      setSessionKey(skey);
14 18
 
15
-      Taro.setStorage({ key: 'sessionKey', data: sessionKey })
16 19
       Taro.setStorage({ key: 'token', data: token })
17
-      Taro.setStorage({ key: 'personId', data: taPerson.personId })
18
-      Taro.setStorage({ key: 'openid', data: taPerson.openid })
19
-
20
-      if (qrcode) {
21
-        Taro.setStorage({ key: 'qrcode', data: qrcode })
22
-      }
23 20
     })
24 21
   }
25 22
 
@@ -45,6 +42,8 @@ export default () => {
45 42
   return {
46 43
     person,
47 44
     peronRoles,
45
+    qrCode,
46
+    sessionKey,
48 47
     setPerson,
49 48
     login,
50 49
     getPhone,

+ 4
- 3
src/utils/hooks/useRouter.js Näytä tiedosto

@@ -1,14 +1,15 @@
1 1
 import Taro, { useRouter } from '@tarojs/taro'
2 2
 import { parseQueryString } from '@/utils'
3
+import { useModel } from '@/store'
3 4
 
4 5
 export default () => {
5 6
   const router = useRouter()
7
+  const { qrCode } = useModel('person')
6 8
 
7 9
   // 扫码进入的
8 10
   if (router?.params?.scene) {
9
-    const qrCodeStr = Taro.getStorageSync('qrcode')
10
-    if (qrCodeStr && qrCodeStr !== 'undefined') {
11
-      const qrParams = parseQueryString(qrCodeStr) || {}
11
+    if (qrCode) {
12
+      const qrParams = parseQueryString(qrCode) || {}
12 13
       router.params = {
13 14
         ...router.params || {},
14 15
         ...qrParams,

+ 0
- 5
src/utils/preFetchData.js Näytä tiedosto

@@ -2,9 +2,6 @@ import Taro from '@tarojs/taro'
2 2
 
3 3
 export default () => {
4 4
 
5
-  const personId = Taro.getStorageSync('personId')
6
-  const openid = Taro.getStorageSync('openid')
7
-
8 5
   return new Promise((resolve, reject) => {
9 6
     Taro.getLocation({
10 7
       success(res) {
@@ -12,8 +9,6 @@ export default () => {
12 9
         Taro.setStorageSync('location', location)
13 10
         resolve({
14 11
           location,
15
-          personId,
16
-          openid
17 12
         })
18 13
       },
19 14
       fail(err) {