提交 a3067053 编写于 作者: D DCloud_LXH

fix(mp): navigateTo eventChannel Disorder of sequence problem

上级 1566d886
......@@ -4,11 +4,12 @@ import {
addSafeAreaInsets,
useDeviceId,
populateParameters,
navigateTo as _navigateTo,
} from '@dcloudio/uni-mp-core'
import { getStorageSync } from './shims'
export { redirectTo, navigateTo } from '@dcloudio/uni-mp-core'
export { redirectTo } from '@dcloudio/uni-mp-core'
function handleNetworkInfo(
fromRes: my.IGetNetworkTypeSuccessResult,
......@@ -488,3 +489,6 @@ export const chooseAddress = {
toRes.errMsg = toRes.errMsg + ' ' + fromRes.resultStatus
},
}
export const navigateTo = my.canIUse('getOpenerEventChannel')
? {}
: _navigateTo()
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
import { navigateTo as _navigateTo } from '@dcloudio/uni-mp-core'
function createTodoMethod(contextName: string, methodName: string) {
return function unsupported() {
......@@ -104,3 +104,5 @@ export const getAccountInfoSync = {
}
},
}
export const navigateTo = _navigateTo()
......@@ -71,9 +71,11 @@ export function initUni(
// 处理 api mp 打包后为不同js,emitter 无法共享问题
if (__PLATFORM__ === 'mp-alipay') {
platform.$emit = $emit
if (!my.canIUse('getOpenerEventChannel'))
platform.getEventChannel = getEventChannel
}
// 处理 api mp 打包后为不同js,getEventChannel 无法共享问题
if (__PLATFORM__ !== 'mp-weixin') {
if (__PLATFORM__ !== 'mp-weixin' && __PLATFORM__ !== 'mp-alipay') {
platform.getEventChannel = getEventChannel
}
......
......@@ -8,7 +8,7 @@ export { getSystemInfoSync } from './getSystemInfoSync'
export { redirectTo } from './redirectTo'
export { previewImage } from './previewImage'
export { showActionSheet } from './showActionSheet'
export { navigateTo, initEventChannel, getEventChannel } from './navigateTo'
export { navigateTo, getEventChannel } from './navigateTo'
export { getDeviceInfo } from './getDeviceInfo'
export { getAppBaseInfo } from './getAppBaseInfo'
export { getWindowInfo } from './getWindowInfo'
......
......@@ -3,11 +3,9 @@ import { MPProtocol } from './types'
const eventChannels: Record<string, EventChannel> = {}
const eventChannelStack: EventChannel[] = []
let id = 0
export function initEventChannel(
function initEventChannel(
events: Record<string, (...args: any[]) => void>,
cache = true
) {
......@@ -15,32 +13,32 @@ export function initEventChannel(
const eventChannel = new __GLOBAL__.EventChannel(id, events)
if (cache) {
eventChannels[id] = eventChannel
eventChannelStack.push(eventChannel)
}
return eventChannel
}
export function getEventChannel(id?: number) {
if (id) {
const eventChannel = eventChannels[id]
delete eventChannels[id]
return eventChannel
}
return eventChannelStack.shift()
export function getEventChannel(id: number) {
const eventChannel = eventChannels[id]
delete eventChannels[id]
return eventChannel
}
export const navigateTo: MPProtocol = {
args(fromArgs) {
const id = initEventChannel(fromArgs.events).id
if (fromArgs.url) {
fromArgs.url =
fromArgs.url +
(fromArgs.url.indexOf('?') === -1 ? '?' : '&') +
'__id__=' +
id
}
},
returnValue(fromRes) {
fromRes.eventChannel = getEventChannel()
},
export const navigateTo = (): MPProtocol => {
let eventChannel: EventChannel
return {
args(fromArgs) {
eventChannel = initEventChannel(fromArgs.events)
if (fromArgs.url) {
fromArgs.url =
fromArgs.url +
(fromArgs.url.indexOf('?') === -1 ? '?' : '&') +
'__id__=' +
eventChannel.id
}
},
returnValue(fromRes) {
fromRes.eventChannel = eventChannel
},
}
}
......@@ -3,7 +3,7 @@ import {
invokeArrayFns,
SLOT_DEFAULT_NAME,
} from '@dcloudio/uni-shared'
import { capitalize, hasOwn, isArray } from '@vue/shared'
import { capitalize, hasOwn, isArray, isFunction } from '@vue/shared'
import {
ComponentPublicInstance,
......@@ -97,6 +97,10 @@ export function initBaseInstance(
if (__PLATFORM__ === 'mp-weixin') {
return options.mpInstance.getOpenerEventChannel()
}
if (__PLATFORM__ === 'mp-alipay') {
if (my.canIUse('getOpenerEventChannel'))
return options.mpInstance.getOpenerEventChannel()
}
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel()
}
......@@ -158,7 +162,12 @@ function callHook(this: ComponentPublicInstance, name: string, args?: unknown) {
name = 'm'
}
if (__PLATFORM__ !== 'mp-weixin') {
if (name === 'onLoad' && args && (args as any).__id__) {
if (
name === 'onLoad' &&
args &&
(args as any).__id__ &&
isFunction(__GLOBAL__.getEventChannel)
) {
;(this as any).__eventChannel__ = __GLOBAL__.getEventChannel(
(args as any).__id__
)
......
import {
redirectTo,
navigateTo,
navigateTo as _navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
}
export { redirectTo, previewImage, getSystemInfo, getSystemInfoSync }
export const navigateTo = _navigateTo()
import {
redirectTo,
navigateTo,
navigateTo as _navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
......@@ -19,9 +19,10 @@ const requestPayment: MPProtocol = {
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
requestPayment,
}
export const navigateTo = _navigateTo()
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
import { navigateTo as _navigateTo } from '@dcloudio/uni-mp-core'
export const navigateTo = _navigateTo()
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
import { navigateTo as _navigateTo } from '@dcloudio/uni-mp-core'
export const navigateTo = _navigateTo()
export const connectSocket = {
args: {
method: false,
......
import {
redirectTo,
navigateTo,
navigateTo as _navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
}
export { redirectTo, previewImage, getSystemInfo, getSystemInfoSync }
export const navigateTo = _navigateTo()
export {
redirectTo,
navigateTo,
previewImage,
getSystemInfo,
getSystemInfoSync,
} from '@dcloudio/uni-mp-core'
import { navigateTo as _navigateTo } from '@dcloudio/uni-mp-core'
export const navigateTo = _navigateTo()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册