diff --git a/src/platforms/mp-jd/runtime/wrapper/component-parser.js b/src/platforms/mp-jd/runtime/wrapper/component-parser.js index 0e79cab9c0845c8d26fc93aa275f8e895755c259..26dbc9c5442b64ee1f54ee73c1d488b8ca3428f9 100644 --- a/src/platforms/mp-jd/runtime/wrapper/component-parser.js +++ b/src/platforms/mp-jd/runtime/wrapper/component-parser.js @@ -1,150 +1,11 @@ -import Vue from 'vue' - -import { - initData, - initSlots, - initVueIds, - handleEvent, - initBehaviors, - initProperties, - initVueComponent -} from 'uni-wrapper/util' - -import { - handleLink, - initBehavior -} from './util' - -export default function parseBaseComponent (vueComponentOptions, { - isPage, - initRelation -} = {}) { - const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions) - - const options = { - multipleSlots: true, - addGlobalClass: true, - ...(vueOptions.options || {}) - } - - const componentOptions = { - options, - data: initData(vueOptions, Vue.prototype), - behaviors: initBehaviors(vueOptions, initBehavior), - properties: initProperties(vueOptions.props, false, vueOptions.__file), - lifetimes: { - attached () { - const properties = this.properties - - const options = { - mpType: isPage.call(this) ? 'page' : 'component', - mpInstance: this, - propsData: properties - } - - initVueIds(properties.vueId, this) - - // 处理父子关系 - initRelation.call(this, { - vuePid: this._$vuePid, - vueOptions: options - }) - - // 初始化 vue 实例 - this.$vm = new VueComponent(options) - - // 处理$slots,$scopedSlots(暂不支持动态变化$slots) - initSlots(this.$vm, properties.vueSlots) - - // 触发首次 setData - this.$vm.$mount() - }, - ready () { - // 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发 - // https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800 - if (this.$vm) { - this.$vm._isMounted = true - this.$vm.__call_hook('mounted') - this.$vm.__call_hook('onReady') - } else { - // this.is && console.warn(this.is + ' is not attached') - } - }, - detached () { - this.$vm && this.$vm.$destroy() - }, - }, - pageLifetimes: { - show (args) { - this.$vm && this.$vm.__call_hook('onPageShow', args) - }, - hide () { - this.$vm && this.$vm.__call_hook('onPageHide') - }, - resize (size) { - this.$vm && this.$vm.__call_hook('onPageResize', size) - } - }, - attached () { - const properties = this.properties - - const options = { - mpType: isPage.call(this) ? 'page' : 'component', - mpInstance: this, - propsData: properties - } - - initVueIds(properties.vueId, this) - - // 处理父子关系 - initRelation.call(this, { - vuePid: this._$vuePid, - vueOptions: options - }) - - // 初始化 vue 实例 - this.$vm = new VueComponent(options) - - // 处理$slots,$scopedSlots(暂不支持动态变化$slots) - initSlots(this.$vm, properties.vueSlots) - - // 触发首次 setData - this.$vm.$mount() - }, - ready () { - // 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发 - // https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800 - if (this.$vm) { - this.$vm._isMounted = true - this.$vm.__call_hook('mounted') - this.$vm.__call_hook('onReady') - } else { - // this.is && console.warn(this.is + ' is not attached') - } - }, - detached () { - this.$vm && this.$vm.$destroy() - }, - methods: { - __l: handleLink, - __e: handleEvent - } - } - // externalClasses - if (vueOptions.externalClasses) { - componentOptions.externalClasses = vueOptions.externalClasses - } - - if (Array.isArray(vueOptions.wxsCallMethods)) { - vueOptions.wxsCallMethods.forEach(callMethod => { - componentOptions.methods[callMethod] = function (args) { - return this.$vm[callMethod](args) - } - }) - } - - if (isPage) { - return componentOptions - } - return [componentOptions, VueComponent] +import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-parser' + +export default function parseComponent (vueComponentOptions) { + const componentOptions = parseBaseComponent(vueComponentOptions) + // 京东小程序 lifetimes 存在兼容问题 + const lifetimes = componentOptions.lifetimes + Object.keys(lifetimes).forEach(key => { + componentOptions[key] = lifetimes[key] + }) + return componentOptions }