提交 296da01b 编写于 作者: Q qiang

build runtime

上级 9120bfb0
...@@ -1434,10 +1434,15 @@ function getEventChannel (id) { ...@@ -1434,10 +1434,15 @@ function getEventChannel (id) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("app-plus") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -2281,10 +2281,15 @@ function parseApp (vm) { ...@@ -2281,10 +2281,15 @@ function parseApp (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-alipay") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -1728,10 +1728,15 @@ function parseApp (vm) { ...@@ -1728,10 +1728,15 @@ function parseApp (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-baidu") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -1474,10 +1474,15 @@ function parseApp$1 (vm) { ...@@ -1474,10 +1474,15 @@ function parseApp$1 (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-kuaishou") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -1640,10 +1640,15 @@ function parseApp$1 (vm) { ...@@ -1640,10 +1640,15 @@ function parseApp$1 (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-qq") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -1807,10 +1807,15 @@ function parseApp (vm) { ...@@ -1807,10 +1807,15 @@ function parseApp (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-toutiao") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -356,111 +356,6 @@ var baseApi = /*#__PURE__*/Object.freeze({ ...@@ -356,111 +356,6 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors interceptors: interceptors
}); });
class EventChannel {
constructor (id, events) {
this.id = id;
this.listener = {};
this.emitCache = {};
if (events) {
Object.keys(events).forEach(name => {
this.on(name, events[name]);
});
}
}
emit (eventName, ...args) {
const fns = this.listener[eventName];
if (!fns) {
return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
}
fns.forEach(opt => {
opt.fn.apply(opt.fn, args);
});
this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
}
on (eventName, fn) {
this._addListener(eventName, 'on', fn);
this._clearCache(eventName);
}
once (eventName, fn) {
this._addListener(eventName, 'once', fn);
this._clearCache(eventName);
}
off (eventName, fn) {
const fns = this.listener[eventName];
if (!fns) {
return
}
if (fn) {
for (let i = 0; i < fns.length;) {
if (fns[i].fn === fn) {
fns.splice(i, 1);
i--;
}
i++;
}
} else {
delete this.listener[eventName];
}
}
_clearCache (eventName) {
const cacheArgs = this.emitCache[eventName];
if (cacheArgs) {
for (; cacheArgs.length > 0;) {
this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
}
}
}
_addListener (eventName, type, fn) {
(this.listener[eventName] || (this.listener[eventName] = [])).push({
fn,
type
});
}
}
const eventChannels = {};
const eventChannelStack = [];
let id = 0;
function initEventChannel (events, cache = true) {
id++;
const eventChannel = new EventChannel(id, events);
if (cache) {
eventChannels[id] = eventChannel;
eventChannelStack.push(eventChannel);
}
return eventChannel
}
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
var navigateTo = {
args (fromArgs, toArgs) {
const id = initEventChannel(fromArgs.events).id;
if (fromArgs.url) {
fromArgs.url = fromArgs.url + (fromArgs.url.indexOf('?') === -1 ? '?' : '&') + '__id__=' + id;
}
},
returnValue (fromRes, toRes) {
fromRes.eventChannel = getEventChannel();
}
};
function findExistsPageIndex (url) { function findExistsPageIndex (url) {
const pages = getCurrentPages(); const pages = getCurrentPages();
let len = pages.length; let len = pages.length;
...@@ -527,6 +422,8 @@ var previewImage = { ...@@ -527,6 +422,8 @@ var previewImage = {
} }
}; };
// import navigateTo from 'uni-helpers/navigate-to'
function addSafeAreaInsets (result) { function addSafeAreaInsets (result) {
if (result.safeArea) { if (result.safeArea) {
const safeArea = result.safeArea; const safeArea = result.safeArea;
...@@ -540,7 +437,7 @@ function addSafeAreaInsets (result) { ...@@ -540,7 +437,7 @@ function addSafeAreaInsets (result) {
} }
const protocols = { const protocols = {
redirectTo, redirectTo,
navigateTo, // navigateTo, // 由于在微信开发者工具的页面参数,会显示__id__参数,因此暂时关闭mp-weixin对于navigateTo的AOP
previewImage, previewImage,
getSystemInfo: { getSystemInfo: {
returnValue: addSafeAreaInsets returnValue: addSafeAreaInsets
...@@ -790,6 +687,74 @@ Component = function (options = {}) { ...@@ -790,6 +687,74 @@ Component = function (options = {}) {
return MPComponent(options) return MPComponent(options)
}; };
class EventChannel {
constructor (id, events) {
this.id = id;
this.listener = {};
this.emitCache = {};
if (events) {
Object.keys(events).forEach(name => {
this.on(name, events[name]);
});
}
}
emit (eventName, ...args) {
const fns = this.listener[eventName];
if (!fns) {
return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
}
fns.forEach(opt => {
opt.fn.apply(opt.fn, args);
});
this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
}
on (eventName, fn) {
this._addListener(eventName, 'on', fn);
this._clearCache(eventName);
}
once (eventName, fn) {
this._addListener(eventName, 'once', fn);
this._clearCache(eventName);
}
off (eventName, fn) {
const fns = this.listener[eventName];
if (!fns) {
return
}
if (fn) {
for (let i = 0; i < fns.length;) {
if (fns[i].fn === fn) {
fns.splice(i, 1);
i--;
}
i++;
}
} else {
delete this.listener[eventName];
}
}
_clearCache (eventName) {
const cacheArgs = this.emitCache[eventName];
if (cacheArgs) {
for (; cacheArgs.length > 0;) {
this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
}
}
}
_addListener (eventName, type, fn) {
(this.listener[eventName] || (this.listener[eventName] = [])).push({
fn,
type
});
}
}
const PAGE_EVENT_HOOKS = [ const PAGE_EVENT_HOOKS = [
'onPullDownRefresh', 'onPullDownRefresh',
'onReachBottom', 'onReachBottom',
...@@ -1505,12 +1470,30 @@ function parseApp (vm) { ...@@ -1505,12 +1470,30 @@ function parseApp (vm) {
}) })
} }
const eventChannels = {};
const eventChannelStack = [];
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("mp-weixin") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
...@@ -1552,10 +1552,15 @@ function parseApp (vm) { ...@@ -1552,10 +1552,15 @@ function parseApp (vm) {
function createApp (vm) { function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
switch ("quickapp-webview") {
case 'mp-weixin':
return this.$scope.getOpenerEventChannel()
default :
if (!this.__eventChannel__) { if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel(); this.__eventChannel__ = new EventChannel();
} }
return this.__eventChannel__ return this.__eventChannel__
}
}; };
const callHook = Vue.prototype.__call_hook; const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) { Vue.prototype.__call_hook = function (hook, args) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册