Your Name пре 3 година
родитељ
комит
8be7ee61c9

+ 1
- 0
config/index.js Прегледај датотеку

@@ -21,6 +21,7 @@ const config = {
21 21
     }
22 22
   },
23 23
   alias: {
24
+    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
24 25
     '@/components': path.resolve(__dirname, '..', 'src/components'),
25 26
     '@/layouts': path.resolve(__dirname, '..', 'src/layouts'),
26 27
   },

BIN
src/assets/icons/comm/goback.png Прегледај датотеку


BIN
src/assets/icons/comm/goback_white.png Прегледај датотеку


BIN
src/assets/icons/tabbar/guide.png Прегледај датотеку


BIN
src/assets/icons/tabbar/guide_active.png Прегледај датотеку


BIN
src/assets/icons/tabbar/mine.png Прегледај датотеку


BIN
src/assets/icons/tabbar/mine_active.png Прегледај датотеку


BIN
src/assets/icons/tabbar/recommend.png Прегледај датотеку


BIN
src/assets/icons/tabbar/recommend_active.png Прегледај датотеку


BIN
src/assets/icons/tabbar/strategy.png Прегледај датотеку


BIN
src/assets/icons/tabbar/strategy_active.png Прегледај датотеку


+ 87
- 0
src/components/CustomNav/index.jsx Прегледај датотеку

@@ -0,0 +1,87 @@
1
+
2
+import { useState, useEffect, useMemo } from 'react'
3
+import Taro from '@tarojs/taro'
4
+import gobackBlack from '@/assets/icons/comm/goback.png'
5
+import gobackWhite from '@/assets/icons/comm/goback_white.png'
6
+import './style.less'
7
+
8
+export default (props) => {
9
+  const { bgImg, logo, title = '首页', home } = props
10
+
11
+  // 菜单胶囊
12
+  const menuBound = useMemo(() => Taro.getMenuButtonBoundingClientRect(), [])
13
+  // 整体顶部导航
14
+  const navStyle = useMemo(() => {
15
+    return {
16
+      height: `${menuBound.bottom}px`,
17
+      backgroundImage: bgImg ? `url(${bgImg})` : 'none',
18
+    }
19
+  }, [menuBound.bottom, bgImg])
20
+  // 导航栏
21
+  const navBarStyle = useMemo(() => {
22
+    return {
23
+      top: `${menuBound.top}px`,
24
+      height: `${menuBound.height}px`
25
+    }
26
+  }, [menuBound.top, menuBound.height])
27
+  // 导航栏按钮
28
+  const actionStyle = useMemo(() => {
29
+    return {
30
+      width: `${menuBound.width + 8}px`,
31
+      paddingLeft: '8px',
32
+      lineHeight: `${menuBound.height}px`,
33
+      height: `${menuBound.height}px`,
34
+    }
35
+  }, [menuBound.width, menuBound.height])
36
+  // 导航栏标题
37
+  const contentStyle = useMemo(() => {
38
+    const screenWidth = menuBound.right + 8;
39
+    return {
40
+      width: `${screenWidth - menuBound.width * 2 - 16}px`,
41
+      color: bgImg ? '#fff' : '#333',
42
+      lineHeight: `${menuBound.height}px`,
43
+      height: `${menuBound.height}px`,
44
+      paddingLeft: '8px',
45
+      paddingRight: '8px',
46
+    }
47
+  }, [menuBound.width, menuBound.height, menuBound.right, bgImg])
48
+  // logo
49
+  const logoStyle = useMemo(() => {
50
+    return {
51
+      width: `${menuBound.height}px`,
52
+      height: `${menuBound.height}px`,
53
+    }
54
+  }, [menuBound.height])
55
+
56
+  const handleAction = () => {
57
+    if (home || logo) return;
58
+
59
+    if (Taro.getCurrentPages().length > 1) {
60
+      Taro.navigateBack({ delta: 1 })
61
+    }
62
+  }
63
+
64
+  return (
65
+    <view className='custom-nav' style={navStyle}>
66
+      <view className='custom-nav-bar' style={navBarStyle}>
67
+        <view className='custom-nav-bar-action' style={actionStyle}>
68
+          {
69
+            !!logo && <image src={logo} className='custom-nav-bar-logo' mode='aspectFit' style={logoStyle} />
70
+          }
71
+          {
72
+            !home && (
73
+              <view>
74
+                <view className='custom-nav-bar-action-part' onClick={handleAction}>
75
+                  {/* <image src={bgImg ? gobackWhite : gobackBlack} className='custom-nav-bar-action-goback' mode='aspectFit' /> */}
76
+                </view>
77
+                <view className='custom-nav-bar-action-part'>
78
+                </view>                
79
+              </view>
80
+            )
81
+          }
82
+        </view>
83
+        <view className='custom-nav-bar-content' style={contentStyle}>{title}</view>
84
+      </view>
85
+    </view>
86
+  )
87
+}

