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