From c50973c7d48f57d9bd29eef64b0c4bef523eb05e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 25 Oct 2021 17:58:05 +0800 Subject: [PATCH] wip(mp): export onLoad --- .../uni-app-plus/dist/uni-app-service.es.js | 2 +- packages/uni-app/dist/uni-app.cjs.js | 6 +- packages/uni-app/dist/uni-app.d.ts | 2 + packages/uni-app/dist/uni-app.es.js | 7 ++- packages/uni-app/src/apiLifecycle.ts | 5 +- packages/uni-cli-shared/src/env/define.ts | 4 ++ packages/uni-h5/dist/uni-h5.es.js | 2 +- packages/uni-mp-baidu/dist/uni.mp.esm.js | 3 +- packages/uni-mp-kuaishou/dist/uni.mp.esm.js | 3 +- packages/uni-mp-qq/build.json | 57 +++++++++++-------- packages/uni-mp-qq/dist/uni.mp.esm.js | 3 +- packages/uni-mp-vue/dist/vue.runtime.esm.js | 33 +++++------ packages/uni-mp-vue/lib/vue.runtime.esm.js | 33 +++++------ packages/uni-mp-weixin/dist/uni.mp.esm.js | 3 +- .../uni-mp-weixin/src/runtime/lifetimes.ts | 4 +- 15 files changed, 100 insertions(+), 67 deletions(-) diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 4eec1beed..24f411846 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -4892,7 +4892,7 @@ var serviceContext = (function (vue) { return 'param extension should not be empty.'; } if (!extension) - params.extension = ['']; + params.extension = ['*']; }, }, }; diff --git a/packages/uni-app/dist/uni-app.cjs.js b/packages/uni-app/dist/uni-app.cjs.js index d56437131..ac0952e82 100644 --- a/packages/uni-app/dist/uni-app.cjs.js +++ b/packages/uni-app/dist/uni-app.cjs.js @@ -18,6 +18,8 @@ const ON_ERROR = 'onError'; const ON_THEME_CHANGE = 'onThemeChange'; const ON_PAGE_NOT_FOUND = 'onPageNotFound'; const ON_UNHANDLE_REJECTION = 'onUnhandledRejection'; +//Page +const ON_LOAD = 'onLoad'; const ON_READY = 'onReady'; const ON_UNLOAD = 'onUnload'; const ON_RESIZE = 'onResize'; @@ -118,7 +120,8 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); - +// 小程序如果想在 setup 的 props 传递页面参数,需要定义 props,故同时暴露 onLoad 吧 +const onLoad = /*#__PURE__*/ createHook(ON_LOAD); const onReady = /*#__PURE__*/ createHook(ON_READY); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onResize = /*#__PURE__*/ createHook(ON_RESIZE); @@ -142,6 +145,7 @@ exports.onBackPress = onBackPress; exports.onError = onError; exports.onHide = onHide; exports.onLaunch = onLaunch; +exports.onLoad = onLoad; exports.onNavigationBarButtonTap = onNavigationBarButtonTap; exports.onNavigationBarSearchInputChanged = onNavigationBarSearchInputChanged; exports.onNavigationBarSearchInputClicked = onNavigationBarSearchInputClicked; diff --git a/packages/uni-app/dist/uni-app.d.ts b/packages/uni-app/dist/uni-app.d.ts index a04a7bcf3..4ccfa30bd 100644 --- a/packages/uni-app/dist/uni-app.d.ts +++ b/packages/uni-app/dist/uni-app.d.ts @@ -14,6 +14,8 @@ export declare const onHide: (hook: () => any, target?: ComponentInternalInstanc export declare const onLaunch: (hook: () => any, target?: ComponentInternalInstance | null) => any; +export declare const onLoad: (hook: () => any, target?: ComponentInternalInstance | null) => any; + export declare const onNavigationBarButtonTap: (hook: () => any, target?: ComponentInternalInstance | null) => any; export declare const onNavigationBarSearchInputChanged: (hook: () => any, target?: ComponentInternalInstance | null) => any; diff --git a/packages/uni-app/dist/uni-app.es.js b/packages/uni-app/dist/uni-app.es.js index 64a5f3ab8..ee2a4fee4 100644 --- a/packages/uni-app/dist/uni-app.es.js +++ b/packages/uni-app/dist/uni-app.es.js @@ -15,6 +15,8 @@ const ON_ERROR = 'onError'; const ON_THEME_CHANGE = 'onThemeChange'; const ON_PAGE_NOT_FOUND = 'onPageNotFound'; const ON_UNHANDLE_REJECTION = 'onUnhandledRejection'; +//Page +const ON_LOAD = 'onLoad'; const ON_READY = 'onReady'; const ON_UNLOAD = 'onUnload'; const ON_RESIZE = 'onResize'; @@ -87,7 +89,8 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); - +// 小程序如果想在 setup 的 props 传递页面参数,需要定义 props,故同时暴露 onLoad 吧 +const onLoad = /*#__PURE__*/ createHook(ON_LOAD); const onReady = /*#__PURE__*/ createHook(ON_READY); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onResize = /*#__PURE__*/ createHook(ON_RESIZE); @@ -105,4 +108,4 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED); const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED); -export { getSsrGlobalData, onAddToFavorites, onBackPress, onError, onHide, onLaunch, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, resolveEasycom, shallowSsrRef, ssrRef }; +export { getSsrGlobalData, onAddToFavorites, onBackPress, onError, onHide, onLaunch, onLoad, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, resolveEasycom, shallowSsrRef, ssrRef }; diff --git a/packages/uni-app/src/apiLifecycle.ts b/packages/uni-app/src/apiLifecycle.ts index 971ce85ac..64ca1c0f0 100644 --- a/packages/uni-app/src/apiLifecycle.ts +++ b/packages/uni-app/src/apiLifecycle.ts @@ -8,6 +8,7 @@ import { ON_ERROR, ON_HIDE, ON_LAUNCH, + ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, @@ -47,8 +48,8 @@ export const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND) export const onUnhandledRejection = /*#__PURE__*/ createHook( ON_UNHANDLE_REJECTION ) - -// export const onLoad = /*#__PURE__*/ createHook(ON_LOAD) +// 小程序如果想在 setup 的 props 传递页面参数,需要定义 props,故同时暴露 onLoad 吧 +export const onLoad = /*#__PURE__*/ createHook(ON_LOAD) export const onReady = /*#__PURE__*/ createHook(ON_READY) export const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD) diff --git a/packages/uni-cli-shared/src/env/define.ts b/packages/uni-cli-shared/src/env/define.ts index 41fd2c1fc..0af6cd597 100644 --- a/packages/uni-cli-shared/src/env/define.ts +++ b/packages/uni-cli-shared/src/env/define.ts @@ -4,8 +4,12 @@ import { parseManifestJsonOnce } from '../json' export function initDefine(stringifyBoolean: boolean = false) { const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR) const isRunByHBuilderX = runByHBuilderX() + const isDebug = !!manifestJson.debug return { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + 'process.env.UNI_DEBUG': stringifyBoolean + ? JSON.stringify(isDebug) + : isDebug, 'process.env.UNI_APP_ID': JSON.stringify(manifestJson.appid || ''), 'process.env.UNI_APP_NAME': JSON.stringify(manifestJson.name || ''), 'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM), diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index b03b979b9..1f72f2adb 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -4627,7 +4627,7 @@ const ChooseImageOptions = { return "param extension should not be empty."; } if (!extension) - params.extension = [""]; + params.extension = ["*"]; } } }; diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index d3ad646e1..c55fa4eaf 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -764,11 +764,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { initRelation(this, relationOptions); // 初始化 vue 实例 const mpInstance = this; + const isMiniProgramPage = isPage(mpInstance); this.$vm = $createComponent({ type: vueOptions, props: properties, }, { - mpType: isPage(mpInstance) ? 'page' : 'component', + mpType: isMiniProgramPage ? 'page' : 'component', mpInstance, slots: properties.vS, parentComponent: relationOptions.parent && relationOptions.parent.$, diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index a499e3fc7..710fae460 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -710,11 +710,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { initRelation(this, relationOptions); // 初始化 vue 实例 const mpInstance = this; + const isMiniProgramPage = isPage(mpInstance); this.$vm = $createComponent({ type: vueOptions, props: properties, }, { - mpType: isPage(mpInstance) ? 'page' : 'component', + mpType: isMiniProgramPage ? 'page' : 'component', mpInstance, slots: properties.vS, parentComponent: relationOptions.parent && relationOptions.parent.$, diff --git a/packages/uni-mp-qq/build.json b/packages/uni-mp-qq/build.json index c965be3a0..954a5a470 100644 --- a/packages/uni-mp-qq/build.json +++ b/packages/uni-mp-qq/build.json @@ -1,24 +1,35 @@ -{ - "input": { - "src/runtime/index.ts": "dist/uni.mp.esm.js", - "src/api/index.ts": "dist/uni.api.esm.js" +[ + { + "input": { + "src/plugin/index.ts": "dist/uni.compiler.js" + }, + "output": { + "format": "cjs" + }, + "external": ["@dcloudio/uni-cli-shared", "@dcloudio/uni-mp-vite"] }, - "alias": { - "entries": [ - { - "find": "@dcloudio/uni-platform", - "replacement": "packages/uni-mp-qq/src/platform/index.ts" - }, - { - "find": "@dcloudio/uni-mp-platform", - "replacement": "packages/uni-mp-core/src/platform/index.ts" - } - ] - }, - "replacements": { - "__GLOBAL__": "qq", - "__PLATFORM__": "\"mp-qq\"", - "__PLATFORM_TITLE__": "QQ小程序" - }, - "external": ["@dcloudio/uni-i18n", "@vue/shared", "vue"] -} + { + "input": { + "src/runtime/index.ts": "dist/uni.mp.esm.js", + "src/api/index.ts": "dist/uni.api.esm.js" + }, + "alias": { + "entries": [ + { + "find": "@dcloudio/uni-platform", + "replacement": "packages/uni-mp-qq/src/platform/index.ts" + }, + { + "find": "@dcloudio/uni-mp-platform", + "replacement": "packages/uni-mp-core/src/platform/index.ts" + } + ] + }, + "replacements": { + "__GLOBAL__": "qq", + "__PLATFORM__": "\"mp-qq\"", + "__PLATFORM_TITLE__": "QQ小程序" + }, + "external": ["@dcloudio/uni-i18n", "@vue/shared", "vue"] + } +] diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index aea9a44fd..bc0624b81 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -710,11 +710,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { initRelation(this, relationOptions); // 初始化 vue 实例 const mpInstance = this; + const isMiniProgramPage = isPage(mpInstance); this.$vm = $createComponent({ type: vueOptions, props: properties, }, { - mpType: isPage(mpInstance) ? 'page' : 'component', + mpType: isMiniProgramPage ? 'page' : 'component', mpInstance, slots: properties.vS, parentComponent: relationOptions.parent && relationOptions.parent.$, diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index 1a4e8b586..9eed60a0b 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -4291,7 +4291,7 @@ const version = "3.2.20"; const resolveFilter = null; function unwrapper(target) { - return toRaw(unref(target)); + return unref(target); } // import deepCopy from './deepCopy' /** @@ -4486,10 +4486,11 @@ function patch(instance, data, oldData) { if (!data) { return; } - // 通常不用序列化,但是好像部分边界情况需要,目前还未排查到 - // pauseTracking() - // data = JSON.parse(JSON.stringify(data)) - // resetTracking() + // TODO 微信小程序会对 props 序列化,目前通过序列化再次触发数据响应式收集,因为 render 中收集的数据可能不全面(也不能仅仅这里收集,render 中也要收集),导致子组件无法局部响应式更新 + // 举例: + // uni-indexed-list 组件传递 item 给 uni-indexed-list-item 组件,uni-indexed-list-item 发送点击到 uni-indexed-list 组件中修改 item.checked + // uni-indexed-list 组件 render 中并未访问 item.checked(在 uni-indexed-list-item 中访问了,但被小程序序列化了,无法响应式),故无法收集依赖 + data = JSON.parse(JSON.stringify(data)); const ctx = instance.ctx; const mpType = ctx.mpType; if (mpType === 'page' || mpType === 'component') { @@ -4498,19 +4499,19 @@ function patch(instance, data, oldData) { const mpInstance = ctx.$scope; const keys = Object.keys(data); // data.__webviewId__ = mpInstance.data.__webviewId__ - pauseTracking(); const diffData = diff(data, oldData || getMPInstanceData(mpInstance, keys)); - resetTracking(); if (Object.keys(diffData).length) { - console.log('[' + - +new Date() + - '][' + - (mpInstance.is || mpInstance.route) + - '][' + - instance.uid + - '][耗时' + - (Date.now() - start) + - ']差量更新', JSON.stringify(diffData)); + if (process.env.UNI_DEBUG) { + console.log('[' + + +new Date() + + '][' + + (mpInstance.is || mpInstance.route) + + '][' + + instance.uid + + '][耗时' + + (Date.now() - start) + + ']差量更新', JSON.stringify(diffData)); + } ctx.__next_tick_pending = true; mpInstance.setData(diffData, () => { ctx.__next_tick_pending = false; diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index d02594679..9af2721a3 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -4291,7 +4291,7 @@ const version = "3.2.20"; const resolveFilter = null; function unwrapper(target) { - return toRaw(unref(target)); + return unref(target); } // import deepCopy from './deepCopy' /** @@ -4486,10 +4486,11 @@ function patch(instance, data, oldData) { if (!data) { return; } - // 通常不用序列化,但是好像部分边界情况需要,目前还未排查到 - // pauseTracking() - // data = JSON.parse(JSON.stringify(data)) - // resetTracking() + // TODO 微信小程序会对 props 序列化,目前通过序列化再次触发数据响应式收集,因为 render 中收集的数据可能不全面(也不能仅仅这里收集,render 中也要收集),导致子组件无法局部响应式更新 + // 举例: + // uni-indexed-list 组件传递 item 给 uni-indexed-list-item 组件,uni-indexed-list-item 发送点击到 uni-indexed-list 组件中修改 item.checked + // uni-indexed-list 组件 render 中并未访问 item.checked(在 uni-indexed-list-item 中访问了,但被小程序序列化了,无法响应式),故无法收集依赖 + data = JSON.parse(JSON.stringify(data)); const ctx = instance.ctx; const mpType = ctx.mpType; if (mpType === 'page' || mpType === 'component') { @@ -4498,19 +4499,19 @@ function patch(instance, data, oldData) { const mpInstance = ctx.$scope; const keys = Object.keys(data); // data.__webviewId__ = mpInstance.data.__webviewId__ - pauseTracking(); const diffData = diff(data, oldData || getMPInstanceData(mpInstance, keys)); - resetTracking(); if (Object.keys(diffData).length) { - console.log('[' + - +new Date() + - '][' + - (mpInstance.is || mpInstance.route) + - '][' + - instance.uid + - '][耗时' + - (Date.now() - start) + - ']差量更新', JSON.stringify(diffData)); + if (process.env.UNI_DEBUG) { + console.log('[' + + +new Date() + + '][' + + (mpInstance.is || mpInstance.route) + + '][' + + instance.uid + + '][耗时' + + (Date.now() - start) + + ']差量更新', JSON.stringify(diffData)); + } ctx.__next_tick_pending = true; mpInstance.setData(diffData, () => { ctx.__next_tick_pending = false; diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index 2dc69d468..d142e6571 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -656,11 +656,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { initRelation(this, relationOptions); // 初始化 vue 实例 const mpInstance = this; + const isMiniProgramPage = isPage(mpInstance); this.$vm = $createComponent({ type: vueOptions, props: properties, }, { - mpType: isPage(mpInstance) ? 'page' : 'component', + mpType: isMiniProgramPage ? 'page' : 'component', mpInstance, slots: properties.vS, parentComponent: relationOptions.parent && relationOptions.parent.$, diff --git a/packages/uni-mp-weixin/src/runtime/lifetimes.ts b/packages/uni-mp-weixin/src/runtime/lifetimes.ts index 2d8bcadd0..cafdafcd2 100644 --- a/packages/uni-mp-weixin/src/runtime/lifetimes.ts +++ b/packages/uni-mp-weixin/src/runtime/lifetimes.ts @@ -34,13 +34,15 @@ export function initLifetimes({ initRelation(this, relationOptions) // 初始化 vue 实例 const mpInstance = this + const isMiniProgramPage = isPage(mpInstance) + this.$vm = $createComponent( { type: vueOptions, props: properties, }, { - mpType: isPage(mpInstance) ? 'page' : 'component', + mpType: isMiniProgramPage ? 'page' : 'component', mpInstance, slots: properties.vS, // vueSlots parentComponent: relationOptions.parent && relationOptions.parent.$, -- GitLab