feat: add Monitor

This commit is contained in:
wuyue.xht 2020-06-10 21:50:45 +08:00
parent fecf34d0d7
commit f915d19dba
3 changed files with 46 additions and 12 deletions

View File

@ -1,11 +0,0 @@
/**
*
* @param {String} gmKey
* @param {Object} params
* @param {String} logKey
*/
export function goldlog(gmKey: string, params: object = {}, logKey: string = 'other'): void {
}

View File

@ -1,5 +1,5 @@
export * from './get-public-path';
export * from './goldlog';
export * from './monitor';
export * from './obx';
export * from './request';
export * from './focus-tracker';

View File

@ -0,0 +1,45 @@
class Monitor {
fn = (params: any) => {
const { AES } = window as any;
if (typeof AES.log === 'function') {
const { p1, p2, p3, p4 = 'OTHER', ...rest } = params || {};
AES.log('event', {
p1,
p2,
p3,
p4,
...rest,
});
}
};
constructor() {
(window as any).AES = (window as any).AES || {};
}
register(fn: () => any) {
if (typeof fn === 'function') {
this.fn = fn;
}
}
log(params: any) {
if (typeof this.fn === 'function') {
this.fn(params);
}
}
setConfig(key: string | object, value?: string): void {
const { AES } = window as any;
if (typeof AES?.setConfig !== 'function') {
return;
}
if (typeof key === 'string' && value) {
AES.setConfig(key, value);
} else if (typeof key === 'object') {
AES.setConfig(key);
}
}
}
export default new Monitor();