[add] EventBus使用 雙向溝通

This commit is contained in:
建喵 2022-08-01 17:12:37 +08:00
parent cf95786b9c
commit 7d4efe136f
9 changed files with 103927 additions and 134 deletions

View File

@ -21,21 +21,28 @@ export default class HelloWorld extends cc.Component {
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// protected onLoad() {} protected onLoad() {
let self = this;
this.Label.string = this.Text;
window["eventBus"].on('SendContent', (content: string) => {
self.Label.string = content;
})
}
public onClickBtn() { public onClickBtn() {
let url: string = window.location.search; window["eventBus"].emit("Alert", "hello");
let URLscheme: any[] = []; // let url: string = window.location.search;
if (url.indexOf("?") !== -1) { // let URLscheme: any[] = [];
let str = url.substring(1); // if (url.indexOf("?") !== -1) {
let strs = str.split("&"); // let str = url.substring(1);
for (let i = 0; i < strs.length; i++) { // let strs = str.split("&");
URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); // for (let i = 0; i < strs.length; i++) {
} // URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
} // }
if (URLscheme["host"]) { // }
opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]); // if (URLscheme["host"]) {
window.close(); // opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
} // window.close();
// }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,9 +7,13 @@
<link href="./src/assets/ZenMaruGothic-Regular.ttf" rel="stylesheet"> <link href="./src/assets/ZenMaruGothic-Regular.ttf" rel="stylesheet">
<!-- <link href="https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic&display=swap" rel="stylesheet"> --> <!-- <link href="https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic&display=swap" rel="stylesheet"> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BJ_ServerState</title> <title>cocos-vue-demo</title>
<script type="module" crossorigin src="./assets/index.12a12ee9.js"></script> <script src="./static/js/EventBus.js" charset="utf-8"></script>
<link rel="stylesheet" href="./assets/index.b312efde.css"> <script src="./static/cocos-build/web-mobile/src/settings.js"></script>
<script src="./static/cocos-build/web-mobile/cocos2d-js.js"></script>
<!-- <script src="./static/cocos-build/web-mobile/main.js"></script> -->
<script type="module" crossorigin src="./assets/index.a0e31fb5.js"></script>
<link rel="stylesheet" href="./assets/index.2f5031fd.css">
</head> </head>
<body> <body>

View File

@ -5,17 +5,20 @@ import 'vue-loading-overlay/dist/vue-loading.css';
import GameCanvas from './components/GameCanvas.vue'; import GameCanvas from './components/GameCanvas.vue';
import Popup from './components/Popup.vue'; import Popup from './components/Popup.vue';
const visible = ref(false) const PopupVisible = ref(false)
const self = {
PopupVisible: PopupVisible
};
window["eventBus"].on('alert', (msg: string) => { window["eventBus"].on('Alert', (msg: string) => {
visible.value = true; PopupVisible.value = true;
}) })
</script> </script>
<template> <template>
<GameCanvas /> <GameCanvas />
<el-dialog v-model="visible" :show-close="false"> <el-dialog v-model="PopupVisible" :show-close="false">
<Popup /> <Popup :APP="self" />
</el-dialog> </el-dialog>
</template> </template>

View File

@ -2,10 +2,17 @@
import { ref } from 'vue'; import { ref } from 'vue';
import 'vue-loading-overlay/dist/vue-loading.css'; import 'vue-loading-overlay/dist/vue-loading.css';
const props = defineProps<{ APP: any }>()
const input = ref('') const input = ref('')
function Send(content: string) {
window["eventBus"].emit("SendContent", content);
props.APP.PopupVisible.value = false;
}
</script> </script>
<template> <template>
<el-input v-model="input" placeholder="Please input A" /> <el-input v-model="input" placeholder="Please input Label" />
<el-input v-model="input" placeholder="Please input B" /> <el-button type="primary" @click.native="() => { Send(input) }" size="large" round>確定
</el-button>
</template> </template>

View File

