@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.2 → 1.0.0-beta.21
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 +23 -23
- package/CHANGELOG.md +221 -0
- package/README.md +318 -238
- package/demo/index.vue +261 -223
- package/index.js +3 -3
- package/package.json +4 -2
- package/src/sdk/BdMapUtils.js +74 -0
- package/src/sdk/BrowserAdapter.js +63 -63
- package/src/sdk/CordovaAdapter.js +20 -20
- package/src/sdk/DingTalkAdapter.js +20 -20
- package/src/sdk/LamboJsBridge.js +90 -73
- package/src/sdk/MobileIMAdaoter.js +67 -0
- package/src/sdk/WeComAdapter.js +367 -301
- package/src/sdk/WechatAdapter.js +69 -34
- package/src/sdk/YunTuAdapter.js +224 -163
- package/src/sdk/yuntu.js +55 -0
- package/yuntu.js +0 -42
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) {
|
|
@@ -87,16 +88,14 @@ class WechatAdapter {
|
|
|
87
88
|
if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
|
|
88
89
|
return reject(new Error('Invalid location data'));
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// 根据坐标得到地址描述
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
});
|
|
91
|
+
// options.needAddress 是否需要地址信息
|
|
92
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
93
|
+
// // 根据坐标得到地址描述
|
|
94
|
+
// const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
|
|
95
|
+
// unifiedLocation.city = res.addressComponents.city
|
|
96
|
+
// unifiedLocation.province = res.addressComponents.province
|
|
97
|
+
// unifiedLocation.address = res.address
|
|
98
|
+
// }
|
|
100
99
|
|
|
101
100
|
resolve(unifiedLocation);
|
|
102
101
|
},
|
|
@@ -108,31 +107,67 @@ class WechatAdapter {
|
|
|
108
107
|
});
|
|
109
108
|
};
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
// 先判断是否需要地理位置 如不需要 直接返回坐标
|
|
111
|
+
if(options.needAddress) {
|
|
112
|
+
fetchLocation('gcj02'.then(unifiedLocation => {
|
|
113
|
+
const result = getAddressByType(unifiedLocation, locationType)
|
|
114
|
+
if(!result) {
|
|
115
|
+
return reject(new Error('Invalid location data'));
|
|
116
|
+
}
|
|
117
|
+
resolve(unifiedLocation);
|
|
118
|
+
}))
|
|
119
|
+
.catch(err => { reject(err) })
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
resolve(fetchLocation(locationType))
|
|
123
|
+
}
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
// // 先取gcj02 再根据type转成不同坐标系
|
|
126
|
+
// fetchLocation('gcj02').then(unifiedLocation => {
|
|
127
|
+
// // options.needAddress 是否需要地址信息
|
|
128
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
129
|
+
// const result = getAddressByType(unifiedLocation, locationType)
|
|
130
|
+
// if(!result) {
|
|
131
|
+
// return reject(new Error('Invalid location data'));
|
|
132
|
+
// }
|
|
133
|
+
// resolve(unifiedLocation);
|
|
134
|
+
// }
|
|
135
|
+
// else {
|
|
136
|
+
// const result = getAxisByType(unifiedLocation, locationType)
|
|
137
|
+
// if(!result) {
|
|
138
|
+
// return reject(new Error('Invalid location data'));
|
|
139
|
+
// }
|
|
140
|
+
// resolve(unifiedLocation);
|
|
141
|
+
// }
|
|
142
|
+
// }).catch(err => {
|
|
143
|
+
// reject(err);
|
|
144
|
+
// });
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
|
|
147
|
+
// if (locationType === 'bd09') {
|
|
148
|
+
// // 先获取 gcj02 坐标
|
|
149
|
+
// fetchLocation('gcj02').then(unifiedLocation => {
|
|
150
|
+
// // 将 gcj02 坐标转换为 bd09
|
|
151
|
+
// const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
|
|
152
|
+
// unifiedLocation.longitude = bd09Lng;
|
|
153
|
+
// unifiedLocation.latitude = bd09Lat;
|
|
154
|
+
// if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
|
|
155
|
+
// return reject(new Error('Invalid location data'));
|
|
156
|
+
// }
|
|
157
|
+
// // options.needAddress 是否需要地址信息
|
|
158
|
+
// if(options.needAddress && !unifiedLocation.address) {
|
|
159
|
+
// // 根据坐标得到地址描述
|
|
160
|
+
// const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
|
|
161
|
+
// unifiedLocation.city = res.addressComponents.city
|
|
162
|
+
// unifiedLocation.province = res.addressComponents.province
|
|
163
|
+
// unifiedLocation.address = res.address
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// resolve(unifiedLocation);
|
|
167
|
+
// }).catch(err => {
|
|
168
|
+
// reject(err);
|
|
169
|
+
// });
|
|
170
|
+
// }
|
|
136
171
|
});
|
|
137
172
|
});
|
|
138
173
|
}
|
package/src/sdk/YunTuAdapter.js
CHANGED
|
@@ -1,163 +1,224 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
import './yuntu';
|
|
2
|
+
|
|
3
|
+
class YunTuAdapter {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
// 标志插件是否已初始化
|
|
6
|
+
this.isInitialized = false;
|
|
7
|
+
this.initializePlugin(options.pluginConfig);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async initializePlugin(pluginConfig) {
|
|
11
|
+
try {
|
|
12
|
+
const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
|
|
13
|
+
? JSON.stringify(pluginConfig)
|
|
14
|
+
: '["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
|
|
15
|
+
// eslint-disable-next-line no-undef
|
|
16
|
+
await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
|
|
17
|
+
this.isInitialized = true;
|
|
18
|
+
this.plugins = JSON.parse(configToUse);
|
|
19
|
+
console.log("Initialized plugins:", this.plugins);
|
|
20
|
+
return this.plugins;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Plugin initialization failed:", error);
|
|
23
|
+
this.isInitialized = false;
|
|
24
|
+
return "Plugin initialization failed:" + error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 其余代码保持不变
|
|
29
|
+
async getPlatform() {
|
|
30
|
+
return {
|
|
31
|
+
platform: 'Yuntu'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getLocation(options) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
|
|
38
|
+
if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
|
|
39
|
+
window.top.geolocation.getCurrentPosition(
|
|
40
|
+
(res) => {
|
|
41
|
+
console.log('YunTu: Location obtained', JSON.stringify(res));
|
|
42
|
+
resolve(res); // 成功获取位置
|
|
43
|
+
},
|
|
44
|
+
(err) => {
|
|
45
|
+
console.error('YunTu: Failed to obtain location', err);
|
|
46
|
+
reject(err); // 获取位置失败
|
|
47
|
+
},
|
|
48
|
+
options
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
52
|
+
console.error('YunTu:', errorMessage);
|
|
53
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async openLocation(options) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
|
|
61
|
+
console.log("1")
|
|
62
|
+
window.top.geolocation.openLocation(
|
|
63
|
+
(err) => {
|
|
64
|
+
console.error('YunTu: Failed to open location', err);
|
|
65
|
+
err.message=err.msg
|
|
66
|
+
reject(err); // 打开地图失败
|
|
67
|
+
},
|
|
68
|
+
JSON.stringify( {
|
|
69
|
+
latitude: options.latitude,
|
|
70
|
+
longitude: options.longitude,
|
|
71
|
+
type: options.type || 'amap' // 默认为高德地图
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
76
|
+
console.error('YunTu:', errorMessage);
|
|
77
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async initKey(options) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
if (window.top.geolocation && typeof window.top.geolocation.initKey === 'function') {
|
|
85
|
+
window.top.geolocation.initKey(function (msg) {
|
|
86
|
+
console.log('YunTu: initKey success', msg);
|
|
87
|
+
resolve(msg); //
|
|
88
|
+
}, JSON.stringify(options) );
|
|
89
|
+
} else {
|
|
90
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
91
|
+
console.error('YunTu:', errorMessage);
|
|
92
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async scanCode(options) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
|
|
100
|
+
window.top.scanCode.startScan(
|
|
101
|
+
(res) => {
|
|
102
|
+
console.log('YunTu: Scan code success', res);
|
|
103
|
+
resolve(res); // 成功获取扫码结果
|
|
104
|
+
},
|
|
105
|
+
(err) => {
|
|
106
|
+
console.error('YunTu: Failed to scan code', err);
|
|
107
|
+
reject(err); // 扫码失败
|
|
108
|
+
},
|
|
109
|
+
options // 传递给扫码方法的选项
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
const errorMessage = 'ScanCode is not initialized or not available';
|
|
113
|
+
console.error('YunTu:', errorMessage);
|
|
114
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async localAuthPlugin(options) {
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
|
|
122
|
+
window.top.localAuthPlugin.auth(
|
|
123
|
+
(res) => {
|
|
124
|
+
console.log('YunTu: local auth success', res);
|
|
125
|
+
resolve(res); // 成功获取认证结果
|
|
126
|
+
},
|
|
127
|
+
(err) => {
|
|
128
|
+
console.error('YunTu: Failed to local auth', err);
|
|
129
|
+
reject(err); // 认证失败
|
|
130
|
+
},
|
|
131
|
+
options // 传递给认证方法的选项
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
135
|
+
console.error('YunTu:', errorMessage);
|
|
136
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async getAvailableBiometrics(options) {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
|
|
144
|
+
window.top.localAuthPlugin.getAvailableBiometrics(
|
|
145
|
+
(res) => {
|
|
146
|
+
console.log('YunTu: Get Available Biometrics', res);
|
|
147
|
+
resolve(res); // 成功获取生物认证列表
|
|
148
|
+
},
|
|
149
|
+
(err) => {
|
|
150
|
+
console.error('YunTu: Failed Get Available Biometrics', err);
|
|
151
|
+
reject(err); // 获取生物认证列表失败
|
|
152
|
+
},
|
|
153
|
+
options // 传递给认证方法的选项
|
|
154
|
+
);
|
|
155
|
+
} else {
|
|
156
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
157
|
+
console.error('YunTu:', errorMessage);
|
|
158
|
+
reject(new Error(errorMessage));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
async takePhoto(options) {
|
|
165
|
+
console.log('YunTu: Taking photo with options', options);
|
|
166
|
+
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
if (window.top.imagePicker) {
|
|
169
|
+
const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
|
|
170
|
+
const pickerFunction = window.top.imagePicker[sourceType];
|
|
171
|
+
options.type= options.outputType.includes("data")?1:0;
|
|
172
|
+
if (typeof pickerFunction === 'function') {
|
|
173
|
+
pickerFunction(
|
|
174
|
+
(res) => {
|
|
175
|
+
console.log('YunTu: Photo selection success', res);
|
|
176
|
+
resolve(res); // 成功获取照片
|
|
177
|
+
},
|
|
178
|
+
(err) => {
|
|
179
|
+
console.error('YunTu: Failed to select photo', err);
|
|
180
|
+
reject(err); // 选择照片失败
|
|
181
|
+
},
|
|
182
|
+
options // 传递给选取照片方法的选项(如果有需要的话)
|
|
183
|
+
);
|
|
184
|
+
} else {
|
|
185
|
+
const errorMessage = `${sourceType} function is not available in ImagePicker`;
|
|
186
|
+
console.error('YunTu:', errorMessage);
|
|
187
|
+
reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
const errorMessage = 'ImagePicker is not initialized or not available';
|
|
191
|
+
console.error('YunTu:', errorMessage);
|
|
192
|
+
reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
async filePreview(options) {
|
|
198
|
+
console.log('YunTu: File preview with options', options);
|
|
199
|
+
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
|
|
202
|
+
window.top.filePreview.openFile(
|
|
203
|
+
(res) => {
|
|
204
|
+
console.log('YunTu: File preview success', res);
|
|
205
|
+
resolve(res); // Successfully previewed the file
|
|
206
|
+
},
|
|
207
|
+
(err) => {
|
|
208
|
+
console.error('YunTu: File preview failed', err);
|
|
209
|
+
reject(err); // Failed to preview the file
|
|
210
|
+
},
|
|
211
|
+
JSON.stringify(options) // Pass the options as a string
|
|
212
|
+
);
|
|
213
|
+
} else {
|
|
214
|
+
const errorMessage = 'FilePreview is not initialized or not available';
|
|
215
|
+
console.error('YunTu:', errorMessage);
|
|
216
|
+
reject(new Error(errorMessage)); // FilePreview interface is not available
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export default YunTuAdapter;
|
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
|
-
}
|