@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.15 → 1.0.0-beta.17

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/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
  # Changelog
2
+ ## [1.0.0-beta.17](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.16...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.17) (2024-11-25)
3
+
4
+
5
+ ### ✨ Features | 新功能
6
+
7
+ * **@lambo-design-mobile/js-bridge:** 修改插件初始化方法 ([dc998de](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/dc998de7a6c6ec6e5e5ba82b2620ac66d1855b90))
8
+ * **@lambo-design-mobile/js-bridge:** 修改插件初始化方法 ([802474e](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/802474e1486410af622fd198097e065afc0c7b11))
9
+
10
+ ## [1.0.0-beta.16](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.15...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.16) (2024-11-12)
11
+
12
+
13
+ ### ✨ Features | 新功能
14
+
15
+ * **@lambo-design-mobile/js-bridge:** 上传图片新增使用blob上传至oss方法 ([feb7e6e](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/feb7e6e79b524b600b7adeef4b81aaa6fc562610))
16
+ * **@lambo-design-mobile/js-bridge:** 上传图片新增使用blob上传至oss方法 ([3223408](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/32234082ed073b94c1d1d37bf96750b87c8f94de))
17
+
2
18
  ## [1.0.0-beta.15](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.14...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.15) (2024-11-01)
3
19
 
4
20
 
package/README.md CHANGED
@@ -210,17 +210,18 @@ import LamboJsBridge from '@lambo-design-mobile/lambo-js-bridge';
210
210
 
211
211
  `params`: Object
212
212
 
213
- | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
214
- |---------------------|-----------|--------------------------|-----|----------|------------------------------------------------------------------|
215
- | count | number | 1 | 否 | 微信、企业微信、钉钉 | 选择图片数量 |
216
- | sizeType | string[] | ['camera', 'album'] | 否 | 微信、企业微信、钉钉 | 相册选取或者拍照。album:相册,camera:相机 |
217
- | outputType | string[] | ['info', 'data', 'oss'] | 否 | 微信、企业微信、钉钉 | 图像输出格式。info 选定图像的本地信息,data 选定图像的base64数据,oss为上传oss-server |
218
- | defaultCameraMode | string | | 否 | 企业微信 | 进入拍照界面的默认模式。normal 单拍,batch 连拍,front 前置摄像头单拍,batch_front 前置摄像头连拍 |
219
- | isSaveToAlbum | boolean | true | 否 | 企业微信 | 拍照时是否保存到系统相册 |
220
- | position | string | back | 否 | 钉钉 | 相机拍照使用的摄像头:front:前置摄像头,back:后置摄像头 |
221
- | ossServerContext | string | | | 微信、企业微信、钉钉 | 上传oss-server服务器地址 |
222
- | ossImgPutUrl | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server图片接口地址 |
223
- | ossImgGetUrl | string | | 是 | 微信、企业微信、钉钉 | 下载oss-server图片接口地址 |
213
+ | 属性 | 类型 | 默认值 | 必填 | 支持平台 | 说明 |
214
+ |-------------------|---------|-------------------------|-----|----------|------------------------------------------------------------------|
215
+ | count | number | 1 | 否 | 微信、企业微信、钉钉 | 选择图片数量 |
216
+ | sizeType | string[] | ['camera', 'album'] | 否 | 微信、企业微信、钉钉 | 相册选取或者拍照。album:相册,camera:相机 |
217
+ | outputType | string[] | ['info', 'data', 'oss'] | 否 | 微信、企业微信、钉钉 | 图像输出格式。info 选定图像的本地信息,data 选定图像的base64数据,oss为上传oss-server |
218
+ | method | string | 'file'或'blob' | 否 | 微信、企业微信、钉钉 | 上传oss方法,默认为blob |
219
+ | defaultCameraMode | string | | 否 | 企业微信 | 进入拍照界面的默认模式。normal 单拍,batch 连拍,front 前置摄像头单拍,batch_front 前置摄像头连拍 |
220
+ | isSaveToAlbum | boolean | true | 否 | 企业微信 | 拍照时是否保存到系统相册 |
221
+ | position | string | back | | 钉钉 | 相机拍照使用的摄像头:front:前置摄像头,back:后置摄像头 |
222
+ | ossServerContext | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server服务器地址 |
223
+ | ossImgPutUrl | string | | 是 | 微信、企业微信、钉钉 | 上传oss-server图片接口地址 |
224
+ | ossImgGetUrl | string | | 是 | 微信、企业微信、钉钉 | 下载oss-server图片接口地址 |
224
225
 
