UNPKG

nimble-ui

Version:
38 lines (35 loc) 974 B
import { deviceInfo, throttle } from 'nimble-lib'; /** * 电话 * @param {Object} options 选项 * @return {Object} */ export default function mobile (options) { options = options || {}; let tel = options.tel || ''; return { /** * 被绑定元素插入父节点时调用 * @param {HTMLElement} el dom元素 * @param {Object} arg 参数 */ inserted (el, arg) { const _tel = (arg.value && arg.value.tel) || tel; if (!_tel) { return; } let _callFn = throttle(_call, 300, this, false); el.addEventListener('click', _callFn); /** * 拨电话 */ function _call () { if (deviceInfo.ios) { location.href = `tel://${_tel}`; } else { location.href = `tel:${_tel}`; } } } }; }