@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.4 → 1.0.0-beta.40

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 CHANGED
@@ -4,6 +4,47 @@
4
4
 
5
5
  LamboJsBridge 是一个js 适配sdk 用于处理H5应用和运行时环境的能力调用。支持微信、钉钉等环境。目前已适配微信(WechatAdapter)和企业微信(WeComAdapter)
6
6
 
7
+ ### Vue 全局引入
8
+
9
+ ``` javascript
10
+ /**
11
+ * Vue main.js 中加入如下代码
12
+ */
13
+ console.log("------ 初始化 LamboJsBridge -------")
14
+ import LamboJsBridge from "@lambo-design-mobile/lambo-js-bridge";
15
+ Vue.use(LamboJsBridge);
16
+ ```
17
+ ### 调用
18
+
19
+ ``` javascript
20
+ // 直接调用扫码功能
21
+ // Vue方法中
22
+ this.$lamboJsBridge.scanCode()
23
+
24
+ //其他Js界面
25
+ Vue.prototype.$lamboJsBridge.scanCode();
26
+ /**
27
+ * 也可以自己封装一层工具类
28
+ * 扫描二维码并返回结果。(需要在APP环境下测试)
29
+ * 此函数通过调用 Flutter scanCode.startScan 方法来启动二维码扫描。
30
+ * 扫描成功后返回扫描结果,若扫描失败则返回错误信息。
31
+ *
32
+ * @returns {Promise<String>} - 返回一个 Promise,当扫描成功时 resolve,返回扫描的结果字符串;如果失败,reject 返回错误信息。
33
+ * @example
34
+ * flutterUtil.scanCode()
35
+ * .then(result => {
36
+ * console.log('扫描结果:', result.msg);
37
+ * })
38
+ * .catch(error => {
39
+ * console.error('扫描失败:', error.msg);
40
+ * });
41
+ */
42
+ flutterUtil.scanCode = function() {
43
+ return Vue.prototype.$lamboJsBridge.scanCode();
44
+ };
45
+ ```
46
+
47
+
7
48
  ### 引入
8
49
 