+ 51
- 0
src/components/CustomNav/style.less Прегледај датотеку

@@ -0,0 +1,51 @@
1
+.custom-nav {
2
+	display: block;
3
+	position: relative;
4
+
5
+  &-bar {    
6
+    position: absolute;
7
+    width: 100%;
8
+    z-index: 1024;
9
+    left: 0;
10
+
11
+    &-action {
12
+      display: inline-block;
13
+      box-sizing: border-box;
14
+
15
+      image {
16
+        display: inline-block;
17
+        border: 0;
18
+      }
19
+
20
+      &-part {
21
+        width: 50%;
22
+        display: inline-block;
23
+        text-align: center;
24
+        height: 100%;
25
+
26
+        image {
27
+          &:first-child {
28
+            width: 16px;
29
+            height: 28px;
30
+          }
31
+        }
32
+      }
33
+    }
34
+
35
+    &-logo {
36
+      border-radius: 50%;
37
+    }
38
+
39
+    &-content {
40
+      display: inline-block;
41
+      text-align: center;
42
+      font-size: 32px;
43
+      cursor: none;
44
+      pointer-events: none;
45
+      text-overflow: ellipsis;
46
+      white-space: nowrap;
47
+      overflow: hidden;
48
+      box-sizing: border-box;
49
+    }
50
+  }
51
+}

+ 2
- 1
src/pages/index/index.config.js Прегледај датотеку

@@ -1,3 +1,4 @@
1 1
 export default {
2
-  navigationBarTitleText: '首页'
2
+  navigationBarTitleText: '首页',
3
+  navigationStyle: 'custom',
3 4
 }

+ 10
- 19
src/pages/index/index.jsx Прегледај датотеку

@@ -1,24 +1,15 @@
1
-import { Component } from 'react'
2
-import { View, Text } from '@tarojs/components'
3
-import './index.less'
4
-
5
-export default class Index extends Component {
6
-
7
-  componentWillMount () { }
8 1
 
9
-  componentDidMount () { }
10
-
11
-  componentWillUnmount () { }
2
+import { View, Text } from '@tarojs/components'
3
+import CustomNav from '@/components/CustomNav'
12 4
 
13
-  componentDidShow () { }
14 5
 
15
-  componentDidHide () { }
6
+import './index.less'
16 7
 
17
-  render () {
18
-    return (
19
-      <View className='index'>
20
-        <Text>Hello world!</Text>
21
-      </View>
22
-    )
23
-  }
8
+export default (props) => {
9
+  return (
10
+    <View className='index'>
11
+      <CustomNav title='首页' />
12
+      <Text>Hello world!</Text>
13
+    </View>
14
+  )
24 15
 }

+ 22
- 2
src/pages/test/index.jsx Прегледај датотеку

@@ -1,7 +1,27 @@
1 1
 import Layout from '@/layouts'
2
-
2
+import Taro, { useRouter } from '@tarojs/taro'
3
+import { useEffect } from 'react'
3 4
 export default (props) => {
5
+  const router = useRouter()
6
+
7
+  console.log('----------->', router)
8
+
9
+  // useEffect(() => {
10
+  //   const t = setTimeout(() => {
11
+  //     try {
12
+  //       Taro.navigateTo({ url: '/pages/test/index?id=1' })
13
+  //     } catch (e) {
14
+  //       console.log('-----eeee------>', e)
15
+  //     }
16
+  //     clearTimeout(t)
17
+  //     console.log('-----setTimeout------>', t)
18
+  //     console.log(Taro.getCurrentPages())
19
+  //   }, 2000)
20
+
21
+  // }, [])
22
+
4 23
   return (
5
-    <Layout>123</Layout>
24
+    <Layout>
25
+    </Layout>
6 26
   )
7 27
 }

+ 10
- 0
src/router/core.js Прегледај датотеку

@@ -0,0 +1,10 @@
1
+
2
+export default function createRouter (routes, options) {
3
+  let current;
4
+  let prev;
5
+  let next;
6
+
7
+  function transitionTo(location) {
8
+
9
+  }
10
+}