@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.21 → 1.0.0-beta.22
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 +292 -277
- package/README.md +404 -318
- package/demo/index.vue +335 -261
- 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 +98 -90
- package/src/sdk/WeComAdapter.js +367 -367
- package/src/sdk/YunTuAdapter.js +369 -224
- package/src/sdk/yuntu.js +55 -55
package/src/sdk/YunTuAdapter.js
CHANGED
|
@@ -1,224 +1,369 @@
|
|
|
1
|
-
import './yuntu';
|
|
2
|
-
|
|
3
|
-
class YunTuAdapter {
|
|
4
|
-
constructor(options) {
|
|
5
|
-
// 标志插件是否已初始化
|
|
6
|
-
this.isInitialized = false;
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
1
|
+
import './yuntu';
|
|
2
|
+
|
|
3
|
+
class YunTuAdapter {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
// 标志插件是否已初始化
|
|
6
|
+
this.isInitialized = false;
|
|
7
|
+
this.audioUrl = null; // 录音文件的 URL
|
|
8
|
+
this.fileName = ''; // 录音文件名称
|
|
9
|
+
this.fileSize = 0; // 录音文件大小
|
|
10
|
+
this.fileType = ''; // 录音文件类型
|
|
11
|
+
this.errorMessage = ''; // 错误信息
|
|
12
|
+
this.recorder = null; // MediaRecorder 实例
|
|
13
|
+
this.streams = null; // 音频流
|
|
14
|
+
this.chunks = []; // 录音数据块
|
|
15
|
+
this.initializePlugin(options.pluginConfig);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async initializePlugin(pluginConfig) {
|
|
19
|
+
try {
|
|
20
|
+
const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
|
|
21
|
+
? JSON.stringify(pluginConfig)
|
|
22
|
+
: '["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
|
|
23
|
+
// eslint-disable-next-line no-undef
|
|
24
|
+
await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
|
|
25
|
+
this.isInitialized = true;
|
|
26
|
+
this.plugins = JSON.parse(configToUse);
|
|
27
|
+
console.log("Initialized plugins:", this.plugins);
|
|
28
|
+
return this.plugins;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("Plugin initialization failed:", error);
|
|
31
|
+
this.isInitialized = false;
|
|
32
|
+
return "Plugin initialization failed:" + error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 启动录音
|
|
37
|
+
async startRecording({
|
|
38
|
+
isAuto = false,
|
|
39
|
+
fftSize = 512,
|
|
40
|
+
fileName = '录音文件.ogg',
|
|
41
|
+
silenceThreshold = 20, // 静音检测的音量阈值
|
|
42
|
+
silenceDuration = 3000, // 超过多少秒静音就停止录音
|
|
43
|
+
silenceDelay = 1000 // 延迟多少秒开始静音检测
|
|
44
|
+
}) {
|
|
45
|
+
console.log("开始录音,模式:", isAuto ? "自动录音" : "普通录音");
|
|
46
|
+
this.errorMessage = ''; // 清空错误信息
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
50
|
+
console.log("成功获取麦克风权限,开始录音...");
|
|
51
|
+
this.streams = stream;
|
|
52
|
+
|
|
53
|
+
// 创建音频上下文
|
|
54
|
+
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
55
|
+
console.log("创建音频上下文:", this.audioContext);
|
|
56
|
+
|
|
57
|
+
// 创建音频分析器
|
|
58
|
+
this.analyser = this.audioContext.createAnalyser();
|
|
59
|
+
console.log("创建音频分析器:", this.analyser);
|
|
60
|
+
|
|
61
|
+
const microphone = this.audioContext.createMediaStreamSource(stream);
|
|
62
|
+
microphone.connect(this.analyser);
|
|
63
|
+
this.analyser.fftSize = fftSize;
|
|
64
|
+
console.log("音频分析器配置完成,FFT Size:", this.analyser.fftSize);
|
|
65
|
+
|
|
66
|
+
// 创建 MediaRecorder 实例
|
|
67
|
+
this.recorder = new MediaRecorder(stream);
|
|
68
|
+
console.log("创建 MediaRecorder 实例:", this.recorder);
|
|
69
|
+
|
|
70
|
+
// 监听数据可用事件
|
|
71
|
+
this.recorder.ondataavailable = (e) => {
|
|
72
|
+
console.log("收到录音数据块,大小:", e.data.size, "字节");
|
|
73
|
+
this.chunks.push(e.data);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 返回 Promise
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
// 监听录音停止事件
|
|
79
|
+
this.recorder.onstop = () => {
|
|
80
|
+
console.log("录音停止,生成音频文件...");
|
|
81
|
+
const blob = new Blob(this.chunks, { type: 'audio/ogg' });
|
|
82
|
+
this.audioUrl = URL.createObjectURL(blob); // 生成录音文件 URL
|
|
83
|
+
const file = new File([blob], fileName, { type: 'audio/ogg' });
|
|
84
|
+
this.fileName = file.name;
|
|
85
|
+
this.fileSize = file.size;
|
|
86
|
+
this.fileType = file.type;
|
|
87
|
+
console.log("生成的音频文件:", file);
|
|
88
|
+
|
|
89
|
+
// 返回包含音频 URL 和文件对象的对象
|
|
90
|
+
resolve({
|
|
91
|
+
audioUrl: this.audioUrl,
|
|
92
|
+
file: file
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// 启动静音检测
|
|
97
|
+
this.startSilenceDetection({
|
|
98
|
+
silenceThreshold,
|
|
99
|
+
silenceDuration,
|
|
100
|
+
silenceDelay
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// 开始录音
|
|
104
|
+
this.recorder.start();
|
|
105
|
+
console.log("录音已开始");
|
|
106
|
+
});
|
|
107
|
+
} catch (err) {
|
|
108
|
+
console.error("获取麦克风权限失败:", err);
|
|
109
|
+
this.errorMessage = "无法访问麦克风,请检查权限设置";
|
|
110
|
+
return Promise.reject(new Error(this.errorMessage)); // 返回错误
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 静音检测
|
|
115
|
+
startSilenceDetection({
|
|
116
|
+
silenceThreshold = 20, // 静音检测的音量阈值
|
|
117
|
+
silenceDuration = 3000, // 超过多少秒静音就停止录音
|
|
118
|
+
silenceDelay = 1000 // 延迟多少秒开始静音检测
|
|
119
|
+
}) {
|
|
120
|
+
console.log("启动静音检测...");
|
|
121
|
+
const bufferLength = this.analyser.frequencyBinCount;
|
|
122
|
+
const dataArray = new Uint8Array(bufferLength);
|
|
123
|
+
let silenceStart = Date.now();
|
|
124
|
+
let isSpeaking = false;
|
|
125
|
+
|
|
126
|
+
const checkVolume = () => {
|
|
127
|
+
this.analyser.getByteFrequencyData(dataArray);
|
|
128
|
+
const volume = Math.max(...dataArray);
|
|
129
|
+
console.debug("当前音量:", volume);
|
|
130
|
+
|
|
131
|
+
if (volume > silenceThreshold) { // 音量阈值
|
|
132
|
+
console.debug("检测到声音,重置静音计时器");
|
|
133
|
+
isSpeaking = true;
|
|
134
|
+
silenceStart = Date.now();
|
|
135
|
+
} else if (isSpeaking && Date.now() - silenceStart > silenceDuration) {
|
|
136
|
+
// 超过指定静音时长
|
|
137
|
+
console.log(`检测到持续 ${silenceDuration / 1000} 秒静音,停止录音`);
|
|
138
|
+
this.stopRecording();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (this.recorder && this.recorder.state === 'recording') {
|
|
143
|
+
requestAnimationFrame(checkVolume);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// 延迟开始静音检测
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
if (this.recorder && this.recorder.state === 'recording') {
|
|
150
|
+
console.log("静音检测正式开始");
|
|
151
|
+
requestAnimationFrame(checkVolume);
|
|
152
|
+
}
|
|
153
|
+
}, silenceDelay);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 停止录音
|
|
157
|
+
async stopRecording() {
|
|
158
|
+
console.log("停止录音...");
|
|
159
|
+
if (this.recorder && this.recorder.state === 'recording') {
|
|
160
|
+
this.recorder.stop();
|
|
161
|
+
console.log("录音已停止");
|
|
162
|
+
}
|
|
163
|
+
if (this.streams) {
|
|
164
|
+
this.streams.getTracks().forEach((track) => {
|
|
165
|
+
track.stop();
|
|
166
|
+
console.log("停止音频轨道:", track);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
this.chunks = []; // 清空录音数据块
|
|
170
|
+
this.audioContext.close();
|
|
171
|
+
console.log("音频上下文已关闭");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async getPlatform() {
|
|
175
|
+
return {
|
|
176
|
+
platform: 'Yuntu'
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async getLocation(options) {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
|
|
183
|
+
if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
|
|
184
|
+
window.top.geolocation.getCurrentPosition(
|
|
185
|
+
(res) => {
|
|
186
|
+
console.log('YunTu: Location obtained', JSON.stringify(res));
|
|
187
|
+
resolve(res); // 成功获取位置
|
|
188
|
+
},
|
|
189
|
+
(err) => {
|
|
190
|
+
console.error('YunTu: Failed to obtain location', err);
|
|
191
|
+
reject(err); // 获取位置失败
|
|
192
|
+
},
|
|
193
|
+
options
|
|
194
|
+
);
|
|
195
|
+
} else {
|
|
196
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
197
|
+
console.error('YunTu:', errorMessage);
|
|
198
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async openLocation(options) {
|
|
204
|
+
return new Promise((resolve, reject) => {
|
|
205
|
+
if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
|
|
206
|
+
console.log("1")
|
|
207
|
+
window.top.geolocation.openLocation(
|
|
208
|
+
(err) => {
|
|
209
|
+
console.error('YunTu: Failed to open location', err);
|
|
210
|
+
err.message=err.msg
|
|
211
|
+
reject(err); // 打开地图失败
|
|
212
|
+
},
|
|
213
|
+
JSON.stringify( {
|
|
214
|
+
latitude: options.latitude,
|
|
215
|
+
longitude: options.longitude,
|
|
216
|
+
type: options.type || 'amap' // 默认为高德地图
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
} else {
|
|
220
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
221
|
+
console.error('YunTu:', errorMessage);
|
|
222
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async initKey(options) {
|
|
228
|
+
return new Promise((resolve, reject) => {
|
|
229
|
+
if (window.top.geolocation && typeof window.top.geolocation.initKey === 'function') {
|
|
230
|
+
window.top.geolocation.initKey(function (msg) {
|
|
231
|
+
console.log('YunTu: initKey success', msg);
|
|
232
|
+
resolve(msg); //
|
|
233
|
+
}, JSON.stringify(options) );
|
|
234
|
+
} else {
|
|
235
|
+
const errorMessage = 'Geolocation is not initialized or not available';
|
|
236
|
+
console.error('YunTu:', errorMessage);
|
|
237
|
+
reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async scanCode(options) {
|
|
243
|
+
return new Promise((resolve, reject) => {
|
|
244
|
+
if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
|
|
245
|
+
window.top.scanCode.startScan(
|
|
246
|
+
(res) => {
|
|
247
|
+
console.log('YunTu: Scan code success', res);
|
|
248
|
+
resolve(res); // 成功获取扫码结果
|
|
249
|
+
},
|
|
250
|
+
(err) => {
|
|
251
|
+
console.error('YunTu: Failed to scan code', err);
|
|
252
|
+
reject(err); // 扫码失败
|
|
253
|
+
},
|
|
254
|
+
options // 传递给扫码方法的选项
|
|
255
|
+
);
|
|
256
|
+
} else {
|
|
257
|
+
const errorMessage = 'ScanCode is not initialized or not available';
|
|
258
|
+
console.error('YunTu:', errorMessage);
|
|
259
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async localAuthPlugin(options) {
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
266
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
|
|
267
|
+
window.top.localAuthPlugin.auth(
|
|
268
|
+
(res) => {
|
|
269
|
+
console.log('YunTu: local auth success', res);
|
|
270
|
+
resolve(res); // 成功获取认证结果
|
|
271
|
+
},
|
|
272
|
+
(err) => {
|
|
273
|
+
console.error('YunTu: Failed to local auth', err);
|
|
274
|
+
reject(err); // 认证失败
|
|
275
|
+
},
|
|
276
|
+
options // 传递给认证方法的选项
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
280
|
+
console.error('YunTu:', errorMessage);
|
|
281
|
+
reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async getAvailableBiometrics(options) {
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
|
|
289
|
+
window.top.localAuthPlugin.getAvailableBiometrics(
|
|
290
|
+
(res) => {
|
|
291
|
+
console.log('YunTu: Get Available Biometrics', res);
|
|
292
|
+
resolve(res); // 成功获取生物认证列表
|
|
293
|
+
},
|
|
294
|
+
(err) => {
|
|
295
|
+
console.error('YunTu: Failed Get Available Biometrics', err);
|
|
296
|
+
reject(err); // 获取生物认证列表失败
|
|
297
|
+
},
|
|
298
|
+
options // 传递给认证方法的选项
|
|
299
|
+
);
|
|
300
|
+
} else {
|
|
301
|
+
const errorMessage = 'local auth is not initialized or not available';
|
|
302
|
+
console.error('YunTu:', errorMessage);
|
|
303
|
+
reject(new Error(errorMessage));
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
async takePhoto(options) {
|
|
310
|
+
console.log('YunTu: Taking photo with options', options);
|
|
311
|
+
|
|
312
|
+
return new Promise((resolve, reject) => {
|
|
313
|
+
if (window.top.imagePicker) {
|
|
314
|
+
const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
|
|
315
|
+
const pickerFunction = window.top.imagePicker[sourceType];
|
|
316
|
+
options.type= options.outputType.includes("data")?1:0;
|
|
317
|
+
if (typeof pickerFunction === 'function') {
|
|
318
|
+
pickerFunction(
|
|
319
|
+
(res) => {
|
|
320
|
+
console.log('YunTu: Photo selection success', res);
|
|
321
|
+
resolve(res); // 成功获取照片
|
|
322
|
+
},
|
|
323
|
+
(err) => {
|
|
324
|
+
console.error('YunTu: Failed to select photo', err);
|
|
325
|
+
reject(err); // 选择照片失败
|
|
326
|
+
},
|
|
327
|
+
options // 传递给选取照片方法的选项(如果有需要的话)
|
|
328
|
+
);
|
|
329
|
+
} else {
|
|
330
|
+
const errorMessage = `${sourceType} function is not available in ImagePicker`;
|
|
331
|
+
console.error('YunTu:', errorMessage);
|
|
332
|
+
reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
const errorMessage = 'ImagePicker is not initialized or not available';
|
|
336
|
+
console.error('YunTu:', errorMessage);
|
|
337
|
+
reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
async filePreview(options) {
|
|
343
|
+
console.log('YunTu: File preview with options', options);
|
|
344
|
+
|
|
345
|
+
return new Promise((resolve, reject) => {
|
|
346
|
+
if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
|
|
347
|
+
window.top.filePreview.openFile(
|
|
348
|
+
(res) => {
|
|
349
|
+
console.log('YunTu: File preview success', res);
|
|
350
|
+
resolve(res); // Successfully previewed the file
|
|
351
|
+
},
|
|
352
|
+
(err) => {
|
|
353
|
+
console.error('YunTu: File preview failed', err);
|
|
354
|
+
reject(err); // Failed to preview the file
|
|
355
|
+
},
|
|
356
|
+
JSON.stringify(options) // Pass the options as a string
|
|
357
|
+
);
|
|
358
|
+
} else {
|
|
359
|
+
const errorMessage = 'FilePreview is not initialized or not available';
|
|
360
|
+
console.error('YunTu:', errorMessage);
|
|
361
|
+
reject(new Error(errorMessage)); // FilePreview interface is not available
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export default YunTuAdapter;
|