|
@@ -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
|
+}
|