引入
ts
import { MorsePwd , simpleMorse } from 't-comm';
// 不支持 tree-shaking 的项目
import { MorsePwd , simpleMorse} from 't-comm/lib/morse-pwd/index';
// 只支持 ESM 的项目
import { MorsePwd , simpleMorse} from 't-comm/es/morse-pwd/index';MorsePwd
参数:
- MorsePwd
new MorsePwd(options)- instance
- static
.init(options)⇒Object
new MorsePwd(options)
摩斯密码初始化
| Param | Type | Description |
|---|---|---|
| options | Object | 选项 |
| options.pwd | Array<number> | 密码 |
| options.cb | function | 成功回调 |
| options.quiet | Boolean | 是否安静模式(不打印日志) |
| options.holdTime | number | 等待多久后就恢复原位 |
| options.envType | 'H5' | 'h5' | 'mp' | 'MP' | 环境类型 |
| options.selector | String | h5模式下的选择器 |
morsePwd.clear()
清除监听事件
Kind: instance method of MorsePwd
Example
typescript
beforeDestroy() {
this.morsePwd.clear();
}MorsePwd.init(options) ⇒ Object
初始化
Kind: static method of MorsePwd
Returns: Object -
MorsePwd实例
| Param | Type | Description |
|---|---|---|
| options | Object | 选项 |
| options.pwd | Array<number> | 密码 |
| options.cb | function | 成功回调 |
| options.quiet | Boolean | 是否安静模式(不打印日志) |
| options.holdTime | number | 等待多久后就恢复原位 |
| options.envType | 'H5' | 'h5' | 'mp' | 'MP' | 环境类型 |
| options.selector | String | h5模式下的选择器 |
Example (小程序环境)
typescript
<template>
<div
class="tip-match-header"
/@longpress="onLongPressWrap"
/@click.stop="onClickWrap"
>
</template>
<script>
export default {
data() {
return {
morsePwd: null,
};
},
mounted() {
this.morsePwd = MorsePwd.init({
pwd: [1, 1, 1, 2, 2, 2, 1, 1, 1],
cb: () => {
this.showToast('hhh');
},
envType: 'MP',
});
},
beforeDestroy() {
this.morsePwd.clear();
},
methods: {
onLongPressWrap() {
this.morsePwd.longPress();
},
onClickWrap() {
this.morsePwd.click();
},
}
}
</script>Example (H5环境)
typescript
<script>
export default {
data() {
return {
morsePwd: null,
};
},
mounted() {
this.morsePwd = MorsePwd.init({
pwd: [1, 1, 1, 2, 2, 2, 1, 1, 1],
cb: () => {
this.showToast('xxx');
},
selector: '#app',
envType: 'H5',
});
},
beforeDestroy() {
this.morsePwd.clear();
},
}
</script>simpleMorse(param)
描述:
简单的摩斯密码,只有点击
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| param | object | 参数 |
示例
ts
simpleMorse({
target: 5, // 目标值
callback: () => console.log('test'),
timeout: 300, // 超时取消
debug: false,
})