Skip to content

Commit ce49a4b

Browse files
committed
Merge branch 'master' into feat-transion-25.05.10
2 parents 61d52c1 + e4944ef commit ce49a4b

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

+604
-144
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',

docs-vitepress/api/composition-api.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,67 @@ createComponent({
128128
`Function`
129129

130130
小程序页面 onLoad 事件,监听页面加载。
131+
::: tip 注意
132+
在页面拼接参数时,不同平台对 URL 参数的处理方式存在差异:
133+
- **微信、QQ、字节跳动、RN**:参数透传,保持原始格式
134+
- **其他平台**:会自动对 encode 后的参数进行 decode
135+
136+
为了提供统一的参数处理方式,`onLoad` 钩子额外提供了一个经过 encode 处理的参数对象,方便业务使用统一的参数格式,同时不影响各平台原有的参数返回。
137+
138+
**微信、QQ、字节跳动、RN下的效果:**
139+
```js
140+
// A页面
141+
...
142+
createPage({
143+
methods: {
144+
jumpPage () {
145+
mpx.navigateTo({
146+
url: `./pages/test?name=${encodeURIComponent('')}&encode=true`
147+
})
148+
}
149+
}
150+
})
151+
...
152+
153+
// test页面
154+
...
155+
createPage({
156+
onLoad(rawQuery, decodedQuery) {
157+
// rawQuery = {name: "%E6%88%91", encode: "true"}
158+
// decodedQuery = {name: "我", encode: "true"}
159+
...
160+
}
161+
})
162+
...
163+
```
164+
**其他平台的效果:**
165+
```js
166+
// A页面
167+
...
168+
createPage({
169+
methods: {
170+
jumpPage () {
171+
mpx.navigateTo({
172+
url: `./pages/test?name=${encodeURIComponent('')}&encode=true`
173+
})
174+
}
175+
}
176+
})
177+
...
178+
179+
// test页面
180+
...
181+
createPage({
182+
onLoad(rawQuery, decodedQuery) {
183+
// rawQuery = {name: "我", encode: "true"}
184+
// decodedQuery = {name: "我", encode: "true"}
185+
...
186+
}
187+
})
188+
...
189+
```
190+
191+
:::
131192

132193
### onShow
133194
`Function`

packages/api-proxy/src/platform/api/route/index.ios.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function isLock (navigationHelper, type, options) {
2525
clearTimeout(timerId)
2626
timerId = setTimeout(() => {
2727
if (navigationHelper.lastSuccessCallback && navigationHelper.lastFailCallback) {
28-
navigationHelper.lastFailCallback('timeout')
28+
navigationHelper.lastFailCallback(`${type}:fail timeout ${options.url || ''}`)
2929
navigationHelper.lastFailCallback = null
3030
}
3131
}, 1000)
@@ -43,7 +43,7 @@ function navigateTo (options = {}) {
4343
if (options.events) {
4444
eventChannel._addListeners(options.events)
4545
}
46-
const { path, queryObj } = parseUrl(options.url)
46+
const { path, queryObj } = parseUrl(options.url, true)
4747
const basePath = getBasePath(navigation)
4848
const finalPath = resolvePath(path, basePath).slice(1)
4949

@@ -70,7 +70,7 @@ function redirectTo (options = {}) {
7070
return
7171
}
7272
if (navigation && navigationHelper) {
73-
const { path, queryObj } = parseUrl(options.url)
73+
const { path, queryObj } = parseUrl(options.url, true)
7474
const basePath = getBasePath(navigation)
7575
const finalPath = resolvePath(path, basePath).slice(1)
7676
navigation.replace(finalPath, queryObj)
@@ -120,7 +120,7 @@ function reLaunch (options = {}) {
120120
return
121121
}
122122
if (navigation && navigationHelper) {
123-
const { path, queryObj } = parseUrl(options.url)
123+
const { path, queryObj } = parseUrl(options.url, true)
124124
const basePath = getBasePath(navigation)
125125
const finalPath = resolvePath(path, basePath).slice(1)
126126
navigation.reset({

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/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/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)