@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/.versionrc +2 -2
- package/CHANGELOG.md +407 -72
- package/README.md +310 -25
- package/demo/index.vue +323 -29
- package/package.json +5 -2
- package/src/sdk/BdMapUtils.js +74 -0
- package/src/sdk/CcworkAdapter.js +81 -0
- package/src/sdk/LPAPI.js +1120 -0
- package/src/sdk/LamboJsBridge.js +73 -25
- package/src/sdk/MobileIMAdapter.js +127 -0
- package/src/sdk/WeComAdapter.js +664 -261
- package/src/sdk/WechatAdapter.js +475 -276
- package/src/sdk/YunTuAdapter.js +209 -89
- package/src/sdk/yuntu.js +55 -0
- package/yuntu.js +0 -42
package/src/sdk/LamboJsBridge.js
CHANGED
|
@@ -1,73 +1,121 @@
|
|
|
1
|
+
/* eslint-disable prefer-destructuring */
|
|
1
2
|
import WechatAdapter from './WechatAdapter';
|
|
2
3
|
import DingTalkAdapter from './DingTalkAdapter';
|
|
3
4
|
import CordovaAdapter from './CordovaAdapter';
|
|
4
5
|
import YunTuAdapter from './YunTuAdapter';
|
|
5
6
|
import WeComAdapter from './WeComAdapter';
|
|
6
7
|
import BrowserAdapter from './BrowserAdapter';
|
|
8
|
+
import MobileIMAdapter from './MobileIMAdapter';
|
|
9
|
+
import CcworkAdapter from './CcworkAdapter';
|
|
7
10
|
|
|
8
11
|
class LamboJsBridge {
|
|
9
12
|
constructor(param) {
|
|
10
|
-
// param.isBdNiJieXi 需要百度地图逆地址解析
|
|
11
|
-
if(param.isBdNiJieXi) {
|
|
12
|
-
const addScript = function (src, cb) {
|
|
13
|
-
const script = document.createElement('script')
|
|
14
|
-
script.src = src
|
|
15
|
-
document.getElementsByTagName('head')[0].appendChild(script)
|
|
16
|
-
script.onload = function () {
|
|
17
|
-
if (!!cb) {
|
|
18
|
-
cb()
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
addScript('https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT')
|
|
23
|
-
addScript(
|
|
24
|
-
'https://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT',
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
13
|
this._detectPlatform(param);
|
|
28
14
|
}
|
|
29
15
|
|
|
30
16
|
_detectPlatform(param) {
|
|
31
|
-
|
|
17
|
+
let userAgent;
|
|
18
|
+
if (param.userAgent) {
|
|
19
|
+
userAgent = param.userAgent;
|
|
20
|
+
} else {
|
|
21
|
+
userAgent = navigator.userAgent.toLowerCase();
|
|
22
|
+
}
|
|
32
23
|
if (/wxwork/.test(userAgent)) {
|
|
33
24
|
this.platform = new WeComAdapter(param);
|
|
34
25
|
} else if (/micromessenger/.test(userAgent)) {
|
|
35
26
|
this.platform = new WechatAdapter(param);
|
|
36
|
-
}else if (/dingtalk/.test(userAgent)) {
|
|
27
|
+
} else if (/dingtalk/.test(userAgent)) {
|
|
37
28
|
this.platform = new DingTalkAdapter(param);
|
|
38
29
|
} else if (/cordova/.test(userAgent)) {
|
|
39
30
|
this.platform = new CordovaAdapter(param);
|
|
40
31
|
} else if (/yuntu/.test(userAgent)) {
|
|
41
32
|
this.platform = new YunTuAdapter(param);
|
|
33
|
+
} else if (/mobileim/.test(userAgent)) {
|
|
34
|
+
this.platform = new MobileIMAdapter(param);
|
|
35
|
+
} else if (/ccwork/.test(userAgent)) {
|
|
36
|
+
this.platform = new CcworkAdapter(param);
|
|
42
37
|
} else {
|
|
43
38
|
this.platform = new BrowserAdapter();
|
|
44
39
|
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async initializePlugin(pluginConfig = []) {
|
|
43
|
+
if (this.platform instanceof YunTuAdapter) {
|
|
44
|
+
return this.platform.initializePlugin(pluginConfig);
|
|
45
|
+
}
|
|
46
|
+
return Promise.resolve();
|
|
45
47
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
// 通用接口:获取初始化信息
|
|
49
50
|
async getPlatform(options = {}) {
|
|
50
51
|
return this.platform.getPlatform(options);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
// 通用接口:获取位置信息
|
|
54
54
|
async getLocation(options = {}) {
|
|
55
|
-
// options = {type:'wgs84'};
|
|
56
55
|
return this.platform.getLocation(options);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
// 通用接口:扫码
|
|
60
58
|
async scanCode(options = {}) {
|
|
61
59
|
return this.platform.scanCode(options);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
|
|
62
|
+
async localAuthPlugin(options = {}) {
|
|
63
|
+
return this.platform.localAuthPlugin(options);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getAvailableBiometrics(options = {}) {
|
|
67
|
+
return this.platform.getAvailableBiometrics(options);
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
async takePhoto(options = {}) {
|
|
66
71
|
return this.platform.takePhoto(options);
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
async openLocation(options = {}){
|
|
74
|
+
async openLocation(options = {}) {
|
|
70
75
|
return this.platform.openLocation(options);
|
|
71
76
|
}
|
|
77
|
+
|
|
78
|
+
async filePreview(options = {}) {
|
|
79
|
+
return this.platform.filePreview(options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async initKey(options = {}) {
|
|
83
|
+
return this.platform.initKey(options);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async init(options = {}) {
|
|
87
|
+
return this.platform.init(options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async startRecording(options = {}) {
|
|
91
|
+
return this.platform.startRecording(options);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async stopRecording(options = {}) {
|
|
95
|
+
return this.platform.stopRecording(options);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async startWeComRecording(options = {}) {
|
|
99
|
+
return this.platform.startWeComRecording(options);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async stopWeComRecording(options = {}) {
|
|
103
|
+
return this.platform.stopWeComRecording(options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async startCcworkRecording(options = {}) {
|
|
107
|
+
return this.platform.startCcworkRecording(options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async downloadFile(options={}){
|
|
111
|
+
return this.platform.downloadFile(options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 创建一个 Vue 插件
|
|
115
|
+
static install(Vue) {
|
|
116
|
+
// 将 LamboJsBridge 实例挂载到 Vue 原型上,全局可用
|
|
117
|
+
Vue.prototype.$lamboJsBridge = new LamboJsBridge({});
|
|
118
|
+
}
|
|
72
119
|
}
|
|
120
|
+
|
|
73
121
|
export default LamboJsBridge;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getAddress } from './BdMapUtils';
|
|
2
|
+
import config from "@lambo-design-mobile/shared/config/config";
|
|
3
|
+
import gcoord from 'gcoord'
|
|
4
|
+
|
|
5
|
+
class MobileIMAdapter {
|
|
6
|
+
constructor(_options) {
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 新门户系统: 我们移动端只能提供坐标数据,没法提供街道地市这些信息。。
|
|
10
|
+
async getLocation(options) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
try {
|
|
13
|
+
let args = {
|
|
14
|
+
// 是否获取地址信息
|
|
15
|
+
// isNeedAddress: true,
|
|
16
|
+
provider: 'baidu', // 使用百度定位能力
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const fetchLocation = () => {
|
|
20
|
+
if(config.isUseBMap) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
let map = new BMap.Map("allmap");
|
|
23
|
+
let longitude = 117.13597023313;
|
|
24
|
+
let latitude = 36.668022891427;
|
|
25
|
+
if (config.defaultLocation) {
|
|
26
|
+
longitude = config.defaultLocation.longitude;
|
|
27
|
+
latitude = config.defaultLocation.latitude;
|
|
28
|
+
}
|
|
29
|
+
let point = new BMap.Point(longitude, latitude);
|
|
30
|
+
map.centerAndZoom(point, 12);
|
|
31
|
+
let geolocation = new BMap.Geolocation();
|
|
32
|
+
// 开启SDK辅助定位
|
|
33
|
+
geolocation.enableSDKLocation();
|
|
34
|
+
geolocation.getCurrentPosition(function(r){
|
|
35
|
+
if(this.getStatus() == BMAP_STATUS_SUCCESS){
|
|
36
|
+
let mk = new BMap.Marker(r.point);
|
|
37
|
+
map.addOverlay(mk);
|
|
38
|
+
map.panTo(r.point);
|
|
39
|
+
resolve ({
|
|
40
|
+
latitude: r.point.lng,
|
|
41
|
+
longitude: r.point.lat,
|
|
42
|
+
accuracy: r.accuracy,
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
console.error('定位失败: ' + this.getStatus())
|
|
46
|
+
reject(new Error('定位失败: ' + this.getStatus()));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
} else {
|
|
51
|
+
return new Promise((resolve2) => {
|
|
52
|
+
window.native.getLocation(args, (res) => {
|
|
53
|
+
const point = res.point;
|
|
54
|
+
let [lng, lat] = gcoord.transform(
|
|
55
|
+
[point.longitude, point.latitude], // 经纬度坐标
|
|
56
|
+
gcoord.BD09, // 当前坐标系
|
|
57
|
+
gcoord.WGS84, // 目标坐标系
|
|
58
|
+
);
|
|
59
|
+
resolve2({
|
|
60
|
+
latitude: lat,
|
|
61
|
+
longitude: lng,
|
|
62
|
+
accuracy: res.point.horizontalAccuracy,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// 先判断是否需要地理位置 如不需要 直接返回坐标
|
|
70
|
+
if (options.needAddress) {
|
|
71
|
+
fetchLocation()
|
|
72
|
+
.then(async (bd09Location) => {
|
|
73
|
+
console.log(
|
|
74
|
+
'with options.needAddress bd09Location',
|
|
75
|
+
bd09Location
|
|
76
|
+
);
|
|
77
|
+
// const result = getAddress(bd09Location.longitude, bd09Location.latitude)
|
|
78
|
+
//平台返回的经纬度是反的 解决了再换回来
|
|
79
|
+
const result = await getAddress(
|
|
80
|
+
bd09Location.latitude,
|
|
81
|
+
bd09Location.longitude
|
|
82
|
+
);
|
|
83
|
+
console.log('with options.needAddress getAddress result', result);
|
|
84
|
+
if (!result) {
|
|
85
|
+
return reject(new Error('Invalid location data'));
|
|
86
|
+
}
|
|
87
|
+
resolve({
|
|
88
|
+
...bd09Location,
|
|
89
|
+
...result,
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
.catch((err) => {
|
|
93
|
+
reject(err);
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
resolve(fetchLocation());
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error('getLocation failed:', err);
|
|
100
|
+
reject(err);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async scanCode(options) {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
try {
|
|
108
|
+
window.native.qrScan((res) => {
|
|
109
|
+
console.log('scanQRCode success:', res);
|
|
110
|
+
resolve(res);
|
|
111
|
+
});
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.error('scanQRCode failed:', err);
|
|
114
|
+
reject(err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getPlatform(options = {}) {
|
|
120
|
+
// 获取初始化信息
|
|
121
|
+
return {
|
|
122
|
+
platform: 'MobileIM',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default MobileIMAdapter;
|