import { innertEvent, getJsError, getHttpError, getCommon, send, logParseJson, getResourceError, getPv, getBehavior, downloadFile } from './utils' import Ajax from './ajax' import Error from './error' import Pv from './pv' import Behavior from './behavior' import IndexDb from './IndexDb' import VueDebugHandler from './vue' const indexDb = new IndexDb(); (window as any).indexDb = indexDb; (window as any).innertEvent = innertEvent; (window as any).VueDebugHandler = VueDebugHandler; const common = getCommon((window as any).CollectCurrentPageInfoId, (window as any).CollectCurrentPageInfoUserId, (window as any).CollectCurrentPageInfoProjectVersion); const list: any[] = []; let canAdd = true; const fn = () => { setTimeout(() => { if (canAdd) { const json = list.splice(0,1); if (json && json.length) { canAdd = false indexDb.addItemToDb(json[0], () => { canAdd = true }); } } fn(); }, 300); } fn(); innertEvent.on('ajax', function(key:string, data?:any) { //console.log(key, data); if (data && data.request.ajaxUrl.indexOf('server/upLog') === -1) { const json = getHttpError(data, common); //send([json]); list.push(json); } }); innertEvent.on('errorStatic', function(key:string, data?:any) { //console.log(key, data); const json = getResourceError(data, common); //send([json]); list.push(json); }); innertEvent.on('errorJs', function(key:string, data?:any) { //console.log(key, data); const json = getJsError(data, common); // send([json]); list.push(json); }); innertEvent.on('pv', function(key:string, data?:any) { //console.log(key, data); const json = getPv(data, common); //send([json]); list.push(json); }); innertEvent.on('behavior', function(key:string, data?:any) { //console.log(key, data); const json = getBehavior(data, common); //send([json]); list.push(json); }); (window as any).logParseJson = logParseJson const ajax = new Ajax(); const error = new Error(); const pv = new Pv(); const behavior = new Behavior(); // 触发下载 alt + k ,下载成功后清除本地数据 document.onkeydown = function(event: Event) { // e.altKey、e.shiftKey、e.ctrlKey const e: any = event || window.event || arguments.callee.caller.arguments[0]; // 按下 alt + k if (e.keyCode === 75 && e.altKey) { const callback = function(list: any[]) { const fileName = new Date().getTime() + '-' + 'info.text'; let content = ''; list.forEach((item, index) => { if (index < list.length-1) { content += item.info + '\n'; } else { content += item.info; } }); downloadFile(fileName, content); indexDb.clear(); } indexDb.getAllItemToDb(callback); } }