9
50
  ``` javascript
@@ -22,15 +63,17 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
22
63
  wechatId:this.wechatId,
23
64
  weComId:this.weComId,
24
65
  dingTalkId:this.dingTalkId,
66
+ pluginConfig:["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin"],
67
+
25
68
  };
26
- this.lamboBridge = new LamboJsBridge(options);
69
+ this.$lamboJsBridge = new LamboJsBridge(options);
27
70
  await this.getPlatform();
28
71
  },
29
72
 
30
73
  methods: {
31
74
  async getPlatform() {
32
75
  try {
33
- const info = await this.lamboBridge.getPlatform(); // 获取初始化信息
76
+ const info = await this.$lamboJsBridge.getPlatform(); // 获取初始化信息
34
77
  this.initInfo = JSON.stringify(info, null, 2); // 美化输出
35
78
  console.log('Init Info:', info);
36
79
  } catch (error) {
@@ -59,6 +102,40 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
59
102
  | appId | string | | 是 | 微信、企业微信、钉钉 | 对应平台的id |
60
103
  | platform | string | | 是 | 微信、企业微信、钉钉 | 当前浏览器平台 |
61
104
 
105
+
106
+ ### 高德地图初始化key(initKey)
107
+
108
+ 获取用户当前的地理位置信息。
109
+ ``` javascript
110
+ async initKey() {
111
+ try {
112
+ const options ={
113
+ androidKey:"41c4c1f35d8d14f5bf1907c173924147",
114
+ iosKey:"465abf5da8c8d62e3caa63952a0957a5"
115
+ };
116
+ const reslut = await this.$lamboJsBridge.initKey(options);
117
+ this.initKeyMessage = `initKey result: ${result}`;
118
+ } catch (error) {
119
+ console.error('Error initKey:', error);
120
+ }
121
+ },
122
+ ```
123
+ ### 参数说明
124
+
125
+ `params`: Object
126
+
127
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
128
+ |------------------|----------|--------|------|-------|-----------------------------------------------------------------------------------------------|
129
+ | androidKey | string | | 否 | yuntu | 前往高德开放平台创建key https://console.amap.com/dev/key/app |
130
+ | iosKey | string | | 否 | yuntu | 前往高德开放平台创建key https://console.amap.com/dev/key/app |
131
+
132
+ ### 返回说明
133
+
134
+ ``
135
+
136
+
137
+
138
+
62
139
  ### 获取地理位置接口(getLocation)
63
140
 
64
141
  获取用户当前的地理位置信息。
@@ -68,7 +145,7 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
68
145
  const options ={
69
146
  // 初始化参数,根据需要填写
70
147
  };
71
- const location = await this.lamboBridge.getLocation(options);
148
+ const location = await this.$lamboJsBridge.getLocation(options);
72
149
  console.log("location",location)
73
150
  this.location += `${JSON.stringify(location)}\n`; // 追加新数据
74
151
  this.latitude = location.latitude; // 存储纬度
@@ -115,7 +192,7 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
115
192
  const options ={
116
193
  // 初始化参数,根据需要填写
117
194
  };
118
- const result = await this.lamboBridge.scanCode(options);
195
+ const result = await this.$lamboJsBridge.scanCode(options);
119
196
  this.scanResult += `${JSON.stringify(result)}\n`; // 追加新数据
120
197
  console.log('Scan result:', result);
121
198
  } catch (error) {
@@ -155,7 +232,7 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
155
232
  ossImgPutUrl: this.ossImgPutUrl,
156
233
  ossImgGetUrl: this.ossImgGetUrl
157
234
  };
158
- const photo = await this.lamboBridge.takePhoto(options);
235
+ const photo = await this.$lamboJsBridge.takePhoto(options);
159
236
  this.photoResult += `${JSON.stringify(photo)}\n`; // 追加新数据
160
237
  console.log('Photo result:', photo);
161
238
  } catch (error) {
@@ -169,27 +246,28 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
169
246
 
170
247
  `params`: Object
171
248
 
172
- | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
173
- |---------------------|-----------|--------------------------|-----|----------|------------------------------------------------------------------|
174
- | count | number | 1 | 否 | 微信、企业微信、钉钉 | 选择图片数量 |
175
- | sizeType | string[] | ['camera', 'album'] | 否 | 微信、企业微信、钉钉 | 相册选取或者拍照。album:相册,camera:相机 |
176
- | outputType | string[] | ['info', 'data', 'oss'] | 否 | 微信、企业微信、钉钉 | 图像输出格式。info 选定图像的本地信息,data 选定图像的base64数据,oss为上传oss-server |
177
- | defaultCameraMode | string | | 否 | 企业微信 | 进入拍照界面的默认模式。normal 单拍,batch 连拍,front 前置摄像头单拍,batch_front 前置摄像头连拍 |
178
- | isSaveToAlbum | boolean | true | 否 | 企业微信 | 拍照时是否保存到系统相册 |
179
- | position | string | back | 否 | 钉钉 | 相机拍照使用的摄像头:front:前置摄像头,back:后置摄像头 |
180
- | ossServerContext | string | | | 微信、企业微信、钉钉 | 上传oss-server服务器地址 |
181
- | ossImgPutUrl | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server图片接口地址 |
182
- | ossImgGetUrl | string | | 是 | 微信、企业微信、钉钉 | 下载oss-server图片接口地址 |
249
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
250
+ |-------------------|---------|-------------------------|-----|----------|------------------------------------------------------------------|
251
+ | count | number | 1 | 否 | 微信、企业微信、钉钉 | 选择图片数量 |
252
+ | sizeType | string[] | ['camera', 'album'] | 否 | 微信、企业微信、钉钉 | 相册选取或者拍照。album:相册,camera:相机 |
253
+ | outputType | string[] | ['info', 'data', 'oss'] | 否 | 微信、企业微信、钉钉 | 图像输出格式。info 选定图像的本地信息,data 选定图像的base64数据,oss为上传oss-server |
254
+ | method | string | 'file'或'blob' | 否 | 微信、企业微信、钉钉 | 上传oss方法,默认为blob |
255
+ | defaultCameraMode | string | | 否 | 企业微信 | 进入拍照界面的默认模式。normal 单拍,batch 连拍,front 前置摄像头单拍,batch_front 前置摄像头连拍 |
256
+ | isSaveToAlbum | boolean | true | 否 | 企业微信 | 拍照时是否保存到系统相册 |
257
+ | position | string | back | | 钉钉 | 相机拍照使用的摄像头:front:前置摄像头,back:后置摄像头 |
258
+ | ossServerContext | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server服务器地址 |
259
+ | ossImgPutUrl | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server图片接口地址 |
260
+ | ossImgGetUrl | string | | 是 | 微信、企业微信、钉钉 | 下载oss-server图片接口地址 |
183
261
 
184
262
  ### 返回说明
185
263
 
186
264
  `Promise<Array>`
187
265
 
188
- | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
189
- |-----------|-----------|--------|------|----------|---------------|
190
- | imageInfo | string[] | | 否 | 微信、企业微信、钉钉 | 选定图像的本地信息 |
191
- | imageData | string[] | | 否 | 微信、企业微信、钉钉 | 选定图像的base64数据 |
192
- | imageOss | string[] | | 否 | 微信、企业微信、钉钉 | 选定图像的oss返回数据 |
266
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
267
+ |-----------|----------|--------|------|----------|---------------|
268
+ | imageInfo | string[] | | 否 | 微信、企业微信、钉钉 | 选定图像的本地信息 |
269
+ | imageData | string[] | | 否 | 微信、企业微信、钉钉 | 选定图像的base64数据 |
270
+ | imageOss | JSON | | 否 | 微信、企业微信、钉钉 | 选定图像的oss返回数据 |
193
271
 
194
272
  ### 使用内置地图查看位置(openLocation)
195
273
 
@@ -204,9 +282,10 @@ async openLocation() {
204
282
  longitude: this.longitude,
205
283
  name: this.name,
206
284
  address: this.address,
207
- scale: this.scale
285
+ scale: this.scale,
286
+ type:"amap"
208
287
  };
209
- await this.lamboBridge.openLocation(options);
288
+ await this.$lamboJsBridge.openLocation(options);
210
289
  this.openLocationResult = '位置已成功打开'; // 成功打开位置时存储信息
211
290
  console.log('Location opened successfully');
212
291
  } else {
@@ -227,12 +306,218 @@ async openLocation() {
227
306
 
228
307
  | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
229
308
  |-----------|--|-----|-----|----------|------------------------------------------------------------------|
230
- | latitude | number | | 是 | 微信、企业微信、钉钉 | 纬度,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系 |
231
- | longitude | number | | 是 | 微信、企业微信、钉钉 | 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系 |
309
+ | latitude | number | | 是 | 微信、企业微信、钉钉、Yuntu | 纬度,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系 |
310
+ | longitude | number | | 是 | 微信、企业微信、钉钉、Yuntu | 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系 |
232
311
  | name | string | | 钉钉 | 微信、企业微信、钉钉 | 位置名称 |
233
312
  | address | string | | 钉钉 | 微信、企业微信、钉钉 | 详细位置 |
234
313
  | scale | number | | 否 | 微信、企业微信 | 缩放比例,范围5~18 |
314
+ | type | string | amap | 否 | Yuntu | 'baidu':百度地图,'amap':高德地图,'URLSchema':自定义协议 |
235
315
 
236
316
  ### 返回说明
237
317
 
238
318
 
319
+
320
+ ### 录音(仅在Flutter环境下可用)
321
+
322
+ 此接口提供音频录制功能,可以开始录音、停止录音以及自动录音。自动录音指检测不到声音后自动停止。
323
+ ``` javascript
324
+ data() {
325
+ return {
326
+ audioUrl: null, // 用于存储录音文件的 URL
327
+ recordingStatus: "not started", // 用于记录当前录音状态
328
+ };
329
+ },
330
+ method:{
331
+ // 开始手动录音
332
+ async startRecording() {
333
+ // 清空之前的录音数据
334
+ this.audioUrl = null;
335
+ this.recordingStatus = 'recording';
336
+ try {
337
+ // 传入 { auto: false } 表示手动录音
338
+ const result = await this.$lamboJsBridge.startRecording({ auto: false });
339
+ console.log("录音开始成功:", result);
340
+ } catch (error) {
341
+ console.error("录音开始失败:", error);
342
+ this.recordingStatus = 'failed';
343
+ }
344
+ },
345
+
346
+ // 开始自动录音
347
+ async startAutoRecording() {
348
+ // 清空之前的录音数据
349
+ this.audioUrl = null;
350
+ this.recordingStatus = 'recording';
351
+ try {
352
+ // 传入 { auto: true } 表示启用自动录音
353
+ const result = await this.$lamboJsBridge.startRecording({ auto: true , silenceDelay: 1, silenceStopSeconds: 2, volumeThreshold: 60});
354
+ console.log("自动录音开始成功:", result);
355
+ } catch (error) {
356
+ console.error("自动录音开始失败:", error);
357
+ this.recordingStatus = 'failed';
358
+ }
359
+ },
360
+
361
+ // 停止录音
362
+ async stopRecording() {
363
+ try {
364
+ const result = await this.$lamboJsBridge.stopRecording();
365
+ console.log("录音停止成功:", result);
366
+ this.recordingStatus = 'stopped';
367
+ // 更新录音文件信息
368
+ this.audioUrl = result.fileUrl || result.msg;
369
+ // 如果你非要用全局函数更新,也可以调用它
370
+ this.updateAudioDisplay(result);
371
+ } catch (error) {
372
+ console.error("录音停止失败:", error);
373
+ this.recordingStatus = 'failed';
374
+ }
375
+ },
376
+
377
+ // 如果你希望借助类似全局函数的形式更新页面,可以这样定义:
378
+ updateAudioDisplay(data) {
379
+ // 更新组件中的数据,页面会自动响应
380
+ this.recordingStatus = 'stopped';
381
+ this.audioUrl = data.fileUrl;
382
+ this.audioPath = data.filePath;
383
+ this.audioData = data.fileData;
384
+ },
385
+ },
386
+ mounted() {
387
+ window.updateAudioDisplay = this.updateAudioDisplay;
388
+ },
389
+ ```
390
+
391
+ ### 参数说明
392
+
393
+ `recordingOptions`: Object
394
+
395
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
396
+ |-----------|---------|-------|-----|----------|---------------------------|
397
+ | isAuto | boolean | false | 否 | Yuntu | 是否开启自动录音。若为 true,则自动开始录音。 |
398
+ | silenceDelay | int | 3 | 否 | Yuntu | 延迟 n 秒后开始静音检测 |
399
+ | silenceStopSeconds | int | 4 | 否 | Yuntu | 连续 n 秒静音停止录音 |
400
+ | volumeThreshold | double | 40 | 否 | Yuntu | 音量阈值,单位为分贝 |
401
+
402
+
403
+ ### 返回说明
404
+
405
+ `Promise<Object>`
406
+
407
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
408
+ |-----------|--|----------|-----|----------|---------------|
409
+ | fileUrl | string | | 是 | Yuntu | 录音文件的URL |
410
+ | filePath | string | | 是 | Yuntu | 录音文件的路径 |
411
+ | fileData | string | | 是 | Yuntu | 录音文件的base64文件 |
412
+ <br>
413
+
414
+ **录音状态** <br>
415
+ **recording**:录音进行中。<br>
416
+ **not started**:录音未开始。<br>
417
+ **stopped**:录音已停止。<br>
418
+ **failed**:录音失败。<br>
419
+
420
+ ### 下载文件(downloadFile)
421
+
422
+ 调用文件下载功能,通过指定文件 URL 下载文件,并自动触发下载行为。
423
+ ``` javascript
424
+ async downloadFile() {
425
+ try {
426
+ const fileUrl = 'http://10.110.34.27/yc_scrm.apk'; // 需要下载的文件 URL
427
+ const fileName = '下载文件'; // 文件保存名称
428
+ await this.$lamboJsBridge.downloadFile({ fileUrl, fileName });
429
+ console.log('Download initiated');
430
+ } catch (error) {
431
+ console.error('Download failed:', error);
432
+ }
433
+ }
434
+ ```
435
+
436
+ ### 参数说明
437
+
438
+ `params`: Object
439
+
440
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
441
+ |-----------|--|----------|-----|----------|-------------------------------------------------------------|
442
+ | fileUrl | string | 无 | 是 | Yuntu | 要下载文件的 URL 地址 |
443
+ | fileName | string | 'downloadedFile' | 否 | Yuntu | 下载后保存的文件名称,建议不包含文件扩展名(可由调用者自行添加扩展名) |
444
+
445
+
446
+ ### 返回说明
447
+
448
+ `Promise<Object>`
449
+
450
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
451
+ |-----------|--|----------|-----|----------|---------|
452
+ | filePath | string | | 是 | Yuntu | 录音文件的路径 |
453
+
454
+ ### 生物认证
455
+
456
+ 提供本地生物特征认证能力,支持指纹/面容识别验证,支持查询设备可用生物特征类型。
457
+
458
+ ``` javascript
459
+ async localAuth() {
460
+ try {
461
+ const options = {
462
+ localizedReason: 'A1',
463
+ biometricHint: 'A2',
464
+ cancelButton: 'A3',
465
+ signInTitle: 'A4'
466
+ }
467
+ const result = await this.$lamboJsBridge.localAuthPlugin(options)
468
+ this.localAuthResult = JSON.stringify(result, null, 2)
469
+ console.log('localAuthResult:', result);
470
+ this.availableBiometrics = '' // 清空另一个结果
471
+ } catch (error) {
472
+ // 结构化错误处理
473
+ const errorMessage = error.msg || error.message || '未知错误';
474
+ const authId = error.authId || '未知设备';
475
+
476
+ this.localAuthResult = `认证失败:${errorMessage},authId:${authId}`;
477
+ console.error('完整错误信息:', error);
478
+ }
479
+ },
480
+ async getAvailableBiometrics() {
481
+ try {
482
+ const result = await this.$lamboJsBridge.getAvailableBiometrics()
483
+ this.availableBiometrics = JSON.stringify(result, null, 2)
484
+ this.localAuthResult = '' // 清空另一个结果
485
+ } catch (error) {
486
+ this.availableBiometrics = `获取失败: ${error.message}`
487
+ }
488
+ },
489
+ ```
490
+
491
+ ### 参数说明
492
+
493
+ `localAuthPlugin params`: Object
494
+
495
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
496
+ |-----------|--------|-------|-----|----------|---------------------|
497
+ | localizedReason | string | 认证 | 否 | Yuntu | 自定义生物识别验证弹窗居中正文文字 |
498
+ | biometricHint | string | 扫描指纹进行身份验证 | 否 | Yuntu | 自定义生物识别验证弹窗副标题文字 |
499
+ | cancelButton | string | 取消 | 否 | Yuntu | 自定义生物识别验证弹窗取消位置按钮文字 |
500
+ | signInTitle | string | 指纹验证 | 否 | Yuntu | 自定义生物识别验证弹窗标题 |
501
+
502
+ <br>
503
+
504
+ `getAvailableBiometrics`: 无需参数
505
+
506
+ ### 返回说明
507
+
508
+ `localAuthPlugin: Promise<Object>`
509
+
510
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
511
+ |--------|--|----------|-----|----------|------|
512
+ | msg | string | | 是 | Yuntu | 返回信息 |
513
+ | authId | string | | 是 | Yuntu | 设备ID |
514
+
515
+ <br>
516
+
517
+ `getAvailableBiometrics: Promise<Object>`
518
+
519
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
520
+ |---------------------|--------|----------|-----|----------|---------|
521
+ | msg | string | | 是 | Yuntu | 返回信息 |
522
+ | availableBiometrics | array | | 是 | Yuntu | 支持的生物识别 |
523
+ | authId | string | | 是 | Yuntu | 设备ID |