Skip to content

Commit adf8696

Browse files
committed
Merge branch 'master' of https://github.com/didi/mpx
2 parents d703de5 + 5b1708d commit adf8696

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+806
-100
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
jd: 'readonly',
1717
qa: 'readonly',
1818
dd: 'readonly',
19+
ks: 'readonly',
1920
Component: 'readonly',
2021
Page: 'readonly',
2122
App: 'readonly',

packages/core/@types/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// declaration for mpx mode
2-
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony'
2+
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony' | 'ks'
33

44
// declaration for mpx env
55
declare let __mpx_env__: string

packages/core/@types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ interface MpxConfig {
412412
rnConfig: RnConfig,
413413
}
414414

415-
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
415+
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'| 'ks' | 'jd' | 'dd'
416416

417417
interface ImplementOptions {
418418
modes?: Array<SupportedMode>

packages/core/src/convertor/convertor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import wxToTtRule from './wxToTt'
99
import wxToDdRule from './wxToDd'
1010
import wxToJdRule from './wxToJd'
1111
import wxToReactRule from './wxToReact'
12+
import wxToKsRule from './wxToKs'
1213

1314
/**
1415
* 转换规则包含四点
@@ -38,7 +39,8 @@ const rulesMap = {
3839
wxToJd: extend({}, defaultConvertRule, wxToJdRule),
3940
wxToIos: extend({}, defaultConvertRule, wxToReactRule),
4041
wxToAndroid: extend({}, defaultConvertRule, wxToReactRule),
41-
wxToHarmony: extend({}, defaultConvertRule, wxToReactRule)
42+
wxToHarmony: extend({}, defaultConvertRule, wxToReactRule),
43+
wxToKs: extend({}, defaultConvertRule, wxToKsRule)
4244
}
4345

4446
export function getConvertRule (convertMode) {

packages/core/src/convertor/getConvertMode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const convertModes = {
88
'wx-dd': 'wxToDd',
99
'wx-ios': 'wxToIos',
1010
'wx-android': 'wxToAndroid',
11-
'wx-harmony': 'wxToHarmony'
11+
'wx-harmony': 'wxToHarmony',
12+
'wx-ks': 'wxToKs'
1213
}
1314

1415
export function getConvertMode (srcMode) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { error } from '@mpxjs/utils'
2+
3+
const BEHAVIORS_MAP = [
4+
'wx://form-field',
5+
'wx://form-field-group',
6+
'wx://form-field-button',
7+
'wx://component-export'
8+
]
9+
10+
export default {
11+
convert (options) {
12+
if (options.behaviors) {
13+
options.behaviors.forEach((behavior, idx) => {
14+
if (BEHAVIORS_MAP.includes(behavior)) {
15+
error(`Built-in behavior "${behavior}" is not supported in ks environment!`, global.currentResource || global.currentModuleId)
16+
options.behaviors.splice(idx, 1)
17+
}
18+
})
19+
}
20+
}
21+
}

packages/core/src/convertor/wxToWeb.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
diffAndCloneA,
77
error,
88
hasOwn,
9-
isDev
9+
isDev,
10+
getDefaultValueByType
1011
} from '@mpxjs/utils'
1112
import { implemented } from '../core/implement'
1213

@@ -56,6 +57,12 @@ export default {
5657
return diffAndCloneA(prop.value).clone
5758
}
5859
: prop.value
60+
} else {
61+
// 没有显式设置value时,根据type自动添加默认值,与微信小程序原生行为保持一致
62+
const defaultValue = getDefaultValueByType(prop.type, 'web')
63+
if (defaultValue !== undefined) {
64+
newProp.default = defaultValue
65+
}
5966
}
6067
props[key] = newProp
6168
} else {

packages/core/src/core/proxy.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import {
3131
wrapMethodsWithErrorHandling,
3232
warn,
3333
error,
34-
getEnvObj
34+
getEnvObj,
35+
def
3536
} from '@mpxjs/utils'
37+
import { renderHelperDefs } from '../platform/builtInMixins/renderHelperMixin'
3638
import {
3739
BEFORECREATE,
3840
CREATED,
@@ -190,6 +192,7 @@ export default class MpxProxy {
190192
this.callHook(CREATED)
191193

192194
if (!isWeb && !isReact) {
195+
this.initRenderHelpers()
193196
this.initRender()
194197
}
195198

@@ -728,6 +731,15 @@ export default class MpxProxy {
728731
this.toggleRecurse(true)
729732
}
730733

734+
initRenderHelpers () {
735+
if (this.options.__nativeRender__ || __mpx_mode__ !== 'ks') return
736+
Object.keys(renderHelperDefs).forEach((key) => {
737+
if (!hasOwn(this.target, key)) {
738+
def(this.target, key, renderHelperDefs[key])
739+
}
740+
})
741+
}
742+
731743
initRender () {
732744
if (this.options.__nativeRender__) return this.doRender()
733745

packages/core/src/helper/MpxScroll/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default class MpxScroll {
5757
const isIntersecting = change.isIntersecting
5858
this.isIntersecting = isIntersecting
5959
if (!isIntersecting) {
60-
// 非 inter section 状态下及时清除 transtorm,以免影响正常滚动时元素的 fixed 定位
61-
this.el.style.cssText = ''
60+
// 非 inter section 状态下及时清除 transform,以免影响正常滚动时元素的 fixed 定位
61+
this.el.style.transform = ''
6262
this.pullDownEventRegister && this.pullDownEventRegister.destroy()
6363
} else {
6464
this.pullDownEventRegister = new EventRegister(this.el, [
@@ -103,7 +103,12 @@ export default class MpxScroll {
103103

104104
transformPage (distance) {
105105
this.translateY = distance
106-
this.el.style.cssText = `transform: translateY(${distance}px)`
106+
if (distance === 0) {
107+
// 距离为 0 时移除 transform,避免影响页面 fixed 定位
108+
this.el.style.transform = ''
109+
} else {
110+
this.el.style.transform = `translateY(${distance}px)`
111+
}
107112
}
108113

109114
onTouchEnd (e) {
@@ -219,8 +224,15 @@ export default class MpxScroll {
219224
}
220225

221226
onReachBottom (onReachBottomDistance, callback) {
222-
const { bottom } = this.el.getBoundingClientRect()
223-
const mark = bottom - window.innerHeight <= onReachBottomDistance
227+
const scrollTop = getScrollTop()
228+
const scrollHeight = document.documentElement.scrollHeight
229+
const clientHeight = window.innerHeight
230+
231+
// 使用 scrollHeight 判断实际内容高度是否超过视口,只有可滚动时才计算触底
232+
const scrollable = scrollHeight > clientHeight
233+
// 距离底部的距离 = 内容总高度 - (当前滚动位置 + 视口高度)
234+
const distanceToBottom = scrollHeight - (scrollTop + clientHeight)
235+
const mark = scrollable && (distanceToBottom <= onReachBottomDistance)
224236

225237
if (!this.bottomReached && mark) {
226238
this.bottomReached = true

packages/core/src/platform/builtInMixins/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
5757
}
5858
// 此为纯增强类mixins,原生模式下不需要注入
5959
if (!rawOptions.__nativeRender__) {
60-
bulitInMixins = bulitInMixins.concat([
61-
renderHelperMixin(),
60+
const enhancedMixins = [
6261
showMixin(type),
6362
i18nMixin(),
6463
dynamicRenderHelperMixin(),
6564
dynamicSlotMixin(),
6665
dynamicRefsMixin()
67-
])
66+
]
67+
if (__mpx_mode__ !== 'ks') {
68+
// ks methods 不支持 _ 或者 $ 开头的方法名,所以 ks 不走 methods mixin
69+
enhancedMixins.unshift(renderHelperMixin())
70+
}
71+
bulitInMixins = bulitInMixins.concat(enhancedMixins)
6872
}
6973
}
7074
return bulitInMixins.filter(item => item)

0 commit comments

Comments
 (0)