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

wip(app): uni-app-plus

上级 3f38cea0
......@@ -303,12 +303,6 @@ declare namespace UniApp {
* @param callback
*/
unsubscribe(event: string, callback?: Function): void
/**
* 执行 Service 层 API 回调
* @param callbackId
* @param args
*/
invokeCallbackHandler(callbackId: number, args: unknown): void
/**
* 向 View 层发送事件
* @param event
......
......@@ -2,6 +2,9 @@ import { UniLifecycleHooks } from '@dcloudio/uni-vue/src/apiLifecycle'
import { ComponentCustomProperties, ComponentInternalInstance } from 'vue'
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$scope: {
$getAppWebview: () => PlusWebviewWebviewObject
}
$page: Page.PageInstance['$page']
__isTabBar: boolean
}
......
......@@ -5,10 +5,10 @@
"output": {
"name": "serviceContext",
"format": "iife",
"banner": "export function createServiceContext(weex, plus,instanceContext){\nconst jsRuntime = {};\nconst setTimeout = instanceContext.setTimeout;\nconst clearTimeout = instanceContext.clearTimeout;\nconst setInterval = instanceContext.setInterval;\nconst clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\n",
"banner": "export function createServiceContext(Vue,weex, plus,instanceContext){\nconst setTimeout = instanceContext.setTimeout;\nconst clearTimeout = instanceContext.clearTimeout;\nconst setInterval = instanceContext.setInterval;\nconst clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\n",
"footer": "const uni = serviceContext.uni;\nconst getApp = serviceContext.getApp;\nconst getCurrentPages = serviceContext.getCurrentPages;\nconst UniServiceJSBridge = serviceContext.UniServiceJSBridge;\nreturn serviceContext;\n}",
"globals": {
"vue": "jsRuntime"
"vue": "Vue"
}
},
"replacements": {
......@@ -22,7 +22,5 @@
"__UNI_FEATURE_I18N_ZH_HANS__": "true",
"__UNI_FEATURE_I18N_ZH_HANT__": "true"
},
"external": [
"vue"
]
}
\ No newline at end of file
"external": ["vue"]
}
......@@ -5608,7 +5608,19 @@
};
function initBridge(subscribeNamespace) {
const emitter = new E();
return extend(emitter, {
return {
on(event, callback) {
return emitter.on(event, callback);
},
once(event, callback) {
return emitter.once(event, callback);
},
off(event, callback) {
return emitter.off(event, callback);
},
emit(event, ...args) {
return emitter.emit(event, ...args);
},
subscribe(event, callback, once = false) {
emitter[once ? "once" : "on"](`${subscribeNamespace}.${event}`, callback);
},
......@@ -5621,7 +5633,7 @@
}
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
});
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
function PolySymbol(name) {
......@@ -5693,11 +5705,6 @@
fromRouteArray.splice(fromRouteArray.length - i - 1, i + 1);
return "/" + fromRouteArray.concat(toRouteArray).join("/");
}
/* @__PURE__ */ extend(initBridge("view"), {
invokeOnCallback(name, res) {
return UniServiceJSBridge.emit("api." + name, res);
}
});
function converPx(value) {
if (/^-?\d+[ur]px$/i.test(value)) {
return value.replace(/(^-?\d+)[ur]px$/i, (text, num) => {
......
......@@ -38,8 +38,10 @@ export * from './ui/popup/showToast'
export * from './plugin/getProvider'
export * from './plugin/oauth'
export * from './plugin/registerRuntime'
export * from './plugin/share'
export * from './plugin/requestPayment'
export * from './plugin/vuePlugin'
export * from './ad/rewardedVideoAd'
export * from './ad/fullScreenVideoAd'
......
import { extend } from '@vue/shared'
import { defineSyncApi } from '@dcloudio/uni-api'
import { ComponentInternalInstance } from 'vue'
interface JsRuntime {
injectHook: (
type: string,
hook: Function,
target: ComponentInternalInstance | null,
prepend: boolean
) => Function | undefined
createApp: typeof createApp
}
export const registerRuntime = defineSyncApi<(runtime: JsRuntime) => void>(
'registerRuntime',
(runtime) => {
// @ts-expect-error
extend(jsRuntime, runtime)
}
)
export { default as __vuePlugin } from '../../framework/plugin'
import { ComponentPublicInstance } from 'vue'
import { extend } from '@vue/shared'
import { initService } from '@dcloudio/uni-core'
import { initEntry } from './initEntry'
import { initTabBar } from './initTabBar'
import { initGlobalEvent } from './initGlobalEvent'
......@@ -13,7 +15,24 @@ const defaultApp = {
globalData: {},
}
export function getApp({ allowDefault = false } = {}) {
if (appCtx) {
// 真实的 App 已初始化
return appCtx
}
if (allowDefault) {
// 返回默认实现
return defaultApp
}
console.error(
'[warn]: getApp() failed. Learn more: https://uniapp.dcloud.io/collocation/frame/window?id=getapp.'
)
}
export function registerApp(appVm: ComponentPublicInstance) {
if (__DEV__) {
console.log('registerApp')
}
appCtx = appVm
appCtx.$vm = appVm
......@@ -24,6 +43,8 @@ export function registerApp(appVm: ComponentPublicInstance) {
appCtx.globalData = extend($options.globalData || {}, appCtx.globalData)
}
initService()
initEntry()
initTabBar()
initGlobalEvent()
......
......@@ -41,6 +41,9 @@ function subscribePlusMessage({
}: {
data: { type: string; args: Record<string, any> }
}) {
if (__DEV__) {
console.log('plusMessage:' + JSON.stringify(data))
}
if (data && data.type) {
UniServiceJSBridge.subscribeHandler('plusMessage.' + data.type, data.args)
}
......
......@@ -13,29 +13,33 @@ export function definePage(pagePath: string, component: VueComponent) {
}
export interface PageProps {
pageId: number
pagePath: string
pageQuery: Record<string, any>
pageInstance: unknown
pageInstance: Page.PageInstance['$page']
}
export function createPage(
pageId: number,
pagePath: string,
pageQuery: Record<string, any>,
pageInstance: unknown,
pageInstance: Page.PageInstance['$page'],
pageOptions: PageNodeOptions
) {
return createApp(pagesMap.get(pagePath)!(), {
pagePath,
pageQuery,
pageInstance,
})
return createApp(
pagesMap.get(pagePath)!({
pageId,
pagePath,
pageQuery,
pageInstance,
})
)
.use(__vuePlugin)
.mount(createPageNode(pageId, pageOptions) as unknown as Element)
.mount(createPageNode(pageId, pageOptions, true) as unknown as Element)
}
function createFactory(component: VueComponent) {
return () => {
return setupPage(component)
return (props: PageProps) => {
return setupPage(component, props)
}
}
import { ComponentPublicInstance } from 'vue'
const pages: ComponentPublicInstance[] = []
export function addCurrentPage(page: ComponentPublicInstance) {
pages.push(page)
}
export function getCurrentPages() {
const curPages: ComponentPublicInstance[] = []
pages.forEach((page) => {
if (page.__isTabBar) {
if (page.$.__isActive) {
curPages.push(page)
}
} else {
curPages.push(page)
}
})
return curPages
}
export * from './define'
export * from './register'
plus.webview.create
export { definePage } from './define'
export { registerPage } from './register'
export { getCurrentPages } from './getCurrentPages'
......@@ -7,6 +7,9 @@ import { createPage } from './define'
import { PageNodeOptions } from '../dom/Page'
import { getStatusbarHeight } from '../../../helpers/statusBar'
import tabBar from '../app/tabBar'
import { addCurrentPage } from './getCurrentPages'
import { initPageInternalInstance } from '@dcloudio/uni-core'
import { ComponentPublicInstance } from 'vue'
export type OpenType =
| 'navigateTo'
......@@ -22,14 +25,17 @@ interface RegisterPageOptions {
query: Record<string, string>
openType: OpenType
webview?: PlusWebviewWebviewObject
vm?: ComponentPublicInstance // nvue vm instance
// eventChannel: unknown
}
export function registerPage({
url,
path,
query,
openType,
webview,
vm,
}: RegisterPageOptions) {
// fast 模式,nvue 首页时,会在nvue中主动调用registerPage并传入首页webview,此时初始化一下首页(因为此时可能还未调用registerApp)
if (webview) {
......@@ -48,6 +54,11 @@ export function registerPage({
routeOptions.meta.id = parseInt(webview.id!)
const isTabBar = !!routeOptions.meta.isTabBar
if (isTabBar) {
tabBar.append(webview)
}
if (__DEV__) {
console.log(`[uni-app] registerPage(${path},${webview.id})`)
}
......@@ -58,14 +69,18 @@ export function registerPage({
;(webview as any).__uniapp_route = route
const pageInstance = initPageInternalInstance(url, query, routeOptions.meta)
if (!(webview as any).nvue) {
createPage(
parseInt(webview.id!),
route,
query,
null,
pageInstance,
initPageOptions(routeOptions)
)
} else {
vm && addCurrentPage(vm)
}
return webview
}
......
import { getRouteOptions, initRouteMeta } from '@dcloudio/uni-core'
import { OpenType } from '.'
import { OpenType } from './register'
export function initRouteOptions(path: string, openType: OpenType) {
// 需要序列化一遍
......
import { ComponentPublicInstance, getCurrentInstance } from 'vue'
import { PageProps, VueComponent } from './define'
import { addCurrentPage } from './getCurrentPages'
export function setupPage(component: VueComponent) {
if (__DEV__) {
console.log(`setupPage`)
}
export function setupPage(
component: VueComponent,
{ pageId, pagePath, pageQuery, pageInstance }: PageProps
) {
const oldSetup = component.setup
component.setup = (props, ctx) => {
const { pagePath, pageQuery } = props as unknown as PageProps
component.setup = (_props, ctx) => {
if (__DEV__) {
console.log(`${pagePath} setup`)
}
const instance = getCurrentInstance()!
const pageVm = instance.proxy!
pageVm.$page = pageInstance
addCurrentPage(initScope(pageId, pageVm))
if (oldSetup) {
return oldSetup(pageQuery as any, ctx)
}
}
return component
}
function initScope(pageId: number, vm: ComponentPublicInstance) {
vm.$scope = {
$getAppWebview() {
return plus.webview.getWebviewById(String(pageId))
},
}
return vm
}
import { App, ComponentInternalInstance } from 'vue'
import { extend } from '@vue/shared'
import { App } from 'vue'
import { initApp } from '@dcloudio/uni-vue'
import { initService } from '@dcloudio/uni-core'
import { initServicePlugin } from '@dcloudio/uni-core'
import { registerApp } from '../app'
interface JsRuntime {
injectHook: (
type: string,
hook: Function,
target: ComponentInternalInstance | null,
prepend: boolean
) => Function | undefined
createApp: typeof createApp
}
export default {
install(app: App, runtime: JsRuntime) {
// @ts-expect-error 赋值全局对象 jsRuntime
extend(jsRuntime, runtime)
install(app: App) {
initMount(app)
initApp(app)
initService(app)
initServicePlugin(app)
},
}
......
import { ComponentInternalInstance } from 'vue'
import { extend } from '@vue/shared'
interface JsRuntime {
injectHook: (
type: string,
hook: Function,
target: ComponentInternalInstance | null,
prepend: boolean
) => Function | undefined
createApp: typeof createApp
}
export function defineRuntime(runtime: JsRuntime) {
// @ts-expect-error
extend(jsRuntime, runtime)
}
import * as uni from './api'
import { UniServiceJSBridge } from './bridge'
import { registerApp as __registerApp } from './framework/app'
import { getApp, registerApp as __registerApp } from './framework/app'
import {
definePage as __definePage,
registerPage as __registerPage,
getCurrentPages,
} from './framework/page'
import __vuePlugin from './framework/plugin'
// ;(uni as any).__$wx__ = uni
export default {
uni,
__vuePlugin,
getApp,
getCurrentPages,
__definePage,
__registerApp,
__registerPage,
......
......@@ -23,9 +23,12 @@ exports.UniAppPlugin = {
formats: ['iife'],
},
rollupOptions: {
// external: ['vue'],
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
globals: {
vue: 'Vue',
},
},
},
},
......
......@@ -13,7 +13,7 @@ function uniMainJsPlugin() {
? createApp(code)
: createLegacyApp(code);
return {
code: `import './pages.json.js';` + JS_RUNTIME_CODE + code,
code: `import './pages.json.js';` + code,
map: this.getCombinedSourcemap(),
};
}
......@@ -22,10 +22,9 @@ function uniMainJsPlugin() {
});
}
exports.uniMainJsPlugin = uniMainJsPlugin;
const JS_RUNTIME_CODE = `import {injectHook as __injectHook__,createApp as __createApp__} from 'vue';const __RUNTIME__ = {injectHook:__injectHook__,createApp:__createApp__};`;
function createApp(code) {
return `const __app__=createApp().app;__app__._component.render=()=>{};__app__.use(__vuePlugin,__RUNTIME__).mount("#app");${code.replace('createSSRApp', 'createVueApp as createSSRApp')}`;
return `const __app__=createApp().app;__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");${code.replace('createSSRApp', 'createVueApp as createSSRApp')}`;
}
function createLegacyApp(code) {
return `function createApp(rootComponent,rootProps){const app=createVueApp(rootComponent,rootProps).use(__vuePlugin,__RUNTIME__);app.render=()=>{};const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};${code.replace('createApp', 'createVueApp')}`;
return `function createApp(rootComponent,rootProps){const app=createVueApp(rootComponent,rootProps).use(uni.__vuePlugin);app.render=()=>{};const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};${code.replace('createApp', 'createVueApp')}`;
}
......@@ -31,12 +31,12 @@ export const UniAppPlugin: UniVitePlugin = {
formats: ['iife'],
},
rollupOptions: {
// external: ['vue'],
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
// globals: {
// vue: 'Vue',
// },
globals: {
vue: 'Vue',
},
},
},
},
......
......@@ -11,7 +11,7 @@ export function uniMainJsPlugin() {
? createApp(code)
: createLegacyApp(code)
return {
code: `import './pages.json.js';` + JS_RUNTIME_CODE + code,
code: `import './pages.json.js';` + code,
map: this.getCombinedSourcemap(),
}
}
......@@ -20,17 +20,15 @@ export function uniMainJsPlugin() {
})
}
const JS_RUNTIME_CODE = `import {injectHook as __injectHook__,createApp as __createApp__} from 'vue';const __RUNTIME__ = {injectHook:__injectHook__,createApp:__createApp__};`
function createApp(code: string) {
return `const __app__=createApp().app;__app__._component.render=()=>{};__app__.use(__vuePlugin,__RUNTIME__).mount("#app");${code.replace(
return `const __app__=createApp().app;__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");${code.replace(
'createSSRApp',
'createVueApp as createSSRApp'
)}`
}
function createLegacyApp(code: string) {
return `function createApp(rootComponent,rootProps){const app=createVueApp(rootComponent,rootProps).use(__vuePlugin,__RUNTIME__);app.render=()=>{};const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};${code.replace(
return `function createApp(rootComponent,rootProps){const app=createVueApp(rootComponent,rootProps).use(uni.__vuePlugin);app.render=()=>{};const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};${code.replace(
'createApp',
'createVueApp'
)}`
......
......@@ -3,6 +3,10 @@
"input": {
"src/service/index.ts": ["dist/service.runtime.esm.js"]
},
"output": {
"banner": "export default function vueFactory (exports) {\n",
"footer": "}"
},
"replacements": {
"__VUE_OPTIONS_API__": "true",
"__VUE_PROD_DEVTOOLS__": "false"
......
export default function vueFactory (exports) {
/**
* Make a map and return a function for checking if a key
* is in that map.
......@@ -11259,4 +11261,129 @@ function injectNativeTagCheck(app) {
function onBeforeActivate() {}
function onBeforeDeactivate() {}
export { BaseTransition, Comment$1 as Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, computed$1 as computed, createApp, createBlock, createComment, createCommentVNode, createElement, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextNode, createTextVNode, createVNode, createApp as createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineEmits, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
var Vue = /*#__PURE__*/Object.freeze({
__proto__: null,
BaseTransition: BaseTransition,
Comment: Comment$1,
Fragment: Fragment,
KeepAlive: KeepAlive,
Static: Static,
Suspense: Suspense,
Teleport: Teleport,
Text: Text,
Transition: Transition,
TransitionGroup: TransitionGroup,
callWithAsyncErrorHandling: callWithAsyncErrorHandling,
callWithErrorHandling: callWithErrorHandling,
camelize: camelize,
capitalize: capitalize,
cloneVNode: cloneVNode,
compatUtils: compatUtils,
computed: computed$1,
createApp: createApp,
createBlock: createBlock,
createComment: createComment,
createCommentVNode: createCommentVNode,
createElement: createElement,
createHydrationRenderer: createHydrationRenderer,
createRenderer: createRenderer,
createSSRApp: createSSRApp,
createSlots: createSlots,
createStaticVNode: createStaticVNode,
createTextNode: createTextNode,
createTextVNode: createTextVNode,
createVNode: createVNode,
createVueApp: createApp,
customRef: customRef,
defineAsyncComponent: defineAsyncComponent,
defineComponent: defineComponent,
defineEmit: defineEmit,
defineEmits: defineEmits,
defineProps: defineProps,
get devtools () { return devtools; },
getCurrentInstance: getCurrentInstance,
getTransitionRawChildren: getTransitionRawChildren,
h: h,
handleError: handleError,
initCustomFormatter: initCustomFormatter,
inject: inject,
injectHook: injectHook,
get isInSSRComponentSetup () { return isInSSRComponentSetup; },
isProxy: isProxy,
isReactive: isReactive,
isReadonly: isReadonly,
isRef: isRef,
isRuntimeOnly: isRuntimeOnly,
isVNode: isVNode,
markRaw: markRaw,
mergeProps: mergeProps,
nextTick: nextTick,
onActivated: onActivated,
onBeforeActivate: onBeforeActivate,
onBeforeDeactivate: onBeforeDeactivate,
onBeforeMount: onBeforeMount,
onBeforeUnmount: onBeforeUnmount,
onBeforeUpdate: onBeforeUpdate,
onDeactivated: onDeactivated,
onErrorCaptured: onErrorCaptured,
onMounted: onMounted,
onRenderTracked: onRenderTracked,
onRenderTriggered: onRenderTriggered,
onServerPrefetch: onServerPrefetch,
onUnmounted: onUnmounted,
onUpdated: onUpdated,
openBlock: openBlock,
popScopeId: popScopeId,
provide: provide,
proxyRefs: proxyRefs,
pushScopeId: pushScopeId,
queuePostFlushCb: queuePostFlushCb,
reactive: reactive,
readonly: readonly,
ref: ref,
registerRuntimeCompiler: registerRuntimeCompiler,
render: render,
renderList: renderList,
renderSlot: renderSlot,
resolveComponent: resolveComponent,
resolveDirective: resolveDirective,
resolveDynamicComponent: resolveDynamicComponent,
resolveFilter: resolveFilter,
resolveTransitionHooks: resolveTransitionHooks,
setBlockTracking: setBlockTracking,
setDevtoolsHook: setDevtoolsHook,
setTransitionHooks: setTransitionHooks,
shallowReactive: shallowReactive,
shallowReadonly: shallowReadonly,
shallowRef: shallowRef,
ssrContextKey: ssrContextKey,
ssrUtils: ssrUtils,
toDisplayString: toDisplayString,
toHandlerKey: toHandlerKey,
toHandlers: toHandlers,
toRaw: toRaw,
toRef: toRef,
toRefs: toRefs,
transformVNodeArgs: transformVNodeArgs,
triggerRef: triggerRef,
unref: unref,
useContext: useContext,
useCssModule: useCssModule,
useCssVars: useCssVars,
useSSRContext: useSSRContext,
useTransitionState: useTransitionState,
vModelText: vModelText,
vShow: vShow,
version: version,
warn: warn,
watch: watch,
watchEffect: watchEffect,
withCtx: withCtx,
withDirectives: withDirectives,
withKeys: withKeys,
withModifiers: withModifiers,
withScopeId: withScopeId
});
exports.Vue = Vue;
}
export * from '../../lib/service.runtime.esm'
import * as Vue from '../../lib/service.runtime.esm'
exports.Vue = Vue
......@@ -7,7 +7,7 @@ import {
interface AppUniConfig {
pages: string[]
window: UniApp.PagesJsonPageStyle
globalStyle: UniApp.PagesJsonPageStyle
nvue: {
compiler: 'uni-app' | 'weex'
styleCompiler: 'weex' | 'uni-app'
......@@ -35,7 +35,7 @@ export function normalizeAppUniConfig(
) {
const config: AppUniConfig = {
pages: [],
window: pagesJson.globalStyle,
globalStyle: pagesJson.globalStyle,
nvue: {
compiler: getNVueCompiler(manifestJson),
styleCompiler: getNVueStyleCompiler(manifestJson),
......
import { extend } from '@vue/shared'
// TODO 等待 vue3 的兼容模式自带emitter
import E from './TinyEmitter'
export function initBridge(
subscribeNamespace: 'service' | 'view'
): Partial<UniApp.UniServiceJSBridge> {
): Omit<UniApp.UniServiceJSBridge, 'invokeOnCallback' | 'publishHandler'> {
// TODO vue3 compatibility builds
const emitter = new E()
return extend(emitter, {
return {
on(event: string, callback: Function) {
return emitter.on(event, callback)
},
once(event: string, callback: Function) {
return emitter.once(event, callback)
},
off(event: string, callback?: Function) {
return emitter.off(event, callback)
},
emit(event: string, ...args: any[]) {
return emitter.emit(event, ...args)
},
subscribe(event: string, callback: Function, once: boolean = false): void {
emitter[once ? 'once' : 'on'](`${subscribeNamespace}.${event}`, callback)
},
......@@ -24,5 +35,5 @@ export function initBridge(
}
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId)
},
})
}
}
import { isString } from '@vue/shared'
import { ComponentPublicInstance } from 'vue'
import { isString } from '@vue/shared'
import { invokeArrayFns } from '@dcloudio/uni-shared'
export function getPageById(id: number) {
return getCurrentPages().find((page) => page.$page.id === id)
}
export function getPageVmById(id: number) {
const page = getPageById(id)
if (page) {
return (page as any).$vm as ComponentPublicInstance
}
}
export function getCurrentPage() {
const pages = getCurrentPages()
const len = pages.length
if (len) {
return pages[len - 1]
}
}
export function getCurrentPageMeta() {
const page = getCurrentPage()
if (page) {
return page.$page.meta
}
}
export function getCurrentPageId() {
const meta = getCurrentPageMeta()
if (meta) {
return meta.id!
}
return -1
}
export function getCurrentPageVm() {
const page = getCurrentPage()
if (page) {
return (page as any).$vm as ComponentPublicInstance
}
}
import { getCurrentPageVm } from './page'
export function invokeHook(name: string, args?: unknown): unknown
export function invokeHook(id: number, name: string, args?: unknown): unknown
......
......@@ -2,6 +2,7 @@ export * from './dom'
export * from './util'
export * from './icon'
export * from './page'
export * from './hook'
export * from './scroll'
export * from './route'
export * from './callbacks'
......
......@@ -16,6 +16,47 @@ export function getPageIdByVm(vm: ComponentPublicInstance) {
}
}
export function getPageById(id: number) {
return getCurrentPages().find((page) => page.$page.id === id)
}
export function getPageVmById(id: number) {
const page = getPageById(id)
if (page) {
return (page as any).$vm as ComponentPublicInstance
}
}
export function getCurrentPage() {
const pages = getCurrentPages()
const len = pages.length
if (len) {
return pages[len - 1]
}
}
export function getCurrentPageMeta() {
const page = getCurrentPage()
if (page) {
return page.$page.meta
}
}
export function getCurrentPageId() {
const meta = getCurrentPageMeta()
if (meta) {
return meta.id!
}
return -1
}
export function getCurrentPageVm() {
const page = getCurrentPage()
if (page) {
return (page as any).$vm as ComponentPublicInstance
}
}
const PAGE_META_KEYS = ['navigationBar', 'pullToRefresh'] as const
function initGlobalStyle() {
......@@ -48,3 +89,19 @@ export function normalizePullToRefreshRpx(
}
return pullToRefresh
}
export function initPageInternalInstance(
url: string,
pageQuery: Record<string, any>,
meta: UniApp.PageRouteMeta
): Page.PageInstance['$page'] {
const { id, route } = meta
return {
id: id!,
path: '/' + route,
route: route,
fullPath: url,
options: pageQuery,
meta,
}
}
export * from './bridge'
export * from './plugin'
export { ServiceJSBridge } from './bridge'
export { initService } from './init'
export { initServicePlugin } from './plugin'
import { initOn } from './on'
import { initSubscribe } from './subscribe'
export function initService() {
if (__NODE_JS__) {
return
}
initOn()
initSubscribe()
}
import { ComponentPublicInstance } from '@vue/runtime-core'
import { getCurrentPage, invokeHook } from './page'
import { invokeHook } from '../../helpers/hook'
import { getCurrentPage } from '../../helpers/page'
export function initOn() {
UniServiceJSBridge.on('onAppEnterForeground', onAppEnterForeground)
......
import { getPageVmById, invokeHook } from './page'
import { getPageVmById } from '../../helpers/page'
import { invokeHook } from '../../helpers/hook'
const SUBSCRIBE_LIFECYCLE_HOOKS = ['onPageScroll', 'onReachBottom']
......
import { App } from 'vue'
import { initAppConfig } from './appConfig'
import { initOn } from './on'
import { initSubscribe } from './subscribe'
export * from './page'
export function initService(app: App) {
export function initServicePlugin(app: App) {
if (__NODE_JS__) {
return
}
initOn()
initSubscribe()
initAppConfig(app._context.config)
}
export * from './bridge'
export * from './plugin'
export { ViewJSBridge } from './bridge'
export { initView } from './init'
export { initViewPlugin } from './plugin'
export { createNativeEvent } from './plugin/componentInstance'
import { initCustomDataset } from '@dcloudio/uni-shared'
import { initLongPress } from './longPress'
import { useRem } from './rem'
export function initView() {
if (__NODE_JS__) {
return
}
useRem()
initCustomDataset()
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress()
}
}
import { App } from 'vue'
import { initLongPress } from './longPress'
import { initAppConfig } from './appConfig'
import { initCustomDataset } from '@dcloudio/uni-shared'
import { useRem } from './rem'
export function initView(app: App) {
export function initViewPlugin(app: App) {
if (__NODE_JS__) {
return
}
useRem()
initCustomDataset()
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress()
}
initAppConfig(app._context.config)
// TODO wxs,behaviors
}
export { createNativeEvent } from './componentInstance'
......@@ -353,7 +353,19 @@ E.prototype = {
};
function initBridge(subscribeNamespace) {
const emitter = new E();
return shared.extend(emitter, {
return {
on(event, callback) {
return emitter.on(event, callback);
},
once(event, callback) {
return emitter.once(event, callback);
},
off(event, callback) {
return emitter.off(event, callback);
},
emit(event, ...args) {
return emitter.emit(event, ...args);
},
subscribe(event, callback, once = false) {
emitter[once ? "once" : "on"](`${subscribeNamespace}.${event}`, callback);
},
......@@ -366,7 +378,7 @@ function initBridge(subscribeNamespace) {
}
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
});
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
uniShared.passive(true);
......@@ -425,6 +437,32 @@ function createSvgIconVNode(path, color = "#000", size = 27) {
function useCurrentPageId() {
return vue.getCurrentInstance().root.proxy.$page.id;
}
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
if (len) {
return pages[len - 1];
}
}
function getCurrentPageMeta() {
const page = getCurrentPage();
if (page) {
return page.$page.meta;
}
}
function getCurrentPageId() {
const meta = getCurrentPageMeta();
if (meta) {
return meta.id;
}
return -1;
}
function getCurrentPageVm() {
const page = getCurrentPage();
if (page) {
return page.$vm;
}
}
const PAGE_META_KEYS = ["navigationBar", "pullToRefresh"];
function initGlobalStyle() {
return JSON.parse(JSON.stringify(__uniConfig.globalStyle || {}));
......@@ -449,6 +487,36 @@ function normalizePullToRefreshRpx(pullToRefresh) {
}
return pullToRefresh;
}
function initPageInternalInstance(url, pageQuery, meta) {
const { id, route } = meta;
return {
id,
path: "/" + route,
route,
fullPath: url,
options: pageQuery,
meta
};
}
function invokeHook(vm, name, args) {
if (shared.isString(vm)) {
args = name;
name = vm;
vm = getCurrentPageVm();
} else if (typeof vm === "number") {
const page = getCurrentPages().find((page2) => page2.$page.id === vm);
if (page) {
vm = page.$vm;
} else {
vm = getCurrentPageVm();
}
}
if (!vm) {
return;
}
const hooks = vm.$[name];
return hooks && uniShared.invokeArrayFns(hooks, args);
}
function getRealRoute(fromRoute, toRoute) {
if (toRoute.indexOf("/") === 0) {
return toRoute;
......@@ -534,51 +602,6 @@ const ServiceJSBridge = /* @__PURE__ */ shared.extend(initBridge("view"), {
return UniServiceJSBridge.emit("api." + name, res);
}
});
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
if (len) {
return pages[len - 1];
}
}
function getCurrentPageMeta() {
const page = getCurrentPage();
if (page) {
return page.$page.meta;
}
}
function getCurrentPageId() {
const meta = getCurrentPageMeta();
if (meta) {
return meta.id;
}
return -1;
}
function getCurrentPageVm() {
const page = getCurrentPage();
if (page) {
return page.$vm;
}
}
function invokeHook(vm, name, args) {
if (shared.isString(vm)) {
args = name;
name = vm;
vm = getCurrentPageVm();
} else if (typeof vm === "number") {
const page = getCurrentPages().find((page2) => page2.$page.id === vm);
if (page) {
vm = page.$vm;
} else {
vm = getCurrentPageVm();
}
}
if (!vm) {
return;
}
const hooks = vm.$[name];
return hooks && uniShared.invokeArrayFns(hooks, args);
}
function converPx(value) {
if (/^-?\d+[ur]px$/i.test(value)) {
return value.replace(/(^-?\d+)[ur]px$/i, (text, num) => {
......@@ -6623,25 +6646,9 @@ function getCurrentPages$1() {
function initPublicPage(route) {
const meta = usePageMeta();
if (!__UNI_FEATURE_PAGES__) {
const { path: path2, alias } = __uniRoutes[0];
return {
id: meta.id,
path: path2,
route: alias.substr(1),
fullPath: path2,
options: {},
meta
};
return initPageInternalInstance(__uniRoutes[0].path, {}, meta);
}
const { path } = route;
return {
id: meta.id,
path,
route: route.meta.route,
fullPath: route.meta.isEntry ? route.meta.pagePath : route.fullPath,
options: {},
meta
};
return initPageInternalInstance(route.fullPath, {}, meta);
}
function initPage(vm) {
const route = vm.$route;
......
import { isFunction, extend, hyphenate, isPlainObject, isString, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, passive, normalizeTarget, isBuiltInComponent, initCustomDataset, invokeArrayFns, SCHEME_RE, DATA_RE, getCustomDataset, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, updateElementStyle, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime } from "@dcloudio/uni-shared";
import { isFunction, extend, isString, hyphenate, isPlainObject, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, passive, initCustomDataset, invokeArrayFns, normalizeTarget, isBuiltInComponent, SCHEME_RE, DATA_RE, getCustomDataset, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, updateElementStyle, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime } from "@dcloudio/uni-shared";
import { openBlock, createBlock, mergeProps, createVNode, toDisplayString, withModifiers, getCurrentInstance, defineComponent, ref, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, renderSlot } from "vue";
import { initVueI18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
......@@ -442,7 +442,19 @@ E.prototype = {
};
function initBridge(subscribeNamespace) {
const emitter2 = new E();
return extend(emitter2, {
return {
on(event, callback) {
return emitter2.on(event, callback);
},
once(event, callback) {
return emitter2.once(event, callback);
},
off(event, callback) {
return emitter2.off(event, callback);
},
emit(event, ...args) {
return emitter2.emit(event, ...args);
},
subscribe(event, callback, once2 = false) {
emitter2[once2 ? "once" : "on"](`${subscribeNamespace}.${event}`, callback);
},
......@@ -455,7 +467,7 @@ function initBridge(subscribeNamespace) {
}
emitter2.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
});
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
const LONGPRESS_TIMEOUT = 350;
......@@ -508,6 +520,38 @@ function initLongPress() {
window.addEventListener("touchend", clearLongPressTimer, passiveOptions$2);
window.addEventListener("touchcancel", clearLongPressTimer, passiveOptions$2);
}
function checkValue$1(value, defaultValue) {
const newValue = Number(value);
return isNaN(newValue) ? defaultValue : newValue;
}
function getWindowWidth$1() {
const screenFix = /^Apple/.test(navigator.vendor) && typeof window.orientation === "number";
const landscape = screenFix && Math.abs(window.orientation) === 90;
var screenWidth = screenFix ? Math[landscape ? "max" : "min"](screen.width, screen.height) : screen.width;
var windowWidth = Math.min(window.innerWidth, document.documentElement.clientWidth, screenWidth) || screenWidth;
return windowWidth;
}
function useRem() {
function updateRem() {
const config = __uniConfig.globalStyle || {};
const maxWidth = checkValue$1(config.rpxCalcMaxDeviceWidth, 960);
const baseWidth = checkValue$1(config.rpxCalcBaseDeviceWidth, 375);
let width = getWindowWidth$1();
width = width <= maxWidth ? width : baseWidth;
document.documentElement.style.fontSize = width / 23.4375 + "px";
}
updateRem();
document.addEventListener("DOMContentLoaded", updateRem);
window.addEventListener("load", updateRem);
window.addEventListener("resize", updateRem);
}
function initView() {
useRem();
initCustomDataset();
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress();
}
}
var attrs = ["top", "left", "right", "bottom"];
var inited$1;
var elementComputedStyle = {};
......@@ -812,6 +856,41 @@ function getPageIdByVm(vm) {
return rootProxy.$page.id;
}
}
function getPageById(id2) {
return getCurrentPages().find((page) => page.$page.id === id2);
}
function getPageVmById(id2) {
const page = getPageById(id2);
if (page) {
return page.$vm;
}
}
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
if (len) {
return pages[len - 1];
}
}
function getCurrentPageMeta() {
const page = getCurrentPage();
if (page) {
return page.$page.meta;
}
}
function getCurrentPageId() {
const meta = getCurrentPageMeta();
if (meta) {
return meta.id;
}
return -1;
}
function getCurrentPageVm() {
const page = getCurrentPage();
if (page) {
return page.$vm;
}
}
const PAGE_META_KEYS = ["navigationBar", "pullToRefresh"];
function initGlobalStyle() {
return JSON.parse(JSON.stringify(__uniConfig.globalStyle || {}));
......@@ -836,6 +915,36 @@ function normalizePullToRefreshRpx(pullToRefresh) {
}
return pullToRefresh;
}
function initPageInternalInstance(url, pageQuery, meta) {
const { id: id2, route } = meta;
return {
id: id2,
path: "/" + route,
route,
fullPath: url,
options: pageQuery,
meta
};
}
function invokeHook(vm, name, args) {
if (isString(vm)) {
args = name;
name = vm;
vm = getCurrentPageVm();
} else if (typeof vm === "number") {
const page = getCurrentPages().find((page2) => page2.$page.id === vm);
if (page) {
vm = page.$vm;
} else {
vm = getCurrentPageVm();
}
}
if (!vm) {
return;
}
const hooks = vm.$[name];
return hooks && invokeArrayFns(hooks, args);
}
function disableScrollListener(evt) {
evt.preventDefault();
}
......@@ -1217,37 +1326,7 @@ function initAppConfig$1(appConfig) {
globalProperties.$gcd = getComponentDescriptor;
}
}
function checkValue$1(value, defaultValue) {
const newValue = Number(value);
return isNaN(newValue) ? defaultValue : newValue;
}
function getWindowWidth$1() {
const screenFix = /^Apple/.test(navigator.vendor) && typeof window.orientation === "number";
const landscape = screenFix && Math.abs(window.orientation) === 90;
var screenWidth = screenFix ? Math[landscape ? "max" : "min"](screen.width, screen.height) : screen.width;
var windowWidth = Math.min(window.innerWidth, document.documentElement.clientWidth, screenWidth) || screenWidth;
return windowWidth;
}
function useRem() {
function updateRem() {
const config = __uniConfig.globalStyle || {};
const maxWidth = checkValue$1(config.rpxCalcMaxDeviceWidth, 960);
const baseWidth = checkValue$1(config.rpxCalcBaseDeviceWidth, 375);
let width = getWindowWidth$1();
width = width <= maxWidth ? width : baseWidth;
document.documentElement.style.fontSize = width / 23.4375 + "px";
}
updateRem();
document.addEventListener("DOMContentLoaded", updateRem);
window.addEventListener("load", updateRem);
window.addEventListener("resize", updateRem);
}
function initView(app) {
useRem();
initCustomDataset();
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress();
}
function initViewPlugin(app) {
initAppConfig$1(app._context.config);
}
const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("view"), {
......@@ -1255,6 +1334,43 @@ const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("view"), {
return UniServiceJSBridge.emit("api." + name, res);
}
});
function initOn() {
UniServiceJSBridge.on("onAppEnterForeground", onAppEnterForeground);
UniServiceJSBridge.on("onAppEnterBackground", onAppEnterBackground);
}
function onAppEnterForeground() {
const page = getCurrentPage();
const showOptions = {
path: "",
query: {}
};
if (page) {
showOptions.path = page.$page.route;
showOptions.query = page.$page.options;
}
invokeHook(getApp(), "onShow", showOptions);
invokeHook(page, "onShow");
}
function onAppEnterBackground() {
invokeHook(getApp(), "onHide");
invokeHook(getCurrentPage(), "onHide");
}
const SUBSCRIBE_LIFECYCLE_HOOKS = ["onPageScroll", "onReachBottom"];
function initSubscribe() {
SUBSCRIBE_LIFECYCLE_HOOKS.forEach((name) => UniServiceJSBridge.subscribe(name, createPageEvent(name)));
}
function createPageEvent(name) {
return (args, pageId) => {
const vm = getPageVmById(pageId);
if (vm) {
invokeHook(vm, name, args);
}
};
}
function initService() {
initOn();
initSubscribe();
}
function querySelector(vm, selector) {
const el = vm.$el.querySelector(selector);
return el && el.__vue__;
......@@ -1296,96 +1412,7 @@ function initAppConfig(appConfig) {
extend(globalProperties, wxInstance);
}
}
function getPageById(id2) {
return getCurrentPages().find((page) => page.$page.id === id2);
}
function getPageVmById(id2) {
const page = getPageById(id2);
if (page) {
return page.$vm;
}
}
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
if (len) {
return pages[len - 1];
}
}
function getCurrentPageMeta() {
const page = getCurrentPage();
if (page) {
return page.$page.meta;
}
}
function getCurrentPageId() {
const meta = getCurrentPageMeta();
if (meta) {
return meta.id;
}
return -1;
}
function getCurrentPageVm() {
const page = getCurrentPage();
if (page) {
return page.$vm;
}
}
function invokeHook(vm, name, args) {
if (isString(vm)) {
args = name;
name = vm;
vm = getCurrentPageVm();
} else if (typeof vm === "number") {
const page = getCurrentPages().find((page2) => page2.$page.id === vm);
if (page) {
vm = page.$vm;
} else {
vm = getCurrentPageVm();
}
}
if (!vm) {
return;
}
const hooks = vm.$[name];
return hooks && invokeArrayFns(hooks, args);
}
function initOn() {
UniServiceJSBridge.on("onAppEnterForeground", onAppEnterForeground);
UniServiceJSBridge.on("onAppEnterBackground", onAppEnterBackground);
}
function onAppEnterForeground() {
const page = getCurrentPage();
const showOptions = {
path: "",
query: {}
};
if (page) {
showOptions.path = page.$page.route;
showOptions.query = page.$page.options;
}
invokeHook(getApp(), "onShow", showOptions);
invokeHook(page, "onShow");
}
function onAppEnterBackground() {
invokeHook(getApp(), "onHide");
invokeHook(getCurrentPage(), "onHide");
}
const SUBSCRIBE_LIFECYCLE_HOOKS = ["onPageScroll", "onReachBottom"];
function initSubscribe() {
SUBSCRIBE_LIFECYCLE_HOOKS.forEach((name) => UniServiceJSBridge.subscribe(name, createPageEvent(name)));
}
function createPageEvent(name) {
return (args, pageId) => {
const vm = getPageVmById(pageId);
if (vm) {
invokeHook(vm, name, args);
}
};
}
function initService(app) {
initOn();
initSubscribe();
function initServicePlugin(app) {
initAppConfig(app._context.config);
}
function converPx(value) {
......@@ -13180,25 +13207,9 @@ function createPageState(type, __id__) {
function initPublicPage(route) {
const meta = usePageMeta();
if (!__UNI_FEATURE_PAGES__) {
const { path: path2, alias } = __uniRoutes[0];
return {
id: meta.id,
path: path2,
route: alias.substr(1),
fullPath: path2,
options: {},
meta
};
return initPageInternalInstance(__uniRoutes[0].path, {}, meta);
}
const { path } = route;
return {
id: meta.id,
path,
route: route.meta.route,
fullPath: route.meta.isEntry ? route.meta.pagePath : route.fullPath,
options: {},
meta
};
return initPageInternalInstance(route.fullPath, {}, meta);
}
function initPage(vm) {
const route = vm.$route;
......@@ -13381,8 +13392,8 @@ function initHistory() {
var index$9 = {
install(app) {
initApp$1(app);
initView(app);
initService(app);
initViewPlugin(app);
initServicePlugin(app);
if (__UNI_FEATURE_PAGES__) {
initRouter(app);
}
......@@ -13396,6 +13407,8 @@ function initApp(vm) {
appVm = vm;
appVm.$vm = vm;
appVm.globalData = appVm.$options.globalData || {};
initService();
initView();
}
function wrapperComponentSetup(comp, { init: init2, setup, before }) {
before && before(comp);
......
import { App } from 'vue'
import { initApp } from '@dcloudio/uni-vue'
import { initView, initService } from '@dcloudio/uni-core'
import { initViewPlugin, initServicePlugin } from '@dcloudio/uni-core'
import { initRouter } from './router'
export default {
install(app: App) {
initApp(app)
initView(app)
initService(app)
initViewPlugin(app)
initServicePlugin(app)
if (__UNI_FEATURE_PAGES__) {
initRouter(app)
......
import { ComponentPublicInstance } from 'vue'
import { initService, initView } from '@dcloudio/uni-core'
let appVm: ComponentPublicInstance
......@@ -10,4 +11,6 @@ export function initApp(vm: ComponentPublicInstance) {
appVm = vm
appVm.$vm = vm
appVm.globalData = appVm.$options.globalData || {}
initService()
initView()
}
......@@ -12,6 +12,7 @@ import {
disableScrollListener,
createScrollListener,
CreateScrollListenerOptions,
initPageInternalInstance,
} from '@dcloudio/uni-core'
import { ON_REACH_BOTTOM_DISTANCE } from '@dcloudio/uni-shared'
import { usePageMeta } from './provide'
......@@ -21,7 +22,7 @@ import { getStateId } from '../../helpers/dom'
const SEP = '$$'
const currentPagesMap = new Map<string, Page.PageInstance>()
const currentPagesMap = new Map<string, ComponentPublicInstance>()
function pruneCurrentPages() {
currentPagesMap.forEach((page, id) => {
......@@ -36,11 +37,11 @@ export function getCurrentPagesMap() {
}
export function getCurrentPages() {
const curPages: Page.PageInstance[] = []
const curPages: ComponentPublicInstance[] = []
const pages = currentPagesMap.values()
for (const page of pages) {
if ((page as ComponentPublicInstance).__isTabBar) {
if ((page as ComponentPublicInstance).$.__isActive) {
if (page.__isTabBar) {
if (page.$.__isActive) {
curPages.push(page)
}
} else {
......@@ -78,25 +79,9 @@ export function createPageState(type: NavigateType, __id__?: number) {
function initPublicPage(route: RouteLocationNormalizedLoaded) {
const meta = usePageMeta()
if (!__UNI_FEATURE_PAGES__) {
const { path, alias } = __uniRoutes[0]
return {
id: meta.id,
path,
route: alias!.substr(1),
fullPath: path,
options: {},
meta,
}
}
const { path } = route
return {
id: meta.id,
path: path,
route: route.meta.route,
fullPath: route.meta.isEntry ? route.meta.pagePath : route.fullPath,
options: {}, // $route.query
meta,
return initPageInternalInstance(__uniRoutes[0].path, {}, meta)
}
return initPageInternalInstance(route.fullPath, {}, meta)
}
export function initPage(vm: ComponentPublicInstance) {
......@@ -105,10 +90,7 @@ export function initPage(vm: ComponentPublicInstance) {
;(vm as any).$vm = vm
;(vm as any).$page = page
vm.__isTabBar = page.meta.isTabBar!
currentPagesMap.set(
normalizeRouteKey(page.path, page.id),
vm as unknown as Page.PageInstance
)
currentPagesMap.set(normalizeRouteKey(page.path, page.id), vm)
}
export function normalizeRouteKey(path: string, id: number) {
......@@ -185,7 +167,7 @@ function pruneRouteCache(key: string) {
}
function updateCurPageAttrs(pageMeta: UniApp.PageRouteMeta) {
const nvueDirKey = 'nvue-dir-' + __uniConfig.nvue['flex-direction']
const nvueDirKey = 'nvue-dir-' + __uniConfig.nvue!['flex-direction']
if (pageMeta.isNVue) {
document.body.setAttribute('nvue', '')
document.body.setAttribute(nvueDirKey, '')
......
export function previewImage({ urls, current }, callbackId) {
const { invokeCallbackHandler: invoke } = UniServiceJSBridge
getApp().$router.push(
{
type: 'navigateTo',
path: '/preview-image',
params: {
urls,
current
}
},
function() {
invoke(callbackId, {
errMsg: 'previewImage:ok'
})
},
function() {
invoke(callbackId, {
errMsg: 'previewImage:fail'
})
}
)
}
......@@ -217,7 +217,7 @@ function parseUrl(url) {
const [path, querystring] = url.split('?', 2);
return {
path,
query: parseQuery(querystring),
query: parseQuery(querystring || ''),
};
}
......
......@@ -213,7 +213,7 @@ function parseUrl(url) {
const [path, querystring] = url.split('?', 2);
return {
path,
query: parseQuery(querystring),
query: parseQuery(querystring || ''),
};
}
......
......@@ -4,6 +4,6 @@ export function parseUrl(url: string) {
const [path, querystring] = url.split('?', 2)
return {
path,
query: parseQuery(querystring),
query: parseQuery(querystring || ''),
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册