亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

快速上手wepy,制作簡易簽名板

標簽:
JavaScript

wepy是开发微信小程序的一个框架

wepy特点:

700

应用是最好的学习方式, 这次用wepy做一个简易签名板

700

源码

<style lang="less">
    
    canvas {        margin: 20px auto;        border: 2px solid #A84631;        width: 300px;        height: 200px;        border-radius: 20px;
    }    .info {        text-align: center;
    }    image{        border: 1px solid #A84631;        width: 60px;        height: 40px;        margin : 5px;        border-radius: 5px;
    }    button {        width: 40%;        float: left;        margin: 5%;
    }</style><template>

    <view>
    <canvas canvas-id="myCanvas"
        disable-scroll=true
        bindtouchstart="start"
        bindtouchmove="move"
        bindtouchend="end"/>

    <view class="info">
        鼠标当前位置: ({{x}}, {{y}})    </view>
    <block>
        <button bindtap="exportImage" type="primary">存图</button>
    </block>    
    <block>
        <button bindtap="clearNow" type="warn">清空</button>
    </block>
    <block wx:for="{{filePathList}}">
        <image class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="{{item}}"/>
    </block>

    </view></template><script>

    import wepy from 'wepy'var ctx = wx.createCanvasContext('myCanvas')export default class Fyxz extends wepy.page {
  data = {        x: 0,        y: 0,        ctx: ctx,        filePath: '',        filePathList: []
      }

      methods = {        start: (e) => {          this.x = e.touches[0].x          this.y = e.touches[0].y
        },        move: (e) => {          this.ctx.moveTo(this.x, this.y)          this.x = e.touches[0].x          this.y = e.touches[0].y          this.ctx.lineTo(this.x, this.y)          this.ctx.stroke()          this.ctx.draw(true)
        },        end: (e) => {

        },        savaImageToDevice: (filePath) => {
          wx.saveImageToPhotosAlbum({
            success(res) {
            }
          })
        },        exportImage: () => {
          wx.canvasToTempFilePath({            x: 0,            y: 0,            width: 300,            height: 200,            destWidth: 300,            destHeight: 200,            canvasId: 'myCanvas',            success: (res) => {              let p = new Promise((resolve, reject) => {                let fp = res.tempFilePath
                resolve(fp)
              })
              p.then((fp) => {                console.log('++++>', fp)                this.filePath = fp                // 将照片保存到缓存
                this.methods.savaImageToDevice(fp)                // 将缓存路径保存到列表
                this.filePathList.push(fp)                // 手动更新数据
                this.$apply()
              }).then(() => {                // 清屏
                this.methods.clearNow();                console.log('更新完毕!')
              })
            }
          })
        },        clearNow: () => {          this.ctx.clearRect(0, 0, 100, 200)          this.ctx.draw()
        }
      }
    }</script>




點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
Web前端工程師
手記
粉絲
3868
獲贊與收藏
283

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消