Skip to content

Commit 0ad8fcc

Browse files
authored
feat: ✨ 新增Signature签名组件
Closes: #505
1 parent 981c8b4 commit 0ad8fcc

10 files changed

Lines changed: 516 additions & 3 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,12 @@ export default defineConfig({
337337
}, {
338338
link: "/component/password-input",
339339
text: "PasswordInput 密码输入框"
340-
}]
340+
},
341+
, {
342+
link: "/component/signature",
343+
text: "Signature 签名"
344+
}
345+
]
341346
}, {
342347
text: "反馈",
343348
collapsed: false,

docs/component/signature.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Signature 组件
2+
`Signature`组件是一个用于生成手写签名的 Vue 组件。它提供了多种自定义选项,包括签名笔的颜色、宽度以及自定义操作按钮
3+
## 基础用法
4+
```html
5+
<wd-signature @confirm="confirm" />
6+
<wd-img :height="img.height" :width="img.width" :src="img.src" v-if="img.src" />
7+
```
8+
9+
```typescript
10+
const img = ref({
11+
width: 0,
12+
height: 0,
13+
src: ''
14+
})
15+
function confirm(result: FileType) {
16+
img.value.src = result.tempFilePath
17+
img.value.height = result.height
18+
img.value.width = result.width
19+
}
20+
```
21+
## 自定义颜色
22+
`pen-color`设置签名笔的颜色,默认为`黑色`
23+
```html
24+
<wd-signature pen-color="red" />
25+
```
26+
27+
28+
## 自定义宽度
29+
`line-width`设置签名笔的宽度,默认为`2`
30+
```html
31+
<wd-signature :line-width="6" />
32+
```
33+
34+
## 自定义按钮
35+
通过`footer`插槽可以自定义按钮
36+
```html
37+
<wd-signature :disabled="disabled">
38+
<template #footer="{ clear, confirm }">
39+
<wd-button block @click="changeDisabled" v-if="disabled">开始签名</wd-button>
40+
<wd-button v-if="!disabled" size="small" plain @click="clear">清除</wd-button>
41+
<wd-button v-if="!disabled" size="small" style="margin-left: 4px" @click="confirm">确认</wd-button>
42+
</template>
43+
</wd-signature>
44+
```
45+
```typescript
46+
const disabled = ref(true)
47+
48+
function changeDisabled() {
49+
disabled.value = false
50+
}
51+
```
52+
## Attributes
53+
| 参数 | 说明 | 类型 | 可选值 | 默认值| 最低版本 |
54+
|-----|------|-----|-------|-------|--------|
55+
| penColor | 签名笔颜色 | String | -- | #000000 | -- |
56+
| lineWidth | 签名笔宽度 | Number | -- | 2 | -- |
57+
| height | 画布的高度 | Number | -- | 200 | -- |
58+
| width | 画布的宽度 | Number | -- | 300 | -- |
59+
| clearText | 清空按钮的文本 | String |-- | 清空 | -- |
60+
| confirmText | 确认按钮的文本 | String | -- | 确认 | -- |
61+
| fileType | 目标文件的类型,[wx.canvasToTempFilePath属性介绍](https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html#%E5%8F%82%E6%95%B0) | String | -- | png | -- |
62+
| quality | 目标文件的类型,[wx.canvasToTempFilePath属性介绍](https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html#%E5%8F%82%E6%95%B0) | Number | -- | 1 |-- |
63+
| exportScale | 导出图片的缩放比例 | Number | -- | 1 |-- |
64+
| disabled | 是否禁用签名板 | Boolean | -- | false | -- |
65+
66+
## Slot
67+
68+
| name | 说明 |参数 | 最低版本 |
69+
| ------- | ------------------------ |--- | -------- |
70+
| footer | 自定义footer | `{ clear, confirm }` |- |
71+
72+
## Events
73+
74+
| 事件名称 | 说明 | 参数 | 最低版本 |
75+
|---------|-----|-----|---------|
76+
| confirm | 点击确认按钮时触发 | `{tempFilePath, width, height}` 分别为生成文件的临时路径 (本地路径)、生成图片宽、生成图片高| - |
77+
| clear | 点击清空按钮时触发 | - | - |
78+
| touchstart | 按下时触发 | `event`| - |
79+
| touchend | 按下结束时触发 | `event` | - |
80+
81+
## Methods
82+
对外暴露函数
83+
84+
| 事件名称 | 说明 | 参数 | 最低版本 |
85+
|--------|------|-----|---------|
86+
| confirm | 点击确认按钮时触发 | `{tempFilePath, width, height}` 分别为生成文件的临时路径 (本地路径)、生成图片宽、生成图片高| - |
87+
| clear | 点击清空按钮时触发 | - | - |

src/pages.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"mp-alipay": {
2828
"allowsBounceVertical": "NO"
2929
},
30-
3130
"navigationBarTitleText": "Icon 图标"
3231
}
3332
},
@@ -802,6 +801,16 @@
802801
"navigationBarTitleText": "PasswordInput 密码输入框"
803802
}
804803
},
804+
{
805+
"path": "pages/signature/Index",
806+
"name": "signature",
807+
"style": {
808+
"mp-alipay": {
809+
"allowsBounceVertical": "NO"
810+
},
811+
"navigationBarTitleText": "Signature 签名"
812+
}
813+
},
805814
{
806815
"path": "pages/backtop/Index",
807816
"name": "backtop",
@@ -858,7 +867,6 @@
858867
"backgroundColorTop": "@bgColorTop",
859868
"backgroundColorBottom": "@bgColorBottom",
860869
"navigationStyle": "default"
861-
862870
// "navigationBarTextStyle": "black",
863871
// "navigationBarBackgroundColor": "#FFF",
864872
// "backgroundColor": "#F8F8F8"

src/pages/index/Index.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ const list = ref([
218218
{
219219
id: 'passwordInput',
220220
name: 'PasswordInput 密码输入框'
221+
},
222+
{
223+
id: 'signature',
224+
name: 'Signature 签名'
221225
}
222226
]
223227
},
@@ -427,37 +431,45 @@ onShareTimeline(() => {
427431
.kind-list__item {
428432
background: $-dark-background2;
429433
}
434+
430435
.title {
431436
color: $-dark-color;
432437
}
438+
433439
:deep(.wd-cell__label) {
434440
color: $-dark-color3 !important;
435441
}
442+
436443
.kind-list__img {
437444
filter: invert(100%);
438445
}
439446
}
447+
440448
.page__hd {
441449
padding: 40px 40px 30px;
442450
margin-bottom: 30px;
443451
background: #fff;
444452
}
453+
445454
.page__title {
446455
text-align: left;
447456
font-size: 20px;
448457
font-weight: 400;
449458
color: #0083ff;
450459
}
460+
451461
.page__desc {
452462
margin-top: 20px;
453463
color: #999;
454464
text-align: left;
455465
font-size: 12px;
456466
}
467+
457468
.page__bd {
458469
padding: 0 15px 30px 20px;
459470
user-select: none;
460471
}
472+
461473
.logo {
462474
display: inline-block;
463475
margin-right: 14px;
@@ -468,31 +480,37 @@ onShareTimeline(() => {
468480
background-size: cover;
469481
vertical-align: middle;
470482
}
483+
471484
.inline {
472485
display: inline-block;
473486
vertical-align: middle;
474487
}
488+
475489
.version {
476490
font-size: 14px;
477491
}
478492
479493
.wd-cell_access {
480494
padding: 15px 20px;
481495
}
496+
482497
.wd-cell__ft {
483498
padding-right: 16px;
484499
position: relative;
485500
}
501+
486502
.wd-cells {
487503
position: relative;
488504
margin-top: 0;
489505
opacity: 0;
490506
transform: translateY(-50%);
491507
transition: 0.3s;
508+
492509
:deep(.wd-cell__label) {
493510
color: rgba(0, 0, 0, 0.65);
494511
}
495512
}
513+
496514
.wd-cells_show {
497515
opacity: 1;
498516
transform: translateY(0);
@@ -502,6 +520,7 @@ onShareTimeline(() => {
502520
border-radius: 30px;
503521
background: #fff;
504522
overflow: hidden;
523+
505524
&:not(:last-child) {
506525
margin-bottom: 20px;
507526
}
@@ -521,20 +540,24 @@ onShareTimeline(() => {
521540
height: 0;
522541
overflow: hidden;
523542
}
543+
524544
.kind-list__item-bd_show {
525545
height: auto;
526546
}
527547
528548
.wd-flex {
529549
display: flex;
530550
}
551+
531552
.wd-flex__item {
532553
flex: 1;
533554
}
555+
534556
.title {
535557
font-size: 14px;
536558
color: rgba(0, 0, 0, 0.85);
537559
}
560+
538561
.page-name {
539562
font-size: 12px;
540563
color: rgba(0, 0, 0, 0.65);

src/pages/signature/Index.vue

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--
2+
* @Author: 810505339
3+
* @Date: 2025-01-10 15:49:26
4+
* @LastEditors: 810505339
5+
* @LastEditTime: 2025-01-11 22:10:22
6+
* @FilePath: \wot-design-uni\src\pages\signature\Index.vue
7+
* 记得注释
8+
-->
9+
<template>
10+
<page-wraper>
11+
<demo-block title="基础用法">
12+
<wd-signature @confirm="confirm" />
13+
<wd-img :height="img.height" :width="img.width" :src="img.src" v-if="img.src" />
14+
</demo-block>
15+
<demo-block title="自定义颜色">
16+
<wd-signature pen-color="red" />
17+
</demo-block>
18+
<demo-block title="自定义宽度">
19+
<wd-signature :line-width="6" />
20+
</demo-block>
21+
<demo-block title="自定义按钮">
22+
<wd-signature :disabled="disabled">
23+
<template #footer="{ clear, confirm }">
24+
<wd-button block @click="changeDisabled" v-if="disabled">开始签名</wd-button>
25+
<wd-button v-if="!disabled" size="small" plain @click="clear">清除</wd-button>
26+
<wd-button v-if="!disabled" size="small" style="margin-left: 4px" @click="confirm">确认</wd-button>
27+
</template>
28+
</wd-signature>
29+
</demo-block>
30+
</page-wraper>
31+
</template>
32+
<script lang="ts" setup>
33+
import type { FileType } from '@/uni_modules/wot-design-uni/components/wd-signature/types'
34+
import { ref } from 'vue'
35+
const img = ref({
36+
width: 0,
37+
height: 0,
38+
src: ''
39+
})
40+
const disabled = ref(true)
41+
function confirm(result: FileType) {
42+
img.value.src = result.tempFilePath
43+
img.value.height = result.height
44+
img.value.width = result.width
45+
}
46+
function changeDisabled() {
47+
disabled.value = false
48+
}
49+
</script>

src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,3 +953,8 @@ $-floating-panel-bar-height: var(--wot-floating-panel-bar-height, 3px) !default;
953953
$-floating-panel-bar-bg: var(--wot-floating-panel-bar-bg, $-color-gray-5) !default; // bar 背景色
954954
$-floating-panel-bar-radius: var(--wot-floating-panel-bar-radius, 4px) !default; // bar 圆角
955955
$-floating-panel-content-bg: var(--wot-floating-panel-content-bg, $-color-white) !default; // 内容背景色
956+
957+
/* signature */
958+
$-signature-bg: var(--wot-signature-bg, $-color-white) !default; // 背景色
959+
$-signature-radius: var(--wot-signature-radius, 4px) !default; // 圆角
960+
$-signature-border: var(--wot-signature-border, 1px solid $-color-gray-5) !default; // 边框圆角
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@import '../common/abstracts/variable';
2+
@import '../common/abstracts/mixin';
3+
4+
@include b(signature) {
5+
@include e(context){
6+
justify-content: center;
7+
align-items: center;
8+
display: flex;
9+
overflow: hidden;
10+
background: $-signature-bg;
11+
border-radius:$-signature-radius;
12+
border:$-signature-border;
13+
}
14+
@include e(footer)
15+
{
16+
margin-top: 4px;
17+
justify-content: flex-end;
18+
display: flex;
19+
& .wd-button + .wd-button{
20+
margin-left: 4px;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)