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

feat: add resolveEasycom

上级 0838634f
......@@ -152,6 +152,7 @@ declare namespace UniApp {
topWindow?: boolean
leftWindow?: boolean
rightWindow?: boolean
maxWidth?: string | number
}
interface PagesJsonPageOptions {
......
......@@ -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;
......@@ -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<typeof ref> | ReturnType<typeof shallowRef>;
......
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 };
export * from './ssr'
export * from './utils'
export * from './apiLifecycle'
import { isString } from '@vue/shared'
export function resolveEasycom(component: unknown, easycom: unknown) {
return isString(component) ? easycom : component
}
......@@ -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));
......
......@@ -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));
......
......@@ -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<typeof useKeepAliveRoute>
......@@ -140,7 +141,7 @@ function useMaxWidth(
layoutState: LayoutState,
rootRef: Ref<HTMLElement | null>
) {
const route = useRoute()
const route = usePageRoute()
function checkMaxWidth() {
const windowWidth = document.body.clientWidth
const maxWidth = parseInt(String(route.meta.maxWidth || 1190))
......
......@@ -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)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册