Skip to content

Signature 签名

介绍

用于签名场景的组件,基于 Canvas 实现。

引入

ts
import { IBestSignature } from "@ibestservices/ibest-ui";

代码演示

基础用法

基础用法

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  @State imgUrl: string = ""
  build() {
    Column({ space: 20 }){
      IBestSignature({
        onConfirm: (url: string) => {
          this.imgUrl = url
        }
      })
      if(this.imgUrl){
        Image(this.imgUrl)
      }
    }
  }
}

自定义样式

自定义样式

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  @State imgUrl: string = ""
  build() {
    Column({ space: 20 }){
      IBestSignature({
        penColor: "#ff0000",
        lineWidth: 5,
        bgColor: "#eee",
        onConfirm: (url: string) => {
          this.imgUrl = url
        }
      })
      if(this.imgUrl){
        Image(this.imgUrl)
      }
    }
  }
}

自定义宽高

自定义宽高

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  @State imgUrl: string = ""
  build() {
    Column({ space: 20 }){
      IBestSignature({
        boardWidth: 300,
        boardHeight: 200,
        onConfirm: (url: string) => {
          this.imgUrl = url
        }
      })
      if(this.imgUrl){
        Image(this.imgUrl)
      }
    }
  }
}

controller 控制器

controller 控制器

点我查看代码
ts
import { IBestSignatureController } from "@ibestservices/ibest-ui";
@Entry
@Component
struct DemoPage {
  @State imgUrl: string = ""
  private controller: IBestSignatureController = new IBestSignatureController()
  build() {
    Column({ space: 20 }){
      IBestSignature({
        controller: this.controller,
        isShowFooter: false,
        onConfirm: (url: string) => {
          this.imgUrl = url
        }
      })
      if(this.imgUrl){
        Image(this.imgUrl)
      }
      Row({ space: 10 }){
        IBestButton({
          text: '清空',
          onClickBtn: () => {
            this.controller.clear()
          }
        })
        IBestButton({
          text: '确认',
          type: 'primary',
          onClickBtn: () => {
            this.controller.confirm()
          }
        })
      }
    }
  }
}

API

@Props

参数说明类型默认值
boardWidth画板宽度, 小于0都默认为百分百number | string100%
boardHeight画板高度number | string200
exportImgType导出图片类型, 可选值 png jpeg webpstringpng
penColor笔触颜色string | number | CanvasGradient | CanvasPattern#000
lineWidth线条宽度number3
bgColor背景色string | number | CanvasGradient | CanvasPattern#fff
clearText清除按钮文案string清空
confirmText确认按钮文案string确认
isShowFooter是否显示底部按钮booleantrue

Events

事件名说明回调参数
onDrawEnd手指离开屏幕触发-
onConfirm点击确定按钮的回调url: string
onClear点击清空按钮的回调-

controller 控制器

方法名说明方法参数
clear清空画板, 会触发onClear事件-
confirm确认签名, 会触发onConfirm事件-