@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.14 → 1.0.0-beta.16
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 +15 -0
- package/README.md +12 -11
- package/demo/index.vue +6 -1
- package/package.json +1 -1
- package/src/sdk/WeComAdapter.js +139 -77
- package/src/sdk/YunTuAdapter.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [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)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ✨ Features | 新功能
|
|
6
|
+
|
|
7
|
+
* **@lambo-design-mobile/js-bridge:** 上传图片新增使用blob上传至oss方法 ([feb7e6e](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/feb7e6e79b524b600b7adeef4b81aaa6fc562610))
|
|
8
|
+
* **@lambo-design-mobile/js-bridge:** 上传图片新增使用blob上传至oss方法 ([3223408](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/32234082ed073b94c1d1d37bf96750b87c8f94de))
|
|
9
|
+
|
|
10
|
+
## [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)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### ✨ Features | 新功能
|
|
14
|
+
|
|
15
|
+
* **@lambo-design-mobile/js-bridge:** 新增flutter插件传入功能 ([ad34d20](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/ad34d20d366f5b0d0d4db5679542960b787070fc))
|
|
16
|
+
|
|
2
17
|
## [1.0.0-beta.14](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.13...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.14) (2024-10-29)
|
|
3
18
|
|
|
4
19
|
## [1.0.0-beta.13](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.12...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.13) (2024-10-28)
|
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
|
|
216
|
-
| sizeType
|
|
217
|
-
| outputType
|
|
218
|
-
|
|
|
219
|
-
|
|
|
220
|
-
|
|
|
221
|
-
|
|
|
222
|
-
|
|
|
223
|
-
|
|
|
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
|
@@ -85,9 +85,11 @@ export default {
|
|
|
85
85
|
weComId:this.weComId,
|
|
86
86
|
agentId:this.agentId,
|
|
87
87
|
dingTalkId:this.dingTalkId,
|
|
88
|
+
pluginConfig:["localAuthPlugin","myPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin"],
|
|
88
89
|
};
|
|
89
90
|
this.$lamboJsBridge = new LamboJsBridge(options);
|
|
90
91
|
await this.getPlatform();
|
|
92
|
+
await this.$lamboJsBridge.initializePlugin(options.pluginConfig);
|
|
91
93
|
},
|
|
92
94
|
methods: {
|
|
93
95
|
async getPlatform() {
|
|
@@ -105,7 +107,7 @@ export default {
|
|
|
105
107
|
// 初始化参数,根据需要填写
|
|
106
108
|
};
|
|
107
109
|
const location = await this.$lamboJsBridge.getLocation(options);
|
|
108
|
-
|
|
110
|
+
console.log("location",location)
|
|
109
111
|
this.location += `${JSON.stringify(location)}\n`; // 追加新数据
|
|
110
112
|
this.latitude = location.latitude; // 存储纬度
|
|
111
113
|
this.longitude = location.longitude; // 存储经度
|
|
@@ -134,11 +136,14 @@ export default {
|
|
|
134
136
|
ossServerContext: this.ossServerContext,
|
|
135
137
|
ossImgPutUrl: this.ossImgPutUrl,
|
|
136
138
|
ossImgGetUrl: this.ossImgGetUrl,
|
|
139
|
+
outputType: ['info','data','oss'],
|
|
140
|
+
method: 'file',
|
|
137
141
|
// sourceType: 'gallery'
|
|
138
142
|
};
|
|
139
143
|
const photos = await this.$lamboJsBridge.takePhoto(options);
|
|
140
144
|
this.photoResult += `${JSON.stringify(photos)}\n`;
|
|
141
145
|
console.log("Photo result:", photos); // 调试输出
|
|
146
|
+
console.log("oss:",photos.imageOss)
|
|
142
147
|
|
|
143
148
|
photos.forEach(photo => {
|
|
144
149
|
if (photo.imageOss && photo.imageOss.url) {
|
package/package.json
CHANGED
package/src/sdk/WeComAdapter.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
199
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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('
|
|
320
|
+
reject(new Error('Upload failed'));
|
|
287
321
|
}
|
|
288
|
-
}
|
|
289
|
-
reject(
|
|
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 = {}) {
|