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

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/demo/index.vue CHANGED
@@ -1,20 +1,24 @@
1
1
  <template>
2
2
  <demo-section>
3
3
  <demo-block title="初始化信息">
4
- <pre v-if="initInfo"><code>{{ initInfo }}</code></pre>
4
+ <pre v-show="initInfo"><code>{{ initInfo }}</code></pre>
5
+ </demo-block>
6
+ <demo-block title="初始化地图Key">
7
+ <van-button @click="initKey">初始化地图Key</van-button>
8
+ <pre v-show="initKeyMessage"><code>{{ initKeyMessage }}</code></pre>
5
9
  </demo-block>
6
10
  <demo-block title="获取定位">
7
11
  <van-button @click="getLocation">获取定位</van-button>
8
- <pre v-if="location"><code>{{ location }}</code></pre>
12
+ <pre v-show="location"><code>{{ location }}</code></pre>
9
13
  </demo-block>
10
14
  <demo-block title="扫码">
11
15
  <van-button @click="scanCode">扫码</van-button>
12
- <pre v-if="scanResult"><code>{{ scanResult }}</code></pre>
16
+ <pre v-show="scanResult"><code>{{ scanResult }}</code></pre>
13
17
  </demo-block>
14
18
  <demo-block title="拍照">
15
19
  <van-button @click="takePhoto">拍照</van-button>
16
- <pre v-if="photoResult"><code>{{ photoResult }}</code></pre>
17
- <div v-if="photoPreviews.length" :class="gridClass">
20
+ <pre v-show="photoResult"><code>{{ photoResult }}</code></pre>
21
+ <div v-show="photoPreviews.length" :class="gridClass">
18
22
  <div v-for="(preview, index) in photoPreviews" :key="index" class="photo-container">
19
23
  <img :src="preview" alt="Photo Preview" class="photo">
20
24
  </div>
@@ -22,19 +26,73 @@
22
26
  </demo-block>
23
27
  <demo-block title="打开位置">
24
28
  <van-button @click="openLocation">打开位置</van-button>
25
- <pre v-if="openLocationResult"><code>{{ openLocationResult }}</code></pre>
29
+ <pre v-show="openLocationResult"><code>{{ openLocationResult }}</code></pre>
26
30
  </demo-block>
27
- </demo-section>
28
- </template>
29
-
31
+ <demo-block title="文件预览">
32
+ <a href="javascript:void(0);" @click="filePreview">点击这里预览文件</a>
33
+ </demo-block>
34
+ <demo-block title="录音(仅在Flutter环境下可用)">
35
+ <van-button @click="startRecording">开始录音</van-button>
36
+ <van-button @click="startAutoRecording" style="margin-left: 5px">自动录音</van-button>
37
+ <van-button @click="stopRecording" style="margin-left: 5px">停止录音</van-button>
38
+ <van-button @click="startWeComRecording" style="margin-left: 5px;">企业微信开始录音</van-button>
39
+ <van-button @click="stopWeComRecording" style="margin-left: 5px;">企业微信停止录音</van-button>
40
+ <van-button @click="startCcworkRecording" style="margin-left: 5px;">云上协同开始录音</van-button>
41
+ <div v-if="recordingStatus === 'recording'">
42
+ <p>正在录音中...</p>
43
+ </div>
44
+ <div v-else-if="recordingStatus === 'not started'">
45
+ <p>录音未开始</p>
46
+ </div>
47
+ <div v-else-if="recordingStatus === 'stopped'">
48
+ <p>录音结束</p>
49
+ </div>
50
+ <div v-else-if="recordingStatus === 'failed'">
51
+ <p>录音失败</p>
52
+ </div>
53
+ <div v-if="audioUrl">
54
+ <h3>录音已完成</h3>
55
+ <audio :src="audioUrl" controls></audio>
56
+ <p>FileUrl:{{ audioUrl }}</p>
57
+ <p>FilePath:{{ audioPath }}</p>
58
+ <p>FileData:{{ audioData }}</p>
59
+ </div>
60
+ </demo-block>
61
+ <demo-block title="下载">
62
+ <van-button @click="downloadFile">下载文件</van-button>
63
+ <p v-if="downloadLink">文件已下载,路径:{{ downloadLink }}</p>
64
+ </demo-block>
65
+ <demo-block title="生物认证">
66
+ <div class="auth-buttons">
67
+ <van-button @click="localAuth" class="auth-button">生物认证</van-button>
68
+ <van-button
69
+ @click="getAvailableBiometrics"
70
+ class="auth-button"
71
+ style="margin-left: 12px"
72
+ >
73
+ 获取生物特征
74
+ </van-button>
75
+ </div>
30
76
 
