1.5.1 • Published 1 year ago

@wines/hand-writing v1.5.1

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@wines/hand-writing

hand writing Canvas手写板

Canvas实现用户签字功能

使用指南

在 page.json 中引入组件

{
  "navigationBarTitleText": "Hand Wrting",
  "usingComponents": {
    "wux-button": "@wines/button",
    "wux-hand-writing": "@wines/hand-writing"
  }
}

示例

import './index.less';
import { PageData, PageCustom } from '@wines/core';
import { $wuxHandWriting } from '@wines/hand-writing';
const random = (min = 0, max = 1) => {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};
Page<PageData, PageCustom>({
  data: {
    height: 300,
    width: 300,
    bgColor: '',
    transparent: 1,
    lineColor: '#1A1A1A',
    lineSize: 1,
    lineMin: 0.5,
    lineMax: 4,
    pressure: 1,
    smoothness: 60,
  },
  onBgColor() {
    this.setData({
      bgColor: ['#fff', '#f0f0f0'][random(0, 1)],
    });
  },
  onTransparent() {
    this.setData({
      transparent: [0.8, 1][random(0, 1)],
    });
  },
  onLineColor() {
    this.setData({
      lineColor: ['#1A1A1A', '#fc5531'][random(0, 1)],
    });
  },
  onLineSize() {
    this.setData({
      lineSize: [0.5, 1, 1.5, 2, 3][random(0, 4)],
    });
  },
  onLineMin() {
    this.setData({
      lineMin: [0.1, 0.2, 0.4, 0.5][random(0, 3)],
    });
  },
  onLineMax() {
    this.setData({
      lineMax: [1, 2, 3, 4][random(0, 3)],
    });
  },
  onPressure() {
    this.setData({
      pressure: [0.5, 1, 2][random(0, 2)],
    });
  },
  onSmoothness() {
    this.setData({
      smoothness: [30, 45, 60, 75][random(0, 3)],
    });
  },
  onReset() {
    $wuxHandWriting().reset();
  },
  onSave() {
    $wuxHandWriting()
      .saveCanvasAsImage()
      .then((filePath: string) => {
        void wx.showModal({
          title: filePath,
        });
      });
  },
});

API

Result props

参数类型描述默认值
prefixClsstring自定义类名前缀wux-hand-writing
widthnumbercanvas 组件的宽度300
heightnumbercanvas 组件的高度300
bgColornumber设置canvas背景色, 不设置,导出的canvas的背景为透明300
transparentnumber透明度1
lineColorstring笔迹颜色#1A1A1A
lineSizenumber笔迹倍数1
lineMinnumber最小笔画半径0.5
lineMaxnumber最大笔画半径4
pressurenumber默认压力1
smoothnessnumber顺滑度,用60的距离来计算速度60

method

// 重置画布到初始化状态
- $wuxHandWriting().reset()
// 保存签名到本地临时图片
- $wuxHandWriting().saveCanvasAsImage()
1.5.1

1 year ago

1.5.0

1 year ago

1.3.5

2 years ago

1.4.0

2 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago