提交 b932347e 编写于 作者: Q qiang

chore: build

上级 15117167
......@@ -7086,25 +7086,27 @@ var serviceContext = (function () {
return api.openLocation(...array)
}
const callbackIds$2 = [];
const callbackOnErrorIds = [];
const callbackOffErrorIds = [];
let watchId;
let successCallbackIds = [];
let errorCallbackIds = [];
let started = false;
let watchId = 0;
/**
* 开始更新定位
*/
function startLocationUpdate ({ type = 'wgs84' }) {
watchId = plus.geolocation.watchPosition(
function startLocationUpdate ({ type = 'gcj02' }, callbackId) {
watchId = watchId || plus.geolocation.watchPosition(
res => {
callbackIds$2.forEach(callbackId => {
started = true;
successCallbackIds.forEach(callbackId => {
invoke$1(callbackId, res.coords);
});
},
error => {
callbackOnErrorIds.forEach(callbackId => {
if (!started) {
invoke$1(callbackId, { errMsg: `startLocationUpdate:fail ${error.message}` });
started = true;
}
errorCallbackIds.forEach(callbackId => {
invoke$1(callbackId, {
errMsg: 'onLocationChange:fail' + error.message
errMsg: `onLocationChange:fail ${error.message}`
});
});
},
......@@ -7112,58 +7114,50 @@ var serviceContext = (function () {
coordsType: type
}
);
setTimeout(() => {
invoke$1(callbackId, {
errMsg: 'startLocationUpdate:ok'
});
}, 100);
}
/**
* 暂停更新定位
* @param {*} callbackId
*/
function stopLocationUpdate (callbackId) {
if (watchId) {
function stopLocationUpdate () {
if (watchId !== 0) {
plus.geolocation.clearWatch(watchId);
} else {
invoke$1(callbackId, { errMsg: 'stopLocationUpdate:fail' });
started = false;
watchId = 0;
}
return {}
}
/**
* 监听更新定位
* @param {*} callbackId
*/
function onLocationChange (callbackId) {
callbackIds$2.push(callbackId);
}
/**
* 监听更新定位失败
* @param {*} callbackId
*/
function onLocationChangeError (callbackId) {
callbackOnErrorIds.push(callbackId);
successCallbackIds.push(callbackId);
}
// 移除实时地理位置变化事件的监听函数
function offLocationChange (callbackId) {
if (callbackId) {
const index = callbackIds$2.indexOf(callbackId);
const index = successCallbackIds.indexOf(callbackId);
if (index >= 0) {
callbackIds$2.splice(index, 1);
} else {
callbackOffErrorIds.forEach(callbackId => {
invoke$1(callbackId, {
errMsg: 'offLocationChange:fail'
});
});
successCallbackIds.splice(index, 1);
}
} else {
callbackIds$2.length = 0;
successCallbackIds = [];
}
}
// 移除实时地理位置变化事件的监听函数
function onLocationChangeError (callbackId) {
errorCallbackIds.push(callbackId);
}
function offLocationChangeError (callbackId) {
callbackOffErrorIds.push(callbackId);
if (callbackId) {
const index = errorCallbackIds.indexOf(callbackId);
if (index >= 0) {
errorCallbackIds.splice(index, 1);
}
} else {
errorCallbackIds = [];
}
}
const RECORD_TIME = 60 * 60 * 1000;
......@@ -12321,8 +12315,8 @@ var serviceContext = (function () {
startLocationUpdate: startLocationUpdate,
stopLocationUpdate: stopLocationUpdate,
onLocationChange: onLocationChange,
onLocationChangeError: onLocationChangeError,
offLocationChange: offLocationChange,
onLocationChangeError: onLocationChangeError,
offLocationChangeError: offLocationChangeError,
startRecord: startRecord,
stopRecord: stopRecord,
......@@ -20743,6 +20737,7 @@ var serviceContext = (function () {
});
const callbacks$7 = [];
const oldCallbacks = [];
onMethod('onThemeChange', function (res) {
callbacks$7.forEach(callbackId => {
......@@ -20756,13 +20751,13 @@ var serviceContext = (function () {
// 旧版本 API,后期文档更新后考虑移除
onMethod('onUIStyleChange', function (res) {
callbacks$7.forEach(callbackId => {
oldCallbacks.forEach(callbackId => {
invoke$1(callbackId, res);
});
});
function onUIStyleChange (callbackId) {
callbacks$7.push(callbackId);
oldCallbacks.push(callbackId);
console.warn('The "uni.onUIStyleChange" API is deprecated, please use "uni.onThemeChange". Learn more: https://uniapp.dcloud.net.cn/api/system/theme.');
}
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -1823,6 +1823,7 @@ const offPushMessage = (fn) => {
}
};
let onKeyboardHeightChangeCallback;
function startGyroscope (params) {
if (hasOwn(params, 'interval')) {
console.warn('支付宝小程序 startGyroscope暂不支持interval');
......@@ -1908,6 +1909,21 @@ function createIntersectionObserver (component, options) {
delete options.observeAll;
}
return my.createIntersectionObserver(options)
}
function onKeyboardHeightChange (callback) {
// 与微信小程序一致仅保留最后一次监听
if (onKeyboardHeightChangeCallback) {
$off('uni:keyboardHeightChange', onKeyboardHeightChangeCallback);
}
onKeyboardHeightChangeCallback = callback;
$on('uni:keyboardHeightChange', onKeyboardHeightChangeCallback);
}
function offKeyboardHeightChange () {
// 与微信小程序一致移除最后一次监听
$off('uni:keyboardHeightChange', onKeyboardHeightChangeCallback);
onKeyboardHeightChangeCallback = null;
}
var api = /*#__PURE__*/Object.freeze({
......@@ -1915,6 +1931,8 @@ var api = /*#__PURE__*/Object.freeze({
startGyroscope: startGyroscope,
createSelectorQuery: createSelectorQuery,
createIntersectionObserver: createIntersectionObserver,
onKeyboardHeightChange: onKeyboardHeightChange,
offKeyboardHeightChange: offKeyboardHeightChange,
createMediaQueryObserver: createMediaQueryObserver,
setStorageSync: setStorageSync,
getStorageSync: getStorageSync,
......@@ -1925,1025 +1943,1043 @@ var api = /*#__PURE__*/Object.freeze({
invokePushCallback: invokePushCallback
});
const PAGE_EVENT_HOOKS = [
'onPullDownRefresh',
'onReachBottom',
'onAddToFavorites',
'onShareTimeline',
'onShareAppMessage',
'onPageScroll',
'onResize',
'onTabItemTap'
];
function initMocks (vm, mocks) {
const mpInstance = vm.$mp[vm.mpType];
mocks.forEach(mock => {
if (hasOwn(mpInstance, mock)) {
vm[mock] = mpInstance[mock];
function findVmByVueId (vm, vuePid) {
const $children = vm.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm
}
});
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm
}
}
}
function hasHook (hook, vueOptions) {
if (!vueOptions) {
return true
function handleLink (event) {
const {
vuePid,
vueOptions
} = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
let parentVm;
if (vuePid) {
parentVm = findVmByVueId(this.$vm, vuePid);
}
if (Vue.options && Array.isArray(Vue.options[hook])) {
return true
if (!parentVm) {
parentVm = this.$vm;
}
vueOptions = vueOptions.default || vueOptions;
vueOptions.parent = parentVm;
}
const isArray = Array.isArray;
const keyList = Object.keys;
if (isFn(vueOptions)) {
if (isFn(vueOptions.extendOptions[hook])) {
function equal (a, b) {
if (a === b) return true
if (a && b && typeof a === 'object' && typeof b === 'object') {
const arrA = isArray(a);
const arrB = isArray(b);
let i, length, key;
if (arrA && arrB) {
length = a.length;
if (length !== b.length) return false
for (i = length; i-- !== 0;) {
if (!equal(a[i], b[i])) return false
}
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
if (arrA !== arrB) return false
const dateA = a instanceof Date;
const dateB = b instanceof Date;
if (dateA !== dateB) return false
if (dateA && dateB) return a.getTime() === b.getTime()
const regexpA = a instanceof RegExp;
const regexpB = b instanceof RegExp;
if (regexpA !== regexpB) return false
if (regexpA && regexpB) return a.toString() === b.toString()
const keys = keyList(a);
length = keys.length;
if (length !== keyList(b).length) {
return false
}
for (i = length; i-- !== 0;) {
if (!hasOwn.call(b, keys[i])) return false
}
for (i = length; i-- !== 0;) {
key = keys[i];
if (!equal(a[key], b[key])) return false
}
return false
}
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
if (Array.isArray(mixins)) {
return !!mixins.find(mixin => hasHook(hook, mixin))
}
}
function initHooks (mpOptions, hooks, vueOptions) {
hooks.forEach(hook => {
if (hasHook(hook, vueOptions)) {
mpOptions[hook] = function (args) {
return this.$vm && this.$vm.__call_hook(hook, args)
};
}
});
return false
}
const customizeRE = /:/g;
const customize = cached((str) => {
return camelize(str.replace(customizeRE, '-'))
});
const isComponent2 = my.canIUse('component2');
const mocks = ['$id'];
function initRefs () {
}
function initUnknownHooks (mpOptions, vueOptions, excludes = []) {
findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes));
function initRelation (detail) {
this.props.onVueInit(detail);
}
function findHooks (vueOptions, hooks = []) {
if (vueOptions) {
Object.keys(vueOptions).forEach((name) => {
if (name.indexOf('on') === 0 && isFn(vueOptions[name])) {
hooks.push(name);
function initSpecialMethods (mpInstance) {
if (!mpInstance.$vm) {
return
}
let path = mpInstance.is || mpInstance.route;
if (!path) {
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1);
}
const specialMethods = my.specialMethods && my.specialMethods[path];
if (specialMethods) {
specialMethods.forEach(method => {
if (isFn(mpInstance.$vm[method])) {
mpInstance[method] = function (event) {
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {};
event.detail.markerId = event.markerId;
}
// TODO normalizeEvent
mpInstance.$vm[method](event);
};
}
});
}
return hooks
}
function initHook (mpOptions, hook, excludes) {
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
mpOptions[hook] = function (args) {
return this.$vm && this.$vm.__call_hook(hook, args)
};
}
}
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
} else {
VueComponent = Vue.extend(vueOptions);
function initChildVues (mpInstance) {
// 此时需保证当前 mpInstance 已经存在 $vm
if (!mpInstance.$vm) {
return
}
vueOptions = VueComponent.options;
return [VueComponent, vueOptions]
}
mpInstance._$childVues && mpInstance._$childVues.forEach(({
vuePid,
vueOptions,
VueComponent,
mpInstance: childMPInstance
}) => {
// 父子关系
handleLink.call(mpInstance, {
detail: {
vuePid,
vueOptions
}
});
function initVueIds (vueIds, mpInstance) {
vueIds = (vueIds || '').split(',');
const len = vueIds.length;
childMPInstance.$vm = new VueComponent(vueOptions);
if (len === 1) {
mpInstance._$vueId = vueIds[0];
} else if (len === 2) {
mpInstance._$vueId = vueIds[0];
mpInstance._$vuePid = vueIds[1];
}
}
initSpecialMethods(childMPInstance);
function initData (vueOptions, context) {
let data = vueOptions.data || {};
const methods = vueOptions.methods || {};
handleRef.call(vueOptions.parent.$scope, childMPInstance);
if (typeof data === 'function') {
try {
data = data.call(context); // 支持 Vue.prototype 上挂的数据
} catch (e) {
if (process.env.VUE_APP_DEBUG) {
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
}
}
} else {
try {
// 对 data 格式化
data = JSON.parse(JSON.stringify(data));
} catch (e) { }
}
childMPInstance.$vm.$mount();
if (!isPlainObject(data)) {
data = {};
}
initChildVues(childMPInstance);
Object.keys(methods).forEach(methodName => {
if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
data[methodName] = methods[methodName];
}
childMPInstance.$vm._isMounted = true;
childMPInstance.$vm.__call_hook('mounted');
childMPInstance.$vm.__call_hook('onReady');
});
return data
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver (name) {
return function observer (newVal, oldVal) {
if (this.$vm) {
this.$vm[name] = newVal; // 为了触发其他非 render watcher
}
}
delete mpInstance._$childVues;
}
function initBehaviors (vueOptions, initBehavior) {
const vueBehaviors = vueOptions.behaviors;
const vueExtends = vueOptions.extends;
const vueMixins = vueOptions.mixins;
let vueProps = vueOptions.props;
if (!vueProps) {
vueOptions.props = vueProps = [];
}
function handleProps (ref) {
const eventProps = {};
let refProps = ref.props;
const eventList = (refProps['data-event-list'] || '').split(',');
// 初始化支付宝小程序组件事件
eventList.forEach(key => {
const handler = refProps[key];
const res = key.match(/^on([A-Z])(\S*)/);
const event = res && (res[1].toLowerCase() + res[2]);
refProps[key] = eventProps[key] = function () {
const props = Object.assign({}, refProps);
props[key] = handler;
// 由于支付宝事件可能包含多个参数,不使用微信小程序事件格式
delete props['data-com-type'];
triggerEvent.bind({ props })(event, {
__args__: [...arguments]
});
};
});
// 处理 props 重写
Object.defineProperty(ref, 'props', {
get () {
return refProps
},
set (value) {
refProps = Object.assign(value, eventProps);
}
});
}
const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"my"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps.name = {
type: String,
default: ''
};
vueProps.value = {
type: [String, Number, Boolean, Array, Object, Date],
default: ''
};
}
}
});
}
{ // alipay 重复定义props会报错,下边的代码对于其他平台也没有意义,保险起见,仅对alipay做处理
function handleRef (ref) {
if (!(ref && this.$vm)) {
return
}
const refName = ref.props['data-ref'];
const refInForName = ref.props['data-ref-in-for'];
if (refName) {
this.$vm.$refs[refName] = ref.$vm || ref;
} else if (refInForName) {
(this.$vm.$refs[refInForName] || (this.$vm.$refs[refInForName] = [])).push(ref.$vm || ref);
}
}
function parsePropType (key, type, defaultValue, file) {
// [String]=>String
if (Array.isArray(type) && type.length === 1) {
return type[0]
function triggerEvent (type, detail, options) {
const handler = this.props && this.props[customize('on-' + type)];
if (!handler) {
return
}
return type
}
function initProperties (props, isBehavior = false, file = '', options) {
const properties = {};
if (!isBehavior) {
properties.vueId = {
type: String,
value: ''
};
{
{
properties.virtualHostStyle = {
type: null,
value: ''
};
properties.virtualHostClass = {
type: null,
value: ''
};
}
const eventOpts = this.props['data-event-opts'];
const eventParams = this.props['data-event-params'];
const comType = this.props['data-com-type'];
const target = {
dataset: {
eventOpts,
eventParams,
comType
}
// scopedSlotsCompiler auto
properties.scopedSlotsCompiler = {
type: String,
value: ''
};
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type: null,
value: [],
observer: function (newVal, oldVal) {
const $slots = Object.create(null);
newVal.forEach(slotName => {
$slots[slotName] = true;
});
this.setData({
$slots
});
}
};
}
if (Array.isArray(props)) { // ['title']
props.forEach(key => {
properties[key] = {
type: null,
observer: createObserver(key)
};
});
} else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
Object.keys(props).forEach(key => {
const opts = props[key];
if (isPlainObject(opts)) { // title:{type:String,default:''}
let value = opts.default;
if (isFn(value)) {
value = value();
}
};
opts.type = parsePropType(key, opts.type);
handler({
type: customize(type),
target,
currentTarget: target,
detail
});
}
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
value,
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
};
const IGNORES = ['$slots', '$scopedSlots'];
function createObserver (isDidUpdate) {
return function observe (props) {
const prevProps = isDidUpdate ? props : this.props;
const nextProps = isDidUpdate ? this.props : props;
if (equal(prevProps, nextProps)) {
return
}
Object.keys(prevProps).forEach(name => {
if (IGNORES.indexOf(name) === -1) {
const prevValue = prevProps[name];
const nextValue = nextProps[name];
if (!isFn(prevValue) && !isFn(nextValue) && !equal(prevValue, nextValue)) {
this.$vm[name] = nextProps[name];
}
}
});
}
return properties
}
function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) { }
event.stopPropagation = noop;
event.preventDefault = noop;
event.target = event.target || {};
if (!hasOwn(event, 'detail')) {
event.detail = {};
const handleLink$1 = (function () {
if (isComponent2) {
return function handleLink$1 (detail) {
return handleLink.call(this, {
detail
})
}
}
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {};
event.detail.markerId = event.markerId;
return function handleLink$1 (detail) {
if (this.$vm && this.$vm._isMounted) { // 父已初始化
return handleLink.call(this, {
detail: {
vuePid: detail.vuePid,
vueOptions: detail.vueOptions
}
})
}
// 支付宝通过 didMount 来实现,先子后父,故等父 ready 之后,统一初始化
(this._$childVues || (this._$childVues = [])).unshift(detail);
}
})();
if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId;
const list = (mp.props['data-event-list'] || '').split(',');
list.forEach(eventName => {
const key = `${eventName}${vueId}`;
if (destory) {
delete this[key];
} else {
this[key] = function () {
mp.props[eventName].apply(this, arguments);
};
}
});
if (!destory) {
handleProps(mp);
}
};
const MPComponent = Component;
function initHook (name, options) {
const oldHook = options[name];
options[name] = function (...args) {
const props = this.props;
if (props && props['data-com-type'] === 'wx') {
handleProps(this);
}
if (oldHook) {
return oldHook.apply(this, args)
}
};
}
if (!MPComponent.__$wrappered) {
MPComponent.__$wrappered = true;
Component = function (options = {}) {
initHook('onInit', options);
return MPComponent(options)
};
}
const PAGE_EVENT_HOOKS = [
'onPullDownRefresh',
'onReachBottom',
'onAddToFavorites',
'onShareTimeline',
'onShareAppMessage',
'onPageScroll',
'onResize',
'onTabItemTap'
];
return event
function initMocks (vm, mocks) {
const mpInstance = vm.$mp[vm.mpType];
mocks.forEach(mock => {
if (hasOwn(mpInstance, mock)) {
vm[mock] = mpInstance[mock];
}
});
}
function getExtraValue (vm, dataPathsArray) {
let context = vm;
dataPathsArray.forEach(dataPathArray => {
const dataPath = dataPathArray[0];
const value = dataPathArray[2];
if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
const propPath = dataPathArray[1];
const valuePath = dataPathArray[3];
function hasHook (hook, vueOptions) {
if (!vueOptions) {
return true
}
let vFor;
if (Number.isInteger(dataPath)) {
vFor = dataPath;
} else if (!dataPath) {
vFor = context;
} else if (typeof dataPath === 'string' && dataPath) {
if (dataPath.indexOf('#s#') === 0) {
vFor = dataPath.substr(3);
} else {
vFor = vm.__get_value(dataPath, context);
}
}
if (Vue.options && Array.isArray(Vue.options[hook])) {
return true
}
if (Number.isInteger(vFor)) {
context = value;
} else if (!propPath) {
context = vFor[value];
} else {
if (Array.isArray(vFor)) {
context = vFor.find(vForItem => {
return vm.__get_value(propPath, vForItem) === value
});
} else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find(vForKey => {
return vm.__get_value(propPath, vFor[vForKey]) === value
});
} else {
console.error('v-for 暂不支持循环数据:', vFor);
}
}
vueOptions = vueOptions.default || vueOptions;
if (valuePath) {
context = vm.__get_value(valuePath, context);
}
if (isFn(vueOptions)) {
if (isFn(vueOptions.extendOptions[hook])) {
return true
}
});
return context
}
function processEventExtra (vm, extra, event, __args__) {
const extraObj = {};
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
extraObj['$' + index] = vm;
} else {
if (dataPath === '$event') { // $event
extraObj['$' + index] = event;
} else if (dataPath === 'arguments') {
extraObj['$' + index] = event.detail ? event.detail.__args__ || __args__ : __args__;
} else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
} else {
extraObj['$' + index] = vm.__get_value(dataPath);
}
}
} else {
extraObj['$' + index] = getExtraValue(vm, dataPath);
}
});
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
}
return extraObj
}
function getObjByArray (arr) {
const obj = {};
for (let i = 1; i < arr.length; i++) {
const element = arr[i];
obj[element[0]] = element[1];
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
return obj
}
function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
// fixed 用户直接触发 mpInstance.triggerEvent
const __args__ = isPlainObject(event.detail)
? event.detail.__args__ || [event.detail]
: [event.detail];
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
}
return __args__
}
const mixins = vueOptions.mixins;
if (Array.isArray(mixins)) {
return !!mixins.find(mixin => hasHook(hook, mixin))
}
}
const extraObj = processEventExtra(vm, extra, event, __args__);
const ret = [];
args.forEach(arg => {
if (arg === '$event') {
if (methodName === '__set_model' && !isCustom) { // input v-model value
ret.push(event.target.value);
} else {
if (isCustom && !isCustomMPEvent) {
ret.push(__args__[0]);
} else { // wxcomponent 组件或内置组件
ret.push(event);
}
}
} else {
if (Array.isArray(arg) && arg[0] === 'o') {
ret.push(getObjByArray(arg));
} else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
ret.push(extraObj[arg]);
} else {
ret.push(arg);
}
function initHooks (mpOptions, hooks, vueOptions) {
hooks.forEach(hook => {
if (hasHook(hook, vueOptions)) {
mpOptions[hook] = function (args) {
return this.$vm && this.$vm.__call_hook(hook, args)
};
}
});
return ret
}
const ONCE = '~';
const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
function initUnknownHooks (mpOptions, vueOptions, excludes = []) {
findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes));
}
function getContextVm (vm) {
let $parent = vm.$parent;
// 父组件是 scoped slots 或者其他自定义组件时继续查找
while ($parent && $parent.$parent && ($parent.$options.generic || $parent.$parent.$options.generic || $parent.$scope._$vuePid)) {
$parent = $parent.$parent;
function findHooks (vueOptions, hooks = []) {
if (vueOptions) {
Object.keys(vueOptions).forEach((name) => {
if (name.indexOf('on') === 0 && isFn(vueOptions[name])) {
hooks.push(name);
}
});
}
return $parent && $parent.$parent
return hooks
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn('事件信息不存在')
}
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn('事件信息不存在')
function initHook$1 (mpOptions, hook, excludes) {
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
mpOptions[hook] = function (args) {
return this.$vm && this.$vm.__call_hook(hook, args)
};
}
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
const isCustom = type.charAt(0) === CUSTOM;
type = isCustom ? type.slice(1) : type;
const isOnce = type.charAt(0) === ONCE;
type = isOnce ? type.slice(1) : type;
if (eventsArray && isMatchEventType(eventType, type)) {
eventsArray.forEach(eventArray => {
const methodName = eventArray[0];
if (methodName) {
let handlerCtx = this.$vm;
if (handlerCtx.$options.generic) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = getContextVm(handlerCtx) || handlerCtx;
}
if (methodName === '$emit') {
handlerCtx.$emit.apply(handlerCtx,
processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
return
}
const handler = handlerCtx[methodName];
if (!isFn(handler)) {
const type = this.$vm.mpType === 'page' ? 'Page' : 'Component';
const path = this.route || this.is;
throw new Error(`${type} "${path}" does not have a method "${methodName}"`)
}
if (isOnce) {
if (handler.once) {
return
}
handler.once = true;
}
let params = processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function initScopedSlotsParams () {
const center = {};
const parents = {};
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
const has = center[vueId];
if (!has) {
parents[vueId] = this;
this.$on('hook:destroyed', () => {
delete parents[vueId];
});
}
return has
};
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
const data = center[vueId];
if (data) {
const object = data[name] || {};
return key ? object[key] : object
} else {
parents[vueId] = this;
this.$on('hook:destroyed', () => {
delete parents[vueId];
});
}
};
Vue.prototype.$setScopedSlotsParams = function (name, value) {
const vueIds = this.$options.propsData.vueId;
if (vueIds) {
const vueId = vueIds.split(',')[0];
const object = center[vueId] = center[vueId] || {};
object[name] = value;
if (parents[vueId]) {
parents[vueId].$forceUpdate();
}
}
};
Vue.mixin({
destroyed () {
const propsData = this.$options.propsData;
const vueId = propsData && propsData.vueId;
if (vueId) {
delete center[vueId];
delete parents[vueId];
}
}
});
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
{
initScopedSlotsParams();
}
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-alipay";
Vue.mixin({
beforeCreate () {
if (!this.$options.mpType) {
return
}
this.mpType = this.$options.mpType;
this.$mp = {
data: {},
[this.mpType]: this.$options.mpInstance
};
this.$scope = this.$options.mpInstance;
delete this.$options.mpType;
delete this.$options.mpInstance;
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
const app = getApp();
if (app.$vm && app.$vm.$i18n) {
this._i18n = app.$vm.$i18n;
}
}
if (this.mpType !== 'app') {
initRefs(this);
initMocks(this, mocks);
}
}
});
const appOptions = {
onLaunch (args) {
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
return
}
this.$vm = vm;
this.$vm.$mp = {
app: this
};
this.$vm.$scope = this;
// vm 上也挂载 globalData
this.$vm.globalData = this.globalData;
this.$vm._isMounted = true;
this.$vm.__call_hook('mounted', args);
this.$vm.__call_hook('onLaunch', args);
}
};
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initAppLocale(Vue, vm, normalizeLocale(my.getSystemInfoSync().language) || LOCALE_EN);
initHooks(appOptions, hooks);
initUnknownHooks(appOptions, vm.$options);
return appOptions
}
function findVmByVueId (vm, vuePid) {
const $children = vm.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm
}
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
} else {
VueComponent = Vue.extend(vueOptions);
}
vueOptions = VueComponent.options;
return [VueComponent, vueOptions]
}
function handleLink (event) {
const {
vuePid,
vueOptions
} = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
let parentVm;
if (vuePid) {
parentVm = findVmByVueId(this.$vm, vuePid);
}
function initVueIds (vueIds, mpInstance) {
vueIds = (vueIds || '').split(',');
const len = vueIds.length;
if (!parentVm) {
parentVm = this.$vm;
if (len === 1) {
mpInstance._$vueId = vueIds[0];
} else if (len === 2) {
mpInstance._$vueId = vueIds[0];
mpInstance._$vuePid = vueIds[1];
}
}
vueOptions.parent = parentVm;
}
const isArray = Array.isArray;
const keyList = Object.keys;
function equal (a, b) {
if (a === b) return true
function initData (vueOptions, context) {
let data = vueOptions.data || {};
const methods = vueOptions.methods || {};
if (a && b && typeof a === 'object' && typeof b === 'object') {
const arrA = isArray(a);
const arrB = isArray(b);
let i, length, key;
if (arrA && arrB) {
length = a.length;
if (length !== b.length) return false
for (i = length; i-- !== 0;) {
if (!equal(a[i], b[i])) return false
if (typeof data === 'function') {
try {
data = data.call(context); // 支持 Vue.prototype 上挂的数据
} catch (e) {
if (process.env.VUE_APP_DEBUG) {
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
}
return true
}
if (arrA !== arrB) return false
const dateA = a instanceof Date;
const dateB = b instanceof Date;
if (dateA !== dateB) return false
if (dateA && dateB) return a.getTime() === b.getTime()
} else {
try {
// 对 data 格式化
data = JSON.parse(JSON.stringify(data));
} catch (e) { }
}
const regexpA = a instanceof RegExp;
const regexpB = b instanceof RegExp;
if (regexpA !== regexpB) return false
if (regexpA && regexpB) return a.toString() === b.toString()
if (!isPlainObject(data)) {
data = {};
}
const keys = keyList(a);
length = keys.length;
if (length !== keyList(b).length) {
return false
}
for (i = length; i-- !== 0;) {
if (!hasOwn.call(b, keys[i])) return false
}
for (i = length; i-- !== 0;) {
key = keys[i];
if (!equal(a[key], b[key])) return false
Object.keys(methods).forEach(methodName => {
if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
data[methodName] = methods[methodName];
}
});
return true
}
return data
}
return false
}
const customizeRE = /:/g;
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
const customize = cached((str) => {
return camelize(str.replace(customizeRE, '-'))
});
function createObserver$1 (name) {
return function observer (newVal, oldVal) {
if (this.$vm) {
this.$vm[name] = newVal; // 为了触发其他非 render watcher
}
}
}
const isComponent2 = my.canIUse('component2');
function initBehaviors (vueOptions, initBehavior) {
const vueBehaviors = vueOptions.behaviors;
const vueExtends = vueOptions.extends;
const vueMixins = vueOptions.mixins;
const mocks = ['$id'];
let vueProps = vueOptions.props;
function initRefs () {
if (!vueProps) {
vueOptions.props = vueProps = [];
}
const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"my"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps.name = {
type: String,
default: ''
};
vueProps.value = {
type: [String, Number, Boolean, Array, Object, Date],
default: ''
};
}
}
});
}
{ // alipay 重复定义props会报错,下边的代码对于其他平台也没有意义,保险起见,仅对alipay做处理
return
}
}
function initRelation (detail) {
this.props.onVueInit(detail);
function parsePropType (key, type, defaultValue, file) {
// [String]=>String
if (Array.isArray(type) && type.length === 1) {
return type[0]
}
return type
}
function initSpecialMethods (mpInstance) {
if (!mpInstance.$vm) {
return
}
let path = mpInstance.is || mpInstance.route;
if (!path) {
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1);
function initProperties (props, isBehavior = false, file = '', options) {
const properties = {};
if (!isBehavior) {
properties.vueId = {
type: String,
value: ''
};
{
{
properties.virtualHostStyle = {
type: null,
value: ''
};
properties.virtualHostClass = {
type: null,
value: ''
};
}
}
// scopedSlotsCompiler auto
properties.scopedSlotsCompiler = {
type: String,
value: ''
};
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type: null,
value: [],
observer: function (newVal, oldVal) {
const $slots = Object.create(null);
newVal.forEach(slotName => {
$slots[slotName] = true;
});
this.setData({
$slots
});
}
};
}
const specialMethods = my.specialMethods && my.specialMethods[path];
if (specialMethods) {
specialMethods.forEach(method => {
if (isFn(mpInstance.$vm[method])) {
mpInstance[method] = function (event) {
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {};
event.detail.markerId = event.markerId;
}
// TODO normalizeEvent
mpInstance.$vm[method](event);
if (Array.isArray(props)) { // ['title']
props.forEach(key => {
properties[key] = {
type: null,
observer: createObserver$1(key)
};
});
} else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
Object.keys(props).forEach(key => {
const opts = props[key];
if (isPlainObject(opts)) { // title:{type:String,default:''}
let value = opts.default;
if (isFn(value)) {
value = value();
}
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
value,
observer: createObserver$1(key)
};
} else { // content:String
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver$1(key)
};
}
});
}
return properties
}
function initChildVues (mpInstance) {
// 此时需保证当前 mpInstance 已经存在 $vm
if (!mpInstance.$vm) {
return
}
mpInstance._$childVues && mpInstance._$childVues.forEach(({
vuePid,
vueOptions,
VueComponent,
mpInstance: childMPInstance
}) => {
// 父子关系
handleLink.call(mpInstance, {
detail: {
vuePid,
vueOptions
}
});
function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) { }
event.stopPropagation = noop;
event.preventDefault = noop;
childMPInstance.$vm = new VueComponent(vueOptions);
event.target = event.target || {};
initSpecialMethods(childMPInstance);
if (!hasOwn(event, 'detail')) {
event.detail = {};
}
handleRef.call(vueOptions.parent.$scope, childMPInstance);
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {};
event.detail.markerId = event.markerId;
}
childMPInstance.$vm.$mount();
if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
}
initChildVues(childMPInstance);
return event
}
childMPInstance.$vm._isMounted = true;
childMPInstance.$vm.__call_hook('mounted');
childMPInstance.$vm.__call_hook('onReady');
});
function getExtraValue (vm, dataPathsArray) {
let context = vm;
dataPathsArray.forEach(dataPathArray => {
const dataPath = dataPathArray[0];
const value = dataPathArray[2];
if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
const propPath = dataPathArray[1];
const valuePath = dataPathArray[3];
delete mpInstance._$childVues;
}
let vFor;
if (Number.isInteger(dataPath)) {
vFor = dataPath;
} else if (!dataPath) {
vFor = context;
} else if (typeof dataPath === 'string' && dataPath) {
if (dataPath.indexOf('#s#') === 0) {
vFor = dataPath.substr(3);
} else {
vFor = vm.__get_value(dataPath, context);
}
}
function handleProps (ref) {
const eventProps = {};
let refProps = ref.props;
const eventList = (refProps['data-event-list'] || '').split(',');
// 初始化支付宝小程序组件事件
Object.keys(refProps).forEach(key => {
if (eventList.includes(key)) {
const handler = refProps[key];
const res = key.match(/^on([A-Z])(\S*)/);
const event = res && (res[1].toLowerCase() + res[2]);
refProps[key] = eventProps[key] = function () {
const props = Object.assign({}, refProps);
props[key] = handler;
// 由于支付宝事件可能包含多个参数,不使用微信小程序事件格式
delete props['data-com-type'];
triggerEvent.bind({ props })(event, {
__args__: [...arguments]
});
};
}
});
// 处理 props 重写
Object.defineProperty(ref, 'props', {
get () {
return refProps
},
set (value) {
refProps = Object.assign(value, eventProps);
if (Number.isInteger(vFor)) {
context = value;
} else if (!propPath) {
context = vFor[value];
} else {
if (Array.isArray(vFor)) {
context = vFor.find(vForItem => {
return vm.__get_value(propPath, vForItem) === value
});
} else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find(vForKey => {
return vm.__get_value(propPath, vFor[vForKey]) === value
});
} else {
console.error('v-for 暂不支持循环数据:', vFor);
}
}
if (valuePath) {
context = vm.__get_value(valuePath, context);
}
}
});
return context
}
function handleRef (ref) {
if (!(ref && this.$vm)) {
return
}
if (ref.props['data-com-type'] === 'wx') {
handleProps(ref);
}
const refName = ref.props['data-ref'];
const refInForName = ref.props['data-ref-in-for'];
if (refName) {
this.$vm.$refs[refName] = ref.$vm || ref;
} else if (refInForName) {
(this.$vm.$refs[refInForName] || (this.$vm.$refs[refInForName] = [])).push(ref.$vm || ref);
function processEventExtra (vm, extra, event, __args__) {
const extraObj = {};
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
extraObj['$' + index] = vm;
} else {
if (dataPath === '$event') { // $event
extraObj['$' + index] = event;
} else if (dataPath === 'arguments') {
extraObj['$' + index] = event.detail ? event.detail.__args__ || __args__ : __args__;
} else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
} else {
extraObj['$' + index] = vm.__get_value(dataPath);
}
}
} else {
extraObj['$' + index] = getExtraValue(vm, dataPath);
}
});
}
return extraObj
}
function triggerEvent (type, detail, options) {
const handler = this.props && this.props[customize('on-' + type)];
if (!handler) {
return
function getObjByArray (arr) {
const obj = {};
for (let i = 1; i < arr.length; i++) {
const element = arr[i];
obj[element[0]] = element[1];
}
return obj
}
const eventOpts = this.props['data-event-opts'];
const eventParams = this.props['data-event-params'];
const comType = this.props['data-com-type'];
function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
const target = {
dataset: {
eventOpts,
eventParams,
comType
// fixed 用户直接触发 mpInstance.triggerEvent
const __args__ = isPlainObject(event.detail)
? event.detail.__args__ || [event.detail]
: [event.detail];
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
}
return __args__
}
};
}
handler({
type: customize(type),
target,
currentTarget: target,
detail
const extraObj = processEventExtra(vm, extra, event, __args__);
const ret = [];
args.forEach(arg => {
if (arg === '$event') {
if (methodName === '__set_model' && !isCustom) { // input v-model value
ret.push(event.target.value);
} else {
if (isCustom && !isCustomMPEvent) {
ret.push(__args__[0]);
} else { // wxcomponent 组件或内置组件
ret.push(event);
}
}
} else {
if (Array.isArray(arg) && arg[0] === 'o') {
ret.push(getObjByArray(arg));
} else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
ret.push(extraObj[arg]);
} else {
ret.push(arg);
}
}
});
return ret
}
const IGNORES = ['$slots', '$scopedSlots'];
const ONCE = '~';
const CUSTOM = '^';
function createObserver$1 (isDidUpdate) {
return function observe (props) {
const prevProps = isDidUpdate ? props : this.props;
const nextProps = isDidUpdate ? this.props : props;
if (equal(prevProps, nextProps)) {
return
}
Object.keys(prevProps).forEach(name => {
if (IGNORES.indexOf(name) === -1) {
const prevValue = prevProps[name];
const nextValue = nextProps[name];
if (!isFn(prevValue) && !isFn(nextValue) && !equal(prevValue, nextValue)) {
this.$vm[name] = nextProps[name];
}
}
});
}
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
const handleLink$1 = (function () {
if (isComponent2) {
return function handleLink$1 (detail) {
return handleLink.call(this, {
detail
})
}
function getContextVm (vm) {
let $parent = vm.$parent;
// 父组件是 scoped slots 或者其他自定义组件时继续查找
while ($parent && $parent.$parent && ($parent.$options.generic || $parent.$parent.$options.generic || $parent.$scope._$vuePid)) {
$parent = $parent.$parent;
}
return function handleLink$1 (detail) {
if (this.$vm && this.$vm._isMounted) { // 父已初始化
return handleLink.call(this, {
detail: {
vuePid: detail.vuePid,
vueOptions: detail.vueOptions
}
})
}
// 支付宝通过 didMount 来实现,先子后父,故等父 ready 之后,统一初始化
(this._$childVues || (this._$childVues = [])).unshift(detail);
return $parent && $parent.$parent
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn('事件信息不存在')
}
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn('事件信息不存在')
}
})();
const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId;
const list = (mp.props['data-event-list'] || '').split(',');
list.forEach(eventName => {
const key = `${eventName}${vueId}`;
if (destory) {
delete this[key];
} else {
this[key] = function () {
mp.props[eventName].apply(this, arguments);
};
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
const isCustom = type.charAt(0) === CUSTOM;
type = isCustom ? type.slice(1) : type;
const isOnce = type.charAt(0) === ONCE;
type = isOnce ? type.slice(1) : type;
if (eventsArray && isMatchEventType(eventType, type)) {
eventsArray.forEach(eventArray => {
const methodName = eventArray[0];
if (methodName) {
let handlerCtx = this.$vm;
if (handlerCtx.$options.generic) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = getContextVm(handlerCtx) || handlerCtx;
}
if (methodName === '$emit') {
handlerCtx.$emit.apply(handlerCtx,
processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
return
}
const handler = handlerCtx[methodName];
if (!isFn(handler)) {
const type = this.$vm.mpType === 'page' ? 'Page' : 'Component';
const path = this.route || this.is;
throw new Error(`${type} "${path}" does not have a method "${methodName}"`)
}
if (isOnce) {
if (handler.once) {
return
}
handler.once = true;
}
let params = processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
});
if (!destory) {
handleProps(mp);
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
};
}
const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function initScopedSlotsParams () {
const center = {};
const parents = {};
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
const has = center[vueId];
if (!has) {
parents[vueId] = this;
this.$on('hook:destroyed', () => {
delete parents[vueId];
});
}
return has
};
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
const data = center[vueId];
if (data) {
const object = data[name] || {};
return key ? object[key] : object
} else {
parents[vueId] = this;
this.$on('hook:destroyed', () => {
delete parents[vueId];
});
}
};
Vue.prototype.$setScopedSlotsParams = function (name, value) {
const vueIds = this.$options.propsData.vueId;
if (vueIds) {
const vueId = vueIds.split(',')[0];
const object = center[vueId] = center[vueId] || {};
object[name] = value;
if (parents[vueId]) {
parents[vueId].$forceUpdate();
}
}
};
Vue.mixin({
destroyed () {
const propsData = this.$options.propsData;
const vueId = propsData && propsData.vueId;
if (vueId) {
delete center[vueId];
delete parents[vueId];
}
}
});
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
{
initScopedSlotsParams();
}
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-alipay";
Vue.mixin({
beforeCreate () {
if (!this.$options.mpType) {
return
}
this.mpType = this.$options.mpType;
this.$mp = {
data: {},
[this.mpType]: this.$options.mpInstance
};
this.$scope = this.$options.mpInstance;
delete this.$options.mpType;
delete this.$options.mpInstance;
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
const app = getApp();
if (app.$vm && app.$vm.$i18n) {
this._i18n = app.$vm.$i18n;
}
}
if (this.mpType !== 'app') {
initRefs(this);
initMocks(this, mocks);
}
}
});
const appOptions = {
onLaunch (args) {
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
return
}
this.$vm = vm;
this.$vm.$mp = {
app: this
};
this.$vm.$scope = this;
// vm 上也挂载 globalData
this.$vm.globalData = this.globalData;
this.$vm._isMounted = true;
this.$vm.__call_hook('mounted', args);
this.$vm.__call_hook('onLaunch', args);
}
};
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initAppLocale(Vue, vm, normalizeLocale(my.getSystemInfoSync().language) || LOCALE_EN);
initHooks(appOptions, hooks);
initUnknownHooks(appOptions, vm.$options);
return appOptions
}
function parseApp (vm) {
Vue.prototype.$onAliGetAuthorize = function onAliGetAuthorize (method, $event) {
......@@ -3084,6 +3120,9 @@ function parsePage (vuePageOptions) {
// 支付宝小程序有些页面事件只能放在events下
onBack () {
this.$vm.__call_hook('onBackPress');
},
onKeyboardHeight (res) {
$emit('uni:keyboardHeightChange', res);
}
},
__r: handleRef,
......@@ -3244,9 +3283,9 @@ function parseComponent (vueComponentOptions, needVueOptions) {
componentOptions.onInit = function onInit () {
initVm.call(this, VueComponent);
};
componentOptions.deriveDataFromProps = createObserver$1();
componentOptions.deriveDataFromProps = createObserver();
} else {
componentOptions.didUpdate = createObserver$1(true);
componentOptions.didUpdate = createObserver(true);
}
if (Array.isArray(vueOptions.wxsCallMethods)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册