提交 2a8712c6 编写于 作者: fxy060608's avatar fxy060608

feat(mp-weixin): add onSaveExitState (#3427)

上级 5c11434f
......@@ -7,6 +7,7 @@ import {
ON_BACK_PRESS,
ON_ERROR,
ON_HIDE,
ON_INIT,
ON_LAUNCH,
ON_LOAD,
ON_NAVIGATION_BAR_BUTTON_TAP,
......@@ -20,6 +21,7 @@ import {
ON_REACH_BOTTOM,
ON_READY,
ON_RESIZE,
ON_SAVE_EXIT_STATE,
ON_SHARE_APP_MESSAGE,
ON_SHARE_TIMELINE,
ON_SHOW,
......@@ -50,6 +52,7 @@ type onPageShowHook = () => void
type onLaunchHook = (options: LaunchOption) => void
type onLoadHook = (query: Record<string, string | undefined>) => void
type onInitHook = onLoadHook
type onErrorHook = (error: string) => void
interface ThemeChangeOption {
theme: 'dark' | 'light'
......@@ -130,6 +133,12 @@ type onShareAppMessageHook = (
options: ShareAppMessageOption
) => CustomShareAppMessage | void
interface SaveExitState {
data: any
expireTimeStamp: number
}
type onSaveExitStateHook = () => SaveExitState
interface NavigationBarButtonTapOption {
index: number
}
......@@ -162,7 +171,10 @@ const createHook =
<T extends Function = () => any>(
lifecycle: typeof UniLifecycleHooks[number]
) =>
(hook: T, target: ComponentInternalInstance | null = getCurrentInstance()) =>
(
hook: T,
target: ComponentInternalInstance | null = getCurrentInstance()
): void =>
// post-create lifecycle registrations are noops during SSR
!isInSSRComponentSetup && injectHook(lifecycle as any, hook, target)
......@@ -179,6 +191,7 @@ export const onPageNotFound =
/*#__PURE__*/ createHook<onPageNotFoundHook>(ON_PAGE_NOT_FOUND)
export const onUnhandledRejection =
/*#__PURE__*/ createHook<onUnhandledRejectionHook>(ON_UNHANDLE_REJECTION)
export const onInit = /*#__PURE__*/ createHook<onInitHook>(ON_INIT)
// 小程序如果想在 setup 的 props 传递页面参数,需要定义 props,故同时暴露 onLoad 吧
export const onLoad = /*#__PURE__*/ createHook<onLoadHook>(ON_LOAD)
export const onReady = /*#__PURE__*/ createHook(ON_READY)
......@@ -194,6 +207,9 @@ export const onTabItemTap =
export const onReachBottom = /*#__PURE__*/ createHook(ON_REACH_BOTTOM)
export const onPullDownRefresh = /*#__PURE__*/ createHook(ON_PULL_DOWN_REFRESH)
export const onSaveExitState =
/*#__PURE__*/ createHook<onSaveExitStateHook>(ON_SAVE_EXIT_STATE)
export const onShareTimeline =
/*#__PURE__*/ createHook<onShareTimelineHook>(ON_SHARE_TIMELINE)
export const onAddToFavorites =
......
......@@ -52,6 +52,8 @@ export const ON_READY = 'onReady'
export const ON_UNLOAD = 'onUnload'
// 百度特有
export const ON_INIT = 'onInit'
// 微信特有
export const ON_SAVE_EXIT_STATE = 'onSaveExitState'
export const ON_RESIZE = 'onResize'
export const ON_BACK_PRESS = 'onBackPress'
......
......@@ -3,6 +3,7 @@ import {
ON_BACK_PRESS,
ON_ERROR,
ON_HIDE,
ON_INIT,
ON_LAUNCH,
ON_LOAD,
ON_NAVIGATION_BAR_BUTTON_TAP,
......@@ -16,6 +17,7 @@ import {
ON_REACH_BOTTOM,
ON_READY,
ON_RESIZE,
ON_SAVE_EXIT_STATE,
ON_SHARE_APP_MESSAGE,
ON_SHARE_TIMELINE,
ON_SHOW,
......@@ -26,6 +28,7 @@ import {
} from './constants'
const PAGE_HOOKS = [
ON_INIT,
ON_LOAD,
ON_SHOW,
ON_HIDE,
......@@ -38,6 +41,7 @@ const PAGE_HOOKS = [
ON_SHARE_TIMELINE,
ON_SHARE_APP_MESSAGE,
ON_ADD_TO_FAVORITES,
ON_SAVE_EXIT_STATE,
ON_NAVIGATION_BAR_BUTTON_TAP,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
......@@ -63,6 +67,7 @@ export const UniLifecycleHooks = [
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
ON_INIT,
ON_LOAD,
ON_READY,
ON_UNLOAD,
......@@ -75,6 +80,7 @@ export const UniLifecycleHooks = [
ON_SHARE_TIMELINE,
ON_ADD_TO_FAVORITES,
ON_SHARE_APP_MESSAGE,
ON_SAVE_EXIT_STATE,
ON_NAVIGATION_BAR_BUTTON_TAP,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册