@bud-fe/h5-native-bridge 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +352 -0
- package/dist/examples/index.d.ts +0 -0
- package/dist/index.d.ts +3 -0
- package/dist/native-bridge.es.js +3316 -0
- package/dist/native-bridge.es.js.map +1 -0
- package/dist/native-bridge.umd.js +2 -0
- package/dist/native-bridge.umd.js.map +1 -0
- package/dist/src/core/errors.d.ts +14 -0
- package/dist/src/core/index.d.ts +172 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/plugins/authentication.d.ts +30 -0
- package/dist/src/plugins/bluetooth.d.ts +399 -0
- package/dist/src/plugins/device.d.ts +117 -0
- package/dist/src/plugins/location.d.ts +89 -0
- package/dist/src/plugins/media.d.ts +157 -0
- package/dist/src/plugins/navigate.d.ts +84 -0
- package/dist/src/plugins/request.d.ts +89 -0
- package/dist/src/plugins/storage.d.ts +52 -0
- package/dist/src/plugins/toast.d.ts +47 -0
- package/dist/src/plugins/userInfo.d.ts +30 -0
- package/dist/src/plugins/wifi.d.ts +65 -0
- package/package.json +46 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface DeviceInfo {
|
|
4
|
+
model: string;
|
|
5
|
+
pixelRatio: number;
|
|
6
|
+
windowWidth: number;
|
|
7
|
+
windowHeight: number;
|
|
8
|
+
version: string;
|
|
9
|
+
storage: string;
|
|
10
|
+
currentBattery: string;
|
|
11
|
+
system: string;
|
|
12
|
+
platform: string;
|
|
13
|
+
screenWidth: number;
|
|
14
|
+
screenHeight: number;
|
|
15
|
+
brand: string;
|
|
16
|
+
fontSizeSetting: number;
|
|
17
|
+
}
|
|
18
|
+
export interface DeviceInfoOptions extends CallbacksBase {
|
|
19
|
+
success?: (deviceInfo: DeviceInfo) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface GetWifiOptions extends CallbacksBase {
|
|
22
|
+
/** 超时时间 int 必选 */
|
|
23
|
+
timeout?: number;
|
|
24
|
+
/** 缓存时间 int 必选 */
|
|
25
|
+
cacheTime?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface KeepScreenOnOptions extends CallbacksBase {
|
|
28
|
+
/** 是否保持屏幕常亮 */
|
|
29
|
+
isKeep: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 获取WIFI 返回结果定义
|
|
33
|
+
* @apiName device.base.getScanWifiListAsync
|
|
34
|
+
*/
|
|
35
|
+
export interface WifiListAsyncResult {
|
|
36
|
+
/** 错误码 int枚举值 必选 取值{ 0:成功 1:json错误 2:系统错误 3:超时 } */
|
|
37
|
+
resultCode: number;
|
|
38
|
+
/** WiFi列表 */
|
|
39
|
+
wifiList?: any[];
|
|
40
|
+
/** 成功或错误信息 */
|
|
41
|
+
resultMessage?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface GetDeviceUUIDOptions extends CallbacksBase {
|
|
44
|
+
uuid?: string;
|
|
45
|
+
}
|
|
46
|
+
declare module "../core" {
|
|
47
|
+
interface PluginMethods {
|
|
48
|
+
getSystemInfo: (options?: DeviceInfoOptions) => Promise<DeviceInfo>;
|
|
49
|
+
getSystemInfoSync: (options?: DeviceInfoOptions) => void;
|
|
50
|
+
getUUID: () => Promise<GetDeviceUUIDOptions>;
|
|
51
|
+
getWifiList: (options?: GetWifiOptions) => Promise<WifiListAsyncResult>;
|
|
52
|
+
setKeepScreenOn: (options: KeepScreenOnOptions) => void;
|
|
53
|
+
}
|
|
54
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 设备信息插件类
|
|
59
|
+
*/
|
|
60
|
+
declare class DevicePlugin implements BridgePlugin {
|
|
61
|
+
readonly name = "device";
|
|
62
|
+
readonly version = "1.0.0";
|
|
63
|
+
private context?;
|
|
64
|
+
/**
|
|
65
|
+
* 安装插件
|
|
66
|
+
*/
|
|
67
|
+
install(context: PluginContext): void;
|
|
68
|
+
/**
|
|
69
|
+
* 设置屏幕常亮状态
|
|
70
|
+
* @param options 配置选项
|
|
71
|
+
* @param options.isKeep 是否保持屏幕常亮,默认为true
|
|
72
|
+
* @param options.success 成功回调
|
|
73
|
+
* @param options.fail 失败回调
|
|
74
|
+
* @param options.complete 完成回调
|
|
75
|
+
* @returns void
|
|
76
|
+
*/
|
|
77
|
+
setKeepScreenOn(options: KeepScreenOnOptions): void;
|
|
78
|
+
/**
|
|
79
|
+
* 同步获取设备系统信息
|
|
80
|
+
*
|
|
81
|
+
* @param options - 获取设备信息的配置选项
|
|
82
|
+
* @returns any - 返回设备信息结果
|
|
83
|
+
*/
|
|
84
|
+
getSystemInfoSync(options?: DeviceInfoOptions): any;
|
|
85
|
+
/**
|
|
86
|
+
* 获取设备信息(Promise 风格)
|
|
87
|
+
*
|
|
88
|
+
* @description
|
|
89
|
+
* 1. 检查插件是否初始化,未初始化则抛出错误
|
|
90
|
+
* 2. 创建并返回一个Promise,用于异步获取设备信息
|
|
91
|
+
* 3. 通过Native Bridge调用原生能力获取设备信息
|
|
92
|
+
*
|
|
93
|
+
* @throws {BridgeError} 当插件未初始化时抛出错误
|
|
94
|
+
* @returns {Promise<DeviceInfo>} 返回包含设备信息的Promise对象
|
|
95
|
+
*/
|
|
96
|
+
getSystemInfo(): Promise<DeviceInfo>;
|
|
97
|
+
/**
|
|
98
|
+
* 获取WiFi列表
|
|
99
|
+
*
|
|
100
|
+
* 该方法通过原生桥接获取当前可用的WiFi列表,返回一个Promise对象
|
|
101
|
+
*
|
|
102
|
+
* @param {GetWifiOptions} [options={}] - 获取WiFi列表的可选参数对象
|
|
103
|
+
* @returns {Promise<WifiListAsyncResult>} 返回一个Promise,解析后包含WiFi列表或错误信息
|
|
104
|
+
* - resultCode: 0表示成功,1表示失败
|
|
105
|
+
* - resultMessage: 结果描述信息
|
|
106
|
+
* - wifiList: WiFi列表数组
|
|
107
|
+
*/
|
|
108
|
+
getWifiList(options?: GetWifiOptions): Promise<WifiListAsyncResult>;
|
|
109
|
+
/**
|
|
110
|
+
* 获取设备的唯一标识符
|
|
111
|
+
* @returns 返回一个Promise,解析后得到设备的UUID信息
|
|
112
|
+
* @throws 如果插件未正确初始化会抛出错误
|
|
113
|
+
*/
|
|
114
|
+
getUUID(): Promise<GetDeviceUUIDOptions>;
|
|
115
|
+
}
|
|
116
|
+
export declare const devicePlugin: DevicePlugin;
|
|
117
|
+
export default devicePlugin;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface LocationInfo {
|
|
4
|
+
/** 经度 */
|
|
5
|
+
longitude: number;
|
|
6
|
+
/** 纬度 */
|
|
7
|
+
latitude: number;
|
|
8
|
+
/** 实际的定位精度半径(单位米) */
|
|
9
|
+
accuracy: number;
|
|
10
|
+
/** 格式化地址,如:北京市朝阳区南磨房镇北京国家广告产业园区 */
|
|
11
|
+
address: string;
|
|
12
|
+
/** 省份,如:北京市 */
|
|
13
|
+
province: string;
|
|
14
|
+
/** 城市,直辖市会返回空 */
|
|
15
|
+
city: string;
|
|
16
|
+
/** 行政区,如:朝阳区 */
|
|
17
|
+
district: string;
|
|
18
|
+
/** 街道,如:西大望路甲12-2号楼 */
|
|
19
|
+
road: string;
|
|
20
|
+
/** 当前设备网络类型,如:wifi、3g等 */
|
|
21
|
+
netType: string;
|
|
22
|
+
/** 当前设备使用移动运营商,如:CMCC等 */
|
|
23
|
+
operatorType: string;
|
|
24
|
+
/** 对错误码的描述 */
|
|
25
|
+
errorMessage?: string;
|
|
26
|
+
/** 错误码 */
|
|
27
|
+
errorCode?: number;
|
|
28
|
+
/** 仅Android支持,wifi设置是否开启,不保证已连接上 */
|
|
29
|
+
isWifiEnabled?: boolean;
|
|
30
|
+
/** 仅Android支持,gps设置是否开启,不保证已经连接上 */
|
|
31
|
+
isGpsEnabled?: boolean;
|
|
32
|
+
/** 仅Android支持,定位返回的经纬度是否是模拟的结果 */
|
|
33
|
+
isFromMock?: boolean;
|
|
34
|
+
/** 仅Android支持,我们使用的是混合定位,具体定位提供者有wifi/lbs/gps" 这三种 */
|
|
35
|
+
provider?: "wifi" | "lbs" | "gps";
|
|
36
|
+
/** 仅Android支持,移动网络是设置是否开启,不保证已经连接上 */
|
|
37
|
+
isMobileEnabled: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface GetLocationOptions extends CallbacksBase {
|
|
40
|
+
success?: (location: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* 期望定位精度半径(单位米),定位结果尽量满足该参数要求,但是不一定能保证小于该误差,
|
|
43
|
+
* 开发者需要读取返回结果的 accuracy 字段校验坐标精度;
|
|
44
|
+
* 建议按照业务需求设置定位精度,推荐采用200m,
|
|
45
|
+
* 可获得较好的精度和较短的响应时长
|
|
46
|
+
*/
|
|
47
|
+
targetAccuracy: number;
|
|
48
|
+
/** 1:获取高德坐标, 0:获取标准坐标;推荐使用高德坐标;标准坐标没有address字段 */
|
|
49
|
+
coordinate: number;
|
|
50
|
+
/** 是否需要带有逆地理编码信息;该功能需要网络请求,请更具自己的业务场景使用 */
|
|
51
|
+
withReGeocode: boolean;
|
|
52
|
+
/** 是否缓存地理位置信息。默认是true。如果true,客户端会对定位的地理位置信息缓存,在缓存期内(2分钟)再次定位会返回旧的定位 */
|
|
53
|
+
useCache: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare module "../core" {
|
|
56
|
+
interface PluginMethods {
|
|
57
|
+
/**
|
|
58
|
+
* 同步获取位置信息
|
|
59
|
+
* @param options 定位选项
|
|
60
|
+
*/
|
|
61
|
+
getLocationSync: (options?: GetLocationOptions) => void;
|
|
62
|
+
/**
|
|
63
|
+
* 异步获取位置信息
|
|
64
|
+
* @param options 定位选项
|
|
65
|
+
*/
|
|
66
|
+
getLocation: (options?: Omit<GetLocationOptions, "success" | "fail">) => Promise<LocationInfo>;
|
|
67
|
+
}
|
|
68
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
declare class LocationPlugin implements BridgePlugin {
|
|
72
|
+
readonly name = "location";
|
|
73
|
+
readonly version = "1.0.0";
|
|
74
|
+
private context?;
|
|
75
|
+
install(context: PluginContext): void;
|
|
76
|
+
/**
|
|
77
|
+
* 获取当前位置信息
|
|
78
|
+
* @param options - 位置选项,可选参数包括:
|
|
79
|
+
* - targetAccuracy: 目标精度,单位米,默认200
|
|
80
|
+
* - coordinate: 坐标类型,默认1(可能表示WGS84)
|
|
81
|
+
* - withReGeocode: 是否需要逆地理编码,默认true
|
|
82
|
+
* - useCache: 是否使用缓存,默认true
|
|
83
|
+
* @returns 返回一个Promise,解析为LocationInfo对象
|
|
84
|
+
*/
|
|
85
|
+
getLocation(options?: Omit<GetLocationOptions, "success" | "fail">): Promise<LocationInfo>;
|
|
86
|
+
getLocationSync(options?: GetLocationOptions): void;
|
|
87
|
+
}
|
|
88
|
+
export declare const locationPlugin: LocationPlugin;
|
|
89
|
+
export default locationPlugin;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase, NativeResponse } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface MediaInfo {
|
|
4
|
+
platform: "android" | "ios" | "unknown";
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
export interface MediaInfoOptions extends CallbacksBase {
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ScanOptions extends CallbacksBase {
|
|
11
|
+
/**
|
|
12
|
+
* 扫码样式。
|
|
13
|
+
* 可选值:
|
|
14
|
+
* - 'qr':二维码扫码框
|
|
15
|
+
* - 'bar':条形码扫码框
|
|
16
|
+
* 默认为 'qr'。
|
|
17
|
+
* 兼容性说明:此字段从必填变为可选,未传递时将使用默认值 'qr',如之前为必填请注意兼容性。
|
|
18
|
+
*/
|
|
19
|
+
key?: "qr" | "bar";
|
|
20
|
+
/**
|
|
21
|
+
* 是否支持从相册选择:
|
|
22
|
+
* 默认值为 true,
|
|
23
|
+
*/
|
|
24
|
+
isSupportAlbum?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ScanRes {
|
|
27
|
+
/** 扫码所得数据 */
|
|
28
|
+
code?: string;
|
|
29
|
+
/**
|
|
30
|
+
* 扫描二维码时返回二维码数据。
|
|
31
|
+
*/
|
|
32
|
+
qrCode?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 扫描条形码时返回条形码数据。
|
|
35
|
+
*/
|
|
36
|
+
barCode?: string;
|
|
37
|
+
/**
|
|
38
|
+
* 扫描结果的最后一帧图片的本地定位符
|
|
39
|
+
*/
|
|
40
|
+
filePath?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 扫描结果的最后一帧图片的本地真实图片路径。
|
|
43
|
+
*/
|
|
44
|
+
fileRealPath?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ChooseImageOptions extends CallbacksBase {
|
|
47
|
+
count?: number;
|
|
48
|
+
sourceType?: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface ChooseImageResponse {
|
|
51
|
+
filePaths: string[];
|
|
52
|
+
fileRealPaths: string[];
|
|
53
|
+
}
|
|
54
|
+
export interface previewImageOptions extends CallbacksBase {
|
|
55
|
+
urls: string[];
|
|
56
|
+
current?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface compressImageOptions extends CallbacksBase {
|
|
59
|
+
filePaths: string[];
|
|
60
|
+
compressLevel?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface compressImageResponse {
|
|
63
|
+
filePaths: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ChooseVideoOptions extends CallbacksBase {
|
|
66
|
+
sourceType?: string[];
|
|
67
|
+
maxDuration?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface ChooseVideoResponse {
|
|
70
|
+
filePath: string;
|
|
71
|
+
duration: number;
|
|
72
|
+
size: number;
|
|
73
|
+
height: number;
|
|
74
|
+
width: number;
|
|
75
|
+
}
|
|
76
|
+
declare module "../core" {
|
|
77
|
+
interface PluginMethods {
|
|
78
|
+
saveImage: (options: MediaInfoOptions) => Promise<NativeResponse>;
|
|
79
|
+
scan: (options: ScanOptions) => Promise<ScanRes>;
|
|
80
|
+
chooseImage: (options?: ChooseImageOptions) => Promise<ChooseImageResponse>;
|
|
81
|
+
previewImage: (options: previewImageOptions) => Promise<void>;
|
|
82
|
+
compressImage: (options: compressImageOptions) => Promise<compressImageResponse>;
|
|
83
|
+
chooseVideo: (options?: ChooseVideoOptions) => Promise<ChooseVideoResponse>;
|
|
84
|
+
}
|
|
85
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 设备信息插件类
|
|
90
|
+
*/
|
|
91
|
+
declare class MediaPlugin implements BridgePlugin {
|
|
92
|
+
readonly name = "media";
|
|
93
|
+
readonly version = "1.0.0";
|
|
94
|
+
private context?;
|
|
95
|
+
/**
|
|
96
|
+
* 安装插件
|
|
97
|
+
*/
|
|
98
|
+
install(context: PluginContext): void;
|
|
99
|
+
/**
|
|
100
|
+
* 执行扫码功能
|
|
101
|
+
*
|
|
102
|
+
* @description 调用原生扫码功能,返回扫码结果。该方法会等待桥接准备就绪后调用原生扫码API。
|
|
103
|
+
*
|
|
104
|
+
* @param options - 扫码配置选项,排除了success和fail回调
|
|
105
|
+
* @param options.complete - 可选的完成回调函数,无论成功或失败都会执行
|
|
106
|
+
*
|
|
107
|
+
* @returns Promise<ScanRes> 返回包含扫码结果的Promise对象
|
|
108
|
+
*
|
|
109
|
+
* @throws {BridgeError} 当插件未正确初始化时抛出PLUGIN_NOT_INITIALIZED错误
|
|
110
|
+
* @throws {BridgeError} 当扫码失败时抛出SYSTEM_ERROR错误
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
*/
|
|
114
|
+
scan(options: Omit<ScanOptions, "success" | "fail">): Promise<ScanRes>;
|
|
115
|
+
/**
|
|
116
|
+
* 保存图片到相册(Promise 风格)
|
|
117
|
+
*/
|
|
118
|
+
saveImage(options: MediaInfoOptions): Promise<NativeResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* 选择图片功能
|
|
121
|
+
* @param options 选择图片的配置选项
|
|
122
|
+
* @returns 返回一个Promise,解析为选择的图片响应数据
|
|
123
|
+
*/
|
|
124
|
+
chooseImage(options?: ChooseImageOptions): Promise<ChooseImageResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* 预览图片功能
|
|
127
|
+
* @param options 预览图片的配置参数对象,包含以下属性:
|
|
128
|
+
* - current: 可选,number类型,默认0,表示从第几张图片开始预览
|
|
129
|
+
* - urls: string[]类型,图片URL数组
|
|
130
|
+
* - 其他可能的自定义参数
|
|
131
|
+
* @returns Promise<void>
|
|
132
|
+
* 成功时:解析为原生返回的结果对象(已JSON.parse处理)
|
|
133
|
+
* 失败时:拒绝返回错误信息
|
|
134
|
+
*/
|
|
135
|
+
previewImage(options: previewImageOptions): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* 压缩图片
|
|
138
|
+
* @param options 压缩图片的配置选项
|
|
139
|
+
* @returns 返回一个Promise,解析为压缩后的图片响应数据
|
|
140
|
+
*/
|
|
141
|
+
compressImage(options: compressImageOptions): Promise<compressImageResponse>;
|
|
142
|
+
/**
|
|
143
|
+
* 选择视频文件
|
|
144
|
+
* @param options 选择视频的配置选项,包含以下属性:
|
|
145
|
+
* @param options.sourceType 视频来源类型,默认同时支持相册和相机['album','camera']
|
|
146
|
+
* @param options.maxDuration 视频最大时长(秒),默认60秒
|
|
147
|
+
* @returns Promise<ChooseVideoResponse> 返回包含视频信息的Promise对象
|
|
148
|
+
* @returns ChooseVideoResponse.filePath 视频临时文件路径
|
|
149
|
+
* @returns ChooseVideoResponse.duration 视频时长(秒)
|
|
150
|
+
* @returns ChooseVideoResponse.size 视频文件大小(字节)
|
|
151
|
+
* @returns ChooseVideoResponse.height 视频高度
|
|
152
|
+
* @returns ChooseVideoResponse.width 视频宽度
|
|
153
|
+
*/
|
|
154
|
+
chooseVideo(options?: ChooseVideoOptions): Promise<ChooseVideoResponse>;
|
|
155
|
+
}
|
|
156
|
+
export declare const mediaPlugin: MediaPlugin;
|
|
157
|
+
export default mediaPlugin;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface NavigateInfo extends CallbacksBase {
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NavigationBarOptions extends CallbacksBase {
|
|
7
|
+
/** 是否显示导航栏
|
|
8
|
+
* 默认显示
|
|
9
|
+
* 否:隐藏导航栏
|
|
10
|
+
*/
|
|
11
|
+
isShowBar?: boolean;
|
|
12
|
+
/** 导航栏标题 */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** 导航栏标题颜色
|
|
15
|
+
* 导航栏背景色,支持十六进制颜色值。
|
|
16
|
+
*/
|
|
17
|
+
backgroundColor?: string;
|
|
18
|
+
/** 是否重置导航栏背景色默认配色。
|
|
19
|
+
*/
|
|
20
|
+
reset?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface navigateBackInfo extends CallbacksBase {
|
|
23
|
+
delta?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface OpenLinkOptions extends CallbacksBase {
|
|
26
|
+
url: string;
|
|
27
|
+
enableShare?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare module "../core" {
|
|
30
|
+
interface PluginMethods {
|
|
31
|
+
/**
|
|
32
|
+
* 导航到指定页面
|
|
33
|
+
* @param options 导航选项
|
|
34
|
+
*/
|
|
35
|
+
navigateTo: (options: NavigateInfo) => void;
|
|
36
|
+
/**
|
|
37
|
+
* 重定向到指定页面
|
|
38
|
+
* @param options 导航选项
|
|
39
|
+
*/
|
|
40
|
+
redirectTo: (options: NavigateInfo) => void;
|
|
41
|
+
/**
|
|
42
|
+
* 重新加载当前页面
|
|
43
|
+
* @param options 导航选项
|
|
44
|
+
*/
|
|
45
|
+
reLaunch: (options: NavigateInfo) => void;
|
|
46
|
+
/**
|
|
47
|
+
* 返回到上一个页面
|
|
48
|
+
* @param options 导航选项
|
|
49
|
+
*/
|
|
50
|
+
navigateBack: (options: navigateBackInfo) => void;
|
|
51
|
+
/**
|
|
52
|
+
* 设置导航栏
|
|
53
|
+
* @param options 样式选项
|
|
54
|
+
*/
|
|
55
|
+
setNavigationBar: (options: NavigationBarOptions) => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* 打开外部链接
|
|
58
|
+
* @param options 链接选项
|
|
59
|
+
*/
|
|
60
|
+
openLink: (options: OpenLinkOptions) => Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declare class NavigatePlugin implements BridgePlugin {
|
|
66
|
+
readonly name = "navigate";
|
|
67
|
+
readonly version = "1.0.0";
|
|
68
|
+
private context?;
|
|
69
|
+
install(context: PluginContext): void;
|
|
70
|
+
setNavigationBar(options: NavigationBarOptions): Promise<void>;
|
|
71
|
+
private navigate;
|
|
72
|
+
navigateTo(options: NavigateInfo): void;
|
|
73
|
+
redirectTo(options: NavigateInfo): void;
|
|
74
|
+
reLaunch(options: NavigateInfo): void;
|
|
75
|
+
navigateBack(options: navigateBackInfo): void;
|
|
76
|
+
/**
|
|
77
|
+
* 打开外部链接
|
|
78
|
+
* @param options 链接选项
|
|
79
|
+
* @returns Promise对象,解析为打开链接的响应
|
|
80
|
+
*/
|
|
81
|
+
openLink(options: OpenLinkOptions): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
export declare const navigatePlugin: NavigatePlugin;
|
|
84
|
+
export default navigatePlugin;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface RequestOptions extends CallbacksBase {
|
|
4
|
+
url: string;
|
|
5
|
+
method?: "GET" | "POST";
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
data?: Record<string, any>;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
cacheModel: "noStore" | "noCache" | "smartCache" | "firstCache";
|
|
10
|
+
dataType?: "json" | "text" | 'base64';
|
|
11
|
+
}
|
|
12
|
+
export interface RequestResponse {
|
|
13
|
+
status: number;
|
|
14
|
+
data: any;
|
|
15
|
+
headers: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export interface UploadFileOptions extends CallbacksBase {
|
|
18
|
+
url: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
fileType: 'image' | 'video' | 'audio';
|
|
22
|
+
formData?: Record<string, any>;
|
|
23
|
+
header?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
export interface UploadFileResponse {
|
|
26
|
+
statusCode: number;
|
|
27
|
+
data: string;
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
export interface DownloadFileOptions extends CallbacksBase {
|
|
31
|
+
url: string;
|
|
32
|
+
header?: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
export interface DownloadFileResponse {
|
|
35
|
+
filePath: string;
|
|
36
|
+
}
|
|
37
|
+
declare module "../core" {
|
|
38
|
+
interface PluginMethods {
|
|
39
|
+
httpRequest: (options: RequestOptions) => Promise<RequestResponse>;
|
|
40
|
+
httpRequestSync: (options: RequestOptions) => void;
|
|
41
|
+
uploadFile: (options: UploadFileOptions) => Promise<UploadFileResponse>;
|
|
42
|
+
downloadFile: (options: DownloadFileOptions) => Promise<DownloadFileResponse>;
|
|
43
|
+
}
|
|
44
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 网络请求插件类
|
|
49
|
+
*/
|
|
50
|
+
declare class RequestPlugin implements BridgePlugin {
|
|
51
|
+
readonly name = "request";
|
|
52
|
+
readonly version = "1.0.0";
|
|
53
|
+
private context?;
|
|
54
|
+
/**
|
|
55
|
+
* 安装插件
|
|
56
|
+
*/
|
|
57
|
+
install(context: PluginContext): void;
|
|
58
|
+
/**
|
|
59
|
+
* 执行HTTP请求
|
|
60
|
+
* @param options 请求配置选项
|
|
61
|
+
* @property {string} url 请求URL(必需)
|
|
62
|
+
* @property {string} [method] HTTP方法,默认为'GET'
|
|
63
|
+
* @property {Object} [headers] 请求头,默认为{'Content-Type': 'application/x-www-form-urlencoded'}
|
|
64
|
+
* @property {Object} [data] 请求数据,默认为{}
|
|
65
|
+
* @property {string} [dataType] 响应数据类型,默认为'json'
|
|
66
|
+
* @property {number} [timeout] 超时时间(毫秒),默认为30000
|
|
67
|
+
* @property {string} [cacheModel] 缓存模式,默认为'noStore'
|
|
68
|
+
* @returns {Promise<RequestResponse>} 返回一个Promise,解析为请求响应结果
|
|
69
|
+
*/
|
|
70
|
+
httpRequest(options: RequestOptions): Promise<RequestResponse>;
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
httpRequestSync(options: RequestOptions): void;
|
|
75
|
+
/**
|
|
76
|
+
* 执行文件上传
|
|
77
|
+
* @param options 上传文件选项
|
|
78
|
+
* @returns Promise<UploadFileResponse> 返回上传结果
|
|
79
|
+
*/
|
|
80
|
+
uploadFile(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* 执行文件下载
|
|
83
|
+
* @param options 下载文件选项
|
|
84
|
+
* @returns Promise<DownloadFileResponse> 返回下载结果
|
|
85
|
+
*/
|
|
86
|
+
downloadFile(options: DownloadFileOptions): Promise<DownloadFileResponse>;
|
|
87
|
+
}
|
|
88
|
+
declare const _default: RequestPlugin;
|
|
89
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface SetStorageOptions extends CallbacksBase {
|
|
4
|
+
key: string;
|
|
5
|
+
data: Record<string, any> | string;
|
|
6
|
+
}
|
|
7
|
+
export interface GetStorageOptions extends CallbacksBase {
|
|
8
|
+
key: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RemoveStorageOptions extends CallbacksBase {
|
|
11
|
+
key: string;
|
|
12
|
+
}
|
|
13
|
+
export interface StorageResponse {
|
|
14
|
+
data?: Record<string, any> | string;
|
|
15
|
+
}
|
|
16
|
+
declare module "../core" {
|
|
17
|
+
interface PluginMethods {
|
|
18
|
+
setStorage: (options: SetStorageOptions) => Promise<string>;
|
|
19
|
+
setStorageSync: (options: SetStorageOptions) => any;
|
|
20
|
+
getStorage: (options: GetStorageOptions) => Promise<string>;
|
|
21
|
+
getStorageSync: (options: GetStorageOptions) => any;
|
|
22
|
+
removeStorage: (options: RemoveStorageOptions) => Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare class StoragePlugin implements BridgePlugin {
|
|
28
|
+
private context?;
|
|
29
|
+
readonly name = "storage";
|
|
30
|
+
readonly version = "1.0.0";
|
|
31
|
+
install(context: PluginContext): void;
|
|
32
|
+
private _createCallbacks;
|
|
33
|
+
private _callNativeMethod;
|
|
34
|
+
/**
|
|
35
|
+
* 同步设置存储数据
|
|
36
|
+
* @param options 存储选项,包含键值和数据
|
|
37
|
+
* @returns 存储响应
|
|
38
|
+
* @throws 如果未提供key,则抛出错误
|
|
39
|
+
*/
|
|
40
|
+
setStorageSync(options: SetStorageOptions): void;
|
|
41
|
+
setStorage(options: SetStorageOptions): Promise<string>;
|
|
42
|
+
getStorageSync(options: GetStorageOptions): any;
|
|
43
|
+
getStorage(options: GetStorageOptions): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* 移除指定的存储数据(异步)
|
|
46
|
+
* @param options 存储选项,包含键值
|
|
47
|
+
* @returns 存储响应
|
|
48
|
+
*/
|
|
49
|
+
removeStorage(options: RemoveStorageOptions): Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
declare const _default: StoragePlugin;
|
|
52
|
+
export default _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface ToastParams {
|
|
4
|
+
/** toast的类型 none, success, fail, exception*/
|
|
5
|
+
type?: "none" | "success" | "fail" | "exception";
|
|
6
|
+
/** 提示信息 */
|
|
7
|
+
content: string;
|
|
8
|
+
/** 显示持续时间,单位毫秒,默认2000ms,按系统规范[android只有两种(<=2s >2s)] */
|
|
9
|
+
duration?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface LoadingParams {
|
|
12
|
+
/** 提示信息 */
|
|
13
|
+
content?: string;
|
|
14
|
+
}
|
|
15
|
+
declare module "../core" {
|
|
16
|
+
interface PluginMethods {
|
|
17
|
+
showToast: (options: ToastParams) => Promise<void>;
|
|
18
|
+
hideToast: () => Promise<void>;
|
|
19
|
+
showLoading: (options: LoadingParams) => Promise<void>;
|
|
20
|
+
hideLoading: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare class ToastPlugin implements BridgePlugin {
|
|
26
|
+
readonly name = "toast";
|
|
27
|
+
readonly version = "1.0.0";
|
|
28
|
+
private context?;
|
|
29
|
+
install(context: PluginContext): void;
|
|
30
|
+
hideLoading(): Promise<void>;
|
|
31
|
+
showLoading(options: LoadingParams): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* 显示Toast提示
|
|
34
|
+
*
|
|
35
|
+
* @param options Toast参数
|
|
36
|
+
* @returns Promise<void>
|
|
37
|
+
*/
|
|
38
|
+
showToast(options: ToastParams): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 隐藏Toast提示
|
|
41
|
+
*
|
|
42
|
+
* @returns Promise<void>
|
|
43
|
+
*/
|
|
44
|
+
hideToast(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare const toastPlugin: ToastPlugin;
|
|
47
|
+
export default toastPlugin;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BridgePlugin, PluginContext } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface ToastParams {
|
|
4
|
+
/** toast的类型 none, success, fail, exception*/
|
|
5
|
+
type: "none" | "success" | "fail" | "exception";
|
|
6
|
+
/** 提示信息 */
|
|
7
|
+
content: string;
|
|
8
|
+
/** 显示持续2000ms时间,单位秒,默认按系统规范[android只有两种(<=2s >2s)] */
|
|
9
|
+
duration?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface LoadingParams {
|
|
12
|
+
/** 提示信息 */
|
|
13
|
+
content?: string;
|
|
14
|
+
}
|
|
15
|
+
declare module "../core" {
|
|
16
|
+
interface PluginMethods {
|
|
17
|
+
getUserInfo: () => Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
interface NativeBridgeCore extends PluginMethods {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
declare class UserInfoPlugin implements BridgePlugin {
|
|
23
|
+
readonly name = "UserInfo";
|
|
24
|
+
readonly version = "1.0.0";
|
|
25
|
+
private context?;
|
|
26
|
+
install(context: PluginContext): void;
|
|
27
|
+
getUserInfo(): Promise<any>;
|
|
28
|
+
}
|
|
29
|
+
export declare const userinfoPlugin: UserInfoPlugin;
|
|
30
|
+
export default userinfoPlugin;
|