🤖 Merge PR #65601 add @types/zwlog-browser by @Jungzl

* add @types/zwlog

* rename to zwlog-browser
This commit is contained in:
Jungzl
2023-05-28 16:36:21 +08:00
committed by GitHub
parent 1dcbca1e96
commit 7e0c6ff9e4
4 changed files with 235 additions and 0 deletions

195
types/zwlog-browser/index.d.ts vendored Normal file
View File

@@ -0,0 +1,195 @@
// Type definitions for non-npm package ZwLog API - zwlog.js 1.0
// Project: //assets.zjzwfw.gov.cn/assets/zwlog/1.0.0/zwlog.js
// Definitions by: Jungzl <https://github.com/jungzl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 4.2
/**
* “浙里办” 多端容器环境支持的数据埋点上报能力。
* This API just for [浙里办](https://apps.apple.com/us/app/zhe-jiang-zheng-wu-fu-wu/id910260096)
* 1. 在页面 head 中先引入 zwjsbridge
* ```js
* <script type="text/javascript" src="//assets.zjzwfw.gov.cn/assets/ZWJSBridge/1.1.0/zwjsbridge.js"></script>
* ```
* 2. 在 zwjsbridge 后面引入 zwlog
* ```js
* <script type="text/javascript" src="//assets.zjzwfw.gov.cn/assets/zwlog/1.0.0/zwlog.js"></script>
* ```
* 3. 在声明 Zwlog 对象实例时,可以传入一些 app 或者用户信息
* ```js
* const zwlog = new ZwLog({
* _user_id:"用户 ID",
* _user_nick:"用户昵称"
* })
* ```
*/
interface ZwLogInitOptions {
/**
* 用户ID
*/
_user_id: string;
/**
* 用户昵称
*/
_user_nick: string;
}
type EventParamsKey =
| 'uidaplus'
| 'spm-url'
| 'spmpre'
| 'spm_cnt'
| 'pvid'
| '_dev_id'
| '_anony_id'
| '_user_id'
| '_user_nick'
| '_session_id';
interface zwlog {
cbQueue: any[];
metaInfo: {
'aplus-cpvdata': {
sdk_info: string;
sdk_version: string;
};
'aplus-exdata': {
sdk_info: string;
sdk_version: string;
};
'aplus-rhost-g': string;
'aplus-rhost-v': string;
'aplus-waiting': string;
appId: string;
} & ZwLogInitOptions;
readyFlag: boolean;
init: () => void;
/**
* 初始化jsapi初始化完成即onReady之后再调用jsapi。
*
* @param callBack 初始化成功回调
*/
onReady(callBack: () => void): void;
/**
* PV日志
*
* @param data
*/
sendPV: (data: {
/**
* IRS 服务侧应用 appid,
*/
miniAppId: string;
/**
* IRS 服务侧应用 appname,
*/
miniAppName: string;
/**
* 页面 ID
*/
pageId: string;
/**
* 页面名称
*/
pageName: string;
/**
* 页面启动到加载完成的时间
*/
t2: number;
/**
* 页面启动到页面响应完成的时间
*/
t0: number;
/**
* 用户登录状态01:未登录/ 02:单点登录)
*/
log_status: '01' | '02';
}) => void;
/**
* 令箭日志
*
* @param data
*/
record: (
/**
* 注册的事件编码 可传空值或特定事件指定编码
*/
trackerEventCode: string,
/**
* 时间类型 取值为'EXP':⾃定义曝光事件/'CLK':⾃定义点击事件/'OTHER': 其他⾃定义事件
*/
eventType: 'EXP' | 'CLK' | 'OTHER' | string,
/**
* 本次事件中上报的事件参数. 其取值为⼀个 JSON 对象(平铺的简单对象,不能多层嵌套)
* JSON 中的 key 不能是以下保留属性uidaplus,spm-url,spmpre,spm_cnt,pvid,_dev_id,_anony_id,_user_id,_user_nick,_session_id
*/
eventParams: Record<string, any> & { [key in EventParamsKey]?: never },
) => void;
/**
* 支付宝上报采集
*
* @param data
*/
sendAliMonitor: (
data:
| {
/**
* 固定值,针对涉及“拆解”业务;
*/
name: 'cj';
/**
* 业务数据
*/
obj: {
/**
* 填写具体业务名称,如“余额查询”
*/
title: string;
/**
* 常规业务taSR医疗或医保业务taSR_YL
*/
c1: string;
/**
* H5 服务 url
*/
url: string;
};
}
| {
/**
* 固定值,针对涉及“办结”业务
*/
name: 'bj';
/**
* 业务数据
*/
obj: {
/**
* 填写具体业务名称,如“余额查询”
*/
title: string;
/**
* 常规业务taSR医疗或医保业务taSR_YL
*/
c1: string;
/**
* 服务耗时,无法统计填写 0
*/
time: number;
/**
* 办结成功或失败
*/
success: boolean;
};
},
) => void;
}
interface ZwLog {
new (initOptions: ZwLogInitOptions): zwlog;
}
declare var ZwLog: ZwLog;

View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "zwlog-browser-tests.ts"]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "@definitelytyped/dtslint/dt.json"
}

View File

@@ -0,0 +1,21 @@
async () => {
const zwlog = new ZwLog({ _user_id: '用户 ID', _user_nick: '用户昵称' });
zwlog.onReady(() => {
zwlog.init();
zwlog.sendPV({
miniAppId: '2002308510',
miniAppName: '小程序名称',
pageId: '页面 ID',
pageName: '页面名称',
t2: 0.3,
t0: 0.3,
log_status: '02',
});
zwlog.cbQueue.push(() => ({ foo: 'bar' }));
zwlog.metaInfo;
zwlog.readyFlag;
zwlog.record('__CLICK__', 'CLK', { dd: 'gg' });
zwlog.sendAliMonitor({ name: 'cj', obj: { title: '余额查询', c1: 'taSR', url: '/pages/index/' } });
});
};