Skip to content

Commit

Permalink
feat(wx): 添加pageOnShareAppMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangwenliang authored and zhangwenliang committed Jan 9, 2021
1 parent 05c6d16 commit 61e9ed2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export enum WxAppEvents {

export enum WxPageEvents {
PageOnShow = 'PageOnShow',
PageOnHide = 'PageOnHide'
PageOnHide = 'PageOnHide',
PageOnShareAppMessage = 'PageOnShareAppMessage'
}

export enum WxConsoleEvents {
Expand Down Expand Up @@ -65,7 +66,8 @@ export enum BREADCRUMBTYPES {
APP_ON_LAUNCH = 'App On Launch',
APP_ON_HIDE = 'App On Hide',
PAGE_ON_SHOW = 'Page On Show',
PAGE_ON_HIDE = 'Page On Hide'
PAGE_ON_HIDE = 'Page On Hide',
PAGE_ON_SHARE_APP_MESSAGE = 'Page On Share App Message'
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/types/breadcrumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface BreadcrumbPushData {
*/
type: BREADCRUMBTYPES
// string for click dom
data: ReportDataType | string | Replace.IRouter | Replace.TriggerConsole | WxLifeCycleBreadcrumb
data: ReportDataType | string | Replace.IRouter | Replace.TriggerConsole | WxLifeCycleBreadcrumb | WxOnShareAppMessageBreadcrumb
/**
* 分为user action、debug、http、
*/
Expand All @@ -27,3 +27,9 @@ export interface WxLifeCycleBreadcrumb {
// scene: number
// shareTicket: any
}

export interface WxOnShareAppMessageBreadcrumb {
path: string
query: IAnyObject
options: WechatMiniprogram.Page.IShareAppMessageOption
}
18 changes: 16 additions & 2 deletions src/wx-mini/handleWxEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BREADCRUMBTYPES, ERRORTYPES } from '@/common/constant'
import { breadcrumb, transportData } from '../core'
import { ReportDataType } from '@/types'
import { WxLifeCycleBreadcrumb } from '@/types/breadcrumb'
import { WxLifeCycleBreadcrumb, WxOnShareAppMessageBreadcrumb } from '@/types/breadcrumb'
import { Replace } from '@/types/replace'
import { getTimestamp, isError, unknownToString } from '@/utils'
import { Severity } from '@/utils/Severity'
Expand Down Expand Up @@ -121,13 +121,27 @@ const HandleWxPageEvents = {
path: page.route,
query: page.options
}
console.log(data)
breadcrumb.push({
category: breadcrumb.getCategory(BREADCRUMBTYPES.PAGE_ON_HIDE),
type: BREADCRUMBTYPES.PAGE_ON_HIDE,
data,
level: Severity.Info
})
},
onShareAppMessage(options: WechatMiniprogram.Page.IShareAppMessageOption) {
console.log('page onShareAppMessage')
const page = getCurrentPages().pop()
const data: WxOnShareAppMessageBreadcrumb = {
path: page.route,
query: page.options,
options
}
breadcrumb.push({
category: breadcrumb.getCategory(BREADCRUMBTYPES.PAGE_ON_SHARE_APP_MESSAGE),
type: BREADCRUMBTYPES.PAGE_ON_SHARE_APP_MESSAGE,
data,
level: Severity.Info
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wx-mini/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function replacePage() {
}
const originPage = Page
Page = function (appOptions: WechatMiniprogram.Page.ILifetime) {
const methods = [WxPageEvents.PageOnShow, WxPageEvents.PageOnHide]
const methods = [WxPageEvents.PageOnShow, WxPageEvents.PageOnHide, WxPageEvents.PageOnShareAppMessage]
methods.forEach((method) => {
addReplaceHandler({
callback: (data) => HandleWxPageEvents[method.replace('PageOn', 'on')](data),
Expand Down

0 comments on commit 61e9ed2

Please sign in to comment.