提交 cfe12ceb 编写于 作者: M mehaotian

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

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