张延森 3 years ago
parent
commit
7dd5c011ec

+ 0
- 2
src/app.js View File

@@ -11,8 +11,6 @@ class App extends Component {
11 11
 
12 12
     // 预拉取数据
13 13
     preFetchData().then((fetchData) => {
14
-      console.log('----fetchData--->', new Date())
15
-
16 14
       setPerson({
17 15
         personId: fetchData.personId,
18 16
         openid: fetchData.openid,

+ 17
- 0
src/components/Spin/Spin2.jsx View File

@@ -0,0 +1,17 @@
1
+import React from 'react'
2
+import { View } from '@tarojs/components'
3
+import Spin from '.'
4
+
5
+import './style.less'
6
+
7
+export default (props) => {
8
+  const { spinning, style, ...leftProps } = props
9
+
10
+  return spinning ? (
11
+    <View className='spin2box' style={style}>
12
+      <View className='spin2'>
13
+        {spinning && <Spin {...leftProps} />}
14
+      </View>
15
+    </View>
16
+  ) : null
17
+}

+ 31
- 0
src/components/Spin/index.jsx View File

@@ -0,0 +1,31 @@
1
+import './style.less'
2
+
3
+export default (props) => {
4
+  const { size = '160rpx', background = 'transparent' } = props
5
+  const wrapperStyle = {
6
+    width: size,
7
+    height: size,
8
+    background,
9
+  }
10
+
11
+  const leftBarStyle = {
12
+    'border-top-right-radius': size,
13
+    'border-bottom-right-radius': size,
14
+  }
15
+
16
+  const rightBarStyle = {
17
+    'border-top-left-radius': size,
18
+    'border-bottom-left-radius': size,
19
+  }
20
+
21
+  return (
22
+    <view className='spin' style={wrapperStyle}>
23
+      <view className='mask-left'>
24
+        <view className='spin-bar' style={leftBarStyle}></view>
25
+      </view>
26
+      <view className='mask-right'>
27
+        <view className='spin-bar' style={rightBarStyle}></view>
28
+      </view>
29
+    </view>
30
+  )
31
+}

+ 132
- 0
src/components/Spin/style.less View File

@@ -0,0 +1,132 @@
1
+
2
+@width: 160px;
3
+
4
+.spin {
5
+  width: @width;
6
+  height: @width;
7
+  border-radius: 100%;
8
+  display: inline-block;
9
+  position: relative;
10
+  animation: spin-rotate 4s linear infinite;
11
+  box-sizing: border-box;
12
+
13
+  view {
14
+    box-sizing: border-box;
15
+    position: absolute;
16
+  }
17
+
18
+  .mask-left, .mask-right {
19
+    // background: #fff;
20
+    top: 0;
21
+    width: calc(50% + 1px);
22
+    height: 100%;
23
+    overflow: hidden;
24
+  }
25
+
26
+  .mask-left {
27
+    left: 0;
28
+
29
+    .spin-bar {
30
+      left: 100%;
31
+      border-top-right-radius: @width;
32
+      border-bottom-right-radius: @width;
33
+      border-left: 0;
34
+      // transform: rotate(180deg);
35
+      transform-origin: center left;
36
+      animation: spin-rotate-right 1.2s cubic-bezier(.25,.5,.25,1) 0.6s infinite, spin-color 2s linear infinite;
37
+    }
38
+  }
39
+
40
+  .mask-right {
41
+    right: 0;
42
+
43
+    .spin-bar {
44
+      left: -100%;
45
+      border-top-left-radius: @width;
46
+      border-bottom-left-radius: @width;
47
+      border-right: 0;
48
+      transform-origin: center right;
49
+      animation: spin-rotate-right 1.2s cubic-bezier(1,.25,.5,.25) infinite, spin-color 2s linear infinite;
50
+    }
51
+  }
52
+
53
+  .spin-bar {
54
+    float: left;
55
+    width: 100%;
56
+    height: 100%;
57
+    border-width: 4px;
58
+    border-style: solid;
59
+  }
60
+}
61
+
62
+@keyframes spin-rotate-right {
63
+  0% {
64
+    transform: rotate(0deg);
65
+  }
66
+
67
+  50% {
68
+    transform: rotate(180deg);
69
+  }
70
+
71
+  100% {
72
+    transform: rotate(360deg);
73
+  }
74
+}
75
+
76
+@keyframes spin-rotate-left {
77
+  0% {
78
+    transform: rotate(180deg);
79
+  }
80
+
81
+  50% {
82
+    transform: rotate(360deg);
83
+  }
84
+
85
+  100% {
86
+    transform: rotate(540deg);
87
+  }
88
+}
89
+
90
+@keyframes spin-rotate {
91
+  0% {
92
+    transform: rotate(0deg);
93
+  }
94
+
95
+  100% {
96
+    transform: rotate(360deg);
97
+  }
98
+}
99
+
100
+@keyframes spin-color {
101
+  0%, 100% {
102
+    border-color: #d62d20;
103
+  }
104
+  40% {
105
+    border-color: #0057e7;
106
+  }
107
+  60% {
108
+    border-color: #008744;
109
+  }
110
+  80%, 90% {
111
+    border-color: #ffa700;
112
+  }
113
+}
114
+
115
+.spin2box {
116
+  width: 100%;
117
+  height: 100%;
118
+  position: absolute;
119
+  top: 0;
120
+  left: 0;
121
+  z-index: 100;
122
+  text-align: center;
123
+  background: rgba(255, 255, 255, .75);
124
+
125
+  .spin2 {
126
+    display: inline-block;
127
+    position: absolute;
128
+    left: 50%;
129
+    top: 50%;
130
+    transform: translate(-50%, -50%);
131
+  }
132
+}

+ 18
- 0
src/layouts/Loading.jsx View File

@@ -0,0 +1,18 @@
1
+import Spin from '@/components/Spin'
2
+import logo from '@/assets/icons/comm/logo_small.png'
3
+import './style.less'
4
+
5
+export default (props) => {
6
+  const { width = '64px', logoVisible } = props
7
+  const height = width
8
+
9
+  return (
10
+    <view className='loading' style={{ width, height }}>
11
+      <Spin size={width} />
12
+      {
13
+        logoVisible !== false &&
14
+        (<image className='loading-logo' src={logo} style={{ width, height }} />)
15
+      }
16
+    </view>
17
+  )
18
+}

+ 39
- 1
src/layouts/index.jsx View File

@@ -1,9 +1,47 @@
1
+
2
+import { useMemo } from 'react'
3
+import Taro from '@tarojs/taro'
1 4
 import { useModel } from '@/store'
2 5
 import useRouter from '@/utils/hooks/useRouter'
6
+import Loading from './Loading'
7
+import { getPageBy, getIndexPageOf } from '../routes'
3 8
 
4 9
 export default (Child) => (props) => {
5 10
   const [person] = useModel('person')
6 11
   const router = useRouter()
7 12
 
8
-  return <Child {...props} person={person} router={router} />
13
+  // 确保人员信息到位
14
+  const loading = !person?.personRole;
15
+
16
+  // 校验人员角色及页面是否对应
17
+  const jumpPage = useMemo(() => {
18
+    const personRole = person?.personRole;
19
+    if (!personRole) return;
20
+
21
+    const isNormalPerson = personRole === 'person'
22
+
23
+    const currentPage = getPageBy(router.path)
24
+    let indexPage = getIndexPageOf(personRole)
25
+    if (!isNormalPerson) {
26
+      indexPage = `${personRole}/${indexPage}`
27
+    }
28
+
29
+    const isMatched = isNormalPerson ?
30
+      // 如果是普通客户, page.root 应该是空的
31
+      !currentPage.root :
32
+      // 其他角色, 应该是对应的
33
+      currentPage.root === personRole
34
+    
35
+    // 如果对应上, 就不跳转
36
+    return isMatched ? undefined : indexPage
37
+  }, [router.path, person?.personRole])
38
+
39
+  if (jumpPage) {
40
+    // 注意此处跳转是没有加上原来的页面参数的
41
+    Taro.reLaunch({
42
+      url: `/${jumpPage}`,
43
+    })
44
+  }
45
+
46
+  return loading ? <Loading /> : <Child {...props} person={person} router={router} />
9 47
 }

+ 18
- 13
src/layouts/style.less View File

@@ -1,20 +1,25 @@
1
-.main-layout {
2
-  display: flex;
3
-  flex-direction: column;
4
-  width: 100vw;
5
-  height: 100vh;
6
-  overflow: hidden;
7
-  box-sizing: border-box;
8 1
 
9
-  .main-navbar {
10
-    flex: none;
2
+.loading {
3
+  margin: 0 auto;
4
+  margin-top: 30vh;
5
+  position: relative;
6
+
7
+  &-logo {
8
+    box-sizing: border-box;
9
+    padding: 12px;
10
+    position: absolute;
11
+    left: 0;
12
+    transform: scale(.75, .75);
13
+    animation: logo-opacity 2s linear infinite;
11 14
   }
15
+}
12 16
 
13
-  .main-tabber {
14
-    flex: none;
17
+@keyframes logo-opacity {
18
+  0%, 100% {
19
+    opacity: 1;
15 20
   }
16 21
 
17
-  .main-container {
18
-    flex: auto;
22
+  50% {
23
+    opacity: .4;
19 24
   }
20 25
 }

+ 13
- 5
src/routes.js View File

@@ -100,17 +100,25 @@ const subPackages = Object.keys(subPages).map((key) => {
100 100
   }
101 101
 })
102 102
 
103
-function getPages(role) {
104
-  if (role === person) {
105
-    return routes.filter(x => !x.root)
103
+// 获取路径对应页面
104
+function getPageBy(path) {
105
+  return routes.filter(x => path.indexOf(x.page) > -1)[0]
106
+}
107
+
108
+// 获取角色首页
109
+function getIndexPageOf(role) {
110
+  if (role === 'person') {
111
+    return routes.filter(x => !x.root && x.isIndex)[0]
106 112
   }
107 113
 
108
-  return routes.filter(x => x.roo === role)
114
+  return routes.filter(x => x.root === role && x.isIndex)[0]
109 115
 }
110 116
 
117
+// eslint-disable-next-line import/no-commonjs
111 118
 module.exports = {
112 119
   routes,
113 120
   pages,
114 121
   subPackages,
115
-  getPages
122
+  getPageBy,
123
+  getIndexPageOf
116 124
 }