|
@@ -0,0 +1,158 @@
|
|
|
+
|
|
|
+import { View, Text, Image, Navigator } from '@tarojs/components'
|
|
|
+import './index.less'
|
|
|
+import Taro from '@tarojs/taro'
|
|
|
+import { Component } from 'react';
|
|
|
+import searchPng from '../../icon/search.png'
|
|
|
+import { observer, inject } from 'mobx-react'
|
|
|
+import { BookStore } from '@src/store/book';
|
|
|
+/**顶部自定义导航
|
|
|
+ *
|
|
|
+ */
|
|
|
+type Props = {
|
|
|
+ children?: JSX.Element, //
|
|
|
+ backgroundColor?: string, // navbar 背景色
|
|
|
+ color?: string // 头部显示内容 颜色
|
|
|
+ fontSize?: number, // 头部显示内容字体大小
|
|
|
+ title?: string, // 头部显示内容
|
|
|
+ tab?: boolean, // 是否是tab类型
|
|
|
+ tabVal?: { // tabs 内容
|
|
|
+ text: number | string, // 展示内容
|
|
|
+ value: number | string // 选中传回内容
|
|
|
+ }[],
|
|
|
+ tabSelect?: string, // tab默认展示第几个
|
|
|
+ search?: boolean, // 是否展示搜索按钮
|
|
|
+ searchBack?: boolean, // 点击搜索触发
|
|
|
+ isToBack?: boolean, // 是否可返回上一页
|
|
|
+ zxTitle?: string, // 资讯头
|
|
|
+ lastRead?: boolean, // 是否展示上次阅读
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function CustomNavbar(WrappedComponent, props: Props) {
|
|
|
+ let { children, title, color, fontSize, backgroundColor, tab = false, tabVal, tabSelect = "", search = false, searchBack = false, isToBack = false, zxTitle = "", lastRead = false } = props
|
|
|
+ log(zxTitle);
|
|
|
+
|
|
|
+ interface Page {
|
|
|
+ props: {
|
|
|
+ store: {
|
|
|
+ indexStore: {
|
|
|
+ navBarTop: number,
|
|
|
+ openType: number,
|
|
|
+ isLastRead: boolean,
|
|
|
+ SET_ISLASTREAD: Function,
|
|
|
+ lastReadLog: any
|
|
|
+ },
|
|
|
+ bookStore: BookStore
|
|
|
+ },
|
|
|
+ extraProp: any,
|
|
|
+ passThroughProps: any
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @inject('store')
|
|
|
+ @observer
|
|
|
+ class Page extends Component {
|
|
|
+ state = {
|
|
|
+ navBar: 0,
|
|
|
+ capsuleWidth: 0,
|
|
|
+ navBarTop: 0,
|
|
|
+
|
|
|
+ }
|
|
|
+ componentDidMount() {
|
|
|
+ log('计算高')
|
|
|
+ const { indexStore: { navBarTop } } = this.props.store
|
|
|
+ let buttonBounding = Taro.getMenuButtonBoundingClientRect()
|
|
|
+ log(buttonBounding);
|
|
|
+ let { height, top, width } = buttonBounding
|
|
|
+ this.setState({ capsuleWidth: width + 10, navBar: (top - navBarTop) * 2 + height + 8, navBarTop })
|
|
|
+ }
|
|
|
+
|
|
|
+ selectHandle = (value: string | number) => {
|
|
|
+ this.props.store.bookStore.setWorkDirection(value as 0 | 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ gotoBack = () => {
|
|
|
+ Taro.navigateBack()
|
|
|
+ }
|
|
|
+ searchBackHandle = () => {
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: '/pages/search/index'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ componentDidUpdate(props) {
|
|
|
+ let oldNavBarTop = this.state.navBarTop
|
|
|
+ let newNavBarTop = this.props.store.indexStore.navBarTop
|
|
|
+ if (oldNavBarTop !== newNavBarTop) {
|
|
|
+ let buttonBounding = Taro.getMenuButtonBoundingClientRect()
|
|
|
+ log(buttonBounding);
|
|
|
+ let { height, top, width } = buttonBounding
|
|
|
+ this.setState({ capsuleWidth: width + 10, navBar: (top - newNavBarTop) * 2 + height + 8, navBarTop: newNavBarTop })
|
|
|
+ }
|
|
|
+ if (props.store.indexStore.openType === 1) {
|
|
|
+ log(123321);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { extraProp, ...passThroughProps } = this.props
|
|
|
+ let { navBar, capsuleWidth } = this.state
|
|
|
+ const { indexStore: { navBarTop, openType, },bookStore } = this.props.store
|
|
|
+ let stateIndex = bookStore.workDirection
|
|
|
+ console.log("stateIndex",stateIndex)
|
|
|
+ return <View style={{ height: navBar + navBarTop + 5 }}>
|
|
|
+ <View className='navbarWrap' style={{ paddingTop: navBarTop, height: navBar, backgroundColor: backgroundColor ? backgroundColor : "#FFFFFF" }}>
|
|
|
+ <View className='content'>
|
|
|
+ {
|
|
|
+ tab ? <View className="navbar">
|
|
|
+ <View className="tabs">
|
|
|
+ {
|
|
|
+ tabVal?.map((item) => {
|
|
|
+ return <View className={`tab ${item.value === stateIndex ? 'select' : ''}`} onClick={() => { this.selectHandle(item.value) }}>
|
|
|
+ <Text>{item.text}</Text>
|
|
|
+ {
|
|
|
+ item.value === stateIndex && <View></View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ search && <View className="search">
|
|
|
+ <Image src={searchPng} className="searchImg" onClick={searchBack ? this.searchBackHandle : () => { }} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ :
|
|
|
+ children ?
|
|
|
+ children :
|
|
|
+ <View className="title" style={{ color: color ? color : "#333333", fontSize: fontSize ? Taro.pxTransform(fontSize) : Taro.pxTransform(48) }}>
|
|
|
+ {
|
|
|
+ isToBack && <View className="back" >
|
|
|
+ <View style={{ backgroundColor: color === '#fff' ? '#fff' : '#fff' }}>
|
|
|
+ <View onClick={this.gotoBack} className="backBt">
|
|
|
+ <Image src={require('../../icon/backBlock.png')} className="searchImg" onClick={() => { }} />
|
|
|
+ </View>
|
|
|
+ <View className="line" style={{ backgroundColor: color === '#fff' ? '#e9e9e9' : '#e9e9e9' }}></View>
|
|
|
+ <View onClick={() => { }} className="homebt">
|
|
|
+ <Image src={require('../../icon/homeBlock.png')} className="searchImg" onClick={() => { }} mode='widthFix' />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ <View className="txt" style={{ color: color ? color : "#333333" }}>{title}</View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ <View style={{ width: capsuleWidth + 'px' }}></View>
|
|
|
+ </View>
|
|
|
+ <View style={{ paddingTop: (navBar + navBarTop + 5), height: `100vh`, boxSizing: 'border-box' }}>
|
|
|
+ <WrappedComponent {...passThroughProps} stateIndex={stateIndex} navBar={navBar + navBarTop + 5} />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Page
|
|
|
+}
|
|
|
+
|
|
|
+export default CustomNavbar
|