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

nvue service

上级 f7ce3bf8
...@@ -42,7 +42,9 @@ function initGlobalListeners ({ ...@@ -42,7 +42,9 @@ function initGlobalListeners ({
const emit = UniServiceJSBridge.emit; const emit = UniServiceJSBridge.emit;
plus.key.addEventListener('backbutton', () => { plus.key.addEventListener('backbutton', () => {
uni.navigateBack(); uni.navigateBack({
from: 'backbutton'
});
}); });
plus.globalEvent.addEventListener('pause', () => { plus.globalEvent.addEventListener('pause', () => {
...@@ -341,6 +343,7 @@ function getCurrentPages () { ...@@ -341,6 +343,7 @@ function getCurrentPages () {
* *
* *
*/ */
/** /**
* 首页需要主动registerPage,二级页面路由跳转时registerPage * 首页需要主动registerPage,二级页面路由跳转时registerPage
*/ */
...@@ -361,6 +364,9 @@ function registerPage ({ ...@@ -361,6 +364,9 @@ function registerPage ({
initWebview(webview, instanceContext, webview.id === '1' && routeOptions); initWebview(webview, instanceContext, webview.id === '1' && routeOptions);
const route = path.slice(1); const route = path.slice(1);
webview.__uniapp_route = route;
pages.push({ pages.push({
route, route,
$getAppWebview () { $getAppWebview () {
......
...@@ -174,118 +174,13 @@ function promisify (name, api) { ...@@ -174,118 +174,13 @@ 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'; const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service';
function noop () { function initPostMessage (nvue) {
const plus = nvue.requireModule('plus');
} return {
/** postMessage (data) {
* 调用无参数,或仅一个参数且为 callback 的 API plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
* @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 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);
} }
} }
} }
...@@ -398,14 +293,7 @@ function initSubNVue (nvue, plus, BroadcastChannel) { ...@@ -398,14 +293,7 @@ function initSubNVue (nvue, plus, BroadcastChannel) {
} }
} }
function initPostMessage (nvue) { function noop () {}
const plus = nvue.requireModule('plus');
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
}
}
}
function initTitleNView (nvue) { function initTitleNView (nvue) {
const eventMaps = { const eventMaps = {
...@@ -485,6 +373,118 @@ function initEventBus (getGlobalEmitter) { ...@@ -485,6 +373,118 @@ function initEventBus (getGlobalEmitter) {
getEmitter = 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 { class MapContext {
constructor (id, ctx) { constructor (id, ctx) {
this.id = id; this.id = id;
...@@ -517,11 +517,14 @@ class MapContext { ...@@ -517,11 +517,14 @@ class MapContext {
} }
function createMapContext (id, vm) { function createMapContext (id, vm) {
const ref = findRefById(id, vm); if (!vm) {
if (!ref) { return global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
global.nativeLog('Can not find `' + id + '`', '__WARN'); }
const elm = findElmById(id, vm);
if (!elm) {
return global.nativeLog('Can not find `' + id + '`', '__WARN')
} }
return new MapContext(id, vm.$refs[ref]) return new MapContext(id, elm)
} }
class VideoContext { class VideoContext {
...@@ -572,11 +575,14 @@ class VideoContext { ...@@ -572,11 +575,14 @@ class VideoContext {
} }
function createVideoContext (id, vm) { function createVideoContext (id, vm) {
const ref = findRefById(id, vm); if (!vm) {
if (!ref) { return global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
global.nativeLog('Can not find `' + id + '`', '__WARN');
} }
return new VideoContext(id, vm.$refs[ref]) const elm = findElmById(id, vm);
if (!elm) {
return global.nativeLog('Can not find `' + id + '`', '__WARN')
}
return new VideoContext(id, elm)
} }
class LivePusherContext { class LivePusherContext {
...@@ -643,11 +649,14 @@ class LivePusherContext { ...@@ -643,11 +649,14 @@ class LivePusherContext {
} }
function createLivePusherContext (id, vm) { function createLivePusherContext (id, vm) {
const ref = findRefById(id, vm); if (!vm) {
if (!ref) { return global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
global.nativeLog('Can not find `' + id + '`', '__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) { ...@@ -2588,6 +2588,14 @@ const outOfChina = function (lng, lat) {
return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false) 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) { function invoke (...args) {
return UniServiceJSBridge.invoke(...args) return UniServiceJSBridge.invoke(...args)
} }
...@@ -2911,133 +2919,6 @@ function getBackgroundAudioState () { ...@@ -2911,133 +2919,6 @@ function getBackgroundAudioState () {
return data 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 DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g']; const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g'];
...@@ -3469,7 +3350,7 @@ function setKeepScreenOn ({ ...@@ -3469,7 +3350,7 @@ function setKeepScreenOn ({
} }
function getClipboardData (options, callbackId) { function getClipboardData (options, callbackId) {
const clipboard = weex.requireModule('clipboard'); const clipboard = requireNativePlugin('clipboard');
clipboard.getString(ret => { clipboard.getString(ret => {
if (ret.result === 'success') { if (ret.result === 'success') {
invoke(callbackId, { invoke(callbackId, {
...@@ -3488,7 +3369,7 @@ function getClipboardData (options, callbackId) { ...@@ -3488,7 +3369,7 @@ function getClipboardData (options, callbackId) {
function setClipboardData ({ function setClipboardData ({
data data
}) { }) {
const clipboard = weex.requireModule('clipboard'); const clipboard = requireNativePlugin('clipboard');
clipboard.setString(data); clipboard.setString(data);
return { return {
errMsg: 'setClipboardData:ok' errMsg: 'setClipboardData:ok'
...@@ -3884,7 +3765,7 @@ let initView = function () { ...@@ -3884,7 +3765,7 @@ let initView = function () {
view.interceptTouchEvent(true); view.interceptTouchEvent(true);
view.addEventListener('click', (e) => { view.addEventListener('click', (e) => {
if (!__wxConfig.__ready__) { // 未 ready,不允许点击 if (!__uniConfig.__ready__) { // 未 ready,不允许点击
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`UNIAPP[tabbar].prevent`); console.log(`UNIAPP[tabbar].prevent`);
} }
...@@ -5305,7 +5186,7 @@ const createDownloadTaskById = function (downloadTaskId, { ...@@ -5305,7 +5186,7 @@ const createDownloadTaskById = function (downloadTaskId, {
header header
} = {}) { } = {}) {
const downloader = plus.downloader.createDownload(url, { 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/', filename: TEMP_PATH + '/download/',
// 需要与其它平台上的表现保持一致,不走重试的逻辑。 // 需要与其它平台上的表现保持一致,不走重试的逻辑。
retry: 0, retry: 0,
...@@ -5455,13 +5336,11 @@ function createRequestTaskById (requestTaskId, { ...@@ -5455,13 +5336,11 @@ function createRequestTaskById (requestTaskId, {
if (!hasContentType && method === 'POST') { if (!hasContentType && method === 'POST') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 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); xhr.setRequestHeader('User-Agent', USER_AGENT);
} }
if (__wxConfig.appid && __wxConfig.crossDomain === true) {
xhr.setRequestHeader('Referer', `https://servicewechat.com/${__wxConfig.appid}/1/`); if (__uniConfig.networkTimeout.request) {
}
if (__wxConfig.networkTimeout.request) {
abortTimeout = setTimeout(() => { abortTimeout = setTimeout(() => {
xhr.onreadystatechange = null; xhr.onreadystatechange = null;
xhr.abort(); xhr.abort();
...@@ -5472,7 +5351,7 @@ function createRequestTaskById (requestTaskId, { ...@@ -5472,7 +5351,7 @@ function createRequestTaskById (requestTaskId, {
statusCode: 0, statusCode: 0,
errMsg: 'timeout' errMsg: 'timeout'
}); });
}, __wxConfig.networkTimeout.request); }, __uniConfig.networkTimeout.request);
} }
if (typeof data !== 'string' && method === 'GET') { if (typeof data !== 'string' && method === 'GET') {
...@@ -5528,7 +5407,7 @@ const createSocketTaskById = function (socketTaskId, { ...@@ -5528,7 +5407,7 @@ const createSocketTaskById = function (socketTaskId, {
protocols protocols
} = {}) { } = {}) {
// fixed by hxy 需要测试是否支持 arraybuffer // fixed by hxy 需要测试是否支持 arraybuffer
const socket = weex.requireModule('webSocket'); const socket = requireNativePlugin('webSocket');
socket.WebSocket(url, Array.isArray(protocols) ? protocols.join(',') : protocols); socket.WebSocket(url, Array.isArray(protocols) ? protocols.join(',') : protocols);
// socket.binaryType = 'arraybuffer' // socket.binaryType = 'arraybuffer'
socketTasks[socketTaskId] = socket; socketTasks[socketTaskId] = socket;
...@@ -5576,7 +5455,7 @@ function operateSocketTask (args) { ...@@ -5576,7 +5455,7 @@ function operateSocketTask (args) {
code, code,
data, data,
socketTaskId socketTaskId
} = PlusNativeBuffer.unpack(args); } = unpack(args);
const socket = socketTasks[socketTaskId]; const socket = socketTasks[socketTaskId];
if (!socket) { if (!socket) {
return { return {
...@@ -5619,7 +5498,7 @@ const createUploadTaskById = function (uploadTaskId, { ...@@ -5619,7 +5498,7 @@ const createUploadTaskById = function (uploadTaskId, {
formData formData
} = {}) { } = {}) {
const uploader = plus.uploader.createUpload(url, { 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, retry: 0,
retryInterval: 0 retryInterval: 0
...@@ -6084,7 +5963,7 @@ function shareAppMessageDirectly ({ ...@@ -6084,7 +5963,7 @@ function shareAppMessageDirectly ({
imageUrl, imageUrl,
useDefaultSnapshot useDefaultSnapshot
}, callbackId) { }, callbackId) {
title = title || __wxConfig.appname; title = title || __uniConfig.appname;
const goShare = () => { const goShare = () => {
share({ share({
provider: 'weixin', provider: 'weixin',
...@@ -6539,21 +6418,12 @@ function showTabBar$2 ({ ...@@ -6539,21 +6418,12 @@ function showTabBar$2 ({
var api$1 = /*#__PURE__*/Object.freeze({ var api$1 = /*#__PURE__*/Object.freeze({
startPullDownRefresh: startPullDownRefresh$1, startPullDownRefresh: startPullDownRefresh$1,
stopPullDownRefresh: stopPullDownRefresh$1, stopPullDownRefresh: stopPullDownRefresh$1,
startRecord: startRecord, chooseImage: chooseImage$1,
stopRecord: stopRecord,
playVoice: playVoice,
pauseVoice: pauseVoice,
stopVoice: stopVoice,
createAudioInstance: createAudioInstance, createAudioInstance: createAudioInstance,
destroyAudioInstance: destroyAudioInstance, destroyAudioInstance: destroyAudioInstance,
setAudioState: setAudioState, setAudioState: setAudioState,
getAudioState: getAudioState, getAudioState: getAudioState,
operateAudio: operateAudio, operateAudio: operateAudio,
getMapCenterLocation: getMapCenterLocation,
moveToMapLocation: moveToMapLocation,
getMapScale: getMapScale,
getMapRegion: getMapRegion,
operateVideoPlayer: operateVideoPlayer,
enableAccelerometer: enableAccelerometer, enableAccelerometer: enableAccelerometer,
addPhoneContact: addPhoneContact, addPhoneContact: addPhoneContact,
openBluetoothAdapter: openBluetoothAdapter, openBluetoothAdapter: openBluetoothAdapter,
...@@ -6599,12 +6469,16 @@ var api$1 = /*#__PURE__*/Object.freeze({ ...@@ -6599,12 +6469,16 @@ var api$1 = /*#__PURE__*/Object.freeze({
chooseLocation: chooseLocation, chooseLocation: chooseLocation,
getLocation: getLocation$1, getLocation: getLocation$1,
openLocation: openLocation$1, openLocation: openLocation$1,
startRecord: startRecord,
stopRecord: stopRecord,
playVoice: playVoice,
pauseVoice: pauseVoice,
stopVoice: stopVoice,
getMusicPlayerState: getMusicPlayerState, getMusicPlayerState: getMusicPlayerState,
operateMusicPlayer: operateMusicPlayer, operateMusicPlayer: operateMusicPlayer,
setBackgroundAudioState: setBackgroundAudioState, setBackgroundAudioState: setBackgroundAudioState,
operateBackgroundAudio: operateBackgroundAudio, operateBackgroundAudio: operateBackgroundAudio,
getBackgroundAudioState: getBackgroundAudioState, getBackgroundAudioState: getBackgroundAudioState,
chooseImage: chooseImage$1,
chooseVideo: chooseVideo$1, chooseVideo: chooseVideo$1,
compressImage: compressImage, compressImage: compressImage,
getImageInfo: getImageInfo$1, 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 { ...@@ -69,11 +69,11 @@ class LivePusherContext {
export function createLivePusherContext (id, vm) { export function createLivePusherContext (id, vm) {
if (!vm) { if (!vm) {
global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN') return global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
} }
const elm = findElmById(id, vm) const elm = findElmById(id, vm)
if (!elm) { if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN') return global.nativeLog('Can not find `' + id + '`', '__WARN')
} }
return new LivePusherContext(id, elm) return new LivePusherContext(id, elm)
} }
...@@ -37,11 +37,11 @@ class MapContext { ...@@ -37,11 +37,11 @@ class MapContext {
export function createMapContext (id, vm) { export function createMapContext (id, vm) {
if (!vm) { if (!vm) {
global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN') return global.nativeLog('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
} }
const elm = findElmById(id, vm) const elm = findElmById(id, vm)
if (!elm) { if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN') return global.nativeLog('Can not find `' + id + '`', '__WARN')
} }
return new MapContext(id, elm) return new MapContext(id, elm)
} }
...@@ -53,11 +53,11 @@ class VideoContext { ...@@ -53,11 +53,11 @@ class VideoContext {
export function createVideoContext (id, vm) { export function createVideoContext (id, vm) {
if (!vm) { if (!vm) {
global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN') return global.nativeLog('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
} }
const elm = findElmById(id, vm) const elm = findElmById(id, vm)
if (!elm) { if (!elm) {
global.nativeLog('Can not find `' + id + '`', '__WARN') return global.nativeLog('Can not find `' + id + '`', '__WARN')
} }
return new VideoContext(id, elm) 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' ...@@ -7,11 +7,6 @@ const FAIL = 'fail'
const COMPLETE = 'complete' const COMPLETE = 'complete'
const CALLBACKS = [SUCCESS, FAIL, COMPLETE] const CALLBACKS = [SUCCESS, FAIL, COMPLETE]
export const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
export function noop () {
}
/** /**
* 调用无参数,或仅一个参数且为 callback 的 API * 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm * @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 { ...@@ -11,6 +11,6 @@ export {
} }
from '../event-bus' from '../event-bus'
export * from '../context/map' export * from '../../../service/api/context/map'
export * from '../context/video' export * from '../../../service/api/context/video'
export * from '../context/live-pusher' export * from '../../../service/api/context/live-pusher'
...@@ -7,12 +7,9 @@ import { ...@@ -7,12 +7,9 @@ import {
} from 'uni-core/helpers/promise' } from 'uni-core/helpers/promise'
import { import {
initSubNVue initSubNVue,
} from '../sub-nvue'
import {
initPostMessage initPostMessage
} from '../post-message' } from '../sub-nvue'
import { import {
initTitleNView 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 { const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
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)
}
}
}
export function initSubNVue (nvue, plus, BroadcastChannel) { export function initSubNVue (nvue, plus, BroadcastChannel) {
let origin let origin
......
import { function noop () {}
noop
} from './util'
export function initTitleNView (nvue) { export function initTitleNView (nvue) {
const eventMaps = { const eventMaps = {
onNavigationBarButtonTap: noop, 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/audio'
export * from './context/background-audio' export * from './context/background-audio'
export * from './context/map'
export * from './context/video'
export * from './device/accelerometer' export * from './device/accelerometer'
export * from './device/add-phone-contact' export * from './device/add-phone-contact'
......
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
import baseApi from 'uni-core/service/api' import baseApi from 'uni-core/service/api'
import platformApi from './api' import platformApi from 'uni-platform/service/api'
const api = Object.create(null) const api = Object.create(null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册