@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.4 → 1.0.0-beta.6
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 +14 -0
- package/README.md +51 -0
- package/demo/index.vue +23 -5
- package/package.json +4 -2
- package/src/sdk/BdMapUtils.js +74 -0
- package/src/sdk/LamboJsBridge.js +17 -20
- package/src/sdk/WechatAdapter.js +71 -38
- package/src/sdk/YunTuAdapter.js +22 -56
- package/src/sdk/yuntu.js +55 -0
- package/yuntu.js +0 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [1.0.0-beta.6](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.5...@lambo-design-mobile/js-bridge@1.0.0-beta.6) (2024-08-29)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
6
|
+
|
|
7
|
+
* **@lambo-design-mobile/js-bridge:** 完善全局调用文档,删除未使用代码 ([309c4af](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/309c4af613be0f8543a53e2d24c3702e44474134))
|
|
8
|
+
|
|
9
|
+
## [1.0.0-beta.5](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.4...@lambo-design-mobile/js-bridge@1.0.0-beta.5) (2024-08-29)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### ✨ Features | 新功能
|
|
13
|
+
|
|
14
|
+
* **@lambo-dsign-mobile/js-bridge:** 新增filepreview ([80de1a1](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/80de1a1b7c7c690ea55895f2c6c9acfbf1859fda))
|
|
15
|
+
|
|
2
16
|
## [1.0.0-beta.4](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.3...@lambo-design-mobile/js-bridge@1.0.0-beta.4) (2024-08-23)
|
|
3
17
|
|
|
4
18
|
|
package/README.md
CHANGED
|
@@ -4,6 +4,57 @@
|
|
|
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
|
+
let lamboJsBridge = new LamboJsBridge();
|
|
16
|
+
try {
|
|
17
|
+
const platformInfo = await lamboJsBridge.getPlatform(); // 获取初始化信息
|
|
18
|
+
console.log('LamboJsBridge Platform Info:', JSON.stringify(platformInfo, null, 2));
|
|
19
|
+
|
|
20
|
+
//yuntu Flutter 平台需要初始化插件
|
|
21
|
+
const pluginConfig = ["scanCodePlugin", "filePreviewPlugin", "imagePickerPlugin"]
|
|
22
|
+
const pluginConfigInfo = await lamboJsBridge.initializePlugin(pluginConfig);
|
|
23
|
+
console.log('LamboJsBridge PluginConfig Info:', pluginConfigInfo);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Error getting init info:', error);
|
|
26
|
+
}
|
|
27
|
+
// 将 lamboJsBridge 挂载到 Vue 原型上
|
|
28
|
+
Vue.prototype.$lamboJsBridge = lamboJsBridge;
|
|
29
|
+
```
|
|
30
|
+
### 调用
|
|
31
|
+
|
|
32
|
+
``` javascript
|
|
33
|
+
// 直接调用扫码功能
|
|
34
|
+
Vue.prototype.$lamboJsBridge.scanCode();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 也可以自己封装一层工具类
|
|
38
|
+
* 扫描二维码并返回结果。(需要在APP环境下测试)
|
|
39
|
+
* 此函数通过调用 Flutter scanCode.startScan 方法来启动二维码扫描。
|
|
40
|
+
* 扫描成功后返回扫描结果,若扫描失败则返回错误信息。
|
|
41
|
+
*
|
|
42
|
+
* @returns {Promise<String>} - 返回一个 Promise,当扫描成功时 resolve,返回扫描的结果字符串;如果失败,reject 返回错误信息。
|
|
43
|
+
* @example
|
|
44
|
+
* flutterUtil.scanCode()
|
|
45
|
+
* .then(result => {
|
|
46
|
+
* console.log('扫描结果:', result.msg);
|
|
47
|
+
* })
|
|
48
|
+
* .catch(error => {
|
|
49
|
+
* console.error('扫描失败:', error.msg);
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
52
|
+
flutterUtil.scanCode = function() {
|
|
53
|
+
return Vue.prototype.$lamboJsBridge.scanCode();
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
7
58
|
### 引入
|
|
8
59
|
|
|
9
60
|
``` javascript
|
package/demo/index.vue
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
<van-button @click="openLocation">打开位置</van-button>
|
|
25
25
|
<pre v-if="openLocationResult"><code>{{ openLocationResult }}</code></pre>
|
|
26
26
|
</demo-block>
|
|
27
|
+
<demo-block title="文件预览">
|
|
28
|
+
<a href="javascript:void(0);" @click="previewFile">点击这里预览文件</a>
|
|
29
|
+
</demo-block>
|
|
27
30
|
</demo-section>
|
|
28
31
|
</template>
|
|
29
32
|
|
|
@@ -43,8 +46,8 @@ export default {
|
|
|
43
46
|
scanResult: '',
|
|
44
47
|
photoResult: '',
|
|
45
48
|
openLocationResult: '', // 添加用于存储打开位置的返回值
|
|
46
|
-
latitude:
|
|
47
|
-
longitude:
|
|
49
|
+
latitude: 117.129, // 存储纬度
|
|
50
|
+
longitude: 36.662, // 存储经度
|
|
48
51
|
ossServerContext: 'ibp-upms-server',
|
|
49
52
|
ossImgPutUrl: '/oss/file/put',
|
|
50
53
|
ossImgGetUrl: '/oss/file/get/',
|
|
@@ -100,11 +103,13 @@ export default {
|
|
|
100
103
|
// 初始化参数,根据需要填写
|
|
101
104
|
};
|
|
102
105
|
const location = await this.lamboBridge.getLocation(options);
|
|
103
|
-
console.log("location",location)
|
|
106
|
+
// console.log("location",location)
|
|
104
107
|
this.location += `${JSON.stringify(location)}\n`; // 追加新数据
|
|
105
108
|
this.latitude = location.latitude; // 存储纬度
|
|
106
109
|
this.longitude = location.longitude; // 存储经度
|
|
107
|
-
console.log(
|
|
110
|
+
console.log("this.latitude:",this.latitude);
|
|
111
|
+
console.log("this.longitude:",this.longitude);
|
|
112
|
+
// console.log('Location:', location);
|
|
108
113
|
} catch (error) {
|
|
109
114
|
console.error('Error getting location:', error);
|
|
110
115
|
}
|
|
@@ -126,7 +131,8 @@ export default {
|
|
|
126
131
|
const options = {
|
|
127
132
|
ossServerContext: this.ossServerContext,
|
|
128
133
|
ossImgPutUrl: this.ossImgPutUrl,
|
|
129
|
-
ossImgGetUrl: this.ossImgGetUrl
|
|
134
|
+
ossImgGetUrl: this.ossImgGetUrl,
|
|
135
|
+
// sourceType: 'gallery'
|
|
130
136
|
};
|
|
131
137
|
const photos = await this.lamboBridge.takePhoto(options);
|
|
132
138
|
this.photoResult += `${JSON.stringify(photos)}\n`;
|
|
@@ -167,6 +173,18 @@ export default {
|
|
|
167
173
|
this.openLocationResult = `打开位置时出错: ${error.message}`; // 存储错误信息
|
|
168
174
|
console.error('Error opening location:', error);
|
|
169
175
|
}
|
|
176
|
+
},
|
|
177
|
+
async previewFile() {
|
|
178
|
+
try {
|
|
179
|
+
const options = {
|
|
180
|
+
title: '预览文件', // 文件的标题
|
|
181
|
+
path: 'http://160.mall.eap.lambo.top/ecm-runtime-server/api/file/get/123456' // 文件的URL路径
|
|
182
|
+
};
|
|
183
|
+
const result = await this.lamboBridge.filePreview(options);
|
|
184
|
+
console.log('File preview result:', result);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error('Error previewing file:', error);
|
|
187
|
+
}
|
|
170
188
|
}
|
|
171
189
|
},
|
|
172
190
|
beforeRouteEnter (to, from, next) {
|
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.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "lambo",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"access": "public",
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
11
11
|
},
|
|
12
|
-
"dependencies": {
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"coordtransform": "^2.1.2"
|
|
14
|
+
},
|
|
13
15
|
"scripts": {
|
|
14
16
|
"release-js-bridge": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
|
15
17
|
"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
|
+
}
|
package/src/sdk/LamboJsBridge.js
CHANGED
|
@@ -6,26 +6,9 @@ import WeComAdapter from './WeComAdapter';
|
|
|
6
6
|
import BrowserAdapter from './BrowserAdapter';
|
|
7
7
|
|
|
8
8
|
class LamboJsBridge {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
this._detectPlatform(param);
|
|
28
|
-
}
|
|
9
|
+
constructor(param) {
|
|
10
|
+
this._detectPlatform(param);
|
|
11
|
+
}
|
|
29
12
|
|
|
30
13
|
_detectPlatform(param) {
|
|
31
14
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
@@ -45,6 +28,16 @@ class LamboJsBridge {
|
|
|
45
28
|
|
|
46
29
|
}
|
|
47
30
|
|
|
31
|
+
// yuntu接口:初始化插件(只有yuntu平台需要)
|
|
32
|
+
async initializePlugin(pluginConfig = []) {
|
|
33
|
+
if (this.platform instanceof YunTuAdapter) {
|
|
34
|
+
return this.platform.initializePlugin(pluginConfig);
|
|
35
|
+
} else {
|
|
36
|
+
// 非 yuntu 平台,直接返回一个已解决的 Promise
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
48
41
|
// 通用接口:获取初始化信息
|
|
49
42
|
async getPlatform(options = {}) {
|
|
50
43
|
return this.platform.getPlatform(options);
|
|
@@ -69,5 +62,9 @@ class LamboJsBridge {
|
|
|
69
62
|
async openLocation(options = {}){
|
|
70
63
|
return this.platform.openLocation(options);
|
|
71
64
|
}
|
|
65
|
+
|
|
66
|
+
async filePreview(options={}){
|
|
67
|
+
return this.platform.filePreview(options);
|
|
68
|
+
}
|
|
72
69
|
}
|
|
73
70
|
export default LamboJsBridge;
|
package/src/sdk/WechatAdapter.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import ajax from "@lambo-design-mobile/shared/utils/ajax";
|
|
5
5
|
import config from "@lambo-design-mobile/shared/config/config";
|
|
6
|
-
import coordtransform from "coordtransform";
|
|
6
|
+
// import coordtransform from "coordtransform";
|
|
7
|
+
import { getAddress, initBdMap, getAddressByType, getAxisByType } from './BdMapUtils';
|
|
7
8
|
|
|
8
9
|
class WechatAdapter {
|
|
9
10
|
constructor(_options) {
|
|
@@ -23,11 +24,9 @@ class WechatAdapter {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
loadScript('//res.wx.qq.com/open/js/jweixin-1.6.0.js')
|
|
26
|
-
.then(script =>
|
|
27
|
-
console.log('Script loaded');
|
|
28
|
-
this.init(_options);
|
|
29
|
-
})
|
|
27
|
+
.then(script => console.log('Script loaded'))
|
|
30
28
|
.catch(err => console.error(err));
|
|
29
|
+
this.init(_options);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async init(options) {
|
|
@@ -87,16 +86,14 @@ class WechatAdapter {
|
|
|
87
86
|
if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
|
|
88
87
|
return reject(new Error('Invalid location data'));
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// 根据坐标得到地址描述
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
});
|
|
89
|
+
// options.needAddress 是否需要地址信息
|
|
90
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
91
|
+
// // 根据坐标得到地址描述
|
|
92
|
+
// const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
|
|
93
|
+
// unifiedLocation.city = res.addressComponents.city
|
|
94
|
+
// unifiedLocation.province = res.addressComponents.province
|
|
95
|
+
// unifiedLocation.address = res.address
|
|
96
|
+
// }
|
|
100
97
|
|
|
101
98
|
resolve(unifiedLocation);
|
|
102
99
|
},
|
|
@@ -108,31 +105,67 @@ class WechatAdapter {
|
|
|
108
105
|
});
|
|
109
106
|
};
|
|
110
107
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
// 先判断是否需要地理位置 如不需要 直接返回坐标
|
|
109
|
+
if(options.needAddress) {
|
|
110
|
+
fetchLocation('gcj02'.then(unifiedLocation => {
|
|
111
|
+
const result = getAddressByType(unifiedLocation, locationType)
|
|
112
|
+
if(!result) {
|
|
113
|
+
return reject(new Error('Invalid location data'));
|
|
114
|
+
}
|
|
115
|
+
resolve(unifiedLocation);
|
|
116
|
+
}))
|
|
117
|
+
.catch(err => { reject(err) })
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
resolve(fetchLocation(locationType))
|
|
121
|
+
}
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
// // 先取gcj02 再根据type转成不同坐标系
|
|
124
|
+
// fetchLocation('gcj02').then(unifiedLocation => {
|
|
125
|
+
// // options.needAddress 是否需要地址信息
|
|
126
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
127
|
+
// const result = getAddressByType(unifiedLocation, locationType)
|
|
128
|
+
// if(!result) {
|
|
129
|
+
// return reject(new Error('Invalid location data'));
|
|
130
|
+
// }
|
|
131
|
+
// resolve(unifiedLocation);
|
|
132
|
+
// }
|
|
133
|
+
// else {
|
|
134
|
+
// const result = getAxisByType(unifiedLocation, locationType)
|
|
135
|
+
// if(!result) {
|
|
136
|
+
// return reject(new Error('Invalid location data'));
|
|
137
|
+
// }
|
|
138
|
+
// resolve(unifiedLocation);
|
|
139
|
+
// }
|
|
140
|
+
// }).catch(err => {
|
|
141
|
+
// reject(err);
|
|
142
|
+
// });
|
|
128
143
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
|
|
145
|
+
// if (locationType === 'bd09') {
|
|
146
|
+
// // 先获取 gcj02 坐标
|
|
147
|
+
// fetchLocation('gcj02').then(unifiedLocation => {
|
|
148
|
+
// // 将 gcj02 坐标转换为 bd09
|
|
149
|
+
// const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
|
|
150
|
+
// unifiedLocation.longitude = bd09Lng;
|
|
151
|
+
// unifiedLocation.latitude = bd09Lat;
|
|
152
|
+
// if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
|
|
153
|
+
// return reject(new Error('Invalid location data'));
|
|
154
|
+
// }
|
|
155
|
+
// // options.needAddress 是否需要地址信息
|
|
156
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
157
|
+
// // 根据坐标得到地址描述
|
|
158
|
+
// const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
|
|
159
|
+
// unifiedLocation.city = res.addressComponents.city
|
|
160
|
+
// unifiedLocation.province = res.addressComponents.province
|
|
161
|
+
// unifiedLocation.address = res.address
|
|
162
|
+
// }
|
|
163
|
+
|
|
164
|
+
// resolve(unifiedLocation);
|
|
165
|
+
// }).catch(err => {
|
|
166
|
+
// reject(err);
|
|
167
|
+
// });
|
|
168
|
+
// }
|
|
136
169
|
});
|
|
137
170
|
});
|
|
138
171
|
}
|
package/src/sdk/YunTuAdapter.js
CHANGED
|
@@ -1,64 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import config from "@lambo-design-mobile/shared/config/config";
|
|
3
|
-
import coordtransform from "coordtransform";
|
|
1
|
+
import './yuntu';
|
|
4
2
|
|
|
5
3
|
class YunTuAdapter {
|
|
6
4
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// 将 yuntu.js 的代码直接放在这里
|
|
10
|
-
window.yuntu = {
|
|
11
|
-
config: function (options) {
|
|
12
|
-
window.flutter_inappwebview.callHandler(
|
|
13
|
-
"yuntu",
|
|
14
|
-
"init",
|
|
15
|
-
options
|
|
16
|
-
)
|
|
17
|
-
},
|
|
18
|
-
exec: function(plugin, action, successCallback, errorCallback, options) {
|
|
19
|
-
window.flutter_inappwebview.callHandler(
|
|
20
|
-
plugin,
|
|
21
|
-
action,
|
|
22
|
-
options
|
|
23
|
-
).then((result) => {
|
|
24
|
-
successCallback(result);
|
|
25
|
-
}).catch((error) => {
|
|
26
|
-
errorCallback(error);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// 等待一个全局函数或变量加载完成
|
|
32
|
-
function waitForGlobalVariableOrFunction(globalName, callHandler, callback) {
|
|
33
|
-
// 设置轮询的时间间隔(毫秒)
|
|
34
|
-
var interval = 100; // 例如,每100毫秒检查一次
|
|
35
|
-
var t = 0;
|
|
36
|
-
// 定义一个定时器函数
|
|
37
|
-
var timer = setInterval(function () {
|
|
38
|
-
console.log(t++);
|
|
39
|
-
if (window[globalName][callHandler] !== undefined) {
|
|
40
|
-
// 全局变量或函数已加载
|
|
41
|
-
clearInterval(timer); // 停止定时器
|
|
42
|
-
callback(); // 执行回调函数
|
|
43
|
-
}
|
|
44
|
-
}, interval);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function yuntuConfig(options) {
|
|
48
|
-
waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler', function () {
|
|
49
|
-
// 在这里执行你的代码,myFunction 已加载
|
|
50
|
-
window.yuntu.config(options);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 直接调用初始化函数
|
|
55
|
-
this.initializePlugin();
|
|
5
|
+
// 标志插件是否已初始化
|
|
6
|
+
this.isInitialized = false;
|
|
56
7
|
}
|
|
57
8
|
|
|
58
|
-
async initializePlugin() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
9
|
+
async initializePlugin(pluginConfig) {
|
|
10
|
+
try {
|
|
11
|
+
// 如果传入的是非空数组,则直接使用;否则使用默认的全部插件配置
|
|
12
|
+
const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
|
|
13
|
+
? JSON.stringify(pluginConfig)
|
|
14
|
+
: '["myPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
|
|
15
|
+
// 调用插件初始化
|
|
16
|
+
await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
|
|
17
|
+
|
|
18
|
+
this.isInitialized = true;
|
|
19
|
+
// 将插件信息解析并存储到 this.plugin
|
|
20
|
+
this.plugins = JSON.parse(configToUse);
|
|
21
|
+
console.log("Initialized plugins:", this.plugins);
|
|
22
|
+
return this.plugins;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Plugin initialization failed:", error);
|
|
25
|
+
this.isInitialized = false;
|
|
26
|
+
return "Plugin initialization failed:" + error;
|
|
27
|
+
}
|
|
62
28
|
}
|
|
63
29
|
|
|
64
30
|
// 其余代码保持不变
|
package/src/sdk/yuntu.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
(function(global) {
|
|
2
|
+
global.yuntu = {
|
|
3
|
+
config: function (options) {
|
|
4
|
+
global.flutter_inappwebview.callHandler(
|
|
5
|
+
"yuntu",
|
|
6
|
+
"init",
|
|
7
|
+
options
|
|
8
|
+
);
|
|
9
|
+
},
|
|
10
|
+
exec: function(plugin, action, successCallback, errorCallback, options) {
|
|
11
|
+
global.flutter_inappwebview.callHandler(
|
|
12
|
+
plugin,
|
|
13
|
+
action,
|
|
14
|
+
options
|
|
15
|
+
).then((result) => {
|
|
16
|
+
successCallback(result);
|
|
17
|
+
}).catch((error) => {
|
|
18
|
+
errorCallback(error);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// 等待一个全局函数或变量加载完成
|
|
24
|
+
function waitForGlobalVariableOrFunction(globalName, callHandler) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var interval = 1000; // 每1000毫秒检查一次
|
|
27
|
+
var timeout = 10000; // 设定最大等待时间 10 秒
|
|
28
|
+
var elapsedTime = 0;
|
|
29
|
+
|
|
30
|
+
var timer = setInterval(function () {
|
|
31
|
+
elapsedTime += interval;
|
|
32
|
+
if (global[globalName] && global[globalName][callHandler] !== undefined) {
|
|
33
|
+
clearInterval(timer); // 停止定时器
|
|
34
|
+
resolve(); // 执行回调函数,表示成功
|
|
35
|
+
console.log("yuntu 插件加载成功");
|
|
36
|
+
} else if (elapsedTime >= timeout) {
|
|
37
|
+
clearInterval(timer); // 停止定时器
|
|
38
|
+
console.log("yuntu 插件加载失败");
|
|
39
|
+
reject(new Error(`Timeout: ${globalName}.${callHandler} not found within ${timeout}ms`));
|
|
40
|
+
}
|
|
41
|
+
}, interval);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
global.yuntuConfig = async function(options) {
|
|
46
|
+
try {
|
|
47
|
+
await waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler');
|
|
48
|
+
global.yuntu.config(options);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error("yuntuConfig 初始化失败:", error);
|
|
51
|
+
throw error; // 如果失败则抛出错误
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
})(window);
|
package/yuntu.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
window.yuntu = {
|
|
2
|
-
config: function (options) {
|
|
3
|
-
window.flutter_inappwebview.callHandler(
|
|
4
|
-
"yuntu",
|
|
5
|
-
"init",
|
|
6
|
-
options
|
|
7
|
-
)
|
|
8
|
-
},
|
|
9
|
-
exec: function(plugin, action, successCallback, errorCallback, options) {
|
|
10
|
-
window.flutter_inappwebview.callHandler(
|
|
11
|
-
plugin,
|
|
12
|
-
action,
|
|
13
|
-
options
|
|
14
|
-
).then((result) => {
|
|
15
|
-
successCallback(result);
|
|
16
|
-
}).catch((error) => {
|
|
17
|
-
errorCallback(error);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// 等待一个全局函数或变量加载完成
|
|
22
|
-
function waitForGlobalVariableOrFunction(globalName, callHandler, callback) {
|
|
23
|
-
// 设置轮询的时间间隔(毫秒)
|
|
24
|
-
var interval = 100; // 例如,每100毫秒检查一次
|
|
25
|
-
var t = 0
|
|
26
|
-
// 定义一个定时器函数
|
|
27
|
-
var timer = setInterval(function () {
|
|
28
|
-
console.log(t++)
|
|
29
|
-
if (window[globalName][callHandler] !== undefined) {
|
|
30
|
-
// 全局变量或函数已加载
|
|
31
|
-
clearInterval(timer); // 停止定时器
|
|
32
|
-
callback(); // 执行回调函数
|
|
33
|
-
}
|
|
34
|
-
}, interval);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function yuntuConfig(options){
|
|
38
|
-
waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler', function () {
|
|
39
|
-
// 在这里执行你的代码,myFunction 已加载
|
|
40
|
-
window.yuntu.config(options);
|
|
41
|
-
});
|
|
42
|
-
}
|