|
|
@@ -350,14 +350,47 @@ export default {
|
|
|
// this.observeDialogUrl = `https://observe.cocorobo.cn/#/newClassroom?userid=${this.userid}&oid=${this.oid}&org=${this.org}&pptid=${pptid}`;
|
|
|
// this.showObserveDialog = true;
|
|
|
|
|
|
- let _pageWindow = window.open(`https://observe.cocorobo.cn/#/newClassroom?userid=${this.userid}&oid=${this.oid}&org=${this.org}&pptid=${pptid}`,'_blank')
|
|
|
- _pageWindow.onload = function(){
|
|
|
- console.log("页面已打开完毕")
|
|
|
- _pageWindow.postMessage({
|
|
|
- type: 'fileData',
|
|
|
- file: file
|
|
|
- }, '*');
|
|
|
- }
|
|
|
+ const url = `https://observe.cocorobo.cn/#/newClassroom?userid=${this.userid}&oid=${this.oid}&org=${this.org}&pptid=${pptid}`;
|
|
|
+ const _pageWindow = window.open(url, '_blank');
|
|
|
+ // 优化:等待新窗口加载完成后再传递消息,避免部分浏览器下页面未初始化无法接收消息的问题
|
|
|
+ const sendFileData = () => {
|
|
|
+ if (!_pageWindow) {
|
|
|
+ console.error("新窗口未成功打开!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ _pageWindow.postMessage(
|
|
|
+ {
|
|
|
+ type: 'fileData',
|
|
|
+ file,
|
|
|
+ },
|
|
|
+ '*'
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ // 轮询检测新窗口加载完成(避免跨域无法onload的情况)
|
|
|
+ let checkCount = 0;
|
|
|
+ const checkLoadedInterval = setInterval(() => {
|
|
|
+ if (_pageWindow.closed) {
|
|
|
+ clearInterval(checkLoadedInterval);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 有的情况下,如果页面已加载会有document.body等属性
|
|
|
+ if (_pageWindow.document && _pageWindow.document.readyState === 'complete') {
|
|
|
+ clearInterval(checkLoadedInterval);
|
|
|
+ sendFileData();
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ // 跨域时会报错,直接尝试发送
|
|
|
+ clearInterval(checkLoadedInterval);
|
|
|
+ sendFileData();
|
|
|
+ }
|
|
|
+ // 最多检测2秒(20次),防止死循环
|
|
|
+ if (++checkCount > 20) {
|
|
|
+ clearInterval(checkLoadedInterval);
|
|
|
+ sendFileData();
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
// setTimeout(()=>{
|
|
|
// window.focus()
|
|
|
// _pageWindow.focus()
|