Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/core/src/convertor/wxToTenon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mergeLifecycle } from './mergeLifecycle'
import { error } from '../helper/log'
import { isObject, diffAndCloneA, hasOwn } from '../helper/utils'
import { implemented } from '../core/implement'
import { CREATED } from '../core/innerLifecycle'
import { CREATED, DESTROYED } from '../core/innerLifecycle'

// 暂不支持的wx选项,后期需要各种花式支持
const unsupported = [
Expand Down Expand Up @@ -49,7 +49,8 @@ export default {
support: true,
// wx输出tenon时额外将onLoad代理到CREATED
lifecycleProxyMap: Object.assign({}, wxLifecycle.lifecycleProxyMap, {
[CREATED]: ['created', 'attached', 'onLoad']
[CREATED]: ['created', 'attached', 'onLoad'],
[DESTROYED]: ['destroyed', 'detached', 'onUnload', 'unmounted'],
}),
convert (options) {
const props = Object.assign({}, options.properties, options.props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export default function pageStatusMixin (mixinType) {
},
onShow () {
this.mpxPageStatus = 'show'
this.onShow && this.onShow()
},
onHide () {
this.mpxPageStatus = 'hide'
this.onHide && this.onHide()
},
onBack () {
this.onBack && this.onBack()
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/platform/patch/tenon/getDefaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ function initProxy (context, rawOptions) {
context.__mpxProxy.created()
}

export function getDefaultOptions (type, { rawOptions = {} }) {
export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
const rootMixins = [{
created () {
[hookNames[0]] (...params) {
if (!this.__mpxProxy) {
initProxy(this, rawOptions)
initProxy(this, rawOptions, currentInject, params)
}
},
mounted () {
[hookNames[1]] () {
this.__mpxProxy && this.__mpxProxy.mounted()
},
updated () {
this.__mpxProxy && this.__mpxProxy.updated()
},
destroyed () {
[hookNames[2]] () {
this.__mpxProxy && this.__mpxProxy.destroyed()
}
},
}]
// 为了在builtMixin中可以使用某些rootMixin实现的特性(如数据响应等),此处builtInMixin在rootMixin之后执行,但是当builtInMixin使用存在对应内建生命周期的目标平台声明周期写法时,可能会出现用户生命周期比builtInMixin中的生命周期先执行的情况,为了避免这种情况发生,builtInMixin应该尽可能使用内建生命周期来编写
rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/platform/patch/tenon/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const COMPONENT_HOOKS = [
// 'deactivated',
'beforeDestroy',
'destroyed',
'errorCaptured'
'errorCaptured',
'beforeUnmount',
'unmounted'
// 'onPageNotFound'
]

Expand All @@ -19,7 +21,8 @@ const PAGE_HOOKS = [
'onReady',
'onShow',
'onHide',
'onUnload'
'onUnload',
// 'onBack',
// 'onPullDownRefresh',
// 'onReachBottom',
// 'onPageScroll',
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack-plugin/lib/platform/template/wx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ module.exports = function getSpec ({ warn, error }) {
},
web () {
return false
},
tenon () {
return false
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
class: this.className,
...getInnerListeners(this, { mergeAfter }),
},
this.$slots.default()
this.$slots.default && this.$slots.default() || ''
);
},
data() {
Expand Down
20 changes: 20 additions & 0 deletions packages/webpack-plugin/lib/style-compiler/plugins/hm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const postcss = require('postcss')
const rpxRegExp = /\b(\d+(\.\d+)?)rpx\b/
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g

module.exports = postcss.plugin('hm', (options = {}) => root => {
function transHm (declaration) {
if (rpxRegExp.test(declaration.value)) {
declaration.value = declaration.value.replace(rpxRegExpG, function (match, $1) {
if ($1 === '0') return $1
return `${$1}hm`
})
}
}

root.walkRules(rule => {
rule.walkDecls(declaration => {
transHm(declaration)
})
})
})