Skip to content
On this page

组件库文档 tmui.design

签名板 SignBoard

签名板全端兼容,用于签名使用


🌶️ 签名板 SignBoard 示例

查看模拟效果
示例模板
vue
<template>
	<tm-app>
		<tm-sheet :width="662">
			<tm-text label="签名板全端兼容,用于签名使用。请在下方书写"></tm-text>
			<tm-divider></tm-divider>
			<tm-sign-board :line-color="colorNow" :line-width="lineWidth" ref="board" :width="638" :height="400"></tm-sign-board>
			<tm-divider></tm-divider>
			<view class="py-24">
				<tm-text label="选择书写颜色"></tm-text>
			</view>
			<tm-radio-group v-model="colorNow">
				<tm-radio :color="item" :value="item" :label="item" v-for="(item, index) in colors" key="index"></tm-radio>
			</tm-radio-group>
			<view class="py-24">
				<tm-text label="拖动改变粗细"></tm-text>
			</view>
			<tm-slider :max="20" v-model="lineWidth" :default-value="lineWidth"></tm-slider>
			<tm-divider></tm-divider>
			<view class="flex flex-row flex-center">
				<tm-button @click="proxy.$refs.board.clear()" label="清空"></tm-button>
				<tm-button color="green" :margin="[24, 0]" @click="saveImg" label="保存签名"></tm-button>
			</view>
		</tm-sheet>
	</tm-app>
</template>
<script lang="ts" setup>
import { ref, getCurrentInstance, computed } from 'vue'
import tmApp from '@/tmui/components/tm-app/tm-app.vue'
import tmSheet from '@/tmui/components/tm-sheet/tm-sheet.vue'
import tmText from '@/tmui/components/tm-text/tm-text.vue'
import tmButton from '@/tmui/components/tm-button/tm-button.vue'
import tmSignBoard from '@/tmui/components/tm-sign-board/tm-sign-board.vue'
import tmDivider from '@/tmui/components/tm-divider/tm-divider.vue'
import tmRadioGroup from '@/tmui/components/tm-radio-group/tm-radio-group.vue'
import tmRadio from '@/tmui/components/tm-radio/tm-radio.vue'
import tmSlider from '@/tmui/components/tm-slider/tm-slider.vue'
const proxy = getCurrentInstance()?.proxy ?? null
const board = ref<InstanceType<typeof tmSignBoard> | null>(null)

const colors = ['red', 'blue', 'black', 'green']
const colorNow = ref('red')
const lineWidth = ref(5)
const saveImg = async () => {
	let src = await board.value?.save()
	uni.showToast({ title: '成功,请查看日志', icon: 'none' })
	console.log(src)
	if (!src) return
	// #ifndef H5
	uni.previewImage({
		current: src,
		urls: [src]
	})
	// #endif
}
</script>

🌶️ 兼容性

APP-VUEAPP-NVUE小程序WEB/H5VUE3/TS
✔️✔️✔️✔️✔️

🌱 参数

参数名类型默认值描述
widthNumber750宽度
heightNumber500高度
lineWidthNumber5笔画粗细
lineColorString"red"笔画颜色,是颜色值,非主题名称

🌹 事件

🌽 slot插槽

🥗 ref方法

如果在安卓端nvue原生的情况下保存二维码有未知问题,请使用vue页面使用本组件。

方法名参数返回值描述
save-Promise<String>h5端返回的是base64数据,其它端是临时图片路径
clear--清除画板