diff --git a/packages/shims-uni-app.d.ts b/packages/shims-uni-app.d.ts index d6efe7bc226d8fa394e0f7349c5a092420236811..3684e90b9c9d130c1265c2bfe0734fab004857e2 100644 --- a/packages/shims-uni-app.d.ts +++ b/packages/shims-uni-app.d.ts @@ -152,6 +152,7 @@ declare namespace UniApp { topWindow?: boolean leftWindow?: boolean rightWindow?: boolean + maxWidth?: string | number } interface PagesJsonPageOptions { diff --git a/packages/uni-app/dist/uni-app.cjs.js b/packages/uni-app/dist/uni-app.cjs.js index acad9b958732b76af245aabf01a7f2859e098d84..a834ee3a7d2e92c4c7ce124295318eeaa9c260bd 100644 --- a/packages/uni-app/dist/uni-app.cjs.js +++ b/packages/uni-app/dist/uni-app.cjs.js @@ -76,6 +76,10 @@ function getSsrGlobalData() { return sanitise(globalData); } +function resolveEasycom(component, easycom) { + return shared.isString(component) ? easycom : component; +} + // @ts-ignore // App and Page const ON_SHOW = 'onShow'; @@ -155,5 +159,6 @@ exports.onTabItemTap = onTabItemTap; exports.onThemeChange = onThemeChange; exports.onUnhandledRejection = onUnhandledRejection; exports.onUnload = onUnload; +exports.resolveEasycom = resolveEasycom; exports.shallowSsrRef = shallowSsrRef; exports.ssrRef = ssrRef; diff --git a/packages/uni-app/dist/uni-app.d.ts b/packages/uni-app/dist/uni-app.d.ts index 6002ef1fa649bda1af11924a875f5495e92ec64b..a04a7bcf3f5459a0601389c3a23644ebc78d0437 100644 --- a/packages/uni-app/dist/uni-app.d.ts +++ b/packages/uni-app/dist/uni-app.d.ts @@ -50,6 +50,8 @@ export declare const onUnhandledRejection: (hook: () => any, target?: ComponentI export declare const onUnload: (hook: () => any, target?: ComponentInternalInstance | null) => any; +export declare function resolveEasycom(component: unknown, easycom: unknown): unknown; + export declare const shallowSsrRef: SSRRef; declare type SSRRef = (value: unknown, key?: string, shallow?: boolean) => ReturnType | ReturnType; diff --git a/packages/uni-app/dist/uni-app.es.js b/packages/uni-app/dist/uni-app.es.js index 237eff4cf4d9c7709f3900776630b1894f320f1b..00ab56a6260595e650a95231cf9d363dfde92caf 100644 --- a/packages/uni-app/dist/uni-app.es.js +++ b/packages/uni-app/dist/uni-app.es.js @@ -1,5 +1,5 @@ import { shallowRef, ref, getCurrentInstance, isInSSRComponentSetup, injectHook } from 'vue'; -import { hasOwn } from '@vue/shared'; +import { hasOwn, isString } from '@vue/shared'; const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val; const UNI_SSR = '__uniSSR'; @@ -41,6 +41,10 @@ function getSsrGlobalData() { return sanitise(globalData); } +function resolveEasycom(component, easycom) { + return isString(component) ? easycom : component; +} + // @ts-ignore // App and Page const ON_SHOW = 'onShow'; @@ -96,4 +100,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, shallowSsrRef, ssrRef }; +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 }; diff --git a/packages/uni-app/src/index.ts b/packages/uni-app/src/index.ts index beea5d62a510ca1988cbc4b357d1a592f262435f..b10eef72b6c129f34e247f7b74ca33be62b236f5 100644 --- a/packages/uni-app/src/index.ts +++ b/packages/uni-app/src/index.ts @@ -1,2 +1,3 @@ export * from './ssr' +export * from './utils' export * from './apiLifecycle' diff --git a/packages/uni-app/src/utils.ts b/packages/uni-app/src/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..85de0c234dcccc56dbd5cd536ec4fd6925459648 --- /dev/null +++ b/packages/uni-app/src/utils.ts @@ -0,0 +1,5 @@ +import { isString } from '@vue/shared' + +export function resolveEasycom(component: unknown, easycom: unknown) { + return isString(component) ? easycom : component +} diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 8dfe11d3d6bc71d27c3c7b6fe569b42fd16c5da8..e3aca5a877c8e23b61b0cfffc716b9af72d28c2d 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -10617,7 +10617,7 @@ function initMediaQuery(minWidth, callback) { return mediaQueryList.matches; } function useMaxWidth(layoutState, rootRef) { - const route = vueRouter.useRoute(); + const route = usePageRoute(); function checkMaxWidth() { const windowWidth = document.body.clientWidth; const maxWidth = parseInt(String(route.meta.maxWidth || 1190)); diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 94b60cc06c733e2a193e5216b364418eacbd4bc1..425e2c4dfb5eeb9adad54e07cdfcaa9d0e317d1d 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -18101,7 +18101,7 @@ function initMediaQuery(minWidth, callback) { return mediaQueryList.matches; } function useMaxWidth(layoutState, rootRef) { - const route = useRoute(); + const route = usePageRoute(); function checkMaxWidth() { const windowWidth = document.body.clientWidth; const maxWidth = parseInt(String(route.meta.maxWidth || 1190)); diff --git a/packages/uni-h5/src/framework/components/layout/index.tsx b/packages/uni-h5/src/framework/components/layout/index.tsx index 16c84c63bc9b086835d483292c7124bf38c2d483..fa8720bf6503251089e8bf6e7b4ca5f48652eb14 100644 --- a/packages/uni-h5/src/framework/components/layout/index.tsx +++ b/packages/uni-h5/src/framework/components/layout/index.tsx @@ -29,6 +29,7 @@ import { checkMinWidth } from '../../../helpers/dom' import { hasOwn } from '@vue/shared' import TabBar from './tabBar' +import { usePageRoute } from '../../setup/provide' type KeepAliveRoute = ReturnType @@ -140,7 +141,7 @@ function useMaxWidth( layoutState: LayoutState, rootRef: Ref ) { - const route = useRoute() + const route = usePageRoute() function checkMaxWidth() { const windowWidth = document.body.clientWidth const maxWidth = parseInt(String(route.meta.maxWidth || 1190)) diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts b/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts index f381f0134bd4b55c9ccdf68ac6c2d2ae39961d50..15bc4a32b51bbcee0a142b6c38db4fb009c3aea6 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts @@ -50,7 +50,7 @@ const baseComponents = [ 'view', ] -const identifierRE = /^([a-zA-Z_$][a-zA-Z\\d_$]*)$/ +// const identifierRE = /^([a-zA-Z_$][a-zA-Z\\d_$]*)$/ export function uniEasycomPlugin( options: UniPluginFilterOptions, @@ -100,11 +100,10 @@ export function uniEasycomPlugin( } const source = matchEasycom(name) if (source) { - return ( - // 解决局部引入组件优先级(理论上让开发者使用script setup就可以解决局部引入) - (identifierRE.test(name) - ? `typeof ${name} !== 'undefined' ? ${name} : ` - : '') + + // 处理easycom组件优先级 + return genResolveEasycomCode( + importDeclarations, + str, addImportDeclaration( importDeclarations, `__easycom_${i++}`, @@ -124,6 +123,19 @@ export function uniEasycomPlugin( } } +const RESOLVE_EASYCOM_IMPORT_CODE = `import { resolveEasycom } from '@dcloudio/uni-app';` + +function genResolveEasycomCode( + importDeclarations: string[], + code: string, + name: string +) { + if (!importDeclarations.includes(RESOLVE_EASYCOM_IMPORT_CODE)) { + importDeclarations.push(RESOLVE_EASYCOM_IMPORT_CODE) + } + return `resolveEasycom(${code},${name})` +} + function resolveBuiltInCssImport(name: string) { const cssImports: string[] = [] if (baseComponents.includes(name)) {