Skip to content

引入

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

参数

new MorsePwd(options)

摩斯密码初始化

ParamTypeDescription
optionsObject选项
options.pwdArray<number>密码
options.cbfunction成功回调
options.quietBoolean是否安静模式(不打印日志)
options.holdTimenumber等待多久后就恢复原位
options.envType&#x27;H5&#x27; | &#x27;h5&#x27; | &#x27;mp&#x27; | &#x27;MP&#x27;环境类型
options.selectorStringh5模式下的选择器

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实例

ParamTypeDescription
optionsObject选项
options.pwdArray<number>密码
options.cbfunction成功回调
options.quietBoolean是否安静模式(不打印日志)
options.holdTimenumber等待多久后就恢复原位
options.envType&#x27;H5&#x27; | &#x27;h5&#x27; | &#x27;mp&#x27; | &#x27;MP&#x27;环境类型
options.selectorStringh5模式下的选择器

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)

描述:简单的摩斯密码,只有点击

参数

参数名类型描述
paramobject参数

示例

ts
simpleMorse({
  target: 5, // 目标值
  callback: () => console.log('test'),
  timeout: 300, // 超时取消
  debug: false,
})