[add] 接webview事件
This commit is contained in:
parent
d62047f183
commit
25ea4df6f8
@ -7,18 +7,53 @@ export default class Manager extends cc.Component {
|
|||||||
@property({ type: cc.WebView })
|
@property({ type: cc.WebView })
|
||||||
public webview: cc.WebView = null
|
public webview: cc.WebView = null
|
||||||
|
|
||||||
|
@property({ type: cc.Node })
|
||||||
|
public BG: cc.Node = null
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Lifecycle
|
//#region Lifecycle
|
||||||
|
|
||||||
protected onLoad(): void {
|
protected onLoad(): void {
|
||||||
this.webview.url = `https://karolchang.github.io/jm-expense-vue-ts/?ignore=${Date.now()}`;
|
let self: this = this;
|
||||||
|
window.addEventListener("message", function (e: MessageEvent<any>): void {
|
||||||
|
let data: any = e.data;
|
||||||
|
let method = data.method;
|
||||||
|
let value = data.value;
|
||||||
|
if (method && self[method]) {
|
||||||
|
if (value) {
|
||||||
|
self[method](...value);
|
||||||
|
return;
|
||||||
|
} else if (self[method]) {
|
||||||
|
self[method]();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`not function: ${method}, value: ${value}`);
|
||||||
|
}, false);
|
||||||
|
let href: string = window.location.href;
|
||||||
|
// window.open(`https://jianmiau.ml:3334/googletest?host=${href}`, "newwindow", "height=100,width=400");
|
||||||
|
|
||||||
|
// this.webview.url = `https://karolchang.github.io/jm-expense-vue-ts/?ignore=${Date.now()}`;
|
||||||
|
this.webview.url = `http://localhost:8080/jm-expense-vue-ts/?ignore=${Date.now()}&host=${href}`;
|
||||||
this.webview.node.active = true;
|
this.webview.node.active = true;
|
||||||
|
|
||||||
cc.view.setResizeCallback(this._resize.bind(this));
|
cc.view.setResizeCallback(this._resize.bind(this));
|
||||||
this._resize();
|
this._resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _closeBG(): void {
|
||||||
|
this.BG.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _log(msg: string): void {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _alert(msg: string): void {
|
||||||
|
alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
private _resize(): void {
|
private _resize(): void {
|
||||||
let Canvas: cc.Canvas = cc.Canvas.instance;
|
let Canvas: cc.Canvas = cc.Canvas.instance;
|
||||||
let rect: DOMRect = cc.game.canvas.getBoundingClientRect();
|
let rect: DOMRect = cc.game.canvas.getBoundingClientRect();
|
||||||
|
Loading…
Reference in New Issue
Block a user