0.5.13 • Published 2 years ago

eft-cool-taro-ui v0.5.13

Weekly downloads
6
License
ISC
Repository
github
Last release
2 years ago

EXE大前端团队的Taro页面布局组件,支持在H5和小程序中使用,更多组件内容不断更新中~

简介

基于 Taro 框架 v1.3.9 开发,为了简化页面布局,解决列表页面经常使用到的下拉刷新、加载更多、顶部和底部区域固定、内容区域自适应高度等问题。将页面分为 header、content、footer三个部分,可以自由设置是否需要 header 和 footer,content 会根据 header 和 footer 调节高度占满屏幕。

组件开发中,可能涉及调整,需要留意最新修改

2021年9月18日 将taro版本升级到v2.2.15

2020年5月9日 将taro版本升级到v2.0.6

使用

首先,使用以下命令安装:

# yarn
$ yarn add eft-cool-taro-ui

# npm
$ npm i eft-cool-taro-ui --save

然后在app.scss引入样式:

@import '~eft-cool-taro-ui/style/index.scss';

最后在页面中使用:

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { EButton, EPage, EModal, ENavbar } from 'eft-cool-taro-ui'

import './index.scss'

export default class Index extends Component {

  config = {
    navigationBarTitleText: '首页'
  }

  constructor() {
    super()
    this.state = {
      noMore: false,
      hasMore: true,
      scrollTop: 0
    }
  }

  componentWillMount() { }

  componentDidMount() {
    Taro.eventCenter.trigger('ERefreshStart')
    // 模拟请求
    setTimeout(() => {
      Taro.eventCenter.trigger('ERefreshEnd')
      this.setState({
        hasMore: true
      })
    }, 1000)
  }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }

  refresh = () => {
    this.setState({
      refreshStatus: 1
    })
    Taro.showToast({
      title: '刷新',
      icon: 'none'
    })
    // 模拟请求
    setTimeout(() => {
      this.setState({
        refreshStatus: 2
      })
    }, Math.random() * 1000)
  }
  refreshLater = () => {
    setTimeout(() => {
      this.refresh()
    }, 1000)
  }

  loadMore = () => {
    setTimeout(() => {
      this.setState({
        hasMore: false,
        noMore: true
      })
    }, 1000)
  }

  openModel = () => {
    this.setState({
      open: true
    })
  }

  hideModal = () => {
    this.setState({
      open: false
    })
  }

  toTop = () => {
    this.setState({
      scrollTop: 0
    })
  }

  handleScrollEnd = (e) => {
    this.setState({
      scrollTop: e.detail.scrollTop
    })
  }

  goBack = () => {
    return true
  }
  render() {
    const { noMore, hasMore, refreshStatus, open, scrollTop } = this.state
    const header = <ENavbar leftText='返回' rightText='Model' onClickRightText={this.openModel} onClickLeft={this.goBack} >首页</ENavbar>
    const footer = <EButton outline circle onClick={this.refreshLater}>1秒后显示刷新</EButton>
    const refresherConfig = {
      recoverTime: 300,
      refreshTime: 1000
    }
    return (
      <View>
        <EModal openModel={open} position='right' onHide={this.hideModal}>
          <View>model</View>
        </EModal>
        <EPage
          renderHeader={<View className='header-container'>{header}</View>}
          renderFooter={<View className='footer-container'>{footer}</View>}
          onRefresh={this.refresh}
          onLoadMore={this.loadMore}
          noMore={noMore}
          hasMore={hasMore}
          hasMoreText='loading'
          refresherConfig={refresherConfig}
          refreshStatus={refreshStatus}
          scrollTop={scrollTop}
          onScrollEnd={this.handleScrollEnd}
        >
          <View className='main-container'>
            <View> Content </View>
            <EButton onClick={this.openModel}>显示modal</EButton>
            <View style={{ height: '30px' }}>content</View>
            <View style={{ height: '300px' }}>content</View>
            <View style={{ height: '300px' }}>content</View>
            <View style={{ height: '300px' }}>content</View>
            <View style={{ height: '300px' }}>content</View>
            <EButton onClick={this.openModel}>显示modal</EButton>
            <EButton onClick={this.openModel}>显示modal</EButton>
            <EButton onClick={this.openModel}>显示modal</EButton>
            <EButton onClick={this.toTop}>回到顶部</EButton>
          </View>
        </EPage>
      </View>
    )
  }
}

props

propspropTypes描述默认值
classNamestring自定义样式名-
renderHeaderelement顶部元素-
renderFooterelement底部元素-
onRefreshfunc下拉刷新回调函数-
onLoadMorefunc滚动到底部加载更多-
onScrollfunc滚动事件-
scrollTopnumber设置竖向滚动条位置0
onScrollEndfunc滚动结束触发-
hasMorebool是否能够加载更多-
noMorebool显示没有更多-
hasMoreTextstring自定义加载更多文字'加载中'
noMoreTextstring自定义没有更多文字'没有更多了'
refresherConfigobject设置加载动画效果详见 refresherConfig 描述
refreshStatusnumber刷新动画1:刷新中 2:刷新完成-
loadMoreThresholdnumber滚动底部多少距离开始加载更多100

refresherConfig

属性类型默认值描述
recoverTimenumber300回弹动画的时间 ms
refreshTimenumber500刷新动画至少显示的时间 ms (用来展示刷新动画, refreshStatus 为 1 时不生效)
thresholdnumber70刷新的阈值(低于这个值的时候不执行刷新)
maxHeightnumber200可拉动的最大高度
heightnumber60刷新动画播放时占的高度
showTextbooltrue显示文字
refreshTextarray'下拉刷新', '释放刷新', '加载中'刷新文字
disabledboolfalse禁用刷新

EPage 支持通过事件来显示和隐藏刷新动画:

Taro.eventCenter.trigger('ERefreshStart') // 显示刷新
Taro.eventCenter.trigger('ERefreshEnd') // 隐藏刷新

组件和props

正在更新完善……

EModal

滑出一个模态框

propspropTypes描述默认值
openModelbool是否显示false
showMaskbool是否显示灰色背景true
positionstring模态框出现的方向: ‘bottom’ | ‘top’ | ‘left’ | ‘right’'bottom'
onHidefunc关闭模态框调用-

ENavbar

导航栏组件

propspropTypes描述默认值
leftTextstring左边文字‘’
rightTextstring右边文字''
onClickRightTextfunc点击右边的文字-
onClickLeftfunc点击右边的文字和图标,不传或者返回 true 时会调用 Taro.navigateBack()-

EActivityIndicator

活动指示器,使用显示加载

propspropTypes描述默认值
sizenumber大小10
colorstring颜色,如:’#01A0FF‘‘#FFFFFF’

EButton

按钮组件

propspropTypes描述默认值
sizestring大小 'large'、'normal'、'small'、'mini''normal'
circlebool是否圆角false
inlinebool是否inlinefalse
outlinebool是否是线性类型按钮false
disabledbool是否禁用false
loadingbool是否显示加载false
0.5.12

2 years ago

0.5.13

2 years ago

0.5.11

2 years ago

0.5.10

3 years ago

0.5.9

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago