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

nvue service

上级 f7ce3bf8
......@@ -34,7 +34,7 @@ function getApp () {
return appCtx
}
function initGlobalListeners ({
function initGlobalListeners ({
uni,
plus,
UniServiceJSBridge
......@@ -42,7 +42,9 @@ function initGlobalListeners ({
const emit = UniServiceJSBridge.emit;
plus.key.addEventListener('backbutton', () => {
uni.navigateBack();
uni.navigateBack({
from: 'backbutton'
});
});
plus.globalEvent.addEventListener('pause', () => {
......@@ -64,7 +66,7 @@ function initGlobalListeners ({
function initAppLaunch (appVm, {
__uniConfig
}) {
}) {
const args = {
path: __uniConfig.entryPagePath,
query: {},
......@@ -340,7 +342,8 @@ function getCurrentPages () {
*
*
*
*/
*/
/**
* 首页需要主动registerPage,二级页面路由跳转时registerPage
*/
......@@ -360,7 +363,10 @@ function registerPage ({
initWebview(webview, instanceContext, webview.id === '1' && routeOptions);
const route = path.slice(1);
const route = path.slice(1);
webview.__uniapp_route = route;
pages.push({
route,
$getAppWebview () {
......
......@@ -174,128 +174,23 @@ function promisify (name, api) {
}
}
const SUCCESS = 'success';
const FAIL = 'fail';
const COMPLETE = 'complete';
const CALLBACKS = [SUCCESS, FAIL, COMPLETE];
const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service';
function noop () {
}
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethodWithoutArgs (vm, method, args, extras) {
if (!vm) {
return
}
if (typeof args === 'undefined') {
return vm[method]()
}
const [, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method]()
}
return vm[method](normalizeCallback(method, callbacks))
}
/**
* 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethod (vm, method, args, extras) {
if (!vm) {
return
}
const [pureArgs, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method](pureArgs)
}
return vm[method](pureArgs, normalizeCallback(method, callbacks))
}
function findRefById (id, vm) {
return findRefByVNode(id, vm._vnode)
}
function findRefByVNode (id, vnode) {
if (!id || !vnode) {
return
}
if (vnode.data &&
vnode.data.ref &&
vnode.data.attrs &&
vnode.data.attrs.id === id) {
return vnode.data.ref
}
const children = vnode.children;
if (!children) {
return
}
for (let i = 0, len = children.length; i < len; i++) {
const ref = findRefByVNode(id, children[i]);
if (ref) {
return ref
function initPostMessage (nvue) {
const plus = nvue.requireModule('plus');
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
}
}
}
function normalizeArgs (args = {}, extras) {
const callbacks = Object.create(null);
const iterator = function iterator (name) {
const callback = args[name];
if (isFn(callback)) {
callbacks[name] = callback;
delete args[name];
}
};
CALLBACKS.forEach(iterator);
extras && extras.forEach(iterator);
return [args, callbacks]
}
function normalizeCallback (method, callbacks) {
return function weexCallback (ret) {
const type = ret.type;
delete ret.type;
const callback = callbacks[type];
if (type === SUCCESS) {
ret.errMsg = `${method}:ok`;
} else if (type === FAIL) {
ret.errMsg = method + ':fail' + (ret.msg ? (' ' + ret.msg) : '');
}
delete ret.code;
delete ret.msg;
isFn(callback) && callback(ret);
if (type === SUCCESS || type === FAIL) {
const complete = callbacks['complete'];
isFn(complete) && complete(ret);
}
}
}
function initSubNVue (nvue, plus, BroadcastChannel) {
function initSubNVue (nvue, plus, BroadcastChannel) {
let origin;
const onMessageCallbacks = [];
const postMessage = nvue.requireModule('plus').postMessage;
const postMessage = nvue.requireModule('plus').postMessage;
const onSubNVueMessage = function onSubNVueMessage (data) {
onMessageCallbacks.forEach(callback => callback({
......@@ -380,14 +275,14 @@ function initSubNVue (nvue, plus, BroadcastChannel) {
closeMask();
return oldClose.apply(webview, args)
};
};
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id);
if (webview && !webview.$processed) {
wrapper(webview);
}
return webview
};
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id);
if (webview && !webview.$processed) {
wrapper(webview);
}
return webview
};
return {
......@@ -398,15 +293,8 @@ function initSubNVue (nvue, plus, BroadcastChannel) {
}
}
function initPostMessage (nvue) {
const plus = nvue.requireModule('plus');
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
}
}
}
function noop () {}
function initTitleNView (nvue) {
const eventMaps = {
onNavigationBarButtonTap: noop,
......@@ -485,6 +373,118 @@ function initEventBus (getGlobalEmitter) {
getEmitter = getGlobalEmitter;
}
const SUCCESS = 'success';
const FAIL = 'fail';
const COMPLETE = 'complete';
const CALLBACKS = [SUCCESS, FAIL, COMPLETE];
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethodWithoutArgs (vm, method, args, extras) {
if (!vm) {
return
}
if (typeof args === 'undefined') {
return vm[method]()
}
const [, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method]()
}
return vm[method](normalizeCallback(method, callbacks))
}
/**
* 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethod (vm, method, args, extras) {
if (!vm) {
return
}
const [pureArgs, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method](pureArgs)
}
return vm[method](pureArgs, normalizeCallback(method, callbacks))
}
function findElmById (id, vm) {
return findElmByVNode(id, vm._vnode)
}
function findElmByVNode (id, vnode) {
if (!id || !vnode) {
return
}
if (
vnode.data &&
vnode.data.attrs &&
vnode.data.attrs.id === id
) {
return vnode.elm
}
const children = vnode.children;
if (!children) {
return
}
for (let i = 0, len = children.length; i < len; i++) {
const elm = findElmByVNode(id, children[i]);
if (elm) {
return elm
}
}
}
function normalizeArgs (args = {}, extras) {
const callbacks = Object.create(null);
const iterator = function iterator (name) {
const callback = args[name];
if (isFn(callback)) {
callbacks[name] = callback;
delete args[name];
}
};
CALLBACKS.forEach(iterator);
extras && extras.forEach(iterator);
return [args, callbacks]
}
function normalizeCallback (method, callbacks) {
return function weexCallback (ret) {
const type = ret.type;
delete ret.type;
const callback = callbacks[type];
if (type === SUCCESS) {
ret.errMsg = `${method}:ok`;
} else if (type === FAIL) {
ret.errMsg = method + ':fail' + (ret.msg ? (' ' + ret.msg) : '');
}
delete ret.code;
delete ret.msg;
isFn(callback) && callback(ret);
if (type === SUCCESS || type === FAIL) {
const complete = callbacks['complete'];
isFn(complete) && complete(ret);
}
}
}
class MapContext {
constructor (id, ctx) {
this.id = id;
......@@ -517,66 +517,72 @@ class MapContext {
}
function createMapContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
if (!vm) {
return global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
return new MapContext(id, vm.$refs[ref])
}
class VideoContext {
constructor (id, ctx) {
this.id = id;
this.ctx = ctx;
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
const elm = findElmById(id, vm);
if (!elm) {
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new MapContext(id, elm)
}
function createVideoContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
}
return new VideoContext(id, vm.$refs[ref])
class VideoContext {
constructor (id, ctx) {
this.id = id;
this.ctx = ctx;
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
}
function createVideoContext (id, vm) {
if (!vm) {
return global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
const elm = findElmById(id, vm);
if (!elm) {
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new VideoContext(id, elm)
}
class LivePusherContext {
......@@ -595,10 +601,10 @@ class LivePusherContext {
pause (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pause', cbs)
}
resume (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
}
resume (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
}
switchCamera (cbs) {
......@@ -612,42 +618,45 @@ class LivePusherContext {
toggleTorch (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'toggleTorch', cbs)
}
playBGM (args) {
return invokeVmMethod(this.ctx, 'playBGM', args)
}
stopBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
}
pauseBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
}
resumeBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
}
setBGMVolume (cbs) {
return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
}
startPreview (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
playBGM (args) {
return invokeVmMethod(this.ctx, 'playBGM', args)
}
stopBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
}
pauseBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
}
resumeBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
}
setBGMVolume (cbs) {
return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
}
startPreview (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
}
stopPreview (args) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopPreview', args)
}
}
}
function createLivePusherContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
if (!vm) {
return global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
const elm = findElmById(id, vm);
if (!elm) {
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new LivePusherContext(id, vm.$refs[ref])
return new LivePusherContext(id, elm)
}
......
......@@ -2588,6 +2588,14 @@ const outOfChina = function (lng, lat) {
return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false)
};
function requireNativePlugin (name) {
return uni.requireNativePlugin(name)
}
function unpack (args) {
return args
}
function invoke (...args) {
return UniServiceJSBridge.invoke(...args)
}
......@@ -2911,133 +2919,6 @@ function getBackgroundAudioState () {
return data
}
function getMapCenterLocation ({
mapId
} = {}, callbackId) {
const nativeMap = plus.maps.getMapById(mapId + '');
if (nativeMap) {
nativeMap.getCurrentCenter((state, {
latitude,
longitude
} = {}) => {
if (state === 0) {
invoke(callbackId, {
latitude,
longitude,
errMsg: 'getMapCenterLocation:ok'
});
} else {
invoke(callbackId, {
errMsg: 'getMapCenterLocation:fail:state[' + state + ']'
});
}
});
} else {
return {
errMsg: 'getMapCenterLocation:fail:地图[' + mapId + ']不存在'
}
}
}
function moveToMapLocation ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '');
if (nativeMap) {
nativeMap.getUserLocation((state, {
latitude,
longitude
} = {}) => {
if (state === 0) {
nativeMap.setCenter(new plus.maps.Point(longitude, latitude));
}
});
}
return {
errMsg: 'moveToMapLocation:ok'
}
}
function getMapScale ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '');
if (nativeMap) {
return {
scale: nativeMap.getZoom(),
errMsg: 'getMapScale:ok'
}
}
return {
errMsg: 'getMapScale:fail:地图[' + mapId + ']不存在'
}
}
function getMapRegion ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '');
if (nativeMap) {
const bounds = nativeMap.getBounds();
const northeast = bounds.getNorthEase();
const southwest = bounds.getSouthWest();
return {
northeast: {
latitude: northeast.getLat(),
longitude: northeast.getLng()
},
southwest: {
latitude: southwest.getLat(),
longitude: southwest.getLng()
},
errMsg: 'getMapRegion:ok'
}
}
return {
errMsg: 'getMapRegion:fail:地图[' + mapId + ']不存在'
}
}
function operateVideoPlayer ({
data,
videoPlayerId,
type
}) {
const nativeVideo = plus.video.getVideoPlayerById(videoPlayerId + '');
if (nativeVideo) {
switch (type) {
case 'play':
case 'pause':
case 'stop':
case 'requestFullScreen':
case 'exitFullScreen':
case 'seek':
case 'playbackRate':
case 'showStatusBar':
nativeVideo[type].apply(nativeVideo, data);
return {
errMsg: 'operateVideoPlayer:ok'
}
case 'sendDanmu':
nativeVideo.sendDanmu({
text: data[0],
color: data[1]
});
return {
errMsg: 'operateVideoPlayer:ok'
}
default:
return {
errMsg: 'operateVideoPlayer:fail:暂不支持[' + type + ']'
}
}
} else {
return {
errMsg: 'operateVideoPlayer:fail:视频组件[' + videoPlayerId + ']不存在'
}
}
}
const DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g'];
......@@ -3469,7 +3350,7 @@ function setKeepScreenOn ({
}
function getClipboardData (options, callbackId) {
const clipboard = weex.requireModule('clipboard');
const clipboard = requireNativePlugin('clipboard');
clipboard.getString(ret => {
if (ret.result === 'success') {
invoke(callbackId, {
......@@ -3488,7 +3369,7 @@ function getClipboardData (options, callbackId) {
function setClipboardData ({
data
}) {
const clipboard = weex.requireModule('clipboard');
const clipboard = requireNativePlugin('clipboard');
clipboard.setString(data);
return {
errMsg: 'setClipboardData:ok'
......@@ -3884,7 +3765,7 @@ let initView = function () {
view.interceptTouchEvent(true);
view.addEventListener('click', (e) => {
if (!__wxConfig.__ready__) { // 未 ready,不允许点击
if (!__uniConfig.__ready__) { // 未 ready,不允许点击
if (process.env.NODE_ENV !== 'production') {
console.log(`UNIAPP[tabbar].prevent`);
}
......@@ -5305,7 +5186,7 @@ const createDownloadTaskById = function (downloadTaskId, {
header
} = {}) {
const downloader = plus.downloader.createDownload(url, {
time: __wxConfig.networkTimeout.downloadFile ? __wxConfig.networkTimeout.downloadFile / 1000 : 120,
time: __uniConfig.networkTimeout.downloadFile ? __uniConfig.networkTimeout.downloadFile / 1000 : 120,
filename: TEMP_PATH + '/download/',
// 需要与其它平台上的表现保持一致,不走重试的逻辑。
retry: 0,
......@@ -5377,7 +5258,7 @@ function createDownloadTask (args) {
}
const USER_AGENT =
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13G36 MicroMessenger/6.5.1 NetType/WIFI Language/zh_CN';
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13G36 MicroMessenger/6.5.1 NetType/WIFI Language/zh_CN';
let requestTaskId = 0;
const requestTasks = {};
......@@ -5455,13 +5336,11 @@ function createRequestTaskById (requestTaskId, {
if (!hasContentType && method === 'POST') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
}
if (__wxConfig.crossDomain === true) {
if (__uniConfig.crossDomain === true) {
xhr.setRequestHeader('User-Agent', USER_AGENT);
}
if (__wxConfig.appid && __wxConfig.crossDomain === true) {
xhr.setRequestHeader('Referer', `https://servicewechat.com/${__wxConfig.appid}/1/`);
}
if (__wxConfig.networkTimeout.request) {
if (__uniConfig.networkTimeout.request) {
abortTimeout = setTimeout(() => {
xhr.onreadystatechange = null;
xhr.abort();
......@@ -5472,7 +5351,7 @@ function createRequestTaskById (requestTaskId, {
statusCode: 0,
errMsg: 'timeout'
});
}, __wxConfig.networkTimeout.request);
}, __uniConfig.networkTimeout.request);
}
if (typeof data !== 'string' && method === 'GET') {
......@@ -5528,7 +5407,7 @@ const createSocketTaskById = function (socketTaskId, {
protocols
} = {}) {
// fixed by hxy 需要测试是否支持 arraybuffer
const socket = weex.requireModule('webSocket');
const socket = requireNativePlugin('webSocket');
socket.WebSocket(url, Array.isArray(protocols) ? protocols.join(',') : protocols);
// socket.binaryType = 'arraybuffer'
socketTasks[socketTaskId] = socket;
......@@ -5576,7 +5455,7 @@ function operateSocketTask (args) {
code,
data,
socketTaskId
} = PlusNativeBuffer.unpack(args);
} = unpack(args);
const socket = socketTasks[socketTaskId];
if (!socket) {
return {
......@@ -5619,7 +5498,7 @@ const createUploadTaskById = function (uploadTaskId, {
formData
} = {}) {
const uploader = plus.uploader.createUpload(url, {
timeout: __wxConfig.networkTimeout.uploadFile ? __wxConfig.networkTimeout.uploadFile / 1000 : 120,
timeout: __uniConfig.networkTimeout.uploadFile ? __uniConfig.networkTimeout.uploadFile / 1000 : 120,
// 需要与其它平台上的表现保持一致,不走重试的逻辑。
retry: 0,
retryInterval: 0
......@@ -6084,7 +5963,7 @@ function shareAppMessageDirectly ({
imageUrl,
useDefaultSnapshot
}, callbackId) {
title = title || __wxConfig.appname;
title = title || __uniConfig.appname;
const goShare = () => {
share({
provider: 'weixin',
......@@ -6539,21 +6418,12 @@ function showTabBar$2 ({
var api$1 = /*#__PURE__*/Object.freeze({
startPullDownRefresh: startPullDownRefresh$1,
stopPullDownRefresh: stopPullDownRefresh$1,
startRecord: startRecord,
stopRecord: stopRecord,
playVoice: playVoice,
pauseVoice: pauseVoice,
stopVoice: stopVoice,
chooseImage: chooseImage$1,
createAudioInstance: createAudioInstance,
destroyAudioInstance: destroyAudioInstance,
setAudioState: setAudioState,
getAudioState: getAudioState,
operateAudio: operateAudio,
getMapCenterLocation: getMapCenterLocation,
moveToMapLocation: moveToMapLocation,
getMapScale: getMapScale,
getMapRegion: getMapRegion,
operateVideoPlayer: operateVideoPlayer,
enableAccelerometer: enableAccelerometer,
addPhoneContact: addPhoneContact,
openBluetoothAdapter: openBluetoothAdapter,
......@@ -6599,12 +6469,16 @@ var api$1 = /*#__PURE__*/Object.freeze({
chooseLocation: chooseLocation,
getLocation: getLocation$1,
openLocation: openLocation$1,
startRecord: startRecord,
stopRecord: stopRecord,
playVoice: playVoice,
pauseVoice: pauseVoice,
stopVoice: stopVoice,
getMusicPlayerState: getMusicPlayerState,
operateMusicPlayer: operateMusicPlayer,
setBackgroundAudioState: setBackgroundAudioState,
operateBackgroundAudio: operateBackgroundAudio,
getBackgroundAudioState: getBackgroundAudioState,
chooseImage: chooseImage$1,
chooseVideo: chooseVideo$1,
compressImage: compressImage,
getImageInfo: getImageInfo$1,
......
import * as appApi from '../../app-plus/service/api/index'
import * as nvueApi from './api/index'
export default Object.assign(appApi, nvueApi)
......@@ -69,11 +69,11 @@ class LivePusherContext {
export function createLivePusherContext (id, vm) {
if (!vm) {
global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
return global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
const elm = findElmById(id, vm)
if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN')
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new LivePusherContext(id, elm)
}
......@@ -37,11 +37,11 @@ class MapContext {
export function createMapContext (id, vm) {
if (!vm) {
global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
return global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
const elm = findElmById(id, vm)
if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN')
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new MapContext(id, elm)
}
......@@ -53,11 +53,11 @@ class VideoContext {
export function createVideoContext (id, vm) {
if (!vm) {
global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
return global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
}
const elm = findElmById(id, vm)
if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN')
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new VideoContext(id, elm)
}
export * from './context/live-pusher'
export * from './context/map'
export * from './context/video'
......@@ -7,11 +7,6 @@ const FAIL = 'fail'
const COMPLETE = 'complete'
const CALLBACKS = [SUCCESS, FAIL, COMPLETE]
export const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
export function noop () {
}
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
......
uni.navigateTo(plus.webview.open)
旧页面通过 viewdisappear 触发 onHide
新页面通过 beforeCreate 触发 onShow
uni.redirectTo(page.webview.close,plus.webview.show)
旧页面通过 beforeDestroy 触发 onUnload
新页面通过 beforeCreate 触发 onShow
uni.switchTab
旧非 Tab 页面通过 beforeDestroy 触发 onUnload
旧 Tab 页面通过 viewdisappear 触发 onHide
新创建 Tab 页面通过 beforeCreate 触发 onShow
新显示 Tab 页面通过 viewdisappear 触发 onShow
uni.reLaunch
旧页面通过 beforeDestroy 触发 onUnload
新页面通过 beforeCreate 触发 onShow
\ No newline at end of file
......@@ -11,6 +11,6 @@ export {
}
from '../event-bus'
export * from '../context/map'
export * from '../context/video'
export * from '../context/live-pusher'
export * from '../../../service/api/context/map'
export * from '../../../service/api/context/video'
export * from '../../../service/api/context/live-pusher'
......@@ -7,12 +7,9 @@ import {
} from 'uni-core/helpers/promise'
import {
initSubNVue
} from '../sub-nvue'
import {
initSubNVue,
initPostMessage
} from '../post-message'
} from '../sub-nvue'
import {
initTitleNView
......
import {
UNIAPP_SERVICE_NVUE_ID
} from './util'
export function initPostMessage (nvue) {
const plus = nvue.requireModule('plus')
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID)
}
}
}
import {
UNIAPP_SERVICE_NVUE_ID
} from './util'
const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
export function initSubNVue (nvue, plus, BroadcastChannel) {
export function initPostMessage (nvue) {
const plus = nvue.requireModule('plus')
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID)
}
}
}
export function initSubNVue (nvue, plus, BroadcastChannel) {
let origin
const onMessageCallbacks = []
const postMessage = nvue.requireModule('plus').postMessage
const postMessage = nvue.requireModule('plus').postMessage
const onSubNVueMessage = function onSubNVueMessage (data) {
onMessageCallbacks.forEach(callback => callback({
......@@ -92,14 +99,14 @@ export function initSubNVue (nvue, plus, BroadcastChannel) {
closeMask()
return oldClose.apply(webview, args)
}
}
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id)
if (webview && !webview.$processed) {
wrapper(webview)
}
return webview
}
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id)
if (webview && !webview.$processed) {
wrapper(webview)
}
return webview
}
return {
......
import {
noop
} from './util'
function noop () {}
export function initTitleNView (nvue) {
const eventMaps = {
onNavigationBarButtonTap: noop,
......
import {
invoke
} from '../../bridge'
export function getMapCenterLocation ({
mapId
} = {}, callbackId) {
const nativeMap = plus.maps.getMapById(mapId + '')
if (nativeMap) {
nativeMap.getCurrentCenter((state, {
latitude,
longitude
} = {}) => {
if (state === 0) {
invoke(callbackId, {
latitude,
longitude,
errMsg: 'getMapCenterLocation:ok'
})
} else {
invoke(callbackId, {
errMsg: 'getMapCenterLocation:fail:state[' + state + ']'
})
}
})
} else {
return {
errMsg: 'getMapCenterLocation:fail:地图[' + mapId + ']不存在'
}
}
}
export function moveToMapLocation ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '')
if (nativeMap) {
nativeMap.getUserLocation((state, {
latitude,
longitude
} = {}) => {
if (state === 0) {
nativeMap.setCenter(new plus.maps.Point(longitude, latitude))
}
})
}
return {
errMsg: 'moveToMapLocation:ok'
}
}
export function getMapScale ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '')
if (nativeMap) {
return {
scale: nativeMap.getZoom(),
errMsg: 'getMapScale:ok'
}
}
return {
errMsg: 'getMapScale:fail:地图[' + mapId + ']不存在'
}
}
export function getMapRegion ({
mapId
} = {}) {
const nativeMap = plus.maps.getMapById(mapId + '')
if (nativeMap) {
const bounds = nativeMap.getBounds()
const northeast = bounds.getNorthEase()
const southwest = bounds.getSouthWest()
return {
northeast: {
latitude: northeast.getLat(),
longitude: northeast.getLng()
},
southwest: {
latitude: southwest.getLat(),
longitude: southwest.getLng()
},
errMsg: 'getMapRegion:ok'
}
}
return {
errMsg: 'getMapRegion:fail:地图[' + mapId + ']不存在'
}
}
export function operateVideoPlayer ({
data,
videoPlayerId,
type
}) {
const nativeVideo = plus.video.getVideoPlayerById(videoPlayerId + '')
if (nativeVideo) {
switch (type) {
case 'play':
case 'pause':
case 'stop':
case 'requestFullScreen':
case 'exitFullScreen':
case 'seek':
case 'playbackRate':
case 'showStatusBar':
nativeVideo[type].apply(nativeVideo, data)
return {
errMsg: 'operateVideoPlayer:ok'
}
case 'sendDanmu':
nativeVideo.sendDanmu({
text: data[0],
color: data[1]
})
return {
errMsg: 'operateVideoPlayer:ok'
}
default:
return {
errMsg: 'operateVideoPlayer:fail:暂不支持[' + type + ']'
}
}
} else {
return {
errMsg: 'operateVideoPlayer:fail:视频组件[' + videoPlayerId + ']不存在'
}
}
}
export * from './context/audio'
export * from './context/background-audio'
export * from './context/map'
export * from './context/video'
export * from './device/accelerometer'
export * from './device/add-phone-contact'
......
......@@ -13,7 +13,7 @@ import {
import baseApi from 'uni-core/service/api'
import platformApi from './api'
import platformApi from 'uni-platform/service/api'
const api = Object.create(null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册