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

build uni-app-plus-nvue

上级 70c212c3
...@@ -817,6 +817,27 @@ var serviceContext = (function () { ...@@ -817,6 +817,27 @@ var serviceContext = (function () {
} }
const callbacks = {}; const callbacks = {};
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE';
// 简单处理 view 层与 service 层的通知系统
/**
* 消费 view 层通知
*/
function consumePlusMessage (type, args) {
// 处理 web-view 组件发送的通知
if (type === WEB_INVOKE_APPSERVICE) {
publish(WEB_INVOKE_APPSERVICE, args.data, args.webviewIds);
return true
}
const callback = callbacks[type];
if (callback) {
callback(args);
if (!callback.keepAlive) {
delete callbacks[type];
}
return true
}
return false
}
/** /**
* 注册 view 层通知 service 层事件处理 * 注册 view 层通知 service 层事件处理
*/ */
...@@ -1368,6 +1389,16 @@ var serviceContext = (function () { ...@@ -1368,6 +1389,16 @@ var serviceContext = (function () {
publish('onKeyboardHeightChange', { publish('onKeyboardHeightChange', {
height: event.height height: event.height
}); });
});
plus.globalEvent.addEventListener('plusMessage', function (e) {
if (process.env.NODE_ENV !== 'production') {
console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data));
}
if (e.data && e.data.type) {
const type = e.data.type;
consumePlusMessage(type, e.data.args || {});
}
}); });
} }
...@@ -4717,12 +4748,12 @@ var serviceContext = (function () { ...@@ -4717,12 +4748,12 @@ var serviceContext = (function () {
barcode.scan(file, (type, code) => { barcode.scan(file, (type, code) => {
if (isDark) { if (isDark) {
plus.navigator.setStatusBarStyle('isDark'); plus.navigator.setStatusBarStyle('isDark');
} }
webview.close('auto'); result = {
result = { type,
type, code
code
}; };
webview.close('auto');
}, () => { }, () => {
plus.nativeUI.toast('识别失败'); plus.nativeUI.toast('识别失败');
}, filters); }, filters);
...@@ -4763,7 +4794,7 @@ var serviceContext = (function () { ...@@ -4763,7 +4794,7 @@ var serviceContext = (function () {
}); });
}); });
webview.addEventListener('close', () => { webview.addEventListener('close', () => {
if (result && 'code' in result) { if (result) {
invoke(callbackId, { invoke(callbackId, {
result: result.code, result: result.code,
scanType: SCAN_MAPS[result.type] || '', scanType: SCAN_MAPS[result.type] || '',
...@@ -4771,11 +4802,12 @@ var serviceContext = (function () { ...@@ -4771,11 +4802,12 @@ var serviceContext = (function () {
path: '', path: '',
errMsg: 'scanCode:ok' errMsg: 'scanCode:ok'
}); });
} else { } else {
invoke(callbackId, { invoke(callbackId, {
errMsg: 'scanCode:fail cancel' errMsg: 'scanCode:fail cancel'
}); });
} }
consumePlusMessage(MESSAGE_TYPE);
}); });
if (isDark) { // 状态栏前景色 if (isDark) { // 状态栏前景色
plus.navigator.setStatusBarStyle('light'); plus.navigator.setStatusBarStyle('light');
...@@ -4790,15 +4822,10 @@ var serviceContext = (function () { ...@@ -4790,15 +4822,10 @@ var serviceContext = (function () {
} }
}); });
} }
// fixed by hxy 注册扫码事件
registerPlusMessage(MESSAGE_TYPE, function (res) { registerPlusMessage(MESSAGE_TYPE, function (res) {
if (res && !res.errMsg) { if (res && 'code' in res) {
result = res; result = res;
} else {
const errMsg = res && res.errMsg ? ' ' + res.errMsg : '';
result = {
errMsg: 'scanCode:fail' + errMsg
};
} }
}, false); }, false);
} }
...@@ -4815,10 +4842,19 @@ var serviceContext = (function () { ...@@ -4815,10 +4842,19 @@ var serviceContext = (function () {
const screenHeight = plus.screen.resolutionHeight; const screenHeight = plus.screen.resolutionHeight;
// 横屏时 iOS 获取的状态栏高度错误,进行纠正 // 横屏时 iOS 获取的状态栏高度错误,进行纠正
var landscape = Math.abs(plus.navigator.getOrientation()) === 90; var landscape = Math.abs(plus.navigator.getOrientation()) === 90;
var statusBarHeight = plus.navigator.getStatusbarHeight(); var statusBarHeight = Math.round(plus.navigator.getStatusbarHeight());
if (ios && landscape) { if (ios && landscape) {
statusBarHeight = Math.min(20, statusBarHeight); statusBarHeight = Math.min(20, statusBarHeight);
} }
var safeAreaInsets;
function getSafeAreaInsets () {
return {
left: 0,
right: 0,
top: titleNView ? 0 : statusBarHeight,
bottom: 0
}
}
// 判断是否存在 titleNView // 判断是否存在 titleNView
var titleNView; var titleNView;
var webview = getLastWebview(); var webview = getLastWebview();
...@@ -4828,7 +4864,22 @@ var serviceContext = (function () { ...@@ -4828,7 +4864,22 @@ var serviceContext = (function () {
titleNView = style && style.titleNView; titleNView = style && style.titleNView;
titleNView = titleNView && titleNView.type === 'default'; titleNView = titleNView && titleNView.type === 'default';
} }
} safeAreaInsets = ios ? webview.getSafeAreaInsets() : getSafeAreaInsets();
} else {
safeAreaInsets = ios ? plus.navigator.getSafeAreaInsets() : getSafeAreaInsets();
}
var windowHeight = Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
: 0) - (isTabBarPage() && tabBar.visible ? TABBAR_HEIGHT : 0), screenHeight);
var windowWidth = screenWidth;
var safeArea = {
left: safeAreaInsets.left,
right: windowWidth - safeAreaInsets.right,
top: safeAreaInsets.top,
bottom: windowHeight - safeAreaInsets.bottom,
width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom
};
return { return {
errMsg: 'getSystemInfo:ok', errMsg: 'getSystemInfo:ok',
brand: '', brand: '',
...@@ -4836,11 +4887,8 @@ var serviceContext = (function () { ...@@ -4836,11 +4887,8 @@ var serviceContext = (function () {
pixelRatio: plus.screen.scale, pixelRatio: plus.screen.scale,
screenWidth, screenWidth,
screenHeight, screenHeight,
// 安卓端 webview 宽度有时比屏幕多 1px,相比取最小值 windowWidth,
// TODO screenWidth,screenHeight windowHeight,
windowWidth: screenWidth,
windowHeight: Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
: 0) - (isTabBarPage() && tabBar.visible ? TABBAR_HEIGHT : 0), screenHeight),
statusBarHeight, statusBarHeight,
language: plus.os.language, language: plus.os.language,
system: plus.os.version, system: plus.os.version,
...@@ -4849,7 +4897,8 @@ var serviceContext = (function () { ...@@ -4849,7 +4897,8 @@ var serviceContext = (function () {
platform, platform,
SDKVersion: '', SDKVersion: '',
windowTop: 0, windowTop: 0,
windowBottom: 0 windowBottom: 0,
safeArea
} }
} }
...@@ -5056,7 +5105,9 @@ var serviceContext = (function () { ...@@ -5056,7 +5105,9 @@ var serviceContext = (function () {
}); });
} }
const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html'; const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html';
const MESSAGE_TYPE$1 = 'chooseLocation';
function chooseLocation$1 (params, callbackId) { function chooseLocation$1 (params, callbackId) {
const statusBarStyle = plus.navigator.getStatusBarStyle(); const statusBarStyle = plus.navigator.getStatusBarStyle();
...@@ -5098,27 +5149,39 @@ var serviceContext = (function () { ...@@ -5098,27 +5149,39 @@ var serviceContext = (function () {
plus.navigator.setStatusBarStyle('light'); plus.navigator.setStatusBarStyle('light');
} }
}); });
} }
let index = 0;
webview.show('slide-in-bottom', ANI_DURATION, () => { let onShow = function () {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`); index++;
}); if (index === 2) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`);
}
};
webview.addEventListener('loaded', onShow);
webview.show('slide-in-bottom', ANI_DURATION, onShow);
let result;
webview.addEventListener('close', () => {
if (result) {
invoke(callbackId, {
name: result.poiname,
address: result.poiaddress,
latitude: result.latlng.lat,
longitude: result.latlng.lng,
errMsg: 'chooseLocation:ok'
});
} else {
consumePlusMessage(MESSAGE_TYPE$1);
invoke(callbackId, {
errMsg: 'chooseLocation:fail cancel'
});
}
});
// fixed by hxy registerPlusMessage(MESSAGE_TYPE$1, function (res) {
registerPlusMessage('chooseLocation', function (res) { if (res && 'latlng' in res) {
if (res && !res.errMsg) { result = res;
invoke(callbackId, {
name: res.poiname,
address: res.poiaddress,
latitude: res.latlng.lat,
longitude: res.latlng.lng,
errMsg: 'chooseLocation:ok'
});
} else {
const errMsg = res && res.errMsg ? ' ' + res.errMsg : '';
invoke(callbackId, {
errMsg: 'chooseLocation:fail' + errMsg
});
} }
}, false); }, false);
} }
......
...@@ -287,21 +287,21 @@ const protocols = { // 需要做转换的 API 列表 ...@@ -287,21 +287,21 @@ const protocols = { // 需要做转换的 API 列表
}, },
scanCode: { scanCode: {
name: 'scan', name: 'scan',
args(fromArgs) { args (fromArgs) {
if (fromArgs.scanType === 'qrCode') { if (fromArgs.scanType === 'qrCode') {
fromArgs.type = 'qr' fromArgs.type = 'qr'
return { return {
onlyFromCamera: 'hideAlbum', onlyFromCamera: 'hideAlbum'
} }
} else if(fromArgs.scanType === 'barCode'){ } else if (fromArgs.scanType === 'barCode') {
fromArgs.type = 'bar' fromArgs.type = 'bar'
return { return {
onlyFromCamera: 'hideAlbum', onlyFromCamera: 'hideAlbum'
} }
} else { } else {
return { return {
scanType: false, scanType: false,
onlyFromCamera: 'hideAlbum', onlyFromCamera: 'hideAlbum'
} }
} }
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册