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

feat(app-plus-nvue): onTabItemTap,onBackPress

上级 ae221537
...@@ -161,8 +161,9 @@ var serviceContext = (function () { ...@@ -161,8 +161,9 @@ var serviceContext = (function () {
return false return false
} }
return page.$page.meta.isTabBar return page.$page.meta.isTabBar
} }
return !!__uniRoutes.find(route => route.path.slice(1) === path) const route = __uniRoutes.find(route => route.path.slice(1) === path);
return route && route.meta.isTabBar
} catch (e) { } catch (e) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('getCurrentPages is not ready'); console.log('getCurrentPages is not ready');
...@@ -1363,7 +1364,6 @@ var serviceContext = (function () { ...@@ -1363,7 +1364,6 @@ var serviceContext = (function () {
const emit = UniServiceJSBridge.emit; const emit = UniServiceJSBridge.emit;
plus.key.addEventListener('backbutton', () => { plus.key.addEventListener('backbutton', () => {
// TODO uni?
uni.navigateBack({ uni.navigateBack({
from: 'backbutton' from: 'backbutton'
}); });
...@@ -1383,22 +1383,22 @@ var serviceContext = (function () { ...@@ -1383,22 +1383,22 @@ var serviceContext = (function () {
isConnected: networkType !== 'none', isConnected: networkType !== 'none',
networkType networkType
}); });
}); });
plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) { plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) {
publish('onKeyboardHeightChange', { publish('onKeyboardHeightChange', {
height: event.height height: event.height
}); });
}); });
plus.globalEvent.addEventListener('plusMessage', function (e) { plus.globalEvent.addEventListener('plusMessage', function (e) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data)); console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data));
} }
if (e.data && e.data.type) { if (e.data && e.data.type) {
const type = e.data.type; const type = e.data.type;
consumePlusMessage(type, e.data.args || {}); consumePlusMessage(type, e.data.args || {});
} }
}); });
} }
...@@ -1418,10 +1418,12 @@ var serviceContext = (function () { ...@@ -1418,10 +1418,12 @@ var serviceContext = (function () {
return return
} }
const currentTab = isTabBarPage(__uniConfig.entryPagePath); __uniConfig.tabBar.selected = 0;
if (currentTab) {
const selected = __uniConfig.tabBar.list.findIndex(page => page.pagePath === __uniConfig.entryPagePath);
if (selected !== -1) {
// 取当前 tab 索引值 // 取当前 tab 索引值
__uniConfig.tabBar.selected = __uniConfig.tabBar.list.indexOf(currentTab); __uniConfig.tabBar.selected = selected;
// 如果真实的首页与 condition 都是 tabbar,无需启用 realEntryPagePath 机制 // 如果真实的首页与 condition 都是 tabbar,无需启用 realEntryPagePath 机制
if (__uniConfig.realEntryPagePath && isTabBarPage(__uniConfig.realEntryPagePath)) { if (__uniConfig.realEntryPagePath && isTabBarPage(__uniConfig.realEntryPagePath)) {
delete __uniConfig.realEntryPagePath; delete __uniConfig.realEntryPagePath;
...@@ -1431,7 +1433,12 @@ var serviceContext = (function () { ...@@ -1431,7 +1433,12 @@ var serviceContext = (function () {
__uniConfig.__ready__ = true; __uniConfig.__ready__ = true;
const onLaunchWebviewReady = function onLaunchWebviewReady () { const onLaunchWebviewReady = function onLaunchWebviewReady () {
const tabBarView = tabBar.init(__uniConfig.tabBar, (item) => { const tabBarView = tabBar.init(__uniConfig.tabBar, (item, index) => {
UniServiceJSBridge.emit('onTabItemTap', {
index,
text: item.text,
pagePath: item.pagePath
});
uni.switchTab({ uni.switchTab({
url: '/' + item.pagePath, url: '/' + item.pagePath,
openType: 'switchTab', openType: 'switchTab',
...@@ -1452,8 +1459,8 @@ var serviceContext = (function () { ...@@ -1452,8 +1459,8 @@ var serviceContext = (function () {
console.log(`[uni-app] registerApp`); console.log(`[uni-app] registerApp`);
} }
appCtx = appVm; appCtx = appVm;
appCtx.globalData = appVm.$options.globalData || {}; appCtx.globalData = appVm.$options.globalData || {};
initOn(UniServiceJSBridge.on, { initOn(UniServiceJSBridge.on, {
...@@ -1938,7 +1945,7 @@ var serviceContext = (function () { ...@@ -1938,7 +1945,7 @@ var serviceContext = (function () {
}; };
const SYNC_API_RE = const SYNC_API_RE =
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; /^\$|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -4882,7 +4889,7 @@ var serviceContext = (function () { ...@@ -4882,7 +4889,7 @@ var serviceContext = (function () {
return { return {
errMsg: 'getSystemInfo:ok', errMsg: 'getSystemInfo:ok',
brand: '', brand: plus.device.vendor,
model: plus.device.model, model: plus.device.model,
pixelRatio: plus.screen.scale, pixelRatio: plus.screen.scale,
screenWidth, screenWidth,
...@@ -8887,16 +8894,28 @@ var serviceContext = (function () { ...@@ -8887,16 +8894,28 @@ var serviceContext = (function () {
} }
function navigateBack$1 ({ function navigateBack$1 ({
from = 'navigateBack',
delta, delta,
animationType, animationType,
animationDuration animationDuration
}) { }) {
const pages = getCurrentPages(); const pages = getCurrentPages();
const len = pages.length;
const currentPage = pages[pages.length - 1];
if (
currentPage.$vm &&
currentPage.$vm.$options.onBackPress &&
currentPage.$vm.__call_hook &&
currentPage.$vm.__call_hook('onBackPress', {
from
})
) {
return
}
uni.hideToast(); // 后退时,关闭 toast,loading uni.hideToast(); // 后退时,关闭 toast,loading
pages[len - 1].$page.meta.isQuit currentPage.$page.meta.isQuit
? quit() ? quit()
: back(delta, animationType, animationDuration); : back(delta, animationType, animationDuration);
} }
......
...@@ -122,7 +122,7 @@ function invokeApi (method, api, options, ...params) { ...@@ -122,7 +122,7 @@ function invokeApi (method, api, options, ...params) {
} }
const SYNC_API_RE = const SYNC_API_RE =
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; /^\$|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
......
...@@ -74,16 +74,28 @@ function back (delta, animationType, animationDuration) { ...@@ -74,16 +74,28 @@ function back (delta, animationType, animationDuration) {
} }
export function navigateBack ({ export function navigateBack ({
from = 'navigateBack',
delta, delta,
animationType, animationType,
animationDuration animationDuration
}) { }) {
const pages = getCurrentPages() const pages = getCurrentPages()
const len = pages.length
const currentPage = pages[pages.length - 1]
if (
currentPage.$vm &&
currentPage.$vm.$options.onBackPress &&
currentPage.$vm.__call_hook &&
currentPage.$vm.__call_hook('onBackPress', {
from
})
) {
return
}
uni.hideToast() // 后退时,关闭 toast,loading uni.hideToast() // 后退时,关闭 toast,loading
pages[len - 1].$page.meta.isQuit currentPage.$page.meta.isQuit
? quit() ? quit()
: back(delta, animationType, animationDuration) : back(delta, animationType, animationDuration)
} }
...@@ -56,8 +56,9 @@ export function isTabBarPage (path = '') { ...@@ -56,8 +56,9 @@ export function isTabBarPage (path = '') {
return false return false
} }
return page.$page.meta.isTabBar return page.$page.meta.isTabBar
} }
return !!__uniRoutes.find(route => route.path.slice(1) === path) const route = __uniRoutes.find(route => route.path.slice(1) === path)
return route && route.meta.isTabBar
} catch (e) { } catch (e) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('getCurrentPages is not ready') console.log('getCurrentPages is not ready')
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
} from './page' } from './page'
import { import {
registerPlusMessage, registerPlusMessage,
consumePlusMessage consumePlusMessage
} from './plus-message' } from './plus-message'
...@@ -17,8 +17,8 @@ import { ...@@ -17,8 +17,8 @@ import {
isTabBarPage isTabBarPage
} from '../api/util' } from '../api/util'
import tabBar from './tab-bar' import tabBar from './tab-bar'
import { import {
publish publish
} from '../bridge' } from '../bridge'
...@@ -43,7 +43,6 @@ function initGlobalListeners () { ...@@ -43,7 +43,6 @@ function initGlobalListeners () {
const emit = UniServiceJSBridge.emit const emit = UniServiceJSBridge.emit
plus.key.addEventListener('backbutton', () => { plus.key.addEventListener('backbutton', () => {
// TODO uni?
uni.navigateBack({ uni.navigateBack({
from: 'backbutton' from: 'backbutton'
}) })
...@@ -63,22 +62,22 @@ function initGlobalListeners () { ...@@ -63,22 +62,22 @@ function initGlobalListeners () {
isConnected: networkType !== 'none', isConnected: networkType !== 'none',
networkType networkType
}) })
}) })
plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) { plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) {
publish('onKeyboardHeightChange', { publish('onKeyboardHeightChange', {
height: event.height height: event.height
}) })
}) })
plus.globalEvent.addEventListener('plusMessage', function (e) { plus.globalEvent.addEventListener('plusMessage', function (e) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data)) console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data))
} }
if (e.data && e.data.type) { if (e.data && e.data.type) {
const type = e.data.type const type = e.data.type
consumePlusMessage(type, e.data.args || {}) consumePlusMessage(type, e.data.args || {})
} }
}) })
} }
...@@ -98,10 +97,12 @@ function initTabBar () { ...@@ -98,10 +97,12 @@ function initTabBar () {
return return
} }
const currentTab = isTabBarPage(__uniConfig.entryPagePath) __uniConfig.tabBar.selected = 0
if (currentTab) {
const selected = __uniConfig.tabBar.list.findIndex(page => page.pagePath === __uniConfig.entryPagePath)
if (selected !== -1) {
// 取当前 tab 索引值 // 取当前 tab 索引值
__uniConfig.tabBar.selected = __uniConfig.tabBar.list.indexOf(currentTab) __uniConfig.tabBar.selected = selected
// 如果真实的首页与 condition 都是 tabbar,无需启用 realEntryPagePath 机制 // 如果真实的首页与 condition 都是 tabbar,无需启用 realEntryPagePath 机制
if (__uniConfig.realEntryPagePath && isTabBarPage(__uniConfig.realEntryPagePath)) { if (__uniConfig.realEntryPagePath && isTabBarPage(__uniConfig.realEntryPagePath)) {
delete __uniConfig.realEntryPagePath delete __uniConfig.realEntryPagePath
...@@ -111,7 +112,12 @@ function initTabBar () { ...@@ -111,7 +112,12 @@ function initTabBar () {
__uniConfig.__ready__ = true __uniConfig.__ready__ = true
const onLaunchWebviewReady = function onLaunchWebviewReady () { const onLaunchWebviewReady = function onLaunchWebviewReady () {
const tabBarView = tabBar.init(__uniConfig.tabBar, (item) => { const tabBarView = tabBar.init(__uniConfig.tabBar, (item, index) => {
UniServiceJSBridge.emit('onTabItemTap', {
index,
text: item.text,
pagePath: item.pagePath
})
uni.switchTab({ uni.switchTab({
url: '/' + item.pagePath, url: '/' + item.pagePath,
openType: 'switchTab', openType: 'switchTab',
...@@ -132,8 +138,8 @@ export function registerApp (appVm) { ...@@ -132,8 +138,8 @@ export function registerApp (appVm) {
console.log(`[uni-app] registerApp`) console.log(`[uni-app] registerApp`)
} }
appCtx = appVm appCtx = appVm
appCtx.globalData = appVm.$options.globalData || {} appCtx.globalData = appVm.$options.globalData || {}
initOn(UniServiceJSBridge.on, { initOn(UniServiceJSBridge.on, {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册