提交 9cd72a49 编写于 作者: Q qiang

chore: build

上级 d93855c9
......@@ -1132,7 +1132,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -1878,21 +1878,40 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -1900,7 +1919,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -1994,7 +2013,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2077,26 +2096,29 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
function parseComponent$1 (vueComponentOptions) {
const componentOptions = parseComponent(vueComponentOptions);
function parseComponent$1 (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseComponent(vueComponentOptions, true);
componentOptions.methods.$getAppWebview = function () {
return plus.webview.getWebviewById(`${this.__wxWebviewId__}`)
};
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$2 = [
......@@ -2107,13 +2129,10 @@ const hooks$2 = [
hooks$2.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent$1(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$2, vuePageOptions);
initHooks(pageOptions.methods, hooks$2, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2133,10 +2152,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, {
isPage,
initRelation
})
return parseBasePage(vuePageOptions)
}
const hooks$3 = [
......@@ -2252,7 +2268,7 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
if (typeof wx[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, wx[name]))
......
......@@ -57,7 +57,13 @@ var serviceContext = (function () {
'getLocation',
'chooseLocation',
'openLocation',
'createMapContext'
'createMapContext',
'onLocationChange',
'onLocationChangeError',
'startLocationUpdate',
'stopLocationUpdate',
'offLocationChange',
'offLocationChangeError'
];
const media = [
......@@ -7086,6 +7092,86 @@ var serviceContext = (function () {
return api.openLocation(...array)
}
const callbackIds$2 = [];
const callbackOnErrorIds = [];
const callbackOffErrorIds = [];
let watchId;
/**
* 开始更新定位
*/
function startLocationUpdate ({ type = 'wgs84' }) {
watchId = plus.geolocation.watchPosition(
res => {
callbackIds$2.forEach(callbackId => {
invoke$1(callbackId, res.coords);
});
},
error => {
callbackOnErrorIds.forEach(callbackId => {
invoke$1(callbackId, {
errMsg: 'onLocationChange:fail' + error.message
});
});
},
{
coordsType: type
}
);
}
/**
* 暂停更新定位
* @param {*} callbackId
*/
function stopLocationUpdate (callbackId) {
if (watchId) {
plus.geolocation.clearWatch(watchId);
} else {
invoke$1(callbackId, { errMsg: 'stopLocationUpdate:fail' });
}
return {}
}
/**
* 监听更新定位
* @param {*} callbackId
*/
function onLocationChange (callbackId) {
callbackIds$2.push(callbackId);
}
/**
* 监听更新定位失败
* @param {*} callbackId
*/
function onLocationChangeError (callbackId) {
callbackOnErrorIds.push(callbackId);
}
// 移除实时地理位置变化事件的监听函数
function offLocationChange (callbackId) {
if (callbackId) {
const index = callbackIds$2.indexOf(callbackId);
if (index >= 0) {
callbackIds$2.splice(index, 1);
} else {
callbackOffErrorIds.forEach(callbackId => {
invoke$1(callbackId, {
errMsg: 'offLocationChange:fail'
});
});
}
} else {
callbackIds$2.length = 0;
}
}
// 移除实时地理位置变化事件的监听函数
function offLocationChangeError (callbackId) {
callbackOffErrorIds.push(callbackId);
}
const RECORD_TIME = 60 * 60 * 1000;
let recorder;
......@@ -11790,7 +11876,9 @@ var serviceContext = (function () {
const data = {
code: e.code,
errMsg: e.message
errCode: e.code,
errMsg: e.message,
detail: e.detail
};
this._adError = data;
......@@ -11800,6 +11888,7 @@ var serviceContext = (function () {
const error = new Error(JSON.stringify(this._adError));
error.code = e.code;
error.errMsg = e.message;
error.detail = e.detail;
if (this._loadPromiseReject != null) {
this._loadPromiseReject(error);
......@@ -12235,6 +12324,12 @@ var serviceContext = (function () {
chooseLocation: chooseLocation$3,
getLocation: getLocation$1,
openLocation: openLocation$3,
startLocationUpdate: startLocationUpdate,
stopLocationUpdate: stopLocationUpdate,
onLocationChange: onLocationChange,
onLocationChangeError: onLocationChangeError,
offLocationChange: offLocationChange,
offLocationChangeError: offLocationChangeError,
startRecord: startRecord,
stopRecord: stopRecord,
playVoice: playVoice,
......@@ -21500,11 +21595,28 @@ var serviceContext = (function () {
}
const onPushMessageCallbacks = [];
let listening = false;
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
// 不能程序启动时就监听,因为离线事件,仅触发一次,框架监听后,无法转发给还没开始监听的开发者
if ( !listening) {
listening = true;
plus.push.addEventListener('click', (result) => {
invokePushCallback({
type: 'click',
message: result
});
});
plus.push.addEventListener('receive', (result) => {
invokePushCallback({
type: 'pushMsg',
message: result
});
});
}
};
const offPushMessage = (fn) => {
......
此差异已折叠。
此差异已折叠。
......@@ -1968,7 +1968,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2843,7 +2843,7 @@ function handleProps (ref) {
}
function handleRef (ref) {
if (!ref) {
if (!(ref && this.$vm)) {
return
}
if (ref.props['data-com-type'] === 'wx') {
......@@ -3093,8 +3093,10 @@ function parsePage (vuePageOptions) {
triggerEvent
};
initHooks(pageOptions, hooks$1, vuePageOptions);
initUnknownHooks(pageOptions, vuePageOptions, ['onReady']);
Object.assign(pageOptions.events, vueOptions.events || {});
initHooks(pageOptions, hooks$1, vueOptions);
initUnknownHooks(pageOptions, vueOptions, ['onReady']);
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
......@@ -3192,7 +3194,7 @@ function initVm (VueComponent) {
}
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const properties = initProperties(vueOptions.props, false, vueOptions.__file);
......@@ -3255,7 +3257,7 @@ function parseComponent (vueComponentOptions) {
});
}
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
function createComponent (vueOptions) {
......@@ -3356,7 +3358,7 @@ if (typeof Proxy !== 'undefined' && "mp-alipay" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(my, name) && !hasOwn(protocols, name)) {
if (typeof my[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, my[name]))
......
......@@ -1488,11 +1488,20 @@ function requestPayment (params) {
} else {
swan.requestPolymerPayment(params);
}
}
function createIntersectionObserver (component, options) {
if (options && options.observeAll) {
options.selectAll = options.observeAll;
delete options.observeAll;
}
return swan.createIntersectionObserver(component, options)
}
var api = /*#__PURE__*/Object.freeze({
__proto__: null,
requestPayment: requestPayment,
createIntersectionObserver: createIntersectionObserver,
createMediaQueryObserver: createMediaQueryObserver,
getPushClientId: getPushClientId,
onPushMessage: onPushMessage,
......@@ -1596,7 +1605,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2332,21 +2341,40 @@ function initBehavior (options) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2354,7 +2382,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2495,7 +2523,7 @@ function fixSetDataEnd (mpInstance) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2578,6 +2606,9 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
......@@ -2586,11 +2617,11 @@ function parseBaseComponent (vueComponentOptions, {
const newLifecycle = swan.canIUse('lifecycle-2-0');
function parseComponent (vueOptions) {
const componentOptions = parseBaseComponent(vueOptions, {
function parseComponent (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
});
}, true);
// 关于百度小程序生命周期的说明(组件作为页面时):
// lifetimes:attached --> methods:onShow --> methods:onLoad --> methods:onReady
......@@ -2651,7 +2682,7 @@ function parseComponent (vueOptions) {
};
delete componentOptions.methods.__l;
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$1 = [
......@@ -2662,13 +2693,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2702,10 +2730,7 @@ function onPageUnload ($vm) {
}
function parsePage (vuePageOptions) {
const pageOptions = parseBasePage(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseBasePage(vuePageOptions);
// 纠正百度小程序生命周期methods:onShow在methods:onLoad之前触发的问题
pageOptions.methods.onShow = function onShow () {
......@@ -2842,7 +2867,7 @@ if (typeof Proxy !== 'undefined' && "mp-baidu" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(swan, name) && !hasOwn(protocols, name)) {
if (typeof swan[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, swan[name]))
......
......@@ -1213,7 +1213,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2014,21 +2014,40 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2036,7 +2055,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2122,7 +2141,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2205,27 +2224,30 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
function parseComponent$1 (vueComponentOptions) {
const componentOptions = parseComponent(vueComponentOptions);
function parseComponent$1 (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseComponent(vueComponentOptions, true);
// 京东小程序 lifetimes 存在兼容问题
const lifetimes = componentOptions.lifetimes;
Object.keys(lifetimes).forEach(key => {
componentOptions[key] = lifetimes[key];
});
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$1 = [
......@@ -2236,13 +2258,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent$1(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2262,10 +2281,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, {
isPage,
initRelation
})
return parseBasePage(vuePageOptions)
}
function parsePage$1 (vuePageOptions) {
......@@ -2376,7 +2392,7 @@ if (typeof Proxy !== 'undefined' && "mp-jd" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(jd, name) && !hasOwn(protocols, name)) {
if (typeof jd[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, jd[name]))
......
......@@ -945,7 +945,16 @@ const protocols = {
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo,
getUserProfile
getUserProfile,
requestPayment: {
name: ks.pay ? 'pay' : 'requestPayment',
args (fromArgs) {
if (typeof fromArgs === 'object') {
// ks.pay 服务类型 id(固定值为 '1')
if (ks.pay && !fromArgs.serviceId) fromArgs.serviceId = '1';
}
}
}
};
const todos = [
'vibrate'
......@@ -1381,7 +1390,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2101,21 +2110,40 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2123,7 +2151,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2209,7 +2237,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2292,17 +2320,20 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
/**
......@@ -2343,8 +2374,8 @@ function fixSetDataEnd (mpInstance) {
}
}
function parseComponent$1 (vueComponentOptions) {
const componentOptions = parseComponent(vueComponentOptions);
function parseComponent$1 (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseComponent(vueComponentOptions, true);
const oldAttached = componentOptions.lifetimes.attached;
componentOptions.lifetimes.attached = function attached () {
// 暂不区分版本
......@@ -2357,7 +2388,7 @@ function parseComponent$1 (vueComponentOptions) {
}
oldAttached.call(this);
};
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$1 = [
......@@ -2368,13 +2399,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent$1(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2394,10 +2422,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, {
isPage,
initRelation
})
return parseBasePage(vuePageOptions)
}
function parsePage$1 (vuePageOptions) {
......@@ -2508,7 +2533,7 @@ if (typeof Proxy !== 'undefined' && "mp-kuaishou" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(ks, name) && !hasOwn(protocols, name)) {
if (typeof ks[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, ks[name]))
......
......@@ -1431,7 +1431,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2148,21 +2148,40 @@ function initBehavior (options) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2170,7 +2189,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2328,7 +2347,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2411,14 +2430,20 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueOptions) {
const [componentOptions, VueComponent] = parseBaseComponent(vueOptions);
function parseComponent (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions, VueComponent] = parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
}, true);
componentOptions.lifetimes.attached = function attached () {
const properties = this.properties;
......@@ -2452,7 +2477,7 @@ function parseComponent (vueOptions) {
componentOptions.methods.__l = handleLink$1;
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$1 = [
......@@ -2463,13 +2488,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2489,10 +2511,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
const pageOptions = parseBasePage(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseBasePage(vuePageOptions);
// 页面需要在 ready 中触发,其他组件是在 handleLink 中触发
pageOptions.lifetimes.ready = function ready () {
if (this.$vm && this.$vm.mpType === 'page') {
......@@ -2624,7 +2643,7 @@ if (typeof Proxy !== 'undefined' && "mp-lark" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(tt, name) && !hasOwn(protocols, name)) {
if (typeof tt[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, tt[name]))
......
......@@ -1548,7 +1548,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2273,21 +2273,40 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2295,7 +2314,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2381,7 +2400,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2471,21 +2490,24 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
function parseComponent$1 (vueComponentOptions) {
return parseComponent(vueComponentOptions)
function parseComponent$1 (vueComponentOptions, needVueOptions) {
return parseComponent(vueComponentOptions, needVueOptions)
}
const hooks$1 = [
......@@ -2496,13 +2518,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent$1(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2522,10 +2541,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, {
isPage,
initRelation
})
return parseBasePage(vuePageOptions)
}
function parsePage$1 (vuePageOptions) {
......@@ -2636,7 +2652,7 @@ if (typeof Proxy !== 'undefined' && "mp-qq" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
if (typeof wx[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, wx[name]))
......
......@@ -1638,7 +1638,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2354,6 +2354,53 @@ function initBehavior (options) {
return Behavior(options)
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return syncRefs(refs, $refs)
}
});
}
function handleLink (event) {
const {
vuePid,
......@@ -2379,31 +2426,12 @@ function isPage () {
return this.__nodeid__ === 0 || this.__nodeId__ === 0
}
function initRefs (vm) {
function initRefs$1 (vm) {
const mpInstance = vm.$scope;
/* eslint-disable no-undef */
const minorVersion = parseInt(tt.getSystemInfoSync().SDKVersion.split('.')[1]);
if (minorVersion > 16) {
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
// mpInstance 销毁后 selectAllComponents 取值为 null
const components = mpInstance.selectAllComponents('.vue-ref') || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs
}
});
initRefs(vm);
} else {
mpInstance.selectAllComponents('.vue-ref', (components) => {
components.forEach(component => {
......@@ -2490,7 +2518,7 @@ function parseApp (vm) {
this.$scope.route = this.$scope.__route__;
}
initRefs(this);
initRefs$1(this);
this.__init_injections(this);
this.__init_provide(this);
......@@ -2555,7 +2583,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2638,6 +2666,9 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
......@@ -2652,8 +2683,11 @@ function currentComponents (mpInstance, callback) {
}
}
function parseComponent (vueOptions) {
const [componentOptions, VueComponent] = parseBaseComponent(vueOptions);
function parseComponent (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions, VueComponent] = parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
}, true);
const lifetimes = componentOptions.lifetimes;
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
......@@ -2719,7 +2753,7 @@ function parseComponent (vueOptions) {
componentOptions.methods.__l = handleLink$1;
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
const hooks$1 = [
......@@ -2730,13 +2764,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2756,10 +2787,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
const pageOptions = parseBasePage(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseBasePage(vuePageOptions);
const lifetimes = pageOptions.lifetimes;
const oldCreated = lifetimes.created;
lifetimes.created = function created () {
......@@ -2903,7 +2931,7 @@ if (typeof Proxy !== 'undefined' && "mp-toutiao" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(tt, name) && !hasOwn(protocols, name)) {
if (typeof tt[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, tt[name]))
......
......@@ -1370,7 +1370,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2120,7 +2120,7 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
......@@ -2134,14 +2134,33 @@ function selectAllComponents (mpInstance, selector, $refs) {
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2149,7 +2168,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2231,7 +2250,7 @@ function stringifyQuery (obj, encodeStr = encode) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2321,17 +2340,20 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
const hooks$1 = [
......@@ -2342,13 +2364,10 @@ const hooks$1 = [
hooks$1.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions);
function parseBasePage (vuePageOptions) {
const [pageOptions, vueOptions] = parseComponent(vuePageOptions, true);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vueOptions);
pageOptions.methods.onLoad = function (query) {
this.options = query;
......@@ -2368,10 +2387,7 @@ function parseBasePage (vuePageOptions, {
}
function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, {
isPage,
initRelation
})
return parseBasePage(vuePageOptions)
}
function createPage (vuePageOptions) {
......@@ -2478,7 +2494,7 @@ if (typeof Proxy !== 'undefined' && "mp-weixin" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
if (typeof wx[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, wx[name]))
......
......@@ -1211,7 +1211,7 @@ function hasHook (hook, vueOptions) {
return false
}
if (isFn(vueOptions[hook])) {
if (isFn(vueOptions[hook]) || Array.isArray(vueOptions[hook])) {
return true
}
const mixins = vueOptions.mixins;
......@@ -2012,21 +2012,40 @@ function initRelation (detail) {
}
function selectAllComponents (mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
const components = mpInstance.selectAllComponents(selector) || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function syncRefs (refs, newRefs) {
const oldKeys = new Set(...Object.keys(refs));
const newKeys = Object.keys(newRefs);
newKeys.forEach(key => {
const oldValue = refs[key];
const newValue = newRefs[key];
if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length && newValue.every(value => oldValue.includes(value))) {
return
}
refs[key] = newValue;
oldKeys.delete(key);
});
oldKeys.forEach(key => {
delete refs[key];
});
return refs
}
function initRefs (vm) {
const mpInstance = vm.$scope;
const refs = {};
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
// TODO 暂不考虑 for 中的 scoped
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2034,7 +2053,7 @@ function initRefs (vm) {
}
$refs[ref].push(component.$vm || component);
});
return $refs
return syncRefs(refs, $refs)
}
});
}
......@@ -2222,8 +2241,8 @@ function parsePage (vuePageOptions) {
triggerEvent: function noop () {}
};
initHooks(pageOptions, hooks$1, vuePageOptions);
initUnknownHooks(pageOptions, vuePageOptions, ['onReady']);
initHooks(pageOptions, hooks$1, vueOptions);
initUnknownHooks(pageOptions, vueOptions, ['onReady']);
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
......@@ -2245,7 +2264,7 @@ function createPage (vuePageOptions) {
function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
} = {}) {
} = {}, needVueOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
const options = {
......@@ -2328,17 +2347,20 @@ function parseBaseComponent (vueComponentOptions, {
});
}
if (needVueOptions) {
return [componentOptions, vueOptions, VueComponent]
}
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
}
function parseComponent (vueComponentOptions) {
function parseComponent (vueComponentOptions, needVueOptions) {
return parseBaseComponent(vueComponentOptions, {
isPage,
initRelation
})
}, needVueOptions)
}
/**
......@@ -2381,8 +2403,8 @@ function fixSetDataEnd (mpInstance) {
// import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-parser'
function parseComponent$1 (vueComponentOptions) {
const componentOptions = parseComponent(vueComponentOptions);
function parseComponent$1 (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseComponent(vueComponentOptions, true);
const oldAttached = componentOptions.lifetimes.attached;
componentOptions.lifetimes.attached = function attached () {
// 暂不区分版本
......@@ -2394,7 +2416,7 @@ function parseComponent$1 (vueComponentOptions) {
}
oldAttached.call(this);
};
return componentOptions
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}
function createComponent (vueOptions) {
......@@ -2495,7 +2517,7 @@ if (typeof Proxy !== 'undefined' && "mp-xhs" !== 'app-plus') {
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(xhs, name) && !hasOwn(protocols, name)) {
if (typeof xhs[name] !== 'function' && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, xhs[name]))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册