@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.38 → 1.0.0-beta.39
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 +395 -388
- package/README.md +523 -523
- package/demo/index.vue +517 -517
- package/index.js +3 -3
- package/package.json +1 -1
- package/src/sdk/BrowserAdapter.js +63 -63
- package/src/sdk/CcworkAdapter.js +80 -80
- package/src/sdk/CordovaAdapter.js +20 -20
- package/src/sdk/DingTalkAdapter.js +20 -20
- package/src/sdk/LPAPI.js +1119 -1119
- package/src/sdk/LamboJsBridge.js +117 -117
- package/src/sdk/MobileIMAdapter.js +127 -127
- package/src/sdk/WeComAdapter.js +648 -576
- package/src/sdk/WechatAdapter.js +430 -342
- package/src/sdk/YunTuAdapter.js +316 -316
- package/src/sdk/yuntu.js +55 -55
package/src/sdk/YunTuAdapter.js
CHANGED
|
@@ -1,316 +1,316 @@
|
|
|
1
|
-
import './yuntu';
|
|
2
|
-
|
|
3
|
-
export const PRINTER_PLUGIN = "printerPlugin"
|
|
4
|
-
|
|
5
|
-
class YunTuAdapter {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
// 标志插件是否已初始化
|
|
8
|
-
this.isInitialized = false;
|
|
9
|
-
this.audioUrl = null; // 录音文件的 URL
|
|
10
|
-
this.fileName = ''; // 录音文件名称
|
|
11
|
-
this.fileType = ''; // 录音文件类型
|
|
12
|
-
this.initializePlugin(options.pluginConfig);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async initializePlugin(pluginConfig) {
|
|
16
|
-
try {
|
|
17
|
-
const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
|
|
18
|
-
? JSON.stringify(pluginConfig)
|
|
19
|
-
: '["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin","' + PRINTER_PLUGIN +'"]';
|
|
20
|
-
// eslint-disable-next-line no-undef
|
|
21
|
-
await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
|
|
22
|
-
this.isInitialized = true;
|
|
23
|
-
this.plugins = JSON.parse(configToUse);
|
|
24
|
-
console.log("Initialized plugins:", this.plugins);
|
|
25
|
-
return this.plugins;
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error("Plugin initialization failed:", error);
|
|
28
|
-
this.isInitialized = false;
|
|
29
|
-
return "Plugin initialization failed:" + error;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// 录音:开始录音(支持自动和手动模式)
|
|
34
|
-
async startRecording(options = { auto: false }) {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
if (window.autoRecord && typeof window.autoRecord.startRecording === 'function') {
|
|
37
|
-
window.autoRecord.startRecording(
|
|
38
|
-
(result) => {
|
|
39
|
-
console.log("录音开始:", result);
|
|
40
|
-
resolve(result);
|
|
41
|
-
},
|
|
42
|
-
(error) => {
|
|
43
|
-
console.error("录音错误:", error);
|
|
44
|
-
reject(error);
|
|
45
|
-
},
|
|
46
|
-
JSON.stringify(options) // 传入参数:{auto: false} 表示手动录音,{auto: true} 表示自动录音
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
reject(new Error("autoRecord 接口不可用"));
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 录音:结束录音,并返回录音结果
|
|
55
|
-
async stopRecording() {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
if (window.autoRecord && typeof window.autoRecord.stopRecording === 'function') {
|
|
58
|
-
window.autoRecord.stopRecording(
|
|
59
|
-
(result) => {
|
|
60
|
-
console.log("录音停止,返回结果:", result);
|
|
61
|
-
// 如果返回数据为字符串,则尝试解析为对象
|
|
62
|
-
try {
|
|
63
|
-
if (typeof result === "string") {
|
|
64
|
-
result = JSON.parse(result);
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error("JSON.parse error:", e);
|
|
68
|
-
}
|
|
69
|
-
resolve(result);
|
|
70
|
-
},
|
|
71
|
-
(error) => {
|
|
72
|
-
console.error("录音结束错误:", error);
|
|
73
|
-
// 同样尝试解析错误信息
|
|
74
|
-
try {
|
|
75
|
-
if (typeof error === "string") {
|
|
76
|
-
error = JSON.parse(error);
|
|
77
|
-
}
|
|
78
|
-
} catch (e) {
|
|
79
|
-
console.error("JSON.parse error:", e);
|
|
80
|
-
}
|
|
81
|
-
reject(error);
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
} else {
|
|
85
|
-
reject(new Error("autoRecord 接口不可用"));
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 新增下载文件接口,options 作为参数传入
|
|
91
|
-
async downloadFile(options) {
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
if (window.fileDownload && typeof window.fileDownload.downloadFile === 'function') {
|
|
94
|
-
window.fileDownload.downloadFile(
|
|
95
|
-
// 成功回调
|
|
96
|
-
(result) => {
|
|
97
|
-
console.log("文件下载成功:", result);
|
|
98
|
-
try {
|
|
99
|
-
if (typeof result === "string") {
|
|
100
|
-
result = JSON.parse(result);
|
|
101
|
-
}
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.error("JSON.parse error:", e);
|
|
104
|
-
}
|
|
105
|
-
resolve(result);
|
|
106
|
-
},
|
|
107
|
-
// 失败回调
|
|
108
|
-
(error) => {
|
|
109
|
-
console.error("文件下载失败:", error);
|
|
110
|
-
reject(error);
|
|
111
|
-
},
|
|
112
|
-
// 直接将传入的 options 对象转为字符串
|
|
113
|
-
JSON.stringify(options)
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
reject(new Error("downloadFile 接口不可用"));
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
async getPlatform() {
|
|
123
|
-
return {
|
|
124
|
-
platform: 'Yuntu'
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async getLocation(options) {
|
|
129
|
-
return new Promise((resolve, reject) => {
|
|
130
|
-
|
|
131
|
-
if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
|
|
132
|
-
window.top.geolocation.getCurrentPosition(
|
|
133
|
-
(res) => {
|
|
134
|
-
console.log('YunTu: Location obtained', JSON.stringify(res));
|
|
135
|
-
resolve(res); // 成功获取位置
|
|
136
|
-
},
|
|
137
|
-
(err) => {
|
|
138
|
-
console.error('YunTu: Failed to obtain location', err);
|
|
139
|
-
reject(err); // 获取位置失败
|
|
140
|
-
},
|
|
141
|
-
options
|
|
142
|
-
);
|
|
143
|
-
} else {
|
|
144
|
-
const errorMessage = 'Geolocation is not initialized or not available';
|
|
145
|
-
console.error('YunTu:', errorMessage);
|
|
146
|
-
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async openLocation(options) {
|
|
152
|
-
return new Promise((resolve, reject) => {
|
|
153
|
-
if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
|
|
154
|
-
console.log("1")
|
|
155
|
-
window.top.geolocation.openLocation(
|
|
156
|
-
(err) => {
|
|
157
|
-
console.error('YunTu: Failed to open location', err);
|
|
158
|
-
err.message=err.msg
|
|
159
|
-
reject(err); // 打开地图失败
|
|
160
|
-
},
|
|
161
|
-
JSON.stringify( {
|
|
162
|
-
latitude: options.latitude,
|
|
163
|
-
longitude: options.longitude,
|
|
164
|
-
type: options.type || 'amap' // 默认为高德地图
|
|
165
|
-
})
|
|
166
|
-
);
|
|
167
|
-
} else {
|
|
168
|
-
const errorMessage = 'Geolocation is not initialized or not available';
|
|
169
|
-
console.error('YunTu:', errorMessage);
|
|
170
|
-
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async initKey(options) {
|
|
176
|
-
return new Promise((resolve, reject) => {
|
|
177
|
-
if (window.top.geolocation && typeof window.top.geolocation.initKey === 'function') {
|
|
178
|
-
window.top.geolocation.initKey(function (msg) {
|
|
179
|
-
console.log('YunTu: initKey success', msg);
|
|
180
|
-
resolve(msg); //
|
|
181
|
-
}, JSON.stringify(options) );
|
|
182
|
-
} else {
|
|
183
|
-
const errorMessage = 'Geolocation is not initialized or not available';
|
|
184
|
-
console.error('YunTu:', errorMessage);
|
|
185
|
-
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async scanCode(options) {
|
|
191
|
-
return new Promise((resolve, reject) => {
|
|
192
|
-
if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
|
|
193
|
-
window.top.scanCode.startScan(
|
|
194
|
-
(res) => {
|
|
195
|
-
console.log('YunTu: Scan code success', res);
|
|
196
|
-
resolve(res); // 成功获取扫码结果
|
|
197
|
-
},
|
|
198
|
-
(err) => {
|
|
199
|
-
console.error('YunTu: Failed to scan code', err);
|
|
200
|
-
reject(err); // 扫码失败
|
|
201
|
-
},
|
|
202
|
-
options // 传递给扫码方法的选项
|
|
203
|
-
);
|
|
204
|
-
} else {
|
|
205
|
-
const errorMessage = 'ScanCode is not initialized or not available';
|
|
206
|
-
console.error('YunTu:', errorMessage);
|
|
207
|
-
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
async localAuthPlugin(options) {
|
|
213
|
-
return new Promise((resolve, reject) => {
|
|
214
|
-
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
|
|
215
|
-
window.top.localAuthPlugin.auth(
|
|
216
|
-
(res) => {
|
|
217
|
-
console.log('YunTu: local auth success', res);
|
|
218
|
-
resolve(res); // 成功获取认证结果
|
|
219
|
-
},
|
|
220
|
-
(err) => {
|
|
221
|
-
console.error('YunTu: Failed to local auth', err);
|
|
222
|
-
reject(err); // 认证失败
|
|
223
|
-
},
|
|
224
|
-
options // 传递给认证方法的选项
|
|
225
|
-
);
|
|
226
|
-
} else {
|
|
227
|
-
const errorMessage = 'local auth is not initialized or not available';
|
|
228
|
-
console.error('YunTu:', errorMessage);
|
|
229
|
-
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async getAvailableBiometrics(options) {
|
|
235
|
-
return new Promise((resolve, reject) => {
|
|
236
|
-
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
|
|
237
|
-
window.top.localAuthPlugin.getAvailableBiometrics(
|
|
238
|
-
(res) => {
|
|
239
|
-
console.log('YunTu: Get Available Biometrics', res);
|
|
240
|
-
resolve(res); // 成功获取生物认证列表
|
|
241
|
-
},
|
|
242
|
-
(err) => {
|
|
243
|
-
console.error('YunTu: Failed Get Available Biometrics', err);
|
|
244
|
-
reject(err); // 获取生物认证列表失败
|
|
245
|
-
},
|
|
246
|
-
options // 传递给认证方法的选项
|
|
247
|
-
);
|
|
248
|
-
} else {
|
|
249
|
-
const errorMessage = 'local auth is not initialized or not available';
|
|
250
|
-
console.error('YunTu:', errorMessage);
|
|
251
|
-
reject(new Error(errorMessage));
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
async takePhoto(options) {
|
|
258
|
-
console.log('YunTu: Taking photo with options', options);
|
|
259
|
-
|
|
260
|
-
return new Promise((resolve, reject) => {
|
|
261
|
-
if (window.top.imagePicker) {
|
|
262
|
-
const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
|
|
263
|
-
const pickerFunction = window.top.imagePicker[sourceType];
|
|
264
|
-
options.type= options.outputType.includes("data")?1:0;
|
|
265
|
-
if (typeof pickerFunction === 'function') {
|
|
266
|
-
pickerFunction(
|
|
267
|
-
(res) => {
|
|
268
|
-
console.log('YunTu: Photo selection success', res);
|
|
269
|
-
resolve(res); // 成功获取照片
|
|
270
|
-
},
|
|
271
|
-
(err) => {
|
|
272
|
-
console.error('YunTu: Failed to select photo', err);
|
|
273
|
-
reject(err); // 选择照片失败
|
|
274
|
-
},
|
|
275
|
-
options // 传递给选取照片方法的选项(如果有需要的话)
|
|
276
|
-
);
|
|
277
|
-
} else {
|
|
278
|
-
const errorMessage = `${sourceType} function is not available in ImagePicker`;
|
|
279
|
-
console.error('YunTu:', errorMessage);
|
|
280
|
-
reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
const errorMessage = 'ImagePicker is not initialized or not available';
|
|
284
|
-
console.error('YunTu:', errorMessage);
|
|
285
|
-
reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
async filePreview(options) {
|
|
291
|
-
console.log('YunTu: File preview with options', options);
|
|
292
|
-
|
|
293
|
-
return new Promise((resolve, reject) => {
|
|
294
|
-
if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
|
|
295
|
-
window.top.filePreview.openFile(
|
|
296
|
-
(res) => {
|
|
297
|
-
console.log('YunTu: File preview success', res);
|
|
298
|
-
resolve(res); // Successfully previewed the file
|
|
299
|
-
},
|
|
300
|
-
(err) => {
|
|
301
|
-
console.error('YunTu: File preview failed', err);
|
|
302
|
-
reject(err); // Failed to preview the file
|
|
303
|
-
},
|
|
304
|
-
JSON.stringify(options) // Pass the options as a string
|
|
305
|
-
);
|
|
306
|
-
} else {
|
|
307
|
-
const errorMessage = 'FilePreview is not initialized or not available';
|
|
308
|
-
console.error('YunTu:', errorMessage);
|
|
309
|
-
reject(new Error(errorMessage)); // FilePreview interface is not available
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export default YunTuAdapter;
|
|
1
|
+
import './yuntu';
|
|
2
|
+
|
|
3
|
+
export const PRINTER_PLUGIN = "printerPlugin"
|
|
4
|
+
|
|
5
|
+
class YunTuAdapter {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
// 标志插件是否已初始化
|
|
8
|
+
this.isInitialized = false;
|
|
9
|
+
this.audioUrl = null; // 录音文件的 URL
|
|
10
|
+
this.fileName = ''; // 录音文件名称
|
|
11
|
+
this.fileType = ''; // 录音文件类型
|
|
12
|
+
this.initializePlugin(options.pluginConfig);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async initializePlugin(pluginConfig) {
|
|
16
|
+
try {
|
|
17
|
+
const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
|
|
18
|
+
? JSON.stringify(pluginConfig)
|
|
19
|
+
: '["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin","' + PRINTER_PLUGIN +'"]';
|
|
20
|
+
// eslint-disable-next-line no-undef
|
|
21
|
+
await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
|
|
22
|
+
this.isInitialized = true;
|
|
23
|
+
this.plugins = JSON.parse(configToUse);
|
|
24
|
+
console.log("Initialized plugins:", this.plugins);
|
|
25
|
+
return this.plugins;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error("Plugin initialization failed:", error);
|
|
28
|
+
this.isInitialized = false;
|
|
29
|
+
return "Plugin initialization failed:" + error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 录音:开始录音(支持自动和手动模式)
|
|
34
|
+
async startRecording(options = { auto: false }) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
if (window.autoRecord && typeof window.autoRecord.startRecording === 'function') {
|
|
37
|
+
window.autoRecord.startRecording(
|
|
38
|
+
(result) => {
|
|
39
|
+
console.log("录音开始:", result);
|
|
40
|
+
resolve(result);
|
|
41
|
+
},
|
|
42
|
+
(error) => {
|
|
43
|
+
console.error("录音错误:", error);
|
|
44
|
+
reject(error);
|
|
45
|
+
},
|
|
46
|
+
JSON.stringify(options) // 传入参数:{auto: false} 表示手动录音,{auto: true} 表示自动录音
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
reject(new Error("autoRecord 接口不可用"));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 录音:结束录音,并返回录音结果
|
|
55
|
+
async stopRecording() {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
if (window.autoRecord && typeof window.autoRecord.stopRecording === 'function') {
|
|
58
|
+
window.autoRecord.stopRecording(
|
|
59
|
+
(result) => {
|
|
60
|
+
console.log("录音停止,返回结果:", result);
|
|
61
|
+
// 如果返回数据为字符串,则尝试解析为对象
|
|
62
|
+
try {
|
|
63
|
+
if (typeof result === "string") {
|
|
64
|
+
result = JSON.parse(result);
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("JSON.parse error:", e);
|
|
68
|
+
}
|
|
69
|
+
resolve(result);
|
|
70
|
+
},
|
|
71
|
+
(error) => {
|
|
72
|
+
console.error("录音结束错误:", error);
|
|
73
|
+
// 同样尝试解析错误信息
|
|
74
|
+
try {
|
|
75
|
+
if (typeof error === "string") {
|
|
76
|
+
error = JSON.parse(error);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error("JSON.parse error:", e);
|
|
80
|
+
}
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
reject(new Error("autoRecord 接口不可用"));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 新增下载文件接口,options 作为参数传入
|
|
91
|
+
async downloadFile(options) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
if (window.fileDownload && typeof window.fileDownload.downloadFile === 'function') {
|
|
94
|
+
window.fileDownload.downloadFile(
|
|
95
|
+
// 成功回调
|
|
96
|
+
(result) => {
|
|
97
|
+
console.log("文件下载成功:", result);
|
|
98
|
+
try {
|
|
99
|
+
if (typeof result === "string") {
|
|
100
|
+
result = JSON.parse(result);
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error("JSON.parse error:", e);
|
|
104
|
+
}
|
|
105
|
+
resolve(result);
|
|
106
|
+
},
|
|
107
|
+
// 失败回调
|
|
108
|
+
(error) => {
|
|
109
|
+
console.error("文件下载失败:", error);
|
|
110
|
+
reject(error);
|
|
111
|
+
},
|
|
112
|
+
// 直接将传入的 options 对象转为字符串
|
|
113
|
+
JSON.stringify(options)
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
reject(new Error("downloadFile 接口不可用"));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
async getPlatform() {
|
|
123
|
+
return {
|
|
124
|
+
platform: 'Yuntu'
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async getLocation(options) {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
|
|
131
|
+
if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
|
|
132
|
+
window.top.geolocation.getCurrentPosition(
|
|
133
|
+
(res) => {
|
|
134
|
+
console.log('YunTu: Location obtained', JSON.stringify(res));
|
|
135
|
+
resolve(res); // 成功获取位置
|
|
136
|
+
},
|
|
137
|
+
(err) => {
|
|
138
|
+
console.error('YunTu: Failed to obtain location', err);
|
|
139
|
+
reject(err); // 获取位置失败
|
|
140
|
+
},
|
|
141
|
+
options
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
145
|
+
console.error('YunTu:', errorMessage);
|
|
146
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async openLocation(options) {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
|
|
154
|
+
console.log("1")
|
|
155
|
+
window.top.geolocation.openLocation(
|
|
156
|
+
(err) => {
|
|
157
|
+
console.error('YunTu: Failed to open location', err);
|
|
158
|
+
err.message=err.msg
|
|
159
|
+
reject(err); // 打开地图失败
|
|
160
|
+
},
|
|
161
|
+
JSON.stringify( {
|
|
162
|
+
latitude: options.latitude,
|
|
163
|
+
longitude: options.longitude,
|
|
164
|
+
type: options.type || 'amap' // 默认为高德地图
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
169
|
+
console.error('YunTu:', errorMessage);
|
|
170
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async initKey(options) {
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
if (window.top.geolocation && typeof window.top.geolocation.initKey === 'function') {
|
|
178
|
+
window.top.geolocation.initKey(function (msg) {
|
|
179
|
+
console.log('YunTu: initKey success', msg);
|
|
180
|
+
resolve(msg); //
|
|
181
|
+
}, JSON.stringify(options) );
|
|
182
|
+
} else {
|
|
183
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
184
|
+
console.error('YunTu:', errorMessage);
|
|
185
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async scanCode(options) {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
|
|
193
|
+
window.top.scanCode.startScan(
|
|
194
|
+
(res) => {
|
|
195
|
+
console.log('YunTu: Scan code success', res);
|
|
196
|
+
resolve(res); // 成功获取扫码结果
|
|
197
|
+
},
|
|
198
|
+
(err) => {
|
|
199
|
+
console.error('YunTu: Failed to scan code', err);
|
|
200
|
+
reject(err); // 扫码失败
|
|
201
|
+
},
|
|
202
|
+
options // 传递给扫码方法的选项
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
const errorMessage = 'ScanCode is not initialized or not available';
|
|
206
|
+
console.error('YunTu:', errorMessage);
|
|
207
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async localAuthPlugin(options) {
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
|
|
215
|
+
window.top.localAuthPlugin.auth(
|
|
216
|
+
(res) => {
|
|
217
|
+
console.log('YunTu: local auth success', res);
|
|
218
|
+
resolve(res); // 成功获取认证结果
|
|
219
|
+
},
|
|
220
|
+
(err) => {
|
|
221
|
+
console.error('YunTu: Failed to local auth', err);
|
|
222
|
+
reject(err); // 认证失败
|
|
223
|
+
},
|
|
224
|
+
options // 传递给认证方法的选项
|
|
225
|
+
);
|
|
226
|
+
} else {
|
|
227
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
228
|
+
console.error('YunTu:', errorMessage);
|
|
229
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async getAvailableBiometrics(options) {
|
|
235
|
+
return new Promise((resolve, reject) => {
|
|
236
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
|
|
237
|
+
window.top.localAuthPlugin.getAvailableBiometrics(
|
|
238
|
+
(res) => {
|
|
239
|
+
console.log('YunTu: Get Available Biometrics', res);
|
|
240
|
+
resolve(res); // 成功获取生物认证列表
|
|
241
|
+
},
|
|
242
|
+
(err) => {
|
|
243
|
+
console.error('YunTu: Failed Get Available Biometrics', err);
|
|
244
|
+
reject(err); // 获取生物认证列表失败
|
|
245
|
+
},
|
|
246
|
+
options // 传递给认证方法的选项
|
|
247
|
+
);
|
|
248
|
+
} else {
|
|
249
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
250
|
+
console.error('YunTu:', errorMessage);
|
|
251
|
+
reject(new Error(errorMessage));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
async takePhoto(options) {
|
|
258
|
+
console.log('YunTu: Taking photo with options', options);
|
|
259
|
+
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
if (window.top.imagePicker) {
|
|
262
|
+
const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
|
|
263
|
+
const pickerFunction = window.top.imagePicker[sourceType];
|
|
264
|
+
options.type= options.outputType.includes("data")?1:0;
|
|
265
|
+
if (typeof pickerFunction === 'function') {
|
|
266
|
+
pickerFunction(
|
|
267
|
+
(res) => {
|
|
268
|
+
console.log('YunTu: Photo selection success', res);
|
|
269
|
+
resolve(res); // 成功获取照片
|
|
270
|
+
},
|
|
271
|
+
(err) => {
|
|
272
|
+
console.error('YunTu: Failed to select photo', err);
|
|
273
|
+
reject(err); // 选择照片失败
|
|
274
|
+
},
|
|
275
|
+
options // 传递给选取照片方法的选项(如果有需要的话)
|
|
276
|
+
);
|
|
277
|
+
} else {
|
|
278
|
+
const errorMessage = `${sourceType} function is not available in ImagePicker`;
|
|
279
|
+
console.error('YunTu:', errorMessage);
|
|
280
|
+
reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
const errorMessage = 'ImagePicker is not initialized or not available';
|
|
284
|
+
console.error('YunTu:', errorMessage);
|
|
285
|
+
reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
async filePreview(options) {
|
|
291
|
+
console.log('YunTu: File preview with options', options);
|
|
292
|
+
|
|
293
|
+
return new Promise((resolve, reject) => {
|
|
294
|
+
if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
|
|
295
|
+
window.top.filePreview.openFile(
|
|
296
|
+
(res) => {
|
|
297
|
+
console.log('YunTu: File preview success', res);
|
|
298
|
+
resolve(res); // Successfully previewed the file
|
|
299
|
+
},
|
|
300
|
+
(err) => {
|
|
301
|
+
console.error('YunTu: File preview failed', err);
|
|
302
|
+
reject(err); // Failed to preview the file
|
|
303
|
+
},
|
|
304
|
+
JSON.stringify(options) // Pass the options as a string
|
|
305
|
+
);
|
|
306
|
+
} else {
|
|
307
|
+
const errorMessage = 'FilePreview is not initialized or not available';
|
|
308
|
+
console.error('YunTu:', errorMessage);
|
|
309
|
+
reject(new Error(errorMessage)); // FilePreview interface is not available
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export default YunTuAdapter;
|