From bc0a4d438dfe344f65cdc1483018a49ad25e847b Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 17 Nov 2021 17:35:30 +0800 Subject: [PATCH] fix(mp-weixin): properties default value --- .../uni-app-plus/dist/uni-app-service.es.js | 16 ++++++++-- packages/uni-h5/dist/uni-h5.es.js | 29 ++++++++++++----- packages/uni-mp-baidu/dist/uni.mp.esm.js | 12 +++++++ packages/uni-mp-core/src/index.ts | 1 + packages/uni-mp-core/src/runtime/util.ts | 10 ++++++ packages/uni-mp-kuaishou/dist/uni.mp.esm.js | 12 +++++++ packages/uni-mp-lark/dist/uni.mp.esm.js | 31 ++++++++++--------- packages/uni-mp-qq/dist/uni.mp.esm.js | 12 +++++++ packages/uni-mp-toutiao/dist/uni.mp.esm.js | 31 ++++++++++--------- .../src/runtime/componentLifetimes.ts | 24 +++++--------- packages/uni-mp-vite/src/plugin/build.ts | 7 ++++- packages/uni-mp-vue/dist/vue.runtime.esm.js | 7 +++-- packages/uni-mp-vue/lib/vue.runtime.esm.js | 6 ++-- packages/uni-mp-vue/src/plugin.ts | 1 + packages/uni-mp-weixin/dist/uni.mp.esm.js | 12 +++++++ .../uni-mp-weixin/src/runtime/lifetimes.ts | 4 +++ .../uni-quickapp-webview/dist/uni.mp.esm.js | 31 ++++++++++--------- 17 files changed, 173 insertions(+), 73 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 89581e574..ae2de3f50 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -5043,7 +5043,8 @@ var serviceContext = (function (vue) { current: { type: [Number, String], }, - }; + }; + const API_CLOSE_PREVIEW_IMAGE = 'closePreviewImage'; const API_GET_VIDEO_INFO = 'getVideoInfo'; const GetVideoInfoOptions = { @@ -7499,7 +7500,17 @@ var serviceContext = (function (vue) { }, }); resolve(); - }, PreviewImageProtocol, PreviewImageOptions); + }, PreviewImageProtocol, PreviewImageOptions); + const closePreviewImage = defineAsyncApi(API_CLOSE_PREVIEW_IMAGE, (_, { resolve, reject }) => { + try { + // @ts-expect-error + plus.nativeUI.closePreviewImage(); + resolve(); + } + catch (error) { + reject(); + } + }); let recorder; let recording = false; @@ -12904,6 +12915,7 @@ var serviceContext = (function (vue) { getImageInfo: getImageInfo, getVideoInfo: getVideoInfo, previewImage: previewImage, + closePreviewImage: closePreviewImage, getRecorderManager: getRecorderManager, saveVideoToPhotosAlbum: saveVideoToPhotosAlbum, saveImageToPhotosAlbum: saveImageToPhotosAlbum, diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 577aa1862..7144b40f1 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -4783,6 +4783,7 @@ const PreviewImageProtocol = { type: [Number, String] } }; +const API_CLOSE_PREVIEW_IMAGE = "closePreviewImage"; const API_GET_VIDEO_INFO = "getVideoInfo"; const GetVideoInfoOptions = { formatArgs: { @@ -17036,23 +17037,34 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({ } }); let state$2 = null; +let imagePreviewInstance; +const closePreviewImageView = () => { + state$2 = null; + nextTick(() => { + imagePreviewInstance == null ? void 0 : imagePreviewInstance.unmount(); + imagePreviewInstance = null; + }); +}; const previewImage = /* @__PURE__ */ defineAsyncApi(API_PREVIEW_IMAGE, (args, { resolve }) => { if (!state$2) { state$2 = reactive(args); nextTick(() => { - const app = createRootApp(ImagePreview, state$2, () => { - state$2 = null; - nextTick(() => { - app.unmount(); - }); - }); - app.mount(ensureRoot("u-a-p")); + imagePreviewInstance = createRootApp(ImagePreview, state$2, closePreviewImageView); + imagePreviewInstance.mount(ensureRoot("u-a-p")); }); } else { extend(state$2, args); } resolve(); }, PreviewImageProtocol, PreviewImageOptions); +const closePreviewImage = /* @__PURE__ */ defineAsyncApi(API_CLOSE_PREVIEW_IMAGE, (_, { resolve, reject }) => { + if (imagePreviewInstance) { + closePreviewImageView(); + resolve(); + } else { + reject(); + } +}); let videoInput = null; const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceType, extension }, { resolve, reject }) => { initI18nChooseFileMsgsOnce(); @@ -19746,6 +19758,7 @@ var api = { chooseFile, chooseImage, previewImage, + closePreviewImage, chooseVideo, request, downloadFile, @@ -21863,4 +21876,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ return openBlock(), createBlock("div", clazz, [loadingVNode]); } }); -export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort }; +export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort }; diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index a953b18e6..5fd45c7a1 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -545,6 +545,16 @@ function handleEvent(event) { return console.warn(type + ' not found'); } this[methodName](event); +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -931,6 +941,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { // 初始化 vue 实例 const mpInstance = this; const isMiniProgramPage = isPage(mpInstance); + // 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined + fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, props: properties, diff --git a/packages/uni-mp-core/src/index.ts b/packages/uni-mp-core/src/index.ts index be6f92207..656a7b94d 100644 --- a/packages/uni-mp-core/src/index.ts +++ b/packages/uni-mp-core/src/index.ts @@ -30,6 +30,7 @@ export { initWxsCallMethods, findVmByVueId, handleEvent, + fixProperties, } from './runtime/util' // protocols diff --git a/packages/uni-mp-core/src/runtime/util.ts b/packages/uni-mp-core/src/runtime/util.ts index 9c3518ecf..4c9ceecbb 100644 --- a/packages/uni-mp-core/src/runtime/util.ts +++ b/packages/uni-mp-core/src/runtime/util.ts @@ -166,3 +166,13 @@ export function handleEvent( } ;(this as any)[methodName](event) } +/** + * @param properties + */ +export function fixProperties(properties: Record) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined + } + }) +} diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index b0f12f2c5..b2189ef9c 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -540,6 +540,16 @@ function handleEvent(event) { return console.warn(type + ' not found'); } this[methodName](event); +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -858,6 +868,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { // 初始化 vue 实例 const mpInstance = this; const isMiniProgramPage = isPage(mpInstance); + // 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined + fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, props: properties, diff --git a/packages/uni-mp-lark/dist/uni.mp.esm.js b/packages/uni-mp-lark/dist/uni.mp.esm.js index db3210fc3..d4c078124 100644 --- a/packages/uni-mp-lark/dist/uni.mp.esm.js +++ b/packages/uni-mp-lark/dist/uni.mp.esm.js @@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) { return parentVm; } } +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { mpInstance.route = mpInstance.__route__; } + // 字节跳动小程序 properties + // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 + // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 + // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null + // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 + // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? + // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, @@ -941,20 +958,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { { return { attached, detached }; } -} -function fixProperties(properties) { - // 字节跳动小程序 properties - // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 - // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 - // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null - // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 - // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? - // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? - Object.keys(properties).forEach((name) => { - if (properties[name] === null) { - properties[name] = undefined; - } - }); } const mocks = [ diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index b112034f2..7f0e364fa 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -510,6 +510,16 @@ function findVmByVueId(instance, vuePid) { return parentVm; } } +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -820,6 +830,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { // 初始化 vue 实例 const mpInstance = this; const isMiniProgramPage = isPage(mpInstance); + // 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined + fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, props: properties, diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index ed23b6897..45b1adee1 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) { return parentVm; } } +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { mpInstance.route = mpInstance.__route__; } + // 字节跳动小程序 properties + // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 + // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 + // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null + // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 + // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? + // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, @@ -957,20 +974,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { }, detached, }; -} -function fixProperties(properties) { - // 字节跳动小程序 properties - // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 - // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 - // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null - // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 - // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? - // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? - Object.keys(properties).forEach((name) => { - if (properties[name] === null) { - properties[name] = undefined; - } - }); } const mocks = [ diff --git a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts index 8a8da9800..40d815193 100644 --- a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts +++ b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts @@ -5,6 +5,7 @@ import { MPComponentInstance, CreateComponentOptions, CreateLifetimesOptions, + fixProperties, } from '@dcloudio/uni-mp-core' import { @@ -42,7 +43,13 @@ export function initLifetimes({ if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { mpInstance.route = mpInstance.__route__ } - + // 字节跳动小程序 properties + // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 + // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 + // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null + // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 + // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? + // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? fixProperties(properties) this.$vm = $createComponent( @@ -98,18 +105,3 @@ export function initLifetimes({ detached, } } - -function fixProperties(properties: Record) { - // 字节跳动小程序 properties - // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 - // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 - // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null - // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 - // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? - // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? - Object.keys(properties).forEach((name) => { - if (properties[name] === null) { - properties[name] = undefined - } - }) -} diff --git a/packages/uni-mp-vite/src/plugin/build.ts b/packages/uni-mp-vite/src/plugin/build.ts index ce257daa0..3e01e8822 100644 --- a/packages/uni-mp-vite/src/plugin/build.ts +++ b/packages/uni-mp-vite/src/plugin/build.ts @@ -34,8 +34,13 @@ export function buildOptions(): UserConfig['build'] { // sourcemap: 'inline', // TODO // target: ['chrome53'], // 由小程序自己启用 es6 编译 emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml + lib: { + // 必须使用 lib 模式,否则会生成 preload 等代码 + fileName: 'app.js', + entry: resolveMainPathOnce(inputDir), + formats: ['cjs'], + }, rollupOptions: { - input: resolveMainPathOnce(inputDir), output: { entryFileNames: 'app.js', format: 'cjs', diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index cc64ce8dc..1ac076b22 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => { }; const publicPropertiesMap = extend(Object.create(null), { $: i => i, - $el: i => i.vnode.el, + // fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的 + // $el: i => i.vnode.el, + $el: i => i.__$el || (i.__$el = {}), $data: i => i.data, $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props), $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs), @@ -4880,6 +4882,7 @@ var plugin = { initApp(app); // TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码 app.config.globalProperties.$createElement = () => { }; + app.config.globalProperties.$el = {}; const oldMount = app.mount; app.mount = function mount(rootContainer) { const instance = oldMount.call(app, rootContainer); @@ -5127,4 +5130,4 @@ function createApp(rootComponent, rootProps = null) { } const createSSRApp = createApp; -export { EffectScope, ReactiveEffect, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; +export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index 30bfd9d86..70c961aa2 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => { }; const publicPropertiesMap = extend(Object.create(null), { $: i => i, - $el: i => i.vnode.el, + // fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的 + // $el: i => i.vnode.el, + $el: i => i.__$el || (i.__$el = {}), $data: i => i.data, $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props), $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs), @@ -4727,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) { function withModifiers() { } function createVNode$1() { } -export { EffectScope, ReactiveEffect, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; +export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; diff --git a/packages/uni-mp-vue/src/plugin.ts b/packages/uni-mp-vue/src/plugin.ts index 11026bd39..5b873c5b6 100644 --- a/packages/uni-mp-vue/src/plugin.ts +++ b/packages/uni-mp-vue/src/plugin.ts @@ -8,6 +8,7 @@ export default { // TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码 app.config.globalProperties.$createElement = () => {} + app.config.globalProperties.$el = {} const oldMount = app.mount app.mount = function mount(rootContainer: any) { diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index be0fd8657..cf7d98254 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -391,6 +391,16 @@ function findVmByVueId(instance, vuePid) { return parentVm; } } +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } function createObserver(name) { @@ -697,6 +707,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { // 初始化 vue 实例 const mpInstance = this; const isMiniProgramPage = isPage(mpInstance); + // 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined + fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, props: properties, diff --git a/packages/uni-mp-weixin/src/runtime/lifetimes.ts b/packages/uni-mp-weixin/src/runtime/lifetimes.ts index 2cd8935ae..b9f7697ac 100644 --- a/packages/uni-mp-weixin/src/runtime/lifetimes.ts +++ b/packages/uni-mp-weixin/src/runtime/lifetimes.ts @@ -5,6 +5,7 @@ import { MPComponentInstance, CreateComponentOptions, CreateLifetimesOptions, + fixProperties, } from '@dcloudio/uni-mp-core' import { @@ -36,6 +37,9 @@ export function initLifetimes({ const mpInstance = this const isMiniProgramPage = isPage(mpInstance) + // 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined + fixProperties(properties) + this.$vm = $createComponent( { type: vueOptions, diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js index 27920a282..3e6f3e07e 100644 --- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js @@ -491,6 +491,16 @@ function initRefs(instance, mpInstance) { return $refs; }, }); +} +/** + * @param properties + */ +function fixProperties(properties) { + Object.keys(properties).forEach((name) => { + if (properties[name] === null) { + properties[name] = undefined; + } + }); } const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; @@ -886,6 +896,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { mpInstance.route = mpInstance.__route__; } + // 字节跳动小程序 properties + // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 + // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 + // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null + // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 + // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? + // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? fixProperties(properties); this.$vm = $createComponent({ type: vueOptions, @@ -910,20 +927,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { { return { attached, detached }; } -} -function fixProperties(properties) { - // 字节跳动小程序 properties - // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到 - // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值 - // 举例: easyinput 的 styles 属性,类型为 Object,`` 在 attached 中 styles 的值为 null - // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值 - // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理? - // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化? - Object.keys(properties).forEach((name) => { - if (properties[name] === null) { - properties[name] = undefined; - } - }); } const instances = Object.create(null); -- GitLab