77
+ <div v-if="localAuthResult" class="result-box">
78
+ <p class="result-title">认证结果:</p>
79
+ <pre><code>{{ localAuthResult }}</code></pre>
80
+ </div>
31
81
 
82
+ <div v-if="availableBiometrics" class="result-box">
83
+ <p class="result-title">支持的特征:</p>
84
+ <pre><code>{{ availableBiometrics }}</code></pre>
85
+ </div>
86
+ </demo-block>
87
+ </demo-section>
88
+ </template>
32
89
 
33
90
  <script>
34
91
  import LamboJsBridge from "../src/sdk/LamboJsBridge";
92
+ import {PRINTER_PLUGIN} from "../src/sdk/YunTuAdapter";
35
93
 
36
94
  export default {
37
- name: 'MyComponent',
95
+ name: 'js-bridge-demo',
38
96
  data() {
39
97
  return {
40
98
  lamboBridge: null,
@@ -43,8 +101,8 @@ export default {
43
101
  scanResult: '',
44
102
  photoResult: '',
45
103
  openLocationResult: '', // 添加用于存储打开位置的返回值
46
- latitude: null, // 存储纬度
47
- longitude: null, // 存储经度
104
+ latitude: 117.129, // 存储纬度
105
+ longitude: 36.662, // 存储经度
48
106
  ossServerContext: 'ibp-upms-server',
49
107
  ossImgPutUrl: '/oss/file/put',
50
108
  ossImgGetUrl: '/oss/file/get/',
@@ -53,18 +111,30 @@ export default {
53
111
  address:'这里是详细位置address',
54
112
  wechatId: 'wx92fab9d3885b0298',
55
113
  weComId: 'wx0eb3ba9d89eca3cb',
114
+ agentId:'1000065',
56
115
  dingTalkId: '',
57
- photoPreviews: []
116
+ photoPreviews: [],
117
+ initKeyMessage: '', // 用于存储 initKey 的返回消息
118
+ recordingWeComStatus: '',
119
+ recordingCcWorkStatus: '',
120
+ recordingFileInfo: {},
121
+ audioUrl: null, // 用于存储录音文件的 URL
122
+ audioPath: null,
123
+ audioData: null,
124
+ recordingStatus: "not started", // 用于记录当前录音状态
125
+ downloadLink : null,
126
+ localAuthResult: '', // 生物认证结果
127
+ availableBiometrics: '' // 支持的生物特征
58
128
  };
59
129
  },
60
130
  computed: {
61
131
  gridClass() {
62
- const length = this.photoPreviews.length;
132
+ const {length} = this.photoPreviews;
63
133
  if (length === 1) {
64
134
  return 'grid-single';
65
- } else if (length > 1 && length <= 4) {
135
+ } if (length > 1 && length <= 4) {
66
136
  return 'grid-two';
67
- } else if (length > 4) {
137
+ } if (length > 4) {
68
138
  return 'grid-three';
69
139
  }
70
140
  return '';
@@ -79,32 +149,177 @@ export default {
79
149
  // 初始化参数,根据需要填写
80
150
  wechatId:this.wechatId,
81
151
  weComId:this.weComId,
152
+ agentId:this.agentId,
82
153
  dingTalkId:this.dingTalkId,
154
+ pluginConfig:["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","autoRecordPlugin","downloadFilePlugin", PRINTER_PLUGIN],
83
155
  };
84
- this.lamboBridge = new LamboJsBridge(options);
156
+ this.$lamboJsBridge = new LamboJsBridge(options);
85
157
  await this.getPlatform();
158
+ // await this.$lamboJsBridge.initializePlugin(options.pluginConfig);
86
159
  },
87
160
  methods: {
88
161
  async getPlatform() {
89
162
  try {
90
- const info = await this.lamboBridge.getPlatform(); // 获取初始化信息
163
+ const info = await this.$lamboJsBridge.getPlatform(); // 获取初始化信息
91
164
  this.initInfo = JSON.stringify(info, null, 2); // 美化输出
92
165
  console.log('Init Info:', info);
93
166
  } catch (error) {
94
167
  console.error('Error getting init info:', error);
95
168
  }
96
169
  },
170
+
171
+ async startWeComRecording() {
172
+ this.recordingWeComStatus = 'processing';
173
+ this.recordingFileInfo = null;
174
+ try {
175
+ await this.$lamboJsBridge.startWeComRecording({
176
+ // 当60秒自动停止并成功时:
177
+ onAutoStopSuccess: (fileInfo) => {
178
+ console.log('【自动停止】处理成功:', fileInfo);
179
+ this.recordingFileInfo = fileInfo;
180
+ this.recordingWeComStatus = 'done';
181
+ },
182
+ // 当60秒自动停止但失败时:
183
+ onAutoStopError: (error) => {
184
+ console.error('【自动停止】处理失败:', error);
185
+ this.recordingWeComStatus = 'error';
186
+ }
187
+ });
188
+
189
+ this.recordingWeComStatus = 'recording';
190
+
191
+ } catch (error) {
192
+ console.error("开始录音失败:", error);
193
+ this.recordingWeComStatus = 'error';
194
+ }
195
+ },
196
+
197
+ async stopWeComRecording() {
198
+ this.recordingWeComStatus = 'processing';
199
+ try {
200
+ const fileInfo = await this.$lamboJsBridge.stopWeComRecording();
201
+ console.log('【手动停止】处理成功:', fileInfo);
202
+ this.recordingFileInfo = fileInfo;
203
+ this.recordingWeComStatus = 'done';
204
+
205
+ } catch (error) {
206
+ console.error('【手动停止】处理失败:', error);
207
+ this.recordingWeComStatus = 'error';
208
+ }
209
+ },
210
+
211
+ async startCcworkRecording() {
212
+ this.recordingCcWorkStatus = 'processing';
213
+ this.recordingFileInfo = null;
214
+
215
+ try {
216
+ console.log('正在调用 startCcworkRecording...');
217
+ const fileInfo = await this.$lamboJsBridge.startCcworkRecording();
218
+ console.log('【录音上传】处理成功:', fileInfo);
219
+ this.recordingFileInfo = fileInfo;
220
+ this.recordingCcWorkStatus = 'done';
221
+
222
+ } catch (error) {
223
+ console.error('【录音上传】处理失败:', error);
224
+ this.recordingCcWorkStatus = 'error';
225
+ }
226
+ },
227
+
228
+ // 开始手动录音
229
+ async startRecording() {
230
+ // 清空之前的录音数据
231
+ this.audioUrl = null;
232
+ this.recordingStatus = 'recording';
233
+ try {
234
+ // 传入 { auto: false } 表示手动录音
235
+ const result = await this.$lamboJsBridge.startRecording({ auto: false });
236
+ console.log("录音开始成功:", result);
237
+ } catch (error) {
238
+ console.error("录音开始失败:", error);
239
+ this.recordingStatus = 'failed';
240
+ }
241
+ },
242
+
243
+ // 开始自动录音
244
+ async startAutoRecording() {
245
+ // 清空之前的录音数据
246
+ this.audioUrl = null;
247
+ this.recordingStatus = 'recording';
248
+ try {
249
+ // 传入 { auto: true } 表示启用自动录音
250
+ const result = await this.$lamboJsBridge.startRecording({ auto: true , silenceDelay: 1, silenceStopSeconds: 2, volumeThreshold: 60});
251
+ console.log("自动录音开始成功:", result);
252
+ } catch (error) {
253
+ console.error("自动录音开始失败:", error);
254
+ this.recordingStatus = 'failed';
255
+ }
256
+ },
257
+
258
+ // 停止录音
259
+ async stopRecording() {
260
+ try {
261
+ const result = await this.$lamboJsBridge.stopRecording();
262
+ console.log("录音停止成功:", result);
263
+ this.recordingStatus = 'stopped';
264
+ // 更新录音文件信息
265
+ this.audioUrl = result.fileUrl || result.msg;
266
+ // 如果你非要用全局函数更新,也可以调用它
267
+ this.updateAudioDisplay(result);
268
+ } catch (error) {
269
+ console.error("录音停止失败:", error);
270
+ this.recordingStatus = 'failed';
271
+ }
272
+ },
273
+
274
+ // 如果你希望借助类似全局函数的形式更新页面,可以这样定义:
275
+ updateAudioDisplay(data) {
276
+ // 更新组件中的数据,页面会自动响应
277
+ this.recordingStatus = 'stopped';
278
+ this.audioUrl = data.fileUrl;
279
+ this.audioPath = data.filePath;
280
+ this.audioData = data.fileData;
281
+ },
282
+
283
+
284
+ async downloadFile(){
285
+ try {
286
+ const fileUrl = 'http://10.110.34.27/sampleFile.txt'; // 要下载的文件 URL
287
+ const fileName = '下载文件.txt'; // 文件名称(建议带上扩展名)
288
+ // 注意传递的参数键需与插件内部代码一致:title 和 path
289
+ let result = await this.$lamboJsBridge.downloadFile({ title: fileName, path: fileUrl });
290
+ console.log('Download initiated, result:', result);
291
+
292
+ // 如果返回的数据为字符串,则尝试解析为对象
293
+ if (typeof result === 'string') {
294
+ try {
295
+ result = JSON.parse(result);
296
+ } catch (e) {
297
+ console.error('解析下载结果失败:', e);
298
+ }
299
+ }
300
+
301
+ // 假设返回的对象中包含 path 属性(如果没有则直接使用 result)
302
+ const filePath = result.path || result;
303
+ // 更新组件数据,显示文件下载路径
304
+ this.downloadLink = filePath;
305
+ } catch (error){
306
+ console.error('Download failed:', error);
307
+ }
308
+ },
309
+
97
310
  async getLocation() {
98
311
  try {
99
312
  const options ={
100
313
  // 初始化参数,根据需要填写
101
314
  };
102
- const location = await this.lamboBridge.getLocation(options);
315
+ const location = await this.$lamboJsBridge.getLocation(options);
103
316
  console.log("location",location)
104
317
  this.location += `${JSON.stringify(location)}\n`; // 追加新数据
105
318
  this.latitude = location.latitude; // 存储纬度
106
319
  this.longitude = location.longitude; // 存储经度
107
- console.log('Location:', location);
320
+ console.log("this.latitude:",this.latitude);
321
+ console.log("this.longitude:",this.longitude);
322
+ // console.log('Location:', location);
108
323
  } catch (error) {
109
324
  console.error('Error getting location:', error);
110
325
  }
@@ -114,7 +329,7 @@ export default {
114
329
  const options ={
115
330
  // 初始化参数,根据需要填写
116
331
  };
117
- const result = await this.lamboBridge.scanCode(options);
332
+ const result = await this.$lamboJsBridge.scanCode(options);
118
333
  this.scanResult += `${JSON.stringify(result)}\n`; // 追加新数据
119
334
  // console.log('Scan result:', result);
120
335
  } catch (error) {
@@ -126,11 +341,15 @@ export default {
126
341
  const options = {
127
342
  ossServerContext: this.ossServerContext,
128
343
  ossImgPutUrl: this.ossImgPutUrl,
129
- ossImgGetUrl: this.ossImgGetUrl
344
+ ossImgGetUrl: this.ossImgGetUrl,
345
+ outputType: ['info','data','oss'],
346
+ method: 'file',
347
+ // sourceType: 'gallery'
130
348
  };
131
- const photos = await this.lamboBridge.takePhoto(options);
349
+ const photos = await this.$lamboJsBridge.takePhoto(options);
132
350
  this.photoResult += `${JSON.stringify(photos)}\n`;
133
351
  console.log("Photo result:", photos); // 调试输出
352
+ console.log("oss:",photos.imageOss)
134
353
 
135
354
  photos.forEach(photo => {
136
355
  if (photo.imageOss && photo.imageOss.url) {
@@ -149,14 +368,15 @@ export default {
149
368
  try {
150
369
  if (this.latitude !== null && this.longitude !== null) {
151
370
  const options = {
152
- //初始化参数,根据需要修改
371
+ // 初始化参数,根据需要修改
153
372
  latitude: this.latitude,
154
373
  longitude: this.longitude,
155
374
  name: this.name,
156
375
  address: this.address,
157
- scale: this.scale
376
+ scale: this.scale,
377
+ type:"amap"
158
378
  };
159
- await this.lamboBridge.openLocation(options);
379
+ await this.$lamboJsBridge.openLocation(options);
160
380
  this.openLocationResult = '位置已成功打开'; // 成功打开位置时存储信息
161
381
  console.log('Location opened successfully');
162
382
  } else {
@@ -167,7 +387,64 @@ export default {
167
387
  this.openLocationResult = `打开位置时出错: ${error.message}`; // 存储错误信息
168
388
  console.error('Error opening location:', error);
169
389
  }
170
- }
390
+ },
391
+ async filePreview() {
392
+ try {
393
+ const options = {
394
+ title: '预览文件.txt', // 文件的标题
395
+ path: 'http://160.mall.eap.lambo.top/ecm-runtime-server/api/file/get/123456' ,// 文件的URL路径
396
+ tokenKey:"lambo-token-ibp"
397
+ };
398
+ const result = await this.$lamboJsBridge.filePreview(options);
399
+ console.log('File preview result:', result);
400
+ } catch (error) {
401
+ console.error('Error previewing file:', error);
402
+ }
403
+ },
404
+ async initKey() {
405
+ try {
406
+ const result = await this.$lamboJsBridge.initKey( {"androidKey":"41c4c1f35d8d14f5bf1907c173924147","iosKey":"465abf5da8c8d62e3caa63952a0957a5"});
407
+ console.log('initKey result:', result);
408
+ this.initKeyMessage = `initKey result: ${JSON.stringify(result)}`;
409
+ } catch (error) {
410
+ this.initKeyMessage = `初始化 Key 时出错: ${error.message}`;
411
+ console.error('Error initializing key:', error);
412
+ }
413
+ },
414
+ async localAuth() {
415
+ try {
416
+ const options = {
417
+ localizedReason: 'A1',
418
+ biometricHint: 'A2',
419
+ cancelButton: 'A3',
420
+ signInTitle: 'A4'
421
+ }
422
+ const result = await this.$lamboJsBridge.localAuthPlugin(options)
423
+ this.localAuthResult = JSON.stringify(result, null, 2)
424
+ console.log('localAuthResult:', result);
425
+ this.availableBiometrics = '' // 清空另一个结果
426
+ } catch (error) {
427
+ // 结构化错误处理
428
+ const errorMessage = error.msg || error.message || '未知错误';
429
+ const authId = error.authId || '未知设备';
430
+
431
+ this.localAuthResult = `认证失败:${errorMessage},authId:${authId}`;
432
+ console.error('完整错误信息:', error);
433
+ }
434
+ },
435
+ async getAvailableBiometrics() {
436
+ try {
437
+
438
+ const result = await this.$lamboJsBridge.getAvailableBiometrics()
439
+ this.availableBiometrics = JSON.stringify(result, null, 2)
440
+ this.localAuthResult = '' // 清空另一个结果
441
+ } catch (error) {
442
+ this.availableBiometrics = `获取失败: ${error.message}`
443
+ }
444
+ },
445
+ },
446
+ mounted() {
447
+ window.updateAudioDisplay = this.updateAudioDisplay;
171
448
  },
172
449
  beforeRouteEnter (to, from, next) {
173
450
  next(vm => {
@@ -181,8 +458,6 @@ export default {
181
458
  };
182
459
  </script>
183
460
 
184
-
185
-
186
461
  <style scoped>
187
462
  pre {
188
463
  background-color: #f5f5f5;
@@ -220,4 +495,23 @@ code {
220
495
  max-width: 100%;
221
496
  border-radius: 4px;
222
497
  }
498
+ .auth-buttons {
499
+ margin-bottom: 16px;
500
+ }
501
+
502
+ .auth-button {
503
+ min-width: 120px;
504
+ }
505
+
506
+ .result-box {
507
+ margin-top: 12px;
508
+ border-top: 1px solid #eee;
509
+ padding-top: 12px;
510
+ }
511
+
512
+ .result-title {
513
+ color: #666;
514
+ font-size: 12px;
515
+ margin-bottom: 8px;
516
+ }
223
517
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design-mobile/lambo-js-bridge",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.41",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -9,7 +9,10 @@
9
9
  "access": "public",
10
10
  "registry": "https://registry.npmjs.org/"
11
11
  },
12
- "dependencies": {},
12
+ "dependencies": {
13
+ "coordtransform": "^2.1.2",
14
+ "gcoord": "^0.1.2"
15
+ },
13
16
  "scripts": {
14
17
  "release-js-bridge": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
15
18
  "release-major": "standard-version --release-as major",
@@ -0,0 +1,74 @@
1
+ import config from "@lambo-design-mobile/shared/config/config";
2
+ import coordtransform from "coordtransform";
3
+
4
+ const addScript = function (src, cb) {
5
+ const script = document.createElement('script')
6
+ script.src = src
7
+ document.getElementsByTagName('head')[0].appendChild(script)
8
+ script.onload = function () {
9
+ if (!!cb) {
10
+ cb()
11
+ }
12
+ }
13
+ }
14
+
15
+ export function initBdMap() {
16
+ let tempAk = 'AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT'
17
+ if (config.akList) {
18
+ tempAk = config.akList[Math.random() * config.akList.length]
19
+ }
20
+ addScript('https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=' + tempAk)
21
+ addScript('https://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=' + tempAk)
22
+ }
23
+
24
+ export function getAddress(longitude, latitude) {
25
+ const myGeo = new BMap.Geocoder({extensions_town: false});
26
+ let city = ''
27
+ let province = ''
28
+ let address = ''
29
+
30
+ // 根据坐标得到地址描述
31
+ myGeo.getLocation(new BMap.Point(longitude, latitude), function(result){
32
+ if (result){
33
+ city = result.addressComponents.city
34
+ province = result.addressComponents.province
35
+ address = result.address
36
+ }
37
+ });
38
+ return {
39
+ city,
40
+ province,
41
+ address
42
+ }
43
+ }
44
+
45
+ export function getAxisByType(unifiedLocation, locationType) {
46
+ // 目前只有wgs84 bd09 gcj02 默认传进unifiedLocation 坐标系为gcj02 不转换
47
+ if(locationType === 'bd09') {
48
+ // 将 gcj02 坐标转换为 bd09
49
+ const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
50
+ unifiedLocation.longitude = bd09Lng;
51
+ unifiedLocation.latitude = bd09Lat;
52
+ }
53
+ else if(locationType === 'wgs84'){
54
+ // 将 gcj02 坐标转换为 bd09
55
+ const [wgs84Lng, wgs84Lat] = coordtransform.gcj02towgs84(unifiedLocation.longitude, unifiedLocation.latitude);
56
+ unifiedLocation.longitude = wgs84Lng;
57
+ unifiedLocation.latitude = wgs84Lat;
58
+ }
59
+ if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
60
+ return false;
61
+ }
62
+ return unifiedLocation
63
+ }
64
+
65
+ export function getAddressByType(unifiedLocation, locationType) {
66
+
67
+ const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
68
+ // 根据坐标得到地址描述
69
+ const res = getAddress(bd09Lng, bd09Lat)
70
+ unifiedLocation.city = res.addressComponents.city
71
+ unifiedLocation.province = res.addressComponents.province
72
+ unifiedLocation.address = res.address
73
+ getAxisByType(unifiedLocation, locationType)
74
+ }
@@ -0,0 +1,81 @@
1
+ import config from '@lambo-design-mobile/shared/config/config';
2
+
3
+ class CcworkAdapter {
4
+ constructor(_options) {
5
+ this.uploadUrl = config.upmsServerContext + '/oss/file/put';
6
+ this.isInitialized = false;
7
+
8
+ this._initPromise = this._initialize();
9
+ }
10
+
11
+ _initialize() {
12
+ return new Promise((resolve, reject) => {
13
+ if (window.ccworkBridge) {
14
+ console.log('ccworkBridge 已存在,直接初始化...');
15
+ this._initBridge(resolve, reject);
16
+ return;
17
+ }
18
+
19
+ console.log('正在加载 ccworkJsbridge.js...');
20
+ const script = document.createElement('script');
21
+ script.src = "https://cc.ccwork.com/file/download/h5/ccworkJsbridge.js";
22
+ script.onload = () => {
23
+ console.log('ccworkJsbridge.js 加载成功,开始初始化...');
24
+ if (window.ccworkBridge) {
25
+ this._initBridge(resolve, reject);
26
+ } else {
27
+ console.error('脚本加载后,window.ccworkBridge 仍然不存在。');
28
+ reject(new Error('ccworkJsbridge 脚本加载失败。'));
29
+ }
30
+ };
31
+ script.onerror = () => {
32
+ console.error('ccworkJsbridge.js 脚本网络加载失败。');
33
+ reject(new Error('ccworkJsbridge 脚本网络加载失败。'));
34
+ };
35
+ document.head.appendChild(script);
36
+ });
37
+ }
38
+
39
+ _initBridge(resolve, reject) {
40
+ try {
41
+ ccworkBridge.init((hasLogin) => {
42
+ console.log(`ccworkBridge 初始化完成,登录状态: ${hasLogin}`);
43
+ this.isInitialized = true;
44
+ resolve(hasLogin);
45
+ });
46
+ } catch (err) {
47
+ console.error('调用 ccworkBridge.init 时出错:', err);
48
+ reject(err);
49
+ }
50
+ }
51
+
52
+ async startCcworkRecording(options = {}) {
53
+ await this._initPromise;
54
+
55
+ return new Promise((resolve, reject) => {
56
+ console.log('正在调用 ccworkRecordingAudio...');
57
+ const params = {
58
+ local: false,
59
+ id: this.uploadUrl
60
+ };
61
+
62
+ ccworkBridge.ccworkRecordingAudio(params, (res) => {
63
+ console.log('录音上传完成,收到回调:', res);
64
+ if (res && res.data && res.data.code === 1) {
65
+ resolve(res.data.data[0]);
66
+ } else {
67
+ reject(new Error(res ? res.message : '录音或上传失败,未知错误。'));
68
+ }
69
+ });
70
+ });
71
+ }
72
+
73
+
74
+ async getPlatform(options = {}) {
75
+ return Promise.resolve({
76
+ platform: 'Ccwork'
77
+ });
78
+ }
79
+ }
80
+
81
+ export default CcworkAdapter;