@ -1,98 +1,89 @@
window.__require = function e(t, n, r) { window.__require = function e(t, n, r) {
function s(o, u) { function s(o, u) {
if (!n[o]) { if (!n[o]) {
if (!t[o]) { if (!t[o]) {
var b = o.split("/"); var b = o.split("/");
b = b[b.length - 1]; b = b[b.length - 1];
if (!t[b]) { if (!t[b]) {
var a = "function" == typeof __require && __require; var a = "function" == typeof __require && __require;
if (!u && a) return a(b, !0); if (!u && a) return a(b, !0);
if (i) return i(b, !0); if (i) return i(b, !0);
throw new Error("Cannot find module '" + o + "'"); throw new Error("Cannot find module '" + o + "'");
} }
o = b; o = b;
} }
var f = n[o] = { var f = n[o] = {
exports: {} exports: {}
}; };
t[o][0].call(f.exports, function (e) { t[o][0].call(f.exports, function(e) {
var n = t[o][1][e]; var n = t[o][1][e];
return s(n || e); return s(n || e);
}, f, f.exports, e, t, n, r); }, f, f.exports, e, t, n, r);
} }
return n[o].exports; return n[o].exports;
} }
var i = "function" == typeof __require && __require; var i = "function" == typeof __require && __require;
for (var o = 0; o < r.length; o++) s(r[o]); for (var o = 0; o < r.length; o++) s(r[o]);
return s; return s;
}({ }({
HelloWorld: [function (require, module, exports) { HelloWorld: [ function(require, module, exports) {
"use strict"; "use strict";
cc._RF.push(module, "fdc7afxuBxOA7RfBuV+NSmm", "HelloWorld"); cc._RF.push(module, "fdc7afxuBxOA7RfBuV+NSmm", "HelloWorld");
"use strict"; "use strict";
var __extends = this && this.__extends || function () { var __extends = this && this.__extends || function() {
var extendStatics = function (d, b) { var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf || { extendStatics = Object.setPrototypeOf || {
__proto__: [] __proto__: []
} instanceof Array && function (d, b) { } instanceof Array && function(d, b) {
d.__proto__ = b; d.__proto__ = b;
} || function (d, b) { } || function(d, b) {
for (var p in b) Object.prototype.hasOwnProperty.call(b, p) && (d[p] = b[p]); for (var p in b) Object.prototype.hasOwnProperty.call(b, p) && (d[p] = b[p]);
}; };
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function(d, b) {
extendStatics(d, b); extendStatics(d, b);
function __() { function __() {
this.constructor = d; this.constructor = d;
} }
d.prototype = null === b ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = null === b ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
}(); }();
var __decorate = this && this.__decorate || function (decorators, target, key, desc) { var __decorate = this && this.__decorate || function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if ("object" === typeof Reflect && "function" === typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r); if ("object" === typeof Reflect && "function" === typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
return c > 3 && r && Object.defineProperty(target, key, r), r; return c > 3 && r && Object.defineProperty(target, key, r), r;
}; };
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var HelloWorld = function (_super) { var HelloWorld = function(_super) {
__extends(HelloWorld, _super); __extends(HelloWorld, _super);
function HelloWorld() { function HelloWorld() {
var _this = null !== _super && _super.apply(this, arguments) || this; var _this = null !== _super && _super.apply(this, arguments) || this;
_this.Label = null; _this.Label = null;
_this.Text = "hello"; _this.Text = "hello";
_this.Btn = null; _this.Btn = null;
return _this; return _this;
} }
HelloWorld.prototype.onClickBtn = function () { HelloWorld.prototype.onLoad = function() {
var url = window.location.search; var self = this;
var URLscheme = []; this.Label.string = this.Text;
if (-1 !== url.indexOf("?")) { window["eventBus"].on("SendContent", function(content) {
var str = url.substring(1); self.Label.string = content;
var strs = str.split("&"); });
for (var i = 0; i < strs.length; i++) URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); };
} HelloWorld.prototype.onClickBtn = function() {
// if (URLscheme["host"]) { window["eventBus"].emit("Alert", "hello");
if (window.location.host) { };
// null === opener || void 0 === opener ? void 0 : opener.window.parent.postMessage({ __decorate([ property(cc.Label) ], HelloWorld.prototype, "Label", void 0);
// window.frames.postMessage({ __decorate([ property ], HelloWorld.prototype, "Text", void 0);
// data: "hello" __decorate([ property(cc.Button) ], HelloWorld.prototype, "Btn", void 0);
// }, window.location.host); HelloWorld = __decorate([ ccclass ], HelloWorld);
// window.close(); return HelloWorld;
window.eventBus.emit("alert", "hello"); }(cc.Component);
return; exports.default = HelloWorld;
} cc._RF.pop();
}; }, {} ]
__decorate([property(cc.Label)], HelloWorld.prototype, "Label", void 0); }, {}, [ "HelloWorld" ]);
__decorate([property], HelloWorld.prototype, "Text", void 0);
__decorate([property(cc.Button)], HelloWorld.prototype, "Btn", void 0);
HelloWorld = __decorate([ccclass], HelloWorld);
return HelloWorld;
}(cc.Component);
exports.default = HelloWorld;
cc._RF.pop();
}, {}]
}, {}, ["HelloWorld"]);