Your Name hace 3 años
padre
commit
6c5d9e56e1
Se han modificado 4 ficheros con 55 adiciones y 2 borrados
  1. 2
    2
      config/dev.js
  2. 5
    0
      src/layout/index.js
  3. 33
    0
      src/layout/useScreen.js
  4. 15
    0
      src/reducers/system.js

+ 2
- 2
config/dev.js Ver fichero

@@ -3,8 +3,8 @@ module.exports = {
3 3
     NODE_ENV: '"development"'
4 4
   },
5 5
   defineConstants: {
6
-    HOST: '"https://xlk.njyz.tech"',
7
-    // HOST: '"http://127.0.0.1:8081"',
6
+    // HOST: '"https://xlk.njyz.tech"',
7
+    HOST: '"http://127.0.0.1:8081"',
8 8
     WSS_HOST: '"wss://xlk.njyz.tech"',
9 9
     OSS_PATH: '"https://xlk-assets.oss-accelerate.aliyuncs.com/"',
10 10
     OSS_FAST_PATH: '"https://xlk-assets.oss-accelerate.aliyuncs.com/"',

+ 5
- 0
src/layout/index.js Ver fichero

@@ -11,12 +11,14 @@ import FixedConsultant from '@/components/FixedConsultant'
11 11
 import { report as reportCustomer } from '@/utils/customer'
12 12
 import { ROLE_CODE } from '@/constants/user'
13 13
 import useAuth from './useAuth'
14
+import useScreen from './useScreen'
14 15
 import { routes } from '../routes'
15 16
 
16 17
 import './style.scss'
17 18
 
18 19
 export default (ChildComponent) => (props) => {
19 20
   const consultant = useSelector(s => s.system.consultant)
21
+  const city = useSelector(s => s.city)
20 22
   const { spinning, userInfo } = useSelector(s => s.user)
21 23
   const { person, ...extInfo } = userInfo || {}
22 24
   const router = useRouter()
@@ -31,6 +33,8 @@ export default (ChildComponent) => (props) => {
31 33
   const [shareContent, setShareContent] = useState({})
32 34
   // 页面埋点
33 35
   const [trackData, setTrackData] = useState({})
36
+  // 开屏广告
37
+  const [firstScreen, showScreen, toggleShowScreen] = useScreen(city.id, person)
34 38
 
35 39
   // 报备客户
36 40
   useEffect(() => {
@@ -90,6 +94,7 @@ export default (ChildComponent) => (props) => {
90 94
             router={router}
91 95
             consultant={consultant}
92 96
             page={page}
97
+            city={city}
93 98
             shareContent={shareContent}
94 99
             trackData={trackData}
95 100
             {...props}

+ 33
- 0
src/layout/useScreen.js Ver fichero

@@ -0,0 +1,33 @@
1
+/**
2
+ * 获取开屏广告
3
+ * @param {*} cityId 
4
+ */
5
+import { useEffect, useState, useCallback } from 'react'
6
+import { useDispatch, useSelector } from 'react-redux'
7
+import { queryExtContents } from '@/services/common'
8
+
9
+export default function useScreen(cityId, person) {
10
+  const dispatch = useDispatch()
11
+
12
+  const [firstScreen, setFirstScreen] = useState()
13
+  const show = useSelector(s => !s.system.firstScreen.filter(x => x === cityId)[0])
14
+  const toggle = useCallback(
15
+    () => dispatch({ type: 'TOGGLE_FIRSTSCREEN', payload: { cityId } }),
16
+    [cityId, dispatch],
17
+  )
18
+
19
+  useEffect(() => {
20
+    if (cityId && person?.personId) {
21
+      queryExtContents({cityId}).then((res) => {
22
+        const screen = (res || []).filter(x => x.showType === 'screen' && x.showPosition === 'index')[0] || {}
23
+        setFirstScreen(screen)
24
+  
25
+        if (screen) {
26
+          toggle()
27
+        }
28
+      })
29
+    }
30
+  }, [cityId, toggle, person?.personId])
31
+
32
+  return [firstScreen, show, toggle]
33
+}

+ 15
- 0
src/reducers/system.js Ver fichero

@@ -13,6 +13,8 @@ const INITIAL_STATE = {
13 13
   recommender: {},
14 14
   // 当前推荐置业顾问信息
15 15
   consultant: {},
16
+  // 开屏广告 - 如果当前城市已展示过, 那么会把 cityId 放入数组
17
+  firstScreen: [],
16 18
 };
17 19
 
18 20
 export default function(state = INITIAL_STATE, action) {
@@ -41,6 +43,19 @@ export default function(state = INITIAL_STATE, action) {
41 43
         consultant: action.payload
42 44
       };
43 45
     }
46
+    case 'TOGGLE_FIRSTSCREEN': {
47
+      const { cityId } = action.payload
48
+      const showed = state.firstScreen.filter(x => x === cityId)[0]
49
+
50
+      if (!showed) {
51
+        return {
52
+          ...state,
53
+          firstScreen: state.firstScreen.concat(cityId)
54
+        };
55
+      }
56
+
57
+      return state;
58
+    }
44 59
 
45 60
     default:
46 61
       return state;