plugin.uts 959 字节
Newer Older
M
mehaotian 已提交
1 2
import { Stat } from '@/uni_modules/uni-stat'
//  // UniStatOptions, UniStatCollectItemsOptions
M
mehaotian 已提交
3 4 5 6 7

// 实例统计sdk
const stat_instance = Stat.getInstance()

const lifecycle = defineMixin({
M
mehaotian 已提交
8
  // onLaunch(options : OnLaunchOptions) { stat_instance.onLaunch(options, this) },
M
mehaotian 已提交
9
  // @ts-ignore
M
mehaotian 已提交
10 11 12 13 14
  onLoad() {
    if (this instanceof Page) {
      stat_instance.onLoad(this)
    }
  },
M
mehaotian 已提交
15
  // @ts-ignore
M
mehaotian 已提交
16 17 18 19 20
  onShow() {
    if (this instanceof Page) {
      stat_instance.onShow(this)
    }
  },
M
mehaotian 已提交
21
  // @ts-ignore
M
mehaotian 已提交
22 23 24 25 26
  onHide() {
    if (this instanceof Page) {
      stat_instance.onHide(this)
    }
  },
M
mehaotian 已提交
27
  // @ts-ignore
M
mehaotian 已提交
28 29 30 31 32 33
  onUnload() {
    if (this instanceof Page) {
      stat_instance.onUnload(this)
    }
  },
  // onError(error : string) { stat_instance.onError(error) }
M
mehaotian 已提交
34 35 36 37
})


export const uniStat = definePlugin({
M
mehaotian 已提交
38 39 40 41
  install(app : VueApp, options : UTSJSONObject) {
    stat_instance.init(options)
    app.mixin(lifecycle)
  }
M
mehaotian 已提交
42
})