UNPKG

@alicloud/cloud-charts

Version:

![](https://img.shields.io/npm/v/@alicloud/cloud-charts?color=%23ff8200)

108 lines (96 loc) 3.03 kB
import { isMobile } from './platform'; import { VERSION, THEME, FullTrackName, FullTestName, TrackName, FullCamelName, FullCrossName, FullQualityName } from '../constants'; import { calcChartScore, postMessage } from './postMessage'; /** * 日志记录 * * 包含 chartLog getLog 方法 * */ var logMap = {}; /** * chartLog 图表日志 * * @param {string} name 图表名称 * @param {string} logType 单次日志类型 * */ export default function chartLog(name, logType, logInfo) { if (!logMap[name]) { logMap[name] = { init: 0, rulesInfo: [], configInfo: [], renderTimeArray: [] }; } if (logType === 'init') { logMap[name][logType] += 1; } else if (logType === 'rulesInfo') { var chartClass = FullCrossName + " " + name; logMap[name][logType].push({ domInfo: { tagName: 'div', className: chartClass, selector: logInfo.selector }, checkItem: logInfo.checkItem, errorInfo: logInfo.errorInfo }); } else if (logType === 'configInfo') { logMap[name][logType].push(logInfo); } else if (logType === 'renderTime') { logMap[name]['renderTimeArray'].push(logInfo); } } export function getLog() { return logMap; } var currentTheme = ''; export function themeLog(name) { currentTheme = name; } var trackable = window[FullTrackName] !== false; var testable = window[FullTestName] !== false; /** * 打点控制函数 * * @param {bool} enable 是否开启打点 * */ export function track(enable) { // 新版本中 G2 不再打点,所以关闭该指令 // G2.track(enable); // F2.track(enable); trackable = enable; } /** * test控制函数 * * @param {bool} enable 是否开启打点 * */ export function test(enable) { testable = enable; } // 打点逻辑,使用黄金令箭 var logUrl = "//gm.mmstat.com/" + TrackName; setTimeout(function () { // 规则计算部分 if (testable) { var chartRulesResult = calcChartScore(logMap); // 方便图表获取质量分数 // 增加一个当前统计的图表数量 window[FullQualityName] = chartRulesResult; postMessage(chartRulesResult); } // 打点部分 if (trackable && process.env.NODE_ENV === 'production') { var chartInit = Object.keys(logMap).map(function (name) { var chartLog = logMap[name]; return name + ":" + chartLog.init; }).join(','); var image = new Image(); // 统计 版本、主题、当前域名、图表初始化次数 image.src = logUrl + "?version=" + VERSION + "&theme=" + (currentTheme || THEME) + "&t=" + Date.now() + "&host=" + (location && location.host) + "&chartinit=" + chartInit + "&uamobile=" + isMobile; } }, 6000); export function warn(component, info) { var _console; for (var _len = arguments.length, other = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { other[_key - 2] = arguments[_key]; } (_console = console).warn.apply(_console, ["[" + FullCamelName + "] " + component + ":", info].concat(other)); }