提交 a8ffe9de 编写于 作者: Q qiang

Merge branch 'dev' of github.com:dcloudio/uni-app into dev

......@@ -8058,28 +8058,39 @@ var serviceContext = (function () {
let todoNavigator = false;
function setTodoNavigator (path, callback, msg) {
todoNavigator = {
path: path,
nvue: __uniRoutes.find(route => route.path === path).meta.isNVue,
navigate: callback
};
if (process.env.NODE_ENV !== 'production') {
console.log(`todoNavigator:${todoNavigator.path} ${msg}`);
}
}
function navigate (path, callback, isAppLaunch) {
{
if (isAppLaunch && __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose && (!__uniConfig.splashscreen.alwaysShowBeforeRender)) {
plus.navigator.closeSplashscreen();
{
if (isAppLaunch && __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose && (!__uniConfig.splashscreen.alwaysShowBeforeRender)) {
plus.navigator.closeSplashscreen();
}
if (!isAppLaunch && todoNavigator) {
return console.error(`已存在待跳转页面${todoNavigator.path},请不要连续多次跳转页面${path}`)
}
if (__uniConfig.renderer === 'native') { // 纯原生无需wait逻辑
// 如果是首页还未初始化,需要等一等,其他无需等待
if (getCurrentPages().length === 0) {
return setTodoNavigator(path, callback, 'waitForReady')
}
return callback()
}
// 未创建 preloadWebview 或 preloadWebview 已被使用
const waitPreloadWebview = !preloadWebview || (preloadWebview && preloadWebview.__uniapp_route);
// 已创建未 loaded
const waitPreloadWebviewReady = preloadWebview && !preloadWebview.loaded;
if (waitPreloadWebview || waitPreloadWebviewReady) {
todoNavigator = {
path: path,
nvue: __uniRoutes.find(route => route.path === path).meta.isNVue,
navigate: callback
};
if (process.env.NODE_ENV !== 'production') {
console.log(`todoNavigator:${todoNavigator.path} ${waitPreloadWebview ? 'waitForCreate' : 'waitForReady'}`);
}
setTodoNavigator(path, callback, waitPreloadWebview ? 'waitForCreate' : 'waitForReady');
} else {
callback();
}
......@@ -8105,6 +8116,15 @@ var serviceContext = (function () {
function navigateFinish () {
{
if (__uniConfig.renderer === 'native') {
if (!todoNavigator) {
return
}
if (todoNavigator.nvue) {
return todoNavigate()
}
return
}
// 创建预加载
const preloadWebview = createPreloadWebview();
if (process.env.NODE_ENV !== 'production') {
......@@ -8227,7 +8247,7 @@ var serviceContext = (function () {
}
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] registerPage`, path, webview.id);
console.log(`[uni-app] registerPage(${path},${webview.id})`);
}
initWebview(webview, routeOptions, path, query);
......@@ -12467,14 +12487,20 @@ var serviceContext = (function () {
subscribeHandler(data.type, data.data, data.pageId);
});
subscribe(WEBVIEW_READY, onWebviewReady);
if (__uniConfig.renderer !== 'native') {
subscribe(WEBVIEW_READY, onWebviewReady);
subscribe(VD_SYNC, onVdSync);
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback);
const entryPagePath = '/' + __uniConfig.entryPagePath;
const routeOptions = __uniRoutes.find(route => route.path === entryPagePath);
if (!routeOptions.meta.isNVue) { // 首页是 vue
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1]);
const entryPagePath = '/' + __uniConfig.entryPagePath;
const routeOptions = __uniRoutes.find(route => route.path === entryPagePath);
if (!routeOptions.meta.isNVue) { // 首页是 vue
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1]);
}
}
// 应该使用subscribe,兼容老版本先用 on api 吧
on('api.' + WEB_INVOKE_APPSERVICE$1, function (data, webviewIds) {
emit('onWebInvokeAppService', data, webviewIds);
......@@ -12482,10 +12508,7 @@ var serviceContext = (function () {
subscribe('onWxsInvokeCallMethod', onWxsInvokeCallMethod);
subscribe(VD_SYNC, onVdSync);
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback);
subscribe(INVOKE_API, onInvokeApi);
subscribe(INVOKE_API, onInvokeApi);
subscribe(WEBVIEW_INSERTED, onWebviewInserted);
subscribe(WEBVIEW_REMOVED, onWebviewRemoved);
......
......@@ -150,7 +150,7 @@ function isValidPage (page, root = '') {
process.UNI_NVUE_ENTRY[pagePath] = getNVueMainJsPath(pagePath)
if (process.env.UNI_USING_V3) { // 不移除
if (process.env.UNI_USING_V3 || process.env.UNI_USING_V3_NATIVE) { // 不移除
page.nvue = true
return true
} else {
......@@ -214,7 +214,7 @@ function parseEntry (pagesJson) {
process.UNI_NVUE_ENTRY = {}
if (process.env.UNI_USING_NATIVE) {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
process.UNI_NVUE_ENTRY['app-config'] = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
process.UNI_NVUE_ENTRY['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
}
......
......@@ -160,7 +160,11 @@ const PLATFORMS = {
const files = ['hybrid/html']
let wxcomponents = []
if (!process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3) {
if (
!process.env.UNI_USING_NATIVE &&
!process.env.UNI_USING_V3 &&
!process.env.UNI_USING_V3_NATIVE
) {
wxcomponents = getCopyOptions(['wxcomponents'], {
to: path.resolve(process.env.UNI_OUTPUT_TMP_DIR, 'wxcomponents')
})
......@@ -535,9 +539,6 @@ module.exports = {
if (process.env.UNI_PLATFORM === 'h5' && vueOptions && vueOptions.runtimeCompiler) {
return '@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.esm.js'
}
if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V3) {
return '@dcloudio/uni-app-plus/dist/service.runtime.esm.js'
}
if (process.env.UNI_USING_COMPONENTS) {
return uniRuntime
}
......
......@@ -45,14 +45,18 @@ const provide = {
'uniCloud': [uniCloudPath, 'default']
}
if (process.env.UNI_USING_V3 || process.env.UNI_USING_NATIVE) {
if (
process.env.UNI_USING_V3 ||
process.env.UNI_USING_NATIVE ||
process.env.UNI_USING_V3_NATIVE
) {
provide['uni.getCurrentSubNVue'] = [path.resolve(__dirname,
'../packages/uni-app-plus-nvue/dist/get-current-sub-nvue.js'), 'default']
provide['uni.requireNativePlugin'] = [path.resolve(__dirname,
'../packages/uni-app-plus-nvue/dist/require-native-plugin.js'), 'default']
}
if (!process.env.UNI_USING_V3) {
if (!process.env.UNI_USING_V3 && !process.env.UNI_USING_V3_NATIVE) {
if (!process.env.UNI_USING_NATIVE) {
provide['uni'] = [path.resolve(__dirname, uniPath), 'default']
}
......@@ -171,7 +175,7 @@ rules.unshift({
}]
})
if (process.env.UNI_USING_NATIVE) {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
plugins.push(new WebpackUniMPPlugin())
const array = [{
from: path.resolve(process.env.UNI_INPUT_DIR, 'static'),
......@@ -181,21 +185,6 @@ if (process.env.UNI_USING_NATIVE) {
array.push({
from: path.resolve(getTemplatePath(), 'common'),
to: process.env.UNI_OUTPUT_DIR
}, {
from: path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/common'
),
to: process.env.UNI_OUTPUT_DIR,
ignore: [
'*.js',
'*.json',
'__uniapppicker.html',
'__uniappview.html',
'__uniappmarker@3x.png',
'__uniappopenlocation.html',
'__uniapppicker.html'
]
})
} else {
let nativeTemplatePath = path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'weapp-tools/template/v8-native')
......
......@@ -5,7 +5,7 @@ const {
class WebpackAppPlusNVuePlugin {
apply(compiler) {
let isFirst = !process.env.UNI_USING_NATIVE
let isFirst = !process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3_NATIVE
const chunkVersions = {}
const changedFiles = []
......
......@@ -105,7 +105,7 @@ class WebpackAppPlusPlugin {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
if (process.env.UNI_USING_NATIVE) {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
return resolve()
}
......
......@@ -124,11 +124,15 @@ async function build (args, api, options) {
await fs.emptyDir(targetDir)
}
if (process.env.UNI_USING_NATIVE) {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
webpackConfigs.length = 0
}
if (process.env.UNI_USING_NATIVE || (process.UNI_NVUE_ENTRY && Object.keys(process.UNI_NVUE_ENTRY).length)) {
if (
process.env.UNI_USING_NATIVE ||
process.env.UNI_USING_V3_NATIVE ||
(process.UNI_NVUE_ENTRY && Object.keys(process.UNI_NVUE_ENTRY).length)
) {
webpackConfigs.push(require('@dcloudio/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js')(process.UNI_NVUE_ENTRY))
}
......
......@@ -172,19 +172,20 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
if (platformOptions.nvueCompiler === 'weex') {
isNVueCompiler = false
}
if (platformOptions.renderer !== 'native' && // 非 native
(
platformOptions.compilerVersion === '3' ||
platformOptions.compilerVersion === 3
)
if (
platformOptions.compilerVersion === '3' ||
platformOptions.compilerVersion === 3
) {
delete process.env.UNI_USING_CACHE
process.env.UNI_USING_V3 = true
platformOptions.usingComponents = true
if (platformOptions.renderer === 'native') {
process.env.UNI_USING_V3_NATIVE = true
} else {
process.env.UNI_USING_V3 = true
platformOptions.usingComponents = true
}
process.env.UNI_OUTPUT_TMP_DIR = ''
isNVueCompiler = true // v3 目前仅支持 uni-app 模式
}
if (platformOptions.renderer === 'native') {
} else if (platformOptions.renderer === 'native') {
// 纯原生目前不提供 cache
delete process.env.UNI_USING_CACHE
process.env.UNI_USING_NATIVE = true
......@@ -267,8 +268,8 @@ const warningMsg =
const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
let hasNVue = false
// 输出编译器版本等信息
if (process.env.UNI_USING_NATIVE) {
console.log('当前nvue编译模式:' + (isNVueCompiler ? 'uni-app' : 'weex') +
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
console.log('当前nvue编译模式' + (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + '' + (isNVueCompiler ? 'uni-app' : 'weex') +
' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074')
} else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp') {
try {
......@@ -362,7 +363,8 @@ if (
process.env.UNI_USING_CACHE &&
process.env.UNI_PLATFORM !== 'h5' &&
!process.env.UNI_USING_V3 &&
!process.env.UNI_USING_NATIVE
!process.env.UNI_USING_NATIVE &&
!process.env.UNI_USING_V3_NATIVE
) { // 使用 cache, 拷贝 cache 的 json
const cacheJsonDir = path.resolve(
process.env.UNI_CLI_CONTEXT,
......
......@@ -67,7 +67,7 @@ function addSubPackagesRequire (compilation) {
class WebpackUniMPPlugin {
apply (compiler) {
if (!process.env.UNI_USING_NATIVE) {
if (!process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3_NATIVE) {
compiler.hooks.emit.tapPromise('webpack-uni-mp-emit', compilation => {
return new Promise((resolve, reject) => {
addSubPackagesRequire(compilation)
......
......@@ -106,11 +106,11 @@ module.exports = function (content) {
})
return appConfigContent
}
if (process.env.UNI_USING_NATIVE) {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
let appConfigContent = ''
jsonFiles.forEach(jsonFile => {
if (jsonFile) {
if (jsonFile.name === 'app-config.js') {
if (jsonFile.name === 'app-config.js' || jsonFile.name === 'define-pages.js') {
appConfigContent = jsonFile.content
} else {
this.emitFile(jsonFile.name, jsonFile.content)
......
......@@ -24,20 +24,21 @@ function parseRoutes (config) {
__uniRoutes.push(route)
})
return __uniRoutes
return __uniRoutes
}
module.exports = function definePages (appJson) {
module.exports = function definePages (appJson) {
const __uniRoutes = parseRoutes(appJson)
delete appJson.page
delete appJson.usingComponents
delete appJson.nvueCompiler
delete appJson.renderer
// 保留renderer
// delete appJson.renderer
return {
name: 'app-config-service.js',
content: `
var isReady=false;var onReadyCallbacks=[];
var isReady=false;var onReadyCallbacks=[];
var __uniConfig = ${JSON.stringify(appJson, null)};
var __uniRoutes = ${JSON.stringify(__uniRoutes)};
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
......
......@@ -55,6 +55,41 @@ function normalizeNetworkTimeout (appJson) {
}
}
function updateFileFlag (appJson) {
// 已经不再根据文件识别,理论可废弃此处的逻辑
if (
process.env.UNI_USING_V3 ||
process.env.UNI_USING_V3_NATIVE
) {
return
}
const nvueCompilerFilePath = path.resolve(process.env.UNI_OUTPUT_DIR, '__uniappnvuecompiler.js')
const nvueCompilerExists = fs.existsSync(nvueCompilerFilePath)
if (appJson.nvueCompiler === 'uni-app') {
if (!nvueCompilerExists) {
fsExtra.outputFile(nvueCompilerFilePath, '')
}
} else {
if (nvueCompilerExists) {
fs.unlinkSync(nvueCompilerFilePath)
}
}
const rendererFilePath = path.resolve(process.env.UNI_OUTPUT_DIR, '__uniapprenderer.js')
const rendererExists = fs.existsSync(rendererFilePath)
if (appJson.renderer === 'native') {
if (!rendererExists) {
fsExtra.outputFile(rendererFilePath, '')
}
} else {
if (rendererExists) {
fs.unlinkSync(rendererFilePath)
}
}
}
module.exports = function (pagesJson, userManifestJson) {
const {
app
......@@ -239,31 +274,7 @@ module.exports = function (pagesJson, userManifestJson) {
appJson.renderer = 'auto'
}
const nvueCompilerFilePath = path.resolve(process.env.UNI_OUTPUT_DIR, '__uniappnvuecompiler.js')
const nvueCompilerExists = fs.existsSync(nvueCompilerFilePath)
if (appJson.nvueCompiler === 'uni-app') {
if (!nvueCompilerExists) {
fsExtra.outputFile(nvueCompilerFilePath, '')
}
} else {
if (nvueCompilerExists) {
fs.unlinkSync(nvueCompilerFilePath)
}
}
const rendererFilePath = path.resolve(process.env.UNI_OUTPUT_DIR, '__uniapprenderer.js')
const rendererExists = fs.existsSync(rendererFilePath)
if (appJson.renderer === 'native') {
if (!rendererExists) {
fsExtra.outputFile(rendererFilePath, '')
}
} else {
if (rendererExists) {
fs.unlinkSync(rendererFilePath)
}
}
updateFileFlag(appJson)
appJson.splashscreen = {
alwaysShowBeforeRender: false, // 是否启用白屏检测 关闭 splash
......@@ -321,7 +332,7 @@ module.exports = function (pagesJson, userManifestJson) {
// 检查原生混淆选项
const confusion = manifestJson.plus.confusion
if (confusion && confusion.resources) {
const resources = {}
const resources = {}
const nvuePages = (appJson.nvue && appJson.nvue.pages) || {}
for (const key in confusion.resources) {
if (path.extname(key) === '.js') { // 支持 js 混淆,过滤掉
......@@ -356,7 +367,10 @@ module.exports = function (pagesJson, userManifestJson) {
const uniApp = require('../../../package.json')['uni-app']
manifestJson.plus['uni-app'] = uniApp
// 控制页类型
const control = process.env.UNI_USING_V3 ? 'uni-v3' : (process.env.UNI_USING_V8 ? 'v8' : 'webview')
const control = (process.env.UNI_USING_V3 || process.env.UNI_USING_V3_NATIVE)
? 'uni-v3'
: (process.env.UNI_USING_V8 ? 'v8' : 'webview')
manifestJson.plus['uni-app'].control = control
manifestJson.plus['uni-app'].nvueCompiler = appJson.nvueCompiler
manifestJson.plus['uni-app'].renderer = appJson.renderer
......@@ -480,7 +494,7 @@ module.exports = function (pagesJson, userManifestJson) {
return [manifest, parseConfig(appJson)]
}
if (process.env.UNI_USING_V3) {
if (process.env.UNI_USING_V3 || process.env.UNI_USING_V3_NATIVE) {
return require('./index.v3')(appJson, manifestJson, {
manifest,
pagesJson,
......
......@@ -59,7 +59,17 @@ function getLocation (base = '/') {
export default {
install (Vue, {
routes
} = {}) {
} = {}) {
if (
__PLATFORM__ === 'h5' &&
Vue.config.devtools &&
typeof window !== 'undefined' &&
window.navigator.userAgent.toLowerCase().indexOf('hbuilderx') !== -1
) {
// HBuilderX 内置浏览器禁用 devtools 提示
Vue.config.devtools = false
}
initPolyfill(Vue)
lifecycleMixin(Vue)
......
import {
invoke,
publish,
arrayBufferToBase64,
base64ToArrayBuffer
publish
} from '../../bridge'
/**
......@@ -53,16 +51,6 @@ function bluetoothOn (method, beforeSuccess) {
return true
}
function checkDevices (data) {
data.devices = data.devices.map(device => {
var advertisData = device.advertisData
if (advertisData && typeof advertisData !== 'string') {
device.advertisData = arrayBufferToBase64(advertisData)
}
return device
})
}
var onBluetoothAdapterStateChange
var onBluetoothDeviceFound
var onBLEConnectionStateChange
......@@ -83,7 +71,7 @@ export function getBluetoothAdapterState (data, callbackId) {
}
export function startBluetoothDevicesDiscovery (data, callbackId) {
onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound', checkDevices)
onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound')
bluetoothExec('startBluetoothDevicesDiscovery', callbackId, data)
}
......@@ -92,7 +80,7 @@ export function stopBluetoothDevicesDiscovery (data, callbackId) {
}
export function getBluetoothDevices (data, callbackId) {
bluetoothExec('getBluetoothDevices', callbackId, {}, checkDevices)
bluetoothExec('getBluetoothDevices', callbackId, {})
}
export function getConnectedBluetoothDevices (data, callbackId) {
......@@ -118,18 +106,12 @@ export function getBLEDeviceCharacteristics (data, callbackId) {
}
export function notifyBLECharacteristicValueChange (data, callbackId) {
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange',
data => {
data.value = arrayBufferToBase64(data.value)
})
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange')
bluetoothExec('notifyBLECharacteristicValueChange', callbackId, data)
}
export function notifyBLECharacteristicValueChanged (data, callbackId) {
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange',
data => {
data.value = arrayBufferToBase64(data.value)
})
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange')
bluetoothExec('notifyBLECharacteristicValueChanged', callbackId, data)
}
......@@ -139,8 +121,5 @@ export function readBLECharacteristicValue (data, callbackId) {
}
export function writeBLECharacteristicValue (data, callbackId) {
if (typeof data.value === 'string') {
data.value = base64ToArrayBuffer(data.value)
}
bluetoothExec('writeBLECharacteristicValue', callbackId, data)
}
......@@ -6,28 +6,39 @@ import {
let todoNavigator = false
function setTodoNavigator (path, callback, msg) {
todoNavigator = {
path: path,
nvue: __uniRoutes.find(route => route.path === path).meta.isNVue,
navigate: callback
}
if (process.env.NODE_ENV !== 'production') {
console.log(`todoNavigator:${todoNavigator.path} ${msg}`)
}
}
export function navigate (path, callback, isAppLaunch) {
if (__PLATFORM__ === 'app-plus') {
if (isAppLaunch && __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose && (!__uniConfig.splashscreen.alwaysShowBeforeRender)) {
plus.navigator.closeSplashscreen()
if (__PLATFORM__ === 'app-plus') {
if (isAppLaunch && __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose && (!__uniConfig.splashscreen.alwaysShowBeforeRender)) {
plus.navigator.closeSplashscreen()
}
if (!isAppLaunch && todoNavigator) {
return console.error(`已存在待跳转页面${todoNavigator.path},请不要连续多次跳转页面${path}`)
}
if (__uniConfig.renderer === 'native') { // 纯原生无需wait逻辑
// 如果是首页还未初始化,需要等一等,其他无需等待
if (getCurrentPages().length === 0) {
return setTodoNavigator(path, callback, 'waitForReady')
}
return callback()
}
// 未创建 preloadWebview 或 preloadWebview 已被使用
const waitPreloadWebview = !preloadWebview || (preloadWebview && preloadWebview.__uniapp_route)
// 已创建未 loaded
const waitPreloadWebviewReady = preloadWebview && !preloadWebview.loaded
if (waitPreloadWebview || waitPreloadWebviewReady) {
todoNavigator = {
path: path,
nvue: __uniRoutes.find(route => route.path === path).meta.isNVue,
navigate: callback
}
if (process.env.NODE_ENV !== 'production') {
console.log(`todoNavigator:${todoNavigator.path} ${waitPreloadWebview ? 'waitForCreate' : 'waitForReady'}`)
}
setTodoNavigator(path, callback, waitPreloadWebview ? 'waitForCreate' : 'waitForReady')
} else {
callback()
}
......@@ -53,6 +64,15 @@ function todoNavigate () {
export function navigateFinish () {
if (__PLATFORM__ === 'app-plus') {
if (__uniConfig.renderer === 'native') {
if (!todoNavigator) {
return
}
if (todoNavigator.nvue) {
return todoNavigate()
}
return
}
// 创建预加载
const preloadWebview = createPreloadWebview()
if (process.env.NODE_ENV !== 'production') {
......
......@@ -61,7 +61,7 @@ export function registerPage ({
}
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] registerPage`, path, webview.id)
console.log(`[uni-app] registerPage(${path},${webview.id})`)
}
initWebview(webview, routeOptions, path, query)
......
......@@ -5,8 +5,8 @@ import {
VD_SYNC_CALLBACK,
INVOKE_API,
WEBVIEW_READY,
WEB_INVOKE_APPSERVICE,
WEBVIEW_INSERTED,
WEB_INVOKE_APPSERVICE,
WEBVIEW_INSERTED,
WEBVIEW_REMOVED
} from '../../../constants'
......@@ -21,11 +21,11 @@ import onVdSyncCallback from './on-vd-sync-callback'
import onInvokeApi from './on-invoke-api'
import onWxsInvokeCallMethod from './on-wxs-invoke-call-method'
import {
onWebviewInserted,
onWebviewRemoved
} from './on-webview-lifecycle'
import {
onWebviewInserted,
onWebviewRemoved
} from './on-webview-lifecycle'
export function initSubscribeHandlers () {
const {
......@@ -45,14 +45,20 @@ export function initSubscribeHandlers () {
subscribeHandler(data.type, data.data, data.pageId)
})
subscribe(WEBVIEW_READY, onWebviewReady)
if (__uniConfig.renderer !== 'native') {
subscribe(WEBVIEW_READY, onWebviewReady)
subscribe(VD_SYNC, onVdSync)
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback)
const entryPagePath = '/' + __uniConfig.entryPagePath
const routeOptions = __uniRoutes.find(route => route.path === entryPagePath)
if (!routeOptions.meta.isNVue) { // 首页是 vue
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1])
const entryPagePath = '/' + __uniConfig.entryPagePath
const routeOptions = __uniRoutes.find(route => route.path === entryPagePath)
if (!routeOptions.meta.isNVue) { // 首页是 vue
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1])
}
}
// 应该使用subscribe,兼容老版本先用 on api 吧
on('api.' + WEB_INVOKE_APPSERVICE, function (data, webviewIds) {
emit('onWebInvokeAppService', data, webviewIds)
......@@ -60,10 +66,7 @@ export function initSubscribeHandlers () {
subscribe('onWxsInvokeCallMethod', onWxsInvokeCallMethod)
subscribe(VD_SYNC, onVdSync)
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback)
subscribe(INVOKE_API, onInvokeApi)
subscribe(INVOKE_API, onInvokeApi)
subscribe(WEBVIEW_INSERTED, onWebviewInserted)
subscribe(WEBVIEW_REMOVED, onWebviewRemoved)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册