225
226
  ### 返回说明
226
227
 
package/demo/index.vue CHANGED
@@ -89,7 +89,7 @@ export default {
89
89
  };
90
90
  this.$lamboJsBridge = new LamboJsBridge(options);
91
91
  await this.getPlatform();
92
- await this.$lamboJsBridge.initializePlugin(options.pluginConfig);
92
+ // await this.$lamboJsBridge.initializePlugin(options.pluginConfig);
93
93
  },
94
94
  methods: {
95
95
  async getPlatform() {
@@ -107,7 +107,7 @@ export default {
107
107
  // 初始化参数,根据需要填写
108
108
  };
109
109
  const location = await this.$lamboJsBridge.getLocation(options);
110
- // console.log("location",location)
110
+ console.log("location",location)
111
111
  this.location += `${JSON.stringify(location)}\n`; // 追加新数据
112
112
  this.latitude = location.latitude; // 存储纬度
113
113
  this.longitude = location.longitude; // 存储经度
@@ -136,11 +136,14 @@ export default {
136
136
  ossServerContext: this.ossServerContext,
137
137
  ossImgPutUrl: this.ossImgPutUrl,
138
138
  ossImgGetUrl: this.ossImgGetUrl,
139
+ outputType: ['info','data','oss'],
140
+ method: 'file',
139
141
  // sourceType: 'gallery'
140
142
  };
141
143
  const photos = await this.$lamboJsBridge.takePhoto(options);
142
144
  this.photoResult += `${JSON.stringify(photos)}\n`;
143
145
  console.log("Photo result:", photos); // 调试输出
146
+ console.log("oss:",photos.imageOss)
144
147
 
145
148
  photos.forEach(photo => {
146
149
  if (photo.imageOss && photo.imageOss.url) {
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.15",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable prefer-destructuring */
1
2
  import WechatAdapter from './WechatAdapter';
2
3
  import DingTalkAdapter from './DingTalkAdapter';
3
4
  import CordovaAdapter from './CordovaAdapter';
@@ -12,7 +13,12 @@ class LamboJsBridge {
12
13
  }
13
14
 
14
15
  _detectPlatform(param) {
15
- const userAgent = navigator.userAgent.toLowerCase();
16
+ let userAgent;
17
+ if (param.userAgent) {
18
+ userAgent = param.userAgent;
19
+ } else {
20
+ userAgent = navigator.userAgent.toLowerCase();
21
+ }
16
22
  if (/wxwork/.test(userAgent)) {
17
23
  this.platform = new WeComAdapter(param);
18
24
  } else if (/micromessenger/.test(userAgent)) {
@@ -28,6 +28,7 @@ class WeComAdapter {
28
28
  document.head.appendChild(script);
29
29
  });
30
30
  }
31
+
31
32
  loadScript('//res.wx.qq.com/open/js/jweixin-1.2.0.js')
32
33
  .then(script => {
33
34
  console.log('Script loaded');
@@ -37,29 +38,28 @@ class WeComAdapter {
37
38
  }
38
39
 
39
40
 
40
-
41
41
  async init(options) {
42
42
  const currentUrl = encodeURIComponent(window.location.href.split('#')[0]);
43
43
  ajax.request({
44
- url: config.upmsServerContext + '/manage/ibpWxCpBaseinfo/gtJsTicket?corpId='+options.weComId+"&agentId="+options.agentId+"&url="+currentUrl,
44
+ url: config.upmsServerContext + '/manage/ibpWxCpBaseinfo/gtJsTicket?corpId=' + options.weComId + "&agentId=" + options.agentId + "&url=" + currentUrl,
45
45
  method: 'get'
46
46
  }).then((resp) => {
47
- if(resp.data.code===1){
48
- const {data} = resp.data
47
+ if (resp.data.code === 1) {
48
+ const {data} = resp.data
49
49
  wx.config({
50
- beta:true,
50
+ beta: true,
51
51
  // debug: true,
52
52
  appId: data.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致
53
53
  // agentid: '1000065', // 必填,企业微信的应用id (e.g. 1000247)
54
54
  timestamp: data.timestamp, // 必填,生成签名的时间戳
55
55
  nonceStr: data.noncestr, // 必填,生成签名的随机串
56
56
  signature: data.signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
57
- jsApiList: ['getLocation','scanQRCode','chooseImage','openLocation','getLocalImgData'], // 必填,传入需要使用的接口名称
57
+ jsApiList: ['getLocation', 'scanQRCode', 'chooseImage', 'openLocation', 'getLocalImgData'], // 必填,传入需要使用的接口名称
58
58
  success(res) {
59
59
  console.log("ready...")
60
60
  },
61
61
  fail(res) {
62
- if(res.errMsg.indexOf('function not exist') > -1){
62
+ if (res.errMsg.indexOf('function not exist') > -1) {
63
63
  alert('版本过低请升级')
64
64
  }
65
65
  }
@@ -68,12 +68,12 @@ class WeComAdapter {
68
68
  wx.error(function (res) {
69
69
  console.error(res)
70
70
  });
71
- wx.ready(function(){
71
+ wx.ready(function () {
72
72
  console.log("ready.....")
73
73
  // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
74
74
  });
75
75
  wx.checkJsApi({
76
- jsApiList: ['getLocation','scanQRCode','chooseImage','openLocation'], // 需要检测的JS接口列表
76
+ jsApiList: ['getLocation', 'scanQRCode', 'chooseImage', 'openLocation', 'getLocalImgData'], // 需要检测的JS接口列表
77
77
  success(res) {
78
78
  // 以键值对的形式返回,可用的api值true,不可用为false
79
79
  // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
@@ -195,62 +195,61 @@ class WeComAdapter {
195
195
  const imageInfo = res.localIds[0]; // 返回选定照片的第一个本地ID
196
196
  const results = {};
197
197
 
198
- if (!options.outputType) {
199
- // outputType为空,返回所有结果
198
+ // 检查 outputType 是否为空或不包含 'info', 'data', 'oss' 中的任意一个值
199
+ if (!options.outputType || !['info', 'data', 'oss'].some(type => options.outputType.includes(type))) {
200
+ options.outputType = ['info', 'data', 'oss'];
201
+ }
202
+
203
+ if (options.outputType.includes('info')) {
200
204
  results.imageInfo = imageInfo;
201
- wx.getLocalImgData({
202
- localId: imageInfo,
203
- success: (dataRes) => {
204
- results.imageData = dataRes.localData;
205
- resolve(results);
206
- },
207
- fail: (err) => {
208
- console.error("getLocalImgData failed:", err);
209
- reject(err);
210
- }
205
+ }
206
+
207
+ if (options.outputType.includes('data')) {
208
+ await new Promise((resolve, reject) => {
209
+ wx.getLocalImgData({
210
+ localId: imageInfo,
211
+ success: (dataRes) => {
212
+ results.imageData = dataRes.localData;
213
+ resolve();
214
+ },
215
+ fail: (err) => {
216
+ console.error("getLocalImgData failed:", err);
217
+ reject(err);
218
+ }
219
+ });
211
220
  });
212
- } else {
213
- if (options.outputType.includes('info')) {
214
- results.imageInfo = imageInfo;
215
- }
216
- if (options.outputType.includes('data')) {
217
- await new Promise((resolve, reject) => {
218
- wx.getLocalImgData({
219
- localId: imageInfo, // 这里使用返回的第一个localId
220
- success: (dataRes) => {
221
- results.imageData = dataRes.localData;
222
- resolve();
223
- },
224
- fail: (err) => {
225
- console.error("getLocalImgData failed:", err);
226
- reject(err);
221
+ }
222
+
223
+ if (options.outputType.includes('oss')) {
224
+ await new Promise((resolve, reject) => {
225
+ wx.getLocalImgData({
226
+ localId: imageInfo,
227
+ success: (dataRes) => {
228
+ const fileName = new Date().getTime() + '.png';
229
+ let file;
230
+ if (options.method == 'file') {
231
+ file = this.dataURLtoFile(dataRes.localData, fileName);
232
+ } else {
233
+ file = this.dataUrltoBlob(dataRes.localData, fileName);
227
234
  }
228
- });
229
- });
230
- }
231
- if (options.outputType.includes('oss')) {
232
- await new Promise((resolve, reject) => {
233
- wx.getLocalImgData({
234
- localId: imageInfo, // 获取base64数据
235
- success: (dataRes) => {
236
- const file = this.dataURLtoFile(dataRes.localData, 'image.png');
237
- this.uploadToOSS(file, options).then((ossResult) => {
238
- results.imageOss = ossResult;
239
- resolve();
240
- }).catch((err) => {
241
- console.error("uploadToOSS failed:", err);
242
- reject(err);
243
- });
244
- },
245
- fail: (err) => {
246
- console.error("getLocalImgData failed:", err);
235
+ this.uploadToOSS(file, options).then((ossResult) => {
236
+ // 将 ossResult 转换为字符串
237
+ results.imageOss = JSON.stringify(ossResult);
238
+ resolve();
239
+ }).catch((err) => {
240
+ console.error("uploadToOSS failed:", err);
247
241
  reject(err);
248
- }
249
- });
242
+ });
243
+ },
244
+ fail: (err) => {
245
+ console.error("getLocalImgData failed:", err);
246
+ reject(err);
247
+ }
250
248
  });
251
- }
252
- resolve(results);
249
+ });
253
250
  }
251
+
252
+ resolve(results);
254
253
  },
255
254
  fail: (err) => {
256
255
  console.error("chooseImage failed:", err);
@@ -261,11 +260,13 @@ class WeComAdapter {
261
260
  });
262
261
  }
263
262
 
263
+
264
+
264
265
  dataURLtoFile(dataurl, filename) {
265
- const arr = dataurl.split(',');
266
+ const arr = dataurl.split(',');
266
267
  const mime = arr[0].match(/:(.*?);/)[1];
267
- const bstr = atob(arr[1]);
268
- let n = bstr.length;
268
+ const bstr = atob(arr[1]);
269
+ let n = bstr.length;
269
270
  const u8arr = new Uint8Array(n);
270
271
  while (n--) {
271
272
  u8arr[n] = bstr.charCodeAt(n);
@@ -273,25 +274,86 @@ class WeComAdapter {
273
274
  return new File([u8arr], filename, {type: mime});
274
275
  }
275
276
 
277
+ dataUrltoBlob(dataurl, filename) {
278
+ const arr = dataurl.split(',');
279
+ const mime = arr[0].match(/:(.*?);/)[1];
280
+ console.log('base64^^^^^', arr[1])
281
+ console.log('mime is ^^^^^^^', mime)
282
+ return this.base64ToBlob(arr[1], mime)
283
+ }
284
+
285
+ base64ToBlob(base64Data, contentType) {
286
+ contentType = contentType || ''
287
+ const sliceSize = 1024
288
+ const byteCharacters = atob(base64Data)
289
+ const bytesLength = byteCharacters.length
290
+ const slicesCount = Math.ceil(bytesLength / sliceSize)
291
+ const byteArrays = new Array(slicesCount)
292
+
293
+ for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
294
+ const begin = sliceIndex * sliceSize
295
+ const end = Math.min(begin + sliceSize, bytesLength)
296
+
297
+ const bytes = new Array(end - begin)
298
+ for (let offset = begin, i = 0; offset < end; ++i, ++offset) {
299
+ bytes[i] = byteCharacters[offset].charCodeAt(0)
300
+ }
301
+ byteArrays[sliceIndex] = new Uint8Array(bytes)
302
+ }
303
+ return new Blob(byteArrays, {type: contentType})
304
+ }
305
+
276
306
  uploadToOSS(file, options) {
277
- return new Promise((resolve, reject) => {
278
- const formData = new FormData();
279
- formData.append('file', file);
280
- ajax.post(options.ossServerContext + options.ossImgPutUrl, formData, { payload : true }).then(response => {
281
- if (response.data.code === 1) {
282
- const result = response.data.data;
283
- if (result.length > 0) {
284
- resolve(result[0]);
307
+ if (options.method == "file") {
308
+ return new Promise((resolve, reject) => {
309
+ const formData = new FormData();
310
+ formData.append('file', file);
311
+ ajax.post(options.ossServerContext + options.ossImgPutUrl, formData, {payload: true}).then(response => {
312
+ if (response.data.code === 1) {
313
+ const result = response.data.data;
314
+ if (result.length > 0) {
315
+ resolve(result[0]);
316
+ } else {
317
+ reject(new Error('No fileId returned'));
318
+ }
285
319
  } else {
286
- reject(new Error('No fileId returned'));
320
+ reject(new Error('Upload failed'));
287
321
  }
288
- } else {
289
- reject(new Error('Upload failed'));
290
- }
291
- }).catch(error =>{
292
- reject(error);
322
+ }).catch(error => {
323
+ reject(error);
324
+ });
293
325
  });
294
- });
326
+ }
327
+ else{
328
+ return new Promise((resolve, reject) => {
329
+ let formData = new FormData()
330
+ console.log('upload to oss file is ^^^^', file)
331
+ formData.append('file', file, file.name || (new Date().getTime() + '.png'))
332
+ for (var value of formData.values()) {
333
+ console.log('upload to oss data is ^^^^', value)
334
+ }
335
+ ajax({
336
+ method: 'post',
337
+ url: options.ossServerContext + options.ossImgPutUrl,
338
+ headers: {'Content-Type': 'multipart/form-data'},
339
+ data: formData,
340
+ payload: true,
341
+ }).then(response => {
342
+ if (response.data.code == 1) {
343
+ const result = response.data.data
344
+ if (result.length > 0) {
345
+ resolve(result[0])
346
+ } else {
347
+ reject(new Error('No fileId returned'))
348
+ }
349
+ } else {
350
+ reject(new Error('Upload failed'))
351
+ }
352
+ }).catch(err => {
353
+ reject(err)
354
+ })
355
+ })
356
+ }
295
357
  }
296
358
 
297
359
  async getPlatform(options = {}) {
@@ -1,10 +1,10 @@
1
1
  import './yuntu';
2
2
 
3
3
  class YunTuAdapter {
4
- constructor() {
4
+ constructor(options) {
5
5
  // 标志插件是否已初始化
6
6
  this.isInitialized = false;
7
- // this.initializePlugin();
7
+ this.initializePlugin(options.pluginConfig);
8
8
  }
9
9
 
10
10
  async initializePlugin(pluginConfig) {
@@ -32,10 +32,6 @@ class YunTuAdapter {
32
32
  }
33
33
 
34
34
  async getLocation(options) {
35
- if (!this.isInitialized) {
36
- await this.initializePlugin(); // 确保插件初始化
37
- }
38
-
39
35
  return new Promise((resolve, reject) => {
40
36
 
41
37
  if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
@@ -59,10 +55,6 @@ class YunTuAdapter {
59
55
  }
60
56
 
61
57
  async openLocation(options) {
62
- if (!this.isInitialized) {
63
- await this.initializePlugin(); // 确保插件初始化
64
- }
65
-
66
58
  return new Promise((resolve, reject) => {
67
59
  if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
68
60
  console.log("1")
@@ -90,10 +82,6 @@ class YunTuAdapter {
90
82
  }
91
83
 
92
84
  async scanCode(options) {
93
- if (!this.isInitialized) {
94
- await this.initializePlugin(); // 确保插件初始化
95
- }
96
-
97
85
  return new Promise((resolve, reject) => {
98
86
  if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
99
87
  window.top.scanCode.startScan(
@@ -116,10 +104,6 @@ class YunTuAdapter {
116
104
  }
117
105
 
118
106
  async localAuthPlugin(options) {
119
- if (!this.isInitialized) {
120
- await this.initializePlugin(); // 确保插件初始化
121
- }
122
-
123
107
  return new Promise((resolve, reject) => {
124
108
  if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
125
109
  window.top.localAuthPlugin.auth(
@@ -142,10 +126,6 @@ class YunTuAdapter {
142
126
  }
143
127
 
144
128
  async getAvailableBiometrics(options) {
145
- if (!this.isInitialized) {
146
- await this.initializePlugin(); // 确保插件初始化
147
- }
148
-
149
129
  return new Promise((resolve, reject) => {
150
130
  if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
151
131
  window.top.localAuthPlugin.getAvailableBiometrics(
@@ -171,10 +151,6 @@ class YunTuAdapter {
171
151
  async takePhoto(options) {
172
152
  console.log('YunTu: Taking photo with options', options);
173
153
 
174
- if (!this.isInitialized) {
175
- await this.initializePlugin(); // 确保插件初始化
176
- }
177
-
178
154
  return new Promise((resolve, reject) => {
179
155
  if (window.top.imagePicker) {
180
156
  const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
@@ -208,10 +184,6 @@ class YunTuAdapter {
208
184
  async filePreview(options) {
209
185
  console.log('YunTu: File preview with options', options);
210
186
 
211
- if (!this.isInitialized) {
212
- await this.initializePlugin(); // Ensure the plugin is initialized
213
- }
214
-
215
187
  return new Promise((resolve, reject) => {
216
188
  if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
217
189
  window.top.filePreview.openFile(