diff --git a/packages/taro-jd/src/components.ts b/packages/taro-jd/src/components.ts new file mode 100644 index 000000000000..921d575e15ab --- /dev/null +++ b/packages/taro-jd/src/components.ts @@ -0,0 +1,8 @@ +import { singleQuote } from '@tarojs/shared' + +export const components = { + // ======== 调整属性 ======== + Swiper: { + 'easing-function': singleQuote('default') + } +} diff --git a/packages/taro-jd/src/program.ts b/packages/taro-jd/src/program.ts index ab7caf0280d9..f13bf216c4f8 100644 --- a/packages/taro-jd/src/program.ts +++ b/packages/taro-jd/src/program.ts @@ -1,5 +1,6 @@ import { TaroPlatformBase } from '@tarojs/service' import { Template } from './template' +import { components } from './components' const PACKAGE_NAME = '@tarojs/plugin-platform-jd' @@ -16,4 +17,27 @@ export default class JD extends TaroPlatformBase { } template = new Template() + + /** + * 1. setupTransaction - init + * 2. setup + * 3. setupTransaction - close + * 4. buildTransaction - init + * 5. build + * 6. buildTransaction - close + */ + constructor (ctx, config) { + super(ctx, config) + + this.setupTransaction.addWrapper({ + close: this.modifyTemplate + }) + } + + /** + * 增加组件或修改组件属性 + */ + modifyTemplate () { + this.template.mergeComponents(this.ctx, components) + } } diff --git a/packages/taro-jd/src/runtime-utils.ts b/packages/taro-jd/src/runtime-utils.ts index 66697e45aa51..ec8be55bdec2 100644 --- a/packages/taro-jd/src/runtime-utils.ts +++ b/packages/taro-jd/src/runtime-utils.ts @@ -1,6 +1,7 @@ import { initNativeApi } from './apis' export { initNativeApi } +export * from './components' export const hostConfig = { initNativeApi } diff --git a/packages/taro-jd/src/runtime.ts b/packages/taro-jd/src/runtime.ts index 0a74179f110e..d8cccb2f4fb4 100644 --- a/packages/taro-jd/src/runtime.ts +++ b/packages/taro-jd/src/runtime.ts @@ -1,4 +1,5 @@ -import { mergeReconciler } from '@tarojs/shared' -import { hostConfig } from './runtime-utils' +import { mergeReconciler, mergeInternalComponents } from '@tarojs/shared' +import { hostConfig, components } from './runtime-utils' mergeReconciler(hostConfig) +mergeInternalComponents(components) diff --git a/packages/taro-jd/types/components.d.ts b/packages/taro-jd/types/components.d.ts new file mode 100644 index 000000000000..962c1b2484d9 --- /dev/null +++ b/packages/taro-jd/types/components.d.ts @@ -0,0 +1,5 @@ +export declare const components: { + Swiper: { + 'easing-function': string; + }; +}; diff --git a/packages/taro-jd/types/program.d.ts b/packages/taro-jd/types/program.d.ts index 35ca5c3b9cc8..e3f203b5d6dd 100644 --- a/packages/taro-jd/types/program.d.ts +++ b/packages/taro-jd/types/program.d.ts @@ -12,4 +12,17 @@ export default class JD extends TaroPlatformBase { script: string; }; template: Template; + /** + * 1. setupTransaction - init + * 2. setup + * 3. setupTransaction - close + * 4. buildTransaction - init + * 5. build + * 6. buildTransaction - close + */ + constructor(ctx: any, config: any); + /** + * 增加组件或修改组件属性 + */ + modifyTemplate(): void; } diff --git a/packages/taro-jd/types/runtime-utils.d.ts b/packages/taro-jd/types/runtime-utils.d.ts index 34f2dcaba95a..4daf4dd0bd5f 100644 --- a/packages/taro-jd/types/runtime-utils.d.ts +++ b/packages/taro-jd/types/runtime-utils.d.ts @@ -1,5 +1,6 @@ import { initNativeApi } from './apis'; export { initNativeApi }; +export * from './components'; export declare const hostConfig: { initNativeApi: typeof initNativeApi; };