UNPKG

t-comm

Version:

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

61 lines (56 loc) 1.77 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tencentDoc_config = require('./config.js'); /** * 判断是否为腾讯文档链接 * @param url 待判断的链接 * * @example * ```ts * isTencentDocLink('https://docs.qq.com/doc/xxx'); // true * isTencentDocLink('https://example.com'); // false * ``` */ function isTencentDocLink() { var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; return !!url && url.startsWith(tencentDoc_config.TENCENT_DOC_URL_PREFIX); } /** * 打开腾讯文档链接 * * - H5 环境下:直接 `window.location.href` 跳转 * - 小程序环境下:跳转到腾讯文档小程序详情页 * * @param jumpUrl 腾讯文档链接(必须以 `https://docs.qq.com/doc` 开头) * @returns 是否为腾讯文档链接(仅当链接合法时执行跳转并返回 true) * * @example * ```ts * openTencentDocLink('https://docs.qq.com/doc/xxx'); * ``` */ function openTencentDocLink() { var jumpUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; if (!isTencentDocLink(jumpUrl)) { return false; } // 小程序环境 if (typeof wx !== 'undefined' && typeof wx.navigateToMiniProgram === 'function') { wx.navigateToMiniProgram({ appId: tencentDoc_config.TENCENT_DOC_MP_APP_ID, path: "".concat(tencentDoc_config.TENCENT_DOC_MP_DETAIL_PATH, "?url=").concat(encodeURIComponent(jumpUrl)), success: function success() { // 打开成功 } }); return true; } // H5 环境 if (typeof window !== 'undefined') { window.location.href = jumpUrl; return true; } return false; } exports.isTencentDocLink = isTencentDocLink; exports.openTencentDocLink = openTencentDocLink;