Работа над LibsPage

This commit is contained in:
Book Pauk
2020-10-28 22:04:47 +07:00
parent 33961abd86
commit d7b24253fe
2 changed files with 60 additions and 6 deletions

View File

@@ -87,9 +87,44 @@ class ExternalLibs extends Vue {
mounted() { mounted() {
this.$refs.window.init(); this.$refs.window.init();
if (!this.frameSrc) if (!this.frameSrc)
this.frameSrc = this.libs.startLink; this.goToStartLink();
this.frameVisible = false;
this.frameVisible = true; this.opener = null;
const host = window.location.host;
const openerHost = (host.indexOf('b.') == 0 ? host.substring(2) : host);
const openerOrigin1 = `http://${openerHost}`;
const openerOrigin2 = `https://${openerHost}`;
window.addEventListener('message', (event) => {
if (event.origin != openerOrigin1 && event.origin != openerOrigin2)
return;
if (!_.isObject(event.data) || event.data.from != 'LibsPage')
return;
if (event.origin == openerOrigin1)
this.opener = window.opener;
else
this.opener = event.source;
this.openerOrigin = event.origin;
console.log(event);
this.recvMessage(event.data);
}, false);
}
recvMessage(d) {
if (d.type == 'mes') {
switch(d.data) {
case 'hello': this.sendMessage({type: 'mes', data: 'ready'}); break;
}
} else if (d.type == 'obj') {
//
}
}
sendMessage(d) {
if (this.opener && this.openerOrigin)
this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin);
} }
get libs() { get libs() {

View File

@@ -29,8 +29,13 @@ class LibsPage extends Vue {
} }
init() { init() {
this.popupWindow = window.open(`http://${window.location.host}/?p=external-libs#/external-libs`); const subdomain = (window.location.protocol != 'http:' ? 'b.' : '');
const origin = `http://${subdomain}${window.location.host}`;
this.popupWindow = window.open(`${origin}/?p=external-libs#/external-libs`);
if (this.popupWindow) { if (this.popupWindow) {
//Проверка закрытия окна //Проверка закрытия окна
(async() => { (async() => {
while(this.popupWindow) { while(this.popupWindow) {
@@ -39,9 +44,23 @@ class LibsPage extends Vue {
await utils.sleep(1000); await utils.sleep(1000);
} }
})(); })();
window.addEventListener('message', (event) => {
if (event.origin !== origin)
return;
console.log(event.data);
}, false);
(async() => {
while(this.popupWindow) {
this.popupWindow.postMessage({from: 'LibsPage', type: 'mes', data: 'hello'}, origin);
await utils.sleep(1000);
} }
})();
this.loadLibs(); this.loadLibs();
} }
}
done() { done() {
if (this.popupWindow) { if (this.popupWindow) {