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

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,13 @@
1
1
  # Changelog
2
+ ## [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
+
4
+
5
+ ### ✨ Features | 新功能
6
+
7
+ * **@lambo-design-mobile/lambo-js-picker:** 修改云途 ([0d8dd53](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/0d8dd5347c349787a1705e0d83531677e34159b2))
8
+
9
+ ## [1.0.0-beta.3](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.2...@lambo-design-mobile/js-bridge@1.0.0-beta.3) (2024-08-22)
10
+
2
11
  ## [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
12
 
4
13
 
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.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -5,30 +5,63 @@ import coordtransform from "coordtransform";
5
5
  class YunTuAdapter {
6
6
  constructor() {
7
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);
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);
15
51
  });
16
52
  }
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));
53
+
54
+ // 直接调用初始化函数
55
+ this.initializePlugin();
23
56
  }
24
57
 
25
58
  async initializePlugin() {
26
59
  window.yuntu.config('["myPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin","appUpdatePlugin"]');
27
60
  this.isInitialized = true;
28
- console.log("this.isInitialized:",this.isInitialized);
61
+ console.log("this.isInitialized:", this.isInitialized);
29
62
  }
30
63
 
31
-
64
+ // 其余代码保持不变
32
65
  async getPlatform() {
33
66
  return {
34
67
  platform: 'Yuntu'