提交 e4ffc1b7 编写于 作者: M mehaotian

fix: 统计新增错误类型,优化错误输出逻辑

上级 5ad27668
......@@ -46,7 +46,6 @@
// observer1.observe({
// entryTypes: ['render', 'navigation'],
// } as PerformanceObserverOptions)
// 统计上报 - 应用启动
// #ifdef APP-ANDROID || APP-IOS || WEB
// uni.report({
......
......@@ -31,6 +31,8 @@ const lifecycle = defineMixin({
export const uniStat = definePlugin({
install(app : VueApp, options : UTSJSONObject) {
// 未关联服务空间
if (Stat.no_space) return
stat_instance.init(options)
app.mixin(lifecycle)
}
......
import { Report } from "./report.uts";
import { StatType } from "./stat-type";
import { EventParams, UniStatOptions, ErrorCallback,ReportErrorCode } from '../../interface.uts'
import { EventParams, UniStatOptions, ErrorCallback, ReportErrorCode } from '../../interface.uts'
import { is_page, is_page_report, get_space, is_push_clientid, calibration } from '../utils/pageInfo.uts'
import { Config } from "../config";
export class Stat {
static __stat_instance : Stat | null = null;
static is_register : boolean = false
static no_space : boolean = false
// 上报逻辑实例
report : Report;
// 使用单例,只初始化一次
static getInstance() : Stat {
// 获取服务空间配置信息
let space = get_space(uniCloud.config)
if (Report.uniCloudInstance == null) {
......@@ -41,7 +41,15 @@ export class Stat {
Report.uniCloudInstance = uniCloud.init(spaceData)
} else {
if (!Stat.no_space) {
// #ifdef WEB
console.log('\x1b[31m应用已集成uni统计,但未关联服务空间,请在uniCloud目录右键关联服务空间\x1b[39m')
// #endif
// #ifndef WEB
console.error('应用已集成uni统计,但未关联服务空间,请在uniCloud目录右键关联服务空间')
// #endif
Stat.no_space = true
}
}
}
......@@ -69,7 +77,6 @@ export class Stat {
init(options : UTSJSONObject) {
// 插件挂载玩成,可以进行后续操作
Stat.is_register = true
// 参数处理
Config.setOptions({ ...options } as UniStatOptions)
const uniStatConfig = Config.getOptions()
......@@ -223,6 +230,10 @@ export class Stat {
}
// 自定义参数上报
appEvent(name : string, options : any | null = null, fn : ErrorCallback) {
if (Stat.no_space) {
fn(false, 61000 as ReportErrorCode)
return
}
if (!Stat.is_register) {
fn(false, 61001 as ReportErrorCode)
return
......
......@@ -7,7 +7,6 @@ const stat = Stat.getInstance()
export const report : Report = function (options : ReportOptions) {
const name = options.name
const option = options.options
//创建一个UniError
stat.appEvent(name, option, (type : boolean, code : ReportErrorCode) => {
if (type) {
const res : ReportSuccess = {
......
......@@ -12,6 +12,10 @@ export type ReportSuccess = {
* 错误码
*/
export type ReportErrorCode =
/**
* 应用已集成uni统计,但未关联服务空间,请在uniCloud目录右键关联服务空间
*/
61000 |
/**
* 统计服务尚未初始化,需在`main.uts`中引入统计插件
*/
......
......@@ -11,6 +11,10 @@ export const ReportUniErrorSubject = 'uni-report';
* @UniError
*/
export const ReportUniErrors:Map<number, string> = new Map([
/**
* 已集成uni统计,但未关联服务空间
*/
[61000, '应用已集成uni统计,但未关联服务空间,请在uniCloud目录右键关联服务空间!'],
/**
* 统计已集成,但未初始化
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册