@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.1 → 1.0.0-beta.2

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,11 @@
1
1
  # Changelog
2
+ ## [1.0.0-beta.2](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.1...@lambo-design-mobile/js-bridge@1.0.0-beta.2) (2024-08-22)
3
+
4
+
5
+ ### ✨ Features | 新功能
6
+
7
+ * **@lambo-design-mobile/js-bridge:** 新增Flutter JsBridge接口 ([96ed86c](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/96ed86c9a530194d43290a23b0df9afbebe383d2))
8
+
2
9
  ## 1.0.0-beta.1 (2024-08-21)
3
10
 
4
11
 
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.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -45,7 +45,7 @@ class LamboJsBridge {
45
45
 
46
46
  }
47
47
 
48
- //通用接口:获取初始化信息
48
+ // 通用接口:获取初始化信息
49
49
  async getPlatform(options = {}) {
50
50
  return this.platform.getPlatform(options);
51
51
  }
@@ -1,21 +1,163 @@
1
+ import ajax from "@lambo-design-mobile/shared/utils/ajax";
2
+ import config from "@lambo-design-mobile/shared/config/config";
3
+ import coordtransform from "coordtransform";
4
+
1
5
  class YunTuAdapter {
6
+ constructor() {
7
+ this.isInitialized = false; // 标志插件是否已初始化
8
+ function loadScript(src) {
9
+ return new Promise((resolve, reject) => {
10
+ const script = document.createElement('script');
11
+ script.src = src;
12
+ script.onload = () => resolve(script);
13
+ script.onerror = () => reject(new Error('Failed to load script'));
14
+ document.head.appendChild(script);
15
+ });
16
+ }
17
+ loadScript('/packages/js-bridge/yuntu.js')
18
+ .then(script => {
19
+ console.log('Script loaded');
20
+ this.initializePlugin(); // 确保初始化完成
21
+ })
22
+ .catch(err => console.error(err));
23
+ }
24
+
25
+ async initializePlugin() {
26
+ window.yuntu.config('["myPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin","appUpdatePlugin"]');
27
+ this.isInitialized = true;
28
+ console.log("this.isInitialized:",this.isInitialized);
29
+ }
30
+
31
+
32
+ async getPlatform() {
33
+ return {
34
+ platform: 'Yuntu'
35
+ };
36
+ }
37
+
2
38
  async getLocation(options) {
3
- // 实现云途移动平台获取位置逻辑
4
- console.log('Yu n Tu: Getting location with options', options);
5
- // 这里应替换为云途移动平台API的实际调用
39
+ if (!this.isInitialized) {
40
+ await this.initializePlugin(); // 确保插件初始化
41
+ }
42
+
43
+ return new Promise((resolve, reject) => {
44
+
45
+ if (window.geolocation && typeof window.geolocation.getCurrentPosition === 'function') {
46
+ window.geolocation.getCurrentPosition(
47
+ (res) => {
48
+ console.log('YunTu: Location obtained', JSON.stringify(res));
49
+ resolve(res); // 成功获取位置
50
+ },
51
+ (err) => {
52
+ console.error('YunTu: Failed to obtain location', err);
53
+ reject(err); // 获取位置失败
54
+ },
55
+ options
56
+ );
57
+ } else {
58
+ const errorMessage = 'Geolocation is not initialized or not available';
59
+ console.error('YunTu:', errorMessage);
60
+ reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
61
+ }
62
+ });
63
+ }
64
+
65
+ async openLocation(options) {
66
+ if (!this.isInitialized) {
67
+ await this.initializePlugin(); // 确保插件初始化
68
+ }
69
+
70
+ return new Promise((resolve, reject) => {
71
+ if (window.geolocation && typeof window.geolocation.openLocation === 'function') {
72
+ console.log("1")
73
+ window.geolocation.openLocation(
74
+ (res) => {
75
+ console.log('YunTu: Open location success', res);
76
+ resolve(res); // 成功打开地图
77
+ },
78
+ (err) => {
79
+ console.error('YunTu: Failed to open location', err);
80
+ reject(err); // 打开地图失败
81
+ },
82
+ {
83
+ latitude: options.latitude,
84
+ longitude: options.longitude,
85
+ type: options.type || 'amap' // 默认为高德地图
86
+ }
87
+ );
88
+ } else {
89
+ const errorMessage = 'Geolocation is not initialized or not available';
90
+ console.error('YunTu:', errorMessage);
91
+ reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
92
+ }
93
+ });
6
94
  }
7
95
 
8
96
  async scanCode(options) {
9
- // 实现云途移动平台扫码逻辑
10
- console.log('YunTu: Scanning code with options', options);
11
- // 这里应替换为云途移动平台API的实际调用
97
+ if (!this.isInitialized) {
98
+ await this.initializePlugin(); // 确保插件初始化
99
+ }
100
+
101
+ return new Promise((resolve, reject) => {
102
+ if (window.scanCode && typeof window.scanCode.startScan === 'function') {
103
+ window.scanCode.startScan(
104
+ (res) => {
105
+ console.log('YunTu: Scan code success', res);
106
+ resolve(res); // 成功获取扫码结果
107
+ },
108
+ (err) => {
109
+ console.error('YunTu: Failed to scan code', err);
110
+ reject(err); // 扫码失败
111
+ },
112
+ options // 传递给扫码方法的选项
113
+ );
114
+ } else {
115
+ const errorMessage = 'ScanCode is not initialized or not available';
116
+ console.error('YunTu:', errorMessage);
117
+ reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
118
+ }
119
+ });
12
120
  }
13
121
 
122
+
14
123
  async takePhoto(options) {
15
- // 实现云途移动平台拍照或选择图片逻辑
16
124
  console.log('YunTu: Taking photo with options', options);
17
- // 这里应替换为云途移动平台API的实际调用
125
+
126
+ if (!this.isInitialized) {
127
+ await this.initializePlugin(); // 确保插件初始化
128
+ }
129
+
130
+ return new Promise((resolve, reject) => {
131
+ if (window.imagePicker) {
132
+ const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
133
+ const pickerFunction = window.imagePicker[sourceType];
134
+
135
+ if (typeof pickerFunction === 'function') {
136
+ pickerFunction(
137
+ (res) => {
138
+ console.log('YunTu: Photo selection success', res);
139
+ resolve(JSON.parse(res)); // 成功获取照片
140
+ },
141
+ (err) => {
142
+ console.error('YunTu: Failed to select photo', err);
143
+ reject(JSON.parse(err)); // 选择照片失败
144
+ },
145
+ options // 传递给选取照片方法的选项(如果有需要的话)
146
+ );
147
+ } else {
148
+ const errorMessage = `${sourceType} function is not available in ImagePicker`;
149
+ console.error('YunTu:', errorMessage);
150
+ reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
151
+ }
152
+ } else {
153
+ const errorMessage = 'ImagePicker is not initialized or not available';
154
+ console.error('YunTu:', errorMessage);
155
+ reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
156
+ }
157
+ });
18
158
  }
159
+
160
+
19
161
  }
20
162
 
21
- export default YunTuAdapter;
163
+ export default YunTuAdapter;
package/yuntu.js ADDED
@@ -0,0 +1,42 @@
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
+ }