diff --git a/packages/uni-cli-shared/src/json/mp/jsonFile.ts b/packages/uni-cli-shared/src/json/mp/jsonFile.ts index b115c3fa6bd08931d59b9670316e60e183df135d..2e5a1842fe80022f7f4f69ac99b26153eccfd58b 100644 --- a/packages/uni-cli-shared/src/json/mp/jsonFile.ts +++ b/packages/uni-cli-shared/src/json/mp/jsonFile.ts @@ -35,6 +35,10 @@ export function hasJsonFile(filename: string) { ) } +export function getComponentJsonFilenames() { + return [...jsonComponentsCache.keys()] +} + export function findJsonFile(filename: string) { if (filename === 'app') { return appJsonCache diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index 3cd9d61ba7f21dbaa4a14c28de539a5dd80783b8..436a55b41757561b23306ffd817ccf2c9fec0032 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -122,6 +122,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -236,7 +242,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -283,6 +289,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook(mpOptions, hook, []); + } + }); } my.appLaunchHooks = []; @@ -878,8 +895,9 @@ function initCreatePage() { if (__VUE_OPTIONS_API__) { pageOptions.data = initData(); } - initHooks(pageOptions, PAGE_HOOKS); + initHooks(pageOptions, PAGE_INIT_HOOKS); initUnknownHooks(pageOptions, vueOptions); + initRuntimeHooks(pageOptions, vueOptions.__runtimeHooks); initWxsCallMethods(pageOptions, vueOptions.wxsCallMethods); return Page(pageOptions); }; diff --git a/packages/uni-mp-alipay/src/runtime/createPage.ts b/packages/uni-mp-alipay/src/runtime/createPage.ts index 6bac84e49e274d984e70d28a63fbfb69b9d5273e..e6a36070930bd57e189ec5eb95e170683654d71b 100644 --- a/packages/uni-mp-alipay/src/runtime/createPage.ts +++ b/packages/uni-mp-alipay/src/runtime/createPage.ts @@ -1,12 +1,13 @@ import { ComponentOptions } from 'vue' import { - PAGE_HOOKS, + PAGE_INIT_HOOKS, initData, initHooks, initUnknownHooks, $destroyComponent, initWxsCallMethods, + initRuntimeHooks, } from '@dcloudio/uni-mp-core' import { @@ -65,9 +66,9 @@ export function initCreatePage() { if (__VUE_OPTIONS_API__) { pageOptions.data = initData(vueOptions) } - initHooks(pageOptions, PAGE_HOOKS) + initHooks(pageOptions, PAGE_INIT_HOOKS) initUnknownHooks(pageOptions, vueOptions) - + initRuntimeHooks(pageOptions, vueOptions.__runtimeHooks) initWxsCallMethods( pageOptions as WechatMiniprogram.Component.MethodOption, vueOptions.wxsCallMethods diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index b41141be905a8122879c9d4b47d5545e514ce946..7576e376b3c7baea0cf4886445b602246ebfe04f 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -190,6 +190,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -299,7 +305,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -346,6 +352,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } swan.appLaunchHooks = []; @@ -891,8 +908,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-mp-core/src/index.ts b/packages/uni-mp-core/src/index.ts index f6cdff8d38a39c671ccc86bf02addec456f5ea56..05a92ad09ebee78efb787180b88da06004ecb123 100644 --- a/packages/uni-mp-core/src/index.ts +++ b/packages/uni-mp-core/src/index.ts @@ -24,9 +24,10 @@ export { } from './runtime/componentOptions' export { initProps } from './runtime/componentProps' export { - PAGE_HOOKS, initHooks, initUnknownHooks, + initRuntimeHooks, + PAGE_INIT_HOOKS, } from './runtime/componentHooks' export { initMocks, initComponentInstance } from './runtime/componentInstance' export { $createComponent, $destroyComponent } from './runtime/component' diff --git a/packages/uni-mp-core/src/runtime/componentHooks.ts b/packages/uni-mp-core/src/runtime/componentHooks.ts index b662ea89c3ebe1baa20a28c258fd625940820e5c..08144a733134a4737123621a3934412a4269201b 100644 --- a/packages/uni-mp-core/src/runtime/componentHooks.ts +++ b/packages/uni-mp-core/src/runtime/componentHooks.ts @@ -1,4 +1,5 @@ import { + MINI_PROGRAM_PAGE_RUNTIME_HOOKS, ON_ADD_TO_FAVORITES, ON_HIDE, ON_LOAD, @@ -18,7 +19,7 @@ import { MiniProgramAppOptions } from '../index' import { CustomAppInstanceProperty } from './app' import { CustomComponentInstanceProperty } from './component' -export const PAGE_HOOKS = [ +export const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -95,3 +96,20 @@ export function initUnknownHooks( ) { findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes)) } + +export function initRuntimeHooks( + mpOptions: MiniProgramAppOptions | WechatMiniprogram.Component.MethodOption, + runtimeHooks?: number +) { + if (!runtimeHooks) { + return + } + const hooks = Object.keys( + MINI_PROGRAM_PAGE_RUNTIME_HOOKS + ) as (keyof typeof MINI_PROGRAM_PAGE_RUNTIME_HOOKS)[] + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook(mpOptions, hook, []) + } + }) +} diff --git a/packages/uni-mp-core/src/runtime/page.ts b/packages/uni-mp-core/src/runtime/page.ts index 8af56e7a53a9bdd9b82ceabc297f21c494909d7b..5aa10e96801eb01f1f2ec833eae6fb03ee0cc61f 100644 --- a/packages/uni-mp-core/src/runtime/page.ts +++ b/packages/uni-mp-core/src/runtime/page.ts @@ -7,7 +7,12 @@ import { parseComponent, CustomComponentInstanceProperty, } from './component' -import { PAGE_HOOKS, initHooks, initUnknownHooks } from './componentHooks' +import { + PAGE_INIT_HOOKS, + initHooks, + initUnknownHooks, + initRuntimeHooks, +} from './componentHooks' import { initPageProps } from './componentProps' function parsePage( @@ -43,9 +48,9 @@ function parsePage( return this.$vm && this.$vm.$callHook(ON_LOAD, query) } - initHooks(methods, PAGE_HOOKS) + initHooks(methods, PAGE_INIT_HOOKS) initUnknownHooks(methods, vueOptions) - + initRuntimeHooks(methods, vueOptions.__runtimeHooks) parse && parse(miniProgramPageOptions, { handleLink }) return miniProgramPageOptions diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index 5177333fabfad92b552a78b5093dd9bf195d7c7c..02c77b2abaafc5f9946b0752c5bae16984e20b74 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -185,6 +185,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -294,7 +300,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -341,6 +347,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } ks.appLaunchHooks = []; @@ -875,8 +892,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-mp-lark/dist/uni.mp.esm.js b/packages/uni-mp-lark/dist/uni.mp.esm.js index c97e9e9059cda574b29a94e17a2b9bdd2f10c34d..bb9dd1b2c27d3e277f8d36e771638a5a3583e446 100644 --- a/packages/uni-mp-lark/dist/uni.mp.esm.js +++ b/packages/uni-mp-lark/dist/uni.mp.esm.js @@ -185,6 +185,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -290,7 +296,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -340,6 +346,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } tt.appLaunchHooks = []; @@ -848,8 +865,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index 16a1e2227e9a8a9c43a74856576e2b020eff422d..08cb7cf40bb6a899238da37860e78c30d264c341 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -185,6 +185,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -290,7 +296,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -337,6 +343,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } qq.appLaunchHooks = []; @@ -837,8 +854,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index ded3997216cdec9d965cc848b1fdbce6c2a137ce..14d3d84e787acaf5d1fa796e8bd3a5db14b0242a 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -185,6 +185,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -290,7 +296,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -340,6 +346,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } tt.appLaunchHooks = []; @@ -848,8 +865,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-mp-vite/src/index.ts b/packages/uni-mp-vite/src/index.ts index 2e240b0cc502d09f824663c8ae0db310f5e74f20..55768c0e7c31c9d4e39f6a3a941d7cd0e528ef88 100644 --- a/packages/uni-mp-vite/src/index.ts +++ b/packages/uni-mp-vite/src/index.ts @@ -10,6 +10,7 @@ import { uniPagesJsonPlugin } from './plugins/pagesJson' import { uniEntryPlugin } from './plugins/entry' import { uniRenderjsPlugin } from './plugins/renderjs' +import { uniRuntimeHooksPlugin } from './plugins/runtimeHooks' import { uniSubpackagePlugin } from './plugins/subpackage' import { uniMiniProgramPluginPlugin } from './plugins/plugin' @@ -32,6 +33,7 @@ export default (options: UniMiniProgramPluginOptions) => { uniEntryPlugin(options), uniViteInjectPlugin(extend({}, options.vite.inject)), uniRenderjsPlugin({ lang: options.template.filter?.lang }), + uniRuntimeHooksPlugin(), uniMiniProgramPlugin(options), (options: { vueOptions?: { script?: Partial } diff --git a/packages/uni-mp-vite/src/plugin/index.ts b/packages/uni-mp-vite/src/plugin/index.ts index 235f75d30e6cb96caf3fcfe2706b142fcaa4b570..edc61aacb3d4ba4d54521c73d5340455374f301f 100644 --- a/packages/uni-mp-vite/src/plugin/index.ts +++ b/packages/uni-mp-vite/src/plugin/index.ts @@ -8,6 +8,7 @@ import { parseManifestJsonOnce, findMiniProgramTemplateFiles, MiniProgramCompilerOptions, + getComponentJsonFilenames, } from '@dcloudio/uni-cli-shared' import type { CompilerOptions } from '@dcloudio/uni-mp-compiler' @@ -22,6 +23,7 @@ import type { SFCTemplateCompileOptions, SFCTemplateCompileResults, } from '@vue/compiler-sfc' +import { hasOwn } from '@vue/shared' export interface UniMiniProgramPluginOptions { cdn?: number @@ -153,6 +155,16 @@ export function uniMiniProgramPlugin( source: templateFiles[filename], }) }) + // 部分组件可能模板为空 + getComponentJsonFilenames().forEach((jsonFilename) => { + if (!hasOwn(templateFiles, jsonFilename)) { + this.emitFile({ + type: 'asset', + fileName: jsonFilename + template.extname, + source: ``, + }) + } + }) if (!nvueCssEmitted) { const nvueCssPaths = getNVueCssPaths(resolvedConfig) if (nvueCssPaths && nvueCssPaths.length) { diff --git a/packages/uni-mp-vite/src/plugins/runtimeHooks.ts b/packages/uni-mp-vite/src/plugins/runtimeHooks.ts new file mode 100644 index 0000000000000000000000000000000000000000..8413e74b906df96dbb92f3db472920c788d83ad4 --- /dev/null +++ b/packages/uni-mp-vite/src/plugins/runtimeHooks.ts @@ -0,0 +1,39 @@ +import type { Plugin } from 'vite' +import { MINI_PROGRAM_PAGE_RUNTIME_HOOKS } from '@dcloudio/uni-shared' +import { isUniPageSfcFile } from '@dcloudio/uni-cli-shared' + +type RuntimeHooks = keyof typeof MINI_PROGRAM_PAGE_RUNTIME_HOOKS + +export function uniRuntimeHooksPlugin(): Plugin { + return { + name: 'vite:uni-mp-runtime-hooks', + enforce: 'post', + async transform(source, id) { + if (!isUniPageSfcFile(id)) { + return null + } + if (!source.includes('_sfc_main')) { + return null + } + + const matches = source.match( + new RegExp( + `(${Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS).join('|')})`, + 'g' + ) + ) + if (!matches) { + return null + } + if (matches.includes('onShareTimeline')) { + matches.push('onShareAppMessage') + } + const hooks = new Set(matches as RuntimeHooks[]) + let flag = 0 + for (const hook of hooks) { + flag |= MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook] + } + return source + `;_sfc_main.__runtimeHooks = ${flag};` + }, + } +} diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index fdeb607d6ae1a0e7a91958d6188f55714bf29b08..f3cf156b79f5e50f01f13a69d064150e71a7132c 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -57,6 +57,12 @@ const invokeArrayFns = (fns, arg) => { return ret; }; +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -162,7 +168,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -209,6 +215,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } wx.appLaunchHooks = []; @@ -709,8 +726,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js index 8df645dfb7fd73852021797cd3c422a498bfd30d..6c05815eb031a8a7d5a2991dd768cf3ccef4bfe9 100644 --- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js @@ -185,6 +185,12 @@ class EventChannel { } } +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; + const eventChannels = {}; const eventChannelStack = []; function getEventChannel(id) { @@ -290,7 +296,7 @@ function callHook(name, args) { return hooks && invokeArrayFns(hooks, args); } -const PAGE_HOOKS = [ +const PAGE_INIT_HOOKS = [ ON_LOAD, ON_SHOW, ON_HIDE, @@ -337,6 +343,17 @@ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) { } function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) { findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes)); +} +function initRuntimeHooks(mpOptions, runtimeHooks) { + if (!runtimeHooks) { + return; + } + const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS); + hooks.forEach((hook) => { + if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) { + initHook$1(mpOptions, hook, []); + } + }); } qa.appLaunchHooks = []; @@ -826,8 +843,9 @@ function parsePage(vueOptions, parseOptions) { }; return this.$vm && this.$vm.$callHook(ON_LOAD, query); }; - initHooks(methods, PAGE_HOOKS); + initHooks(methods, PAGE_INIT_HOOKS); initUnknownHooks(methods, vueOptions); + initRuntimeHooks(methods, vueOptions.__runtimeHooks); parse && parse(miniProgramPageOptions, { handleLink }); return miniProgramPageOptions; } diff --git a/packages/uni-shared/dist/uni-shared.cjs.js b/packages/uni-shared/dist/uni-shared.cjs.js index e2637c45aee1f7252a0127e886e8cbe7aabf2dfc..2af23c4a64413c3c3144aa2c879f36543b294785 100644 --- a/packages/uni-shared/dist/uni-shared.cjs.js +++ b/packages/uni-shared/dist/uni-shared.cjs.js @@ -1201,7 +1201,12 @@ const UniLifecycleHooks = [ ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, -]; +]; +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; function getEnvLocale() { const { env } = process; @@ -1242,6 +1247,7 @@ exports.EventModifierFlags = EventModifierFlags; exports.I18N_JSON_DELIMITERS = I18N_JSON_DELIMITERS; exports.JSON_PROTOCOL = JSON_PROTOCOL; exports.LINEFEED = LINEFEED; +exports.MINI_PROGRAM_PAGE_RUNTIME_HOOKS = MINI_PROGRAM_PAGE_RUNTIME_HOOKS; exports.NAVBAR_HEIGHT = NAVBAR_HEIGHT; exports.NODE_TYPE_COMMENT = NODE_TYPE_COMMENT; exports.NODE_TYPE_ELEMENT = NODE_TYPE_ELEMENT; diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts index 60b459c5ac74e991b2c020a246f8378294dc4b11..7279fc281c9f486225b195bf809672fc71640ec8 100644 --- a/packages/uni-shared/dist/uni-shared.d.ts +++ b/packages/uni-shared/dist/uni-shared.d.ts @@ -258,6 +258,12 @@ export declare const JSON_PROTOCOL = "json://"; export declare const LINEFEED = "\n"; +export declare const MINI_PROGRAM_PAGE_RUNTIME_HOOKS: { + readonly onPageScroll: 1; + readonly onShareAppMessage: number; + readonly onShareTimeline: number; +}; + export declare const NAVBAR_HEIGHT = 44; declare type NavigateToOptionEvents = Record void>; diff --git a/packages/uni-shared/dist/uni-shared.es.js b/packages/uni-shared/dist/uni-shared.es.js index d006ca45a21c2cef69e96b7a9b53c39fc09c8944..ff08bc3cbb4f1c16fc4e7f8e587ccd4ad44099ec 100644 --- a/packages/uni-shared/dist/uni-shared.es.js +++ b/packages/uni-shared/dist/uni-shared.es.js @@ -1197,7 +1197,12 @@ const UniLifecycleHooks = [ ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, -]; +]; +const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +}; function getEnvLocale() { const { env } = process; @@ -1205,4 +1210,4 @@ function getEnvLocale() { return (lang && lang.replace(/[.:].*/, '')) || 'en'; } -export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle }; +export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle }; diff --git a/packages/uni-shared/src/lifecycle.ts b/packages/uni-shared/src/lifecycle.ts index 496c70cb87eb426970fd13dab2ffc799dcdb3fc4..73b4c1cbc66693c1c22e6a255202dba4f46d8ad5 100644 --- a/packages/uni-shared/src/lifecycle.ts +++ b/packages/uni-shared/src/lifecycle.ts @@ -75,3 +75,9 @@ export const UniLifecycleHooks = [ ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ] as const + +export const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, +} as const diff --git a/packages/uni-stat/dist/uni-stat.cjs.js b/packages/uni-stat/dist/uni-stat.cjs.js index 4af6d924ca392e0972d2f22139b2c3f414cbc0ab..76202c843939d042a5d19a8ecab0ada0dbf55f19 100644 --- a/packages/uni-stat/dist/uni-stat.cjs.js +++ b/packages/uni-stat/dist/uni-stat.cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var version = "3.0.0-alpha-3030220211217012"; +var version = "3.0.0-alpha-3030320211224001"; const STAT_VERSION = version; const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index bbc0f31c56c1aa996ffc537ee31fa8700881b288..d63b1dba650953692e8e04d5d53fd5a8f106f9dd 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -1,4 +1,4 @@ -var version = "3.0.0-alpha-3030220211217012"; +var version = "3.0.0-alpha-3030320211224001"; const STAT_VERSION = version; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';