diff --git a/packages/uni-components/src/helpers/useListeners.ts b/packages/uni-components/src/helpers/useListeners.ts index ff90f4a6af00019cc41f41458b36c8042a6449f1..c3ae59c6f4ed97e1e496e85753b9a1bcb13afb90 100644 --- a/packages/uni-components/src/helpers/useListeners.ts +++ b/packages/uni-components/src/helpers/useListeners.ts @@ -4,7 +4,7 @@ import { useCurrentPageId } from '@dcloudio/uni-core' export function useListeners( props: { id: string }, - listeners: Record + listeners: Record void> ) { if (__NODE_JS__) { return @@ -26,7 +26,7 @@ export function useListeners( function _addListeners( id: string, - listeners: Record, + listeners: Record void>, watch?: boolean ) { const pageId = useCurrentPageId() @@ -59,7 +59,7 @@ function _addListeners( function _removeListeners( id: string, - listeners: Record, + listeners: Record void>, watch?: boolean ) { const pageId = useCurrentPageId() diff --git a/packages/uni-h5-vite/dist/plugins/pagesJson.js b/packages/uni-h5-vite/dist/plugins/pagesJson.js index d0eefa53aeb7746d5159e653aaba0f493d9f12f4..d6b1f9e35ce59d500cfa17d1f59fe838258cf45c 100644 --- a/packages/uni-h5-vite/dist/plugins/pagesJson.js +++ b/packages/uni-h5-vite/dist/plugins/pagesJson.js @@ -37,7 +37,7 @@ function generatePagesJsonCode(ssr, jsonStr, config) { const cssCode = generateCssCode(config); return ` import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue' -import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5' +import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent, setupWindow } from '@dcloudio/uni-h5' import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '${manifestJsonPath}' ${importLayoutComponentsCode} const extend = Object.assign @@ -116,18 +116,18 @@ function generateCssCode(config) { return cssFiles.map((file) => `import '${file}'`).join('\n'); } function generateLayoutComponentsCode(globalName, pagesJson) { - const windowNames = [ - 'topWindow', - 'leftWindow', - 'rightWindow', - ]; + const windowNames = { + topWindow: -1, + leftWindow: -2, + rightWindow: -3, + }; let importLayoutComponentsCode = ''; let defineLayoutComponentsCode = `${globalName}.__uniLayout = ${globalName}.__uniLayout || {}\n`; - windowNames.forEach((name) => { + Object.keys(windowNames).forEach((name) => { const windowConfig = pagesJson[name]; if (windowConfig && windowConfig.path) { importLayoutComponentsCode += `import ${name} from './${windowConfig.path}'\n`; - defineLayoutComponentsCode += `${globalName}.__uniConfig.${name}.component = ${name}\n`; + defineLayoutComponentsCode += `${globalName}.__uniConfig.${name}.component = setupWindow(${name},${windowNames[name]})\n`; } }); return { diff --git a/packages/uni-h5-vite/src/plugins/pagesJson.ts b/packages/uni-h5-vite/src/plugins/pagesJson.ts index 3bf4c1d15c198b9c65cfd70b454c2cc76d1e8fe7..d427d74c9a5b4df4bced3f3cf10d843cbcdad382 100644 --- a/packages/uni-h5-vite/src/plugins/pagesJson.ts +++ b/packages/uni-h5-vite/src/plugins/pagesJson.ts @@ -54,7 +54,7 @@ function generatePagesJsonCode( return ` import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue' -import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5' +import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent, setupWindow } from '@dcloudio/uni-h5' import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '${manifestJsonPath}' ${importLayoutComponentsCode} const extend = Object.assign @@ -143,18 +143,20 @@ function generateLayoutComponentsCode( globalName: string, pagesJson: UniApp.PagesJson ) { - const windowNames: Array<'topWindow' | 'leftWindow' | 'rightWindow'> = [ - 'topWindow', - 'leftWindow', - 'rightWindow', - ] + const windowNames = { + topWindow: -1, + leftWindow: -2, + rightWindow: -3, + } let importLayoutComponentsCode = '' let defineLayoutComponentsCode = `${globalName}.__uniLayout = ${globalName}.__uniLayout || {}\n` - windowNames.forEach((name) => { - const windowConfig = pagesJson[name] + Object.keys(windowNames).forEach((name) => { + const windowConfig = pagesJson[name as keyof typeof windowNames] if (windowConfig && windowConfig.path) { importLayoutComponentsCode += `import ${name} from './${windowConfig.path}'\n` - defineLayoutComponentsCode += `${globalName}.__uniConfig.${name}.component = ${name}\n` + defineLayoutComponentsCode += `${globalName}.__uniConfig.${name}.component = setupWindow(${name},${ + windowNames[name as keyof typeof windowNames] + })\n` } }) diff --git a/packages/uni-h5/api.ts b/packages/uni-h5/api.ts index a651ee3184d126f270a05ad110470eff60910dc0..8f7bf055a2040015c1962e89e43caf627910afc1 100644 --- a/packages/uni-h5/api.ts +++ b/packages/uni-h5/api.ts @@ -20,6 +20,7 @@ const BLACKLIST = [ 'useTabBar', 'setupApp', 'setupPage', + 'setupWindow', 'plugin', 'cssBackdropFilter', 'cssConstant', diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index d4657aa9587b30e55fa8092020a46907fd07618a..87458614b2927d113f1d75c3f141994a693a4d31 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -6834,7 +6834,7 @@ function wrapperComponentSetup(comp, { init, setup, before }) { init(instance.proxy); const query = setup(instance); if (oldSetup) { - return oldSetup(query, ctx); + return oldSetup(query || props2, ctx); } }; } @@ -6846,6 +6846,18 @@ function setupComponent(comp, options) { } return comp; } +function setupWindow(comp, id) { + return setupComponent(comp, { + init: (vm) => { + vm.$page = { + id + }; + }, + setup(instance) { + instance.root = instance; + } + }); +} function setupPage(comp) { return setupComponent(comp, { init: initPage, @@ -10809,5 +10821,6 @@ exports.setStorage = setStorage; exports.setStorageSync = setStorageSync; exports.setupApp = setupApp; exports.setupPage = setupPage; +exports.setupWindow = setupWindow; exports.uni = uni$1; exports.useTabBar = useTabBar; diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 5b71cfc4fe33c910ba898fe6654bc6964feb2d3e..ec5cf8f664759d368ea68ea80f27ef7b725ab829 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -13574,7 +13574,7 @@ function wrapperComponentSetup(comp, { init: init2, setup, before }) { init2(instance2.proxy); const query = setup(instance2); if (oldSetup) { - return oldSetup(query, ctx); + return oldSetup(query || props2, ctx); } }; } @@ -13586,6 +13586,18 @@ function setupComponent(comp, options) { } return comp; } +function setupWindow(comp, id2) { + return setupComponent(comp, { + init: (vm) => { + vm.$page = { + id: id2 + }; + }, + setup(instance2) { + instance2.root = instance2; + } + }); +} function setupPage(comp) { return setupComponent(comp, { init: initPage, @@ -21155,4 +21167,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ return openBlock(), createBlock("div", clazz, [loadingVNode]); } }); -export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$1 as Audio, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 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, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, 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, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, 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, useTabBar, vibrateLong, vibrateShort }; +export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$1 as Audio, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 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, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, 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, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setNavigationBarColor, setNavigationBarTitle, 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, useTabBar, vibrateLong, vibrateShort }; diff --git a/packages/uni-h5/lib/resolve-id.js b/packages/uni-h5/lib/resolve-id.js deleted file mode 100644 index d9f9691e99ccb3660047095c8a68258ddff02a44..0000000000000000000000000000000000000000 --- a/packages/uni-h5/lib/resolve-id.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @type {import('vite').Plugin} - */ -const UniH5ResolveIdPlugin = { - name: 'vite:uni-h5-resolve-id', - resolveId(id) { - if (id === 'vue') { - id = '@dcloudio/uni-h5-vue' - } - const cache = resolveCache[id] - if (cache) { - return cache - } - - for (const { test, resolveId } of resolvedIds) { - if (!test(id)) { - continue - } - const file = resolveId(id) - if (!file) { - continue - } - resolveCache[id] = file - debugResolve(id, file) - return file - } - }, -} diff --git a/packages/uni-h5/lib/uni.plugin.js b/packages/uni-h5/lib/uni.plugin.js deleted file mode 100644 index d99eadf34ec5176ef03e09740b71f9342922fea7..0000000000000000000000000000000000000000 --- a/packages/uni-h5/lib/uni.plugin.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @type {import('vite').Plugin} - */ -const UniH5Plugin = { - name: 'vite:uni-h5', - uni: { - transformEvent: { - tap: 'click', - }, - }, -} - -module.exports = UniH5Plugin diff --git a/packages/uni-h5/package.json b/packages/uni-h5/package.json index 003fa108dc3772ab19cff226a770335bbc494553..d8892e67e47cf7e35e43cf6686e0665ad2b8df57 100644 --- a/packages/uni-h5/package.json +++ b/packages/uni-h5/package.json @@ -6,7 +6,6 @@ "module": "./dist/uni-h5.es.js", "files": [ "dist", - "lib", "style" ], "sideEffects": false, diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index 93122c1f2b543dd0f4da33eb179bf3051199696d..a8ed56e1fba35c4a42e4061f7f5028950e517529 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -30,7 +30,7 @@ import { usePageMeta, usePageRoute } from './provide' interface SetupComponentOptions { init: (vm: ComponentPublicInstance) => void - setup: (instance: ComponentInternalInstance) => Record + setup: (instance: ComponentInternalInstance) => Record | void before?: (comp: DefineComponent) => void } @@ -45,7 +45,7 @@ function wrapperComponentSetup( init(instance.proxy!) const query = setup(instance) if (oldSetup) { - return oldSetup(query, ctx) + return oldSetup(query || props, ctx) } } } @@ -59,11 +59,24 @@ function setupComponent(comp: any, options: SetupComponentOptions) { return comp } +export function setupWindow(comp: any, id: number) { + return setupComponent(comp, { + init: (vm) => { + vm.$page = { + id, + } as Page.PageInstance['$page'] + }, + setup(instance) { + instance.root = instance // windows 中组件 root 指向 window + }, + }) +} + export function setupPage(comp: any) { return setupComponent(comp, { init: initPage, setup(instance) { - instance.root = instance // 组件root指向页面 + instance.root = instance // 组件 root 指向页面 const route = usePageRoute() // node环境不触发Page生命周期 if (__NODE_JS__) {