提交 ebb73f88 编写于 作者: Q qiang

feat: app-plus uni.onNetworkStatusChange

上级 9f4217af
import {
invoke
} from 'uni-core/service/bridge'
import {
onMethod
} from '../../platform'
const callbacks = []
onMethod('onNetworkStatusChange', res => {
callbacks.forEach(callbackId => {
invoke(callbackId, res)
})
})
export function onNetworkStatusChange (callbackId) {
callbacks.push(callbackId)
}
...@@ -18,6 +18,10 @@ import { ...@@ -18,6 +18,10 @@ import {
import tabBar from './tab-bar' import tabBar from './tab-bar'
import {
publish
} from '../bridge'
let appCtx let appCtx
const NETWORK_TYPES = [ const NETWORK_TYPES = [
...@@ -54,7 +58,7 @@ function initGlobalListeners () { ...@@ -54,7 +58,7 @@ function initGlobalListeners () {
plus.globalEvent.addEventListener('netchange', () => { plus.globalEvent.addEventListener('netchange', () => {
const networkType = NETWORK_TYPES[plus.networkinfo.getCurrentType()] const networkType = NETWORK_TYPES[plus.networkinfo.getCurrentType()]
emit('onNetworkStatusChange', { publish('onNetworkStatusChange', {
isConnected: networkType !== 'none', isConnected: networkType !== 'none',
networkType networkType
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册