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

fix(mp-weixin): properties default value

上级 35d77e03
...@@ -5043,7 +5043,8 @@ var serviceContext = (function (vue) { ...@@ -5043,7 +5043,8 @@ var serviceContext = (function (vue) {
current: { current: {
type: [Number, String], type: [Number, String],
}, },
}; };
const API_CLOSE_PREVIEW_IMAGE = 'closePreviewImage';
const API_GET_VIDEO_INFO = 'getVideoInfo'; const API_GET_VIDEO_INFO = 'getVideoInfo';
const GetVideoInfoOptions = { const GetVideoInfoOptions = {
...@@ -7499,7 +7500,17 @@ var serviceContext = (function (vue) { ...@@ -7499,7 +7500,17 @@ var serviceContext = (function (vue) {
}, },
}); });
resolve(); 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 recorder;
let recording = false; let recording = false;
...@@ -12904,6 +12915,7 @@ var serviceContext = (function (vue) { ...@@ -12904,6 +12915,7 @@ var serviceContext = (function (vue) {
getImageInfo: getImageInfo, getImageInfo: getImageInfo,
getVideoInfo: getVideoInfo, getVideoInfo: getVideoInfo,
previewImage: previewImage, previewImage: previewImage,
closePreviewImage: closePreviewImage,
getRecorderManager: getRecorderManager, getRecorderManager: getRecorderManager,
saveVideoToPhotosAlbum: saveVideoToPhotosAlbum, saveVideoToPhotosAlbum: saveVideoToPhotosAlbum,
saveImageToPhotosAlbum: saveImageToPhotosAlbum, saveImageToPhotosAlbum: saveImageToPhotosAlbum,
......
...@@ -4783,6 +4783,7 @@ const PreviewImageProtocol = { ...@@ -4783,6 +4783,7 @@ const PreviewImageProtocol = {
type: [Number, String] type: [Number, String]
} }
}; };
const API_CLOSE_PREVIEW_IMAGE = "closePreviewImage";
const API_GET_VIDEO_INFO = "getVideoInfo"; const API_GET_VIDEO_INFO = "getVideoInfo";
const GetVideoInfoOptions = { const GetVideoInfoOptions = {
formatArgs: { formatArgs: {
...@@ -17036,23 +17037,34 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({ ...@@ -17036,23 +17037,34 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({
} }
}); });
let state$2 = null; 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 }) => { const previewImage = /* @__PURE__ */ defineAsyncApi(API_PREVIEW_IMAGE, (args, { resolve }) => {
if (!state$2) { if (!state$2) {
state$2 = reactive(args); state$2 = reactive(args);
nextTick(() => { nextTick(() => {
const app = createRootApp(ImagePreview, state$2, () => { imagePreviewInstance = createRootApp(ImagePreview, state$2, closePreviewImageView);
state$2 = null; imagePreviewInstance.mount(ensureRoot("u-a-p"));
nextTick(() => {
app.unmount();
});
});
app.mount(ensureRoot("u-a-p"));
}); });
} else { } else {
extend(state$2, args); extend(state$2, args);
} }
resolve(); resolve();
}, PreviewImageProtocol, PreviewImageOptions); }, PreviewImageProtocol, PreviewImageOptions);
const closePreviewImage = /* @__PURE__ */ defineAsyncApi(API_CLOSE_PREVIEW_IMAGE, (_, { resolve, reject }) => {
if (imagePreviewInstance) {
closePreviewImageView();
resolve();
} else {
reject();
}
});
let videoInput = null; let videoInput = null;
const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceType, extension }, { resolve, reject }) => { const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceType, extension }, { resolve, reject }) => {
initI18nChooseFileMsgsOnce(); initI18nChooseFileMsgsOnce();
...@@ -19746,6 +19758,7 @@ var api = { ...@@ -19746,6 +19758,7 @@ var api = {
chooseFile, chooseFile,
chooseImage, chooseImage,
previewImage, previewImage,
closePreviewImage,
chooseVideo, chooseVideo,
request, request,
downloadFile, downloadFile,
...@@ -21863,4 +21876,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ ...@@ -21863,4 +21876,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]); 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 };
...@@ -545,6 +545,16 @@ function handleEvent(event) { ...@@ -545,6 +545,16 @@ function handleEvent(event) {
return console.warn(type + ' not found'); return console.warn(type + ' not found');
} }
this[methodName](event); 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -931,6 +941,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -931,6 +941,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例 // 初始化 vue 实例
const mpInstance = this; const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance); const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
props: properties, props: properties,
......
...@@ -30,6 +30,7 @@ export { ...@@ -30,6 +30,7 @@ export {
initWxsCallMethods, initWxsCallMethods,
findVmByVueId, findVmByVueId,
handleEvent, handleEvent,
fixProperties,
} from './runtime/util' } from './runtime/util'
// protocols // protocols
......
...@@ -166,3 +166,13 @@ export function handleEvent( ...@@ -166,3 +166,13 @@ export function handleEvent(
} }
;(this as any)[methodName](event) ;(this as any)[methodName](event)
} }
/**
* @param properties
*/
export function fixProperties(properties: Record<string, any>) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined
}
})
}
...@@ -540,6 +540,16 @@ function handleEvent(event) { ...@@ -540,6 +540,16 @@ function handleEvent(event) {
return console.warn(type + ' not found'); return console.warn(type + ' not found');
} }
this[methodName](event); 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -858,6 +868,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -858,6 +868,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例 // 初始化 vue 实例
const mpInstance = this; const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance); const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
props: properties, props: properties,
......
...@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) { ...@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm; 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__; mpInstance.route = mpInstance.__route__;
} }
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties); fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
...@@ -941,20 +958,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -941,20 +958,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
{ {
return { attached, detached }; return { attached, detached };
} }
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 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 = [ const mocks = [
......
...@@ -510,6 +510,16 @@ function findVmByVueId(instance, vuePid) { ...@@ -510,6 +510,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm; 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -820,6 +830,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -820,6 +830,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例 // 初始化 vue 实例
const mpInstance = this; const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance); const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
props: properties, props: properties,
......
...@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) { ...@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm; 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__; mpInstance.route = mpInstance.__route__;
} }
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties); fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
...@@ -957,20 +974,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -957,20 +974,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
}, },
detached, detached,
}; };
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 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 = [ const mocks = [
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
MPComponentInstance, MPComponentInstance,
CreateComponentOptions, CreateComponentOptions,
CreateLifetimesOptions, CreateLifetimesOptions,
fixProperties,
} from '@dcloudio/uni-mp-core' } from '@dcloudio/uni-mp-core'
import { import {
...@@ -42,7 +43,13 @@ export function initLifetimes({ ...@@ -42,7 +43,13 @@ export function initLifetimes({
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__ mpInstance.route = mpInstance.__route__
} }
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties) fixProperties(properties)
this.$vm = $createComponent( this.$vm = $createComponent(
...@@ -98,18 +105,3 @@ export function initLifetimes({ ...@@ -98,18 +105,3 @@ export function initLifetimes({
detached, detached,
} }
} }
function fixProperties(properties: Record<string, any>) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 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
}
})
}
...@@ -34,8 +34,13 @@ export function buildOptions(): UserConfig['build'] { ...@@ -34,8 +34,13 @@ export function buildOptions(): UserConfig['build'] {
// sourcemap: 'inline', // TODO // sourcemap: 'inline', // TODO
// target: ['chrome53'], // 由小程序自己启用 es6 编译 // target: ['chrome53'], // 由小程序自己启用 es6 编译
emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
lib: {
// 必须使用 lib 模式,否则会生成 preload 等代码
fileName: 'app.js',
entry: resolveMainPathOnce(inputDir),
formats: ['cjs'],
},
rollupOptions: { rollupOptions: {
input: resolveMainPathOnce(inputDir),
output: { output: {
entryFileNames: 'app.js', entryFileNames: 'app.js',
format: 'cjs', format: 'cjs',
......
...@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => { ...@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => {
}; };
const publicPropertiesMap = extend(Object.create(null), { const publicPropertiesMap = extend(Object.create(null), {
$: i => i, $: 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, $data: i => i.data,
$props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props), $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
$attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs), $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
...@@ -4880,6 +4882,7 @@ var plugin = { ...@@ -4880,6 +4882,7 @@ var plugin = {
initApp(app); initApp(app);
// TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码 // TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码
app.config.globalProperties.$createElement = () => { }; app.config.globalProperties.$createElement = () => { };
app.config.globalProperties.$el = {};
const oldMount = app.mount; const oldMount = app.mount;
app.mount = function mount(rootContainer) { app.mount = function mount(rootContainer) {
const instance = oldMount.call(app, rootContainer); const instance = oldMount.call(app, rootContainer);
...@@ -5127,4 +5130,4 @@ function createApp(rootComponent, rootProps = null) { ...@@ -5127,4 +5130,4 @@ function createApp(rootComponent, rootProps = null) {
} }
const createSSRApp = createApp; 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 };
...@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => { ...@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => {
}; };
const publicPropertiesMap = extend(Object.create(null), { const publicPropertiesMap = extend(Object.create(null), {
$: i => i, $: 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, $data: i => i.data,
$props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props), $props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
$attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs), $attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
...@@ -4727,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) { ...@@ -4727,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) {
function withModifiers() { } function withModifiers() { }
function createVNode$1() { } 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 };
...@@ -8,6 +8,7 @@ export default { ...@@ -8,6 +8,7 @@ export default {
// TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码 // TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码
app.config.globalProperties.$createElement = () => {} app.config.globalProperties.$createElement = () => {}
app.config.globalProperties.$el = {}
const oldMount = app.mount const oldMount = app.mount
app.mount = function mount(rootContainer: any) { app.mount = function mount(rootContainer: any) {
......
...@@ -391,6 +391,16 @@ function findVmByVueId(instance, vuePid) { ...@@ -391,6 +391,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm; return parentVm;
} }
} }
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
} }
function createObserver(name) { function createObserver(name) {
...@@ -697,6 +707,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -697,6 +707,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例 // 初始化 vue 实例
const mpInstance = this; const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance); const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
props: properties, props: properties,
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
MPComponentInstance, MPComponentInstance,
CreateComponentOptions, CreateComponentOptions,
CreateLifetimesOptions, CreateLifetimesOptions,
fixProperties,
} from '@dcloudio/uni-mp-core' } from '@dcloudio/uni-mp-core'
import { import {
...@@ -36,6 +37,9 @@ export function initLifetimes({ ...@@ -36,6 +37,9 @@ export function initLifetimes({
const mpInstance = this const mpInstance = this
const isMiniProgramPage = isPage(mpInstance) const isMiniProgramPage = isPage(mpInstance)
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties)
this.$vm = $createComponent( this.$vm = $createComponent(
{ {
type: vueOptions, type: vueOptions,
......
...@@ -491,6 +491,16 @@ function initRefs(instance, mpInstance) { ...@@ -491,6 +491,16 @@ function initRefs(instance, mpInstance) {
return $refs; 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]; const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
...@@ -886,6 +896,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -886,6 +896,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) { if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__; mpInstance.route = mpInstance.__route__;
} }
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties); fixProperties(properties);
this.$vm = $createComponent({ this.$vm = $createComponent({
type: vueOptions, type: vueOptions,
...@@ -910,20 +927,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) { ...@@ -910,20 +927,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
{ {
return { attached, detached }; return { attached, detached };
} }
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 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); const instances = Object.create(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册