uniapp签名签字板lime-signature

使用前需在插件市场安装插件 插件ID:lime-signature

HTML代码

<template>
  <view class='signature h-100'>
    <view class='h-100'>
      <l-signature
        disableScroll
        backgroundColor='#ddd'
        ref='signatureRef'
        :penColor='penColor'
        :penSize='penSize'
        :openSmooth='openSmooth'
      ></l-signature>
    </view>
    <view class='button'>
      <view @click='onClick("clear")'>
        <!-- clear按钮的SVG图标 -->
      </view>
      <view @click='onClick("undo")'>
        <!-- undo按钮的SVG图标 -->
      </view>
      <view @click='onClick("save")'>
        <!-- save按钮的SVG图标 -->
      </view>
    </view>
  </view>
</template>

JavaScript

<script>
export default {
  data() {
    return {
      title: 'Hello',
      penColor: 'red',
      penSize: 5,
      url: '',
      openSmooth: true
    }
  },
  methods: {
    onClick(type) {
      if (type == 'openSmooth') {
        this.openSmooth = !this.openSmooth
        return
      }
      if (type == 'save') {
        this.$refs.signatureRef.canvasToTempFilePath({
          success: (res) => {
            // 是否为空画板 无签名
            console.log(res.isEmpty)
            // 生成图片的临时路径
            // H5 生成的是base64
            this.url = res.tempFilePath
          }
        })
        return
      }
      if (this.$refs.signatureRef)
        this.$refs.signatureRef[type]()
    }
  }
}
</script>

Css代码

<style>
.signature {
  position: relative;
}
.button {
  position: absolute;
  background: #fff;
  padding: 10px;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  width: 100%;
  align-items: center;
}
.h-100 {
  height: 100%;
}
</style>

API

Props

参数说明类型默认值
penSize画笔大小number2
minLineWidth线条最小宽number2
maxLineWidth线条最大宽number6
penColor画笔颜色stringblack
backgroundColor背景颜色string“”
type指定 canvas 类型string2d
openSmooth是否模拟压感booleanfalse
beforeDelay延时初始化,在放在弹窗里可以使用 (毫秒)number0
maxHistoryLength限制历史记录数,即最大可撤销数,传入0则关闭历史记录功能boolean20
landscape横屏boolean
disableScroll当在写字时,禁止屏幕滚动以及下拉刷新booleantrue
boundingBox只生成内容区域,即未画部分不生成,有性能的损耗booleanfalse

事件 Events

事件名说明回调
undo撤消,回退到上一步
clear清空,清空画板
canvasToTempFilePath保存,生成图片,与官方保持一致,但不需要传canvasId

Vue 2 和 Vue 3 的平台兼容性:

平台/浏览器Vue 2 兼容性Vue 3 兼容性
App
快应用××
微信小程序
支付宝小程序
百度小程序
字节小程序
QQ小程序
HBuilderX 3.5.4 app-vue
HBuilderX 3.5.4 app-nvue
钉钉小程序××
快手小程序××
飞书小程序××
京东小程序××
H5-Safari
Android Browser
微信浏览器(Android)
QQ浏览器(Android)
Chrome
IE××
Edge××
Firefox
PC-Safari
文章链接:http://iwebg.cn/index.php/2023/07/21/uniapp%e7%ad%be%e5%90%8d%e7%ad%be%e5%ad%97%e6%9d%bflime-signature/

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