UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

131 lines (130 loc) 3.51 kB
interface IMorsePwd { pwd: Array<number>; cb: Function; quiet?: boolean; holdTime?: number; envType: 'H5' | 'h5' | 'mp' | 'MP'; selector?: keyof HTMLElementTagNameMap; } declare class MorsePwd { /** * 初始化 * @static * @param {Object} options 选项 * @param {Array<number>} options.pwd 密码 * @param {Function} options.cb 成功回调 * @param {Boolean} options.quiet 是否安静模式(不打印日志) * @param {number} options.holdTime 等待多久后就恢复原位 * @param {'H5' | 'h5' | 'mp' | 'MP'} options.envType 环境类型 * @param {String} options.selector h5模式下的选择器 * * @example <caption>小程序环境</caption> * <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 <caption>H5环境</caption> * <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> * * @returns {Object} MorsePwd实例 */ static init(options: IMorsePwd): MorsePwd; pwd: Array<number>; cb: Function; holdTime: number; quiet: Boolean; selector?: keyof HTMLElementTagNameMap; envType?: 'H5' | 'h5' | 'mp' | 'MP'; clickCode: number; longPressCode: number; curIdx: number; holdTimer: any; h5Dom: any; longPressTimer: any; isLongTouch: Boolean; /** * 摩斯密码初始化 * @constructor * @param {Object} options 选项 * @param {Array<number>} options.pwd 密码 * @param {Function} options.cb 成功回调 * @param {Boolean} options.quiet 是否安静模式(不打印日志) * @param {number} options.holdTime 等待多久后就恢复原位 * @param {'H5' | 'h5' | 'mp' | 'MP'} options.envType 环境类型 * @param {String} options.selector h5模式下的选择器 */ constructor(options: IMorsePwd); bindEvent(): void; onTouchStart(): void; onTouchEnd(): void; onTouchMove(): void; /** * 清除监听事件 * @example * beforeDestroy() { * this.morsePwd.clear(); * } */ clear(): void; operation(type: number): void; reset(): void; click(): void; suc(): void; longPress(): void; log(...args: Array<unknown>): void; } export { MorsePwd };