index.uts 873 字节
Newer Older
M
mehaotian 已提交
1 2
import { Report, ReportOptions, ReportSuccess, ReportErrorCode } from './interface.uts'
import { ReportFailImpl } from "./unierror.uts"
M
mehaotian 已提交
3 4 5 6 7 8 9
import { Stat } from './common/core/stat.uts'
const stat = Stat.getInstance()


export const report : Report = function (options : ReportOptions) {
	const name = options.name
	const option = options.options
M
mehaotian 已提交
10 11 12
	//创建一个UniError
	stat.appEvent(name, option, (type : boolean, code : ReportErrorCode) => {
		if (type) {
M
mehaotian 已提交
13 14 15 16 17 18
			const res : ReportSuccess = {
				errMsg: 'report:ok',
			}
			options.success?.(res)
			options.complete?.(res)
		} else {
M
mehaotian 已提交
19
			let err = new ReportFailImpl(code);
M
mehaotian 已提交
20 21 22 23 24 25 26
			options.fail?.(err)
			options.complete?.(err)
		}
	})
}

export { Stat } from './common/core/stat.uts'
27
// --- 导出统计类型 ---
M
mehaotian 已提交
28
export { UniStatOptions, UniStatCollectItemsOptions, ReportFail } from './interface.uts'