Name Last update
config
src
.editorconfig
.eslintrc
.gitignore
changelog.md
package.json
project.config.json
readme.md
yarn.lock

可以watch 这个项目,有更新,及时知道

项目会不断迭代,有需求欢迎issue 如果能帮到你,那就给个star呗!

文章

功能列表

  • 封装api请求方式
  • 更方便的创建action:增加createApiAction
  • 基础像素试着为1倍即:1px 会编译成 2rpx(小程序默认是2倍)符合习惯
  • 基础demo案列
  • 增加生成海报类

生成海报使用方式

        <view className='posterWrapper' style='width:{{posterWidth}}px;height:{{posterHeight}}px;' catchtap='prevent'>
          <canvas className='poster' width='{{posterWidth* 2}}' height='{{posterHeight * 2}}' canvas-id='poster' style='width:{{posterWidth}}px;height:{{posterHeight}}px;'></canvas>
        </view>

  constructor(props) {
    super(props)
    this.state = {
      posterWidth: '375',
      posterHeight: '500',
      posterInfo: {
        tempBg: 'xxx.png'
      },
      offset: 1,
    }
    let config = {
      id: 'poster',
      background: {
        image: this.state.posterInfo.tempBg,
        width: this.state.posterWidth,
        height: this.state.posterHeight,
      }
    }
    console.log(config)
    this.poster = new Poster(config)

    // console.log(this.poster)
  }

  genPoster = () => {
    const that = this
    this.poster.drawBackground()
    this.poster.ctx.draw(true, function () {
      console.log('poster', '海报绘制完成')
      that.poster.generateTempImage()
    })
  }

用法

npm i

npm start

更优雅的创建action

未封装前

function articleList(data) {
  return { type: LIST, payload: data }
}

export function list() { console.log('list') return (dispatch) => { // service.get('/v1/article/list') // .then((res) => { // dispatch(articleList(res.data.article)) // })

Taro.request({
  url: 'http://api.shudong.wang/v1/article/list',
  data: {
    foo: 'foo',
    bar: 10
  },
  header: {
    'content-type': 'application/json'
  }
}).then((res) => {
  dispatch(articleList(res.data.article))
})

} }

![2018-09-25-15-50-45](http://s.shudong.wang/2018-09-25-15-50-45.png)
> 封装后请求api的使用方式

export const list = createApiAction(LIST, params => api.get('news/list', params))

![2018-09-25-15-51-45](http://s.shudong.wang/2018-09-25-15-51-45.png)