From aa3d440c4b56f53ad6cb312252d9a210a8680035 Mon Sep 17 00:00:00 2001 From: Fai Date: Tue, 23 Apr 2019 18:38:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(api):=20=E6=96=B0=E5=A2=9E=20PluginAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/base.ts | 4 +-- src/api/dashboard.ts | 2 +- src/api/internal.ts | 2 +- src/api/plugin.ts | 68 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/api/plugin.ts diff --git a/src/api/base.ts b/src/api/base.ts index d5fff5a7..d1b53566 100644 --- a/src/api/base.ts +++ b/src/api/base.ts @@ -34,8 +34,8 @@ export class APIBase { this.sdk.destroy() } - call(name: string, ...params: any[]): any { - return this.sdk.send( + call(name: string, ...params: any[]): Promise { + return this.sdk.send( { method: name, params: params || [] /*, version: this.version */ }, this.isolatedAPI().indexOf(name) > -1 ) diff --git a/src/api/dashboard.ts b/src/api/dashboard.ts index ef5e762a..debd787b 100644 --- a/src/api/dashboard.ts +++ b/src/api/dashboard.ts @@ -17,7 +17,7 @@ export interface DashboardAPI { class HostAPI extends APIBase { registerHostNode(...params: any[]) { - return this.call('registerHostNode', ...params) + return this.call('registerHostNode', ...params) } transferStyleNode(...params: any[]) { diff --git a/src/api/internal.ts b/src/api/internal.ts index 51666803..506577d4 100644 --- a/src/api/internal.ts +++ b/src/api/internal.ts @@ -14,7 +14,7 @@ class HostAPI extends APIBase { } registerHostNode(...params: any[]) { - return this.call('registerHostNode', ...params) + return this.call('registerHostNode', ...params) } transferStyleNode(...params: any[]) { diff --git a/src/api/plugin.ts b/src/api/plugin.ts new file mode 100644 index 00000000..aadc9646 --- /dev/null +++ b/src/api/plugin.ts @@ -0,0 +1,68 @@ +import { AppSDK } from '../sdk/AppSDK' +import { APIBase, factory, IFactory } from './base' + +const bridge: TeambitionMobileSDK | void = window.TeambitionMobileSDK + +export interface PluginAPI { + /** + * 显示 Toast 消息 + */ + essage(type: PluginAPIEssageType, config: PluginAPIEssageConfig): Promise + + /** + * 重新拉取插件数据 + */ + refresh(): Promise + + /** + * 关闭 iframe 弹窗 + */ + close(): Promise +} + +class HostAPI extends APIBase implements PluginAPI { + essage(type: PluginAPIEssageType, config: PluginAPIEssageConfig) { + bridge && bridge.call('showToast', { type, ...config }) + return this.call('essage', config) + } + + refresh() { + bridge && bridge.call('forwardAction', { action: 'refreshPlugin' }) + return this.call('refresh') + } + + close() { + bridge && bridge.call('exit') + return this.call('close') + } +} + +export type PluginAPIEssageType = 'success' | 'error' | 'info' | 'warning' + +export interface PluginAPIEssageConfig { + message: string + description?: string +} + +export const hostAPI: IFactory = (sdk: AppSDK) => { + return factory(sdk, HostAPI) +} + +declare global { + interface TeambitionMobileSDK { + call( + method: 'showToast', + params: { + type: 'success' | 'error' | 'info' | 'warning' + message: string + description?: string + }, + ): void + call(method: 'exit'): void + call(method: 'forwardAction', params: { action: 'refreshPlugin' }): void + } + + interface Window { + TeambitionMobileSDK?: TeambitionMobileSDK + } +} From 5cdf0ccde17a3db49abcb15aee8707e6cf6d9e24 Mon Sep 17 00:00:00 2001 From: Fai Date: Tue, 21 May 2019 14:54:43 +0800 Subject: [PATCH 2/2] 0.6.10-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0bddeaa..f7d7eacf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tb-apps-sdk", - "version": "0.6.9", + "version": "0.6.10-alpha.1", "description": "A sdk for communications between teambiton web and other envs.", "main": "./index.js", "scripts": {