添加无界模式初始化代码
This commit is contained in:
parent
e5b8380fe3
commit
2b60548fa9
|
@ -10,10 +10,11 @@ import { SessionStorage, Cookies, useQuasar, setCssVar } from "quasar";
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import EventBus, { EventNamesDefine } from "src/common/EventBus";
|
import EventBus, { EventNamesDefine } from "src/common/EventBus";
|
||||||
import { useStore } from "src/store";
|
import { IWuJieInterface, useStore } from "src/store";
|
||||||
import GlobalData from "./common/GlobalData";
|
import GlobalData from "./common/GlobalData";
|
||||||
import { EProductNames } from "./entities/ProductNames";
|
import { EProductNames } from "./entities/ProductNames";
|
||||||
import { api } from "./boot/axios";
|
import { api } from "./boot/axios";
|
||||||
|
import { WuJieInitializer } from "./common/WuJieInitializer";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "App",
|
name: "App",
|
||||||
|
@ -24,8 +25,9 @@ export default defineComponent({
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
|
||||||
if ((window as any).$wujie) {
|
if ((window as any).$wujie) {
|
||||||
const $wujie = (window as any).$wujie;
|
const $wujie = (window as any).$wujie as IWuJieInterface;
|
||||||
$store.commit("setWuJie", $wujie);
|
$store.commit("setWuJie", $wujie);
|
||||||
|
WuJieInitializer.initialize($wujie, $store, $q, $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.title = $t.t("title");
|
document.title = $t.t("title");
|
||||||
|
|
|
@ -18,7 +18,6 @@ import ClientConnectionCustom from "./ClientConnectionCustom";
|
||||||
import MagicWallConfig from "src/entities/MagicWallConfig";
|
import MagicWallConfig from "src/entities/MagicWallConfig";
|
||||||
import WuJieReconnectingWebSocket from "./WuJieReconnectingWebSocket";
|
import WuJieReconnectingWebSocket from "./WuJieReconnectingWebSocket";
|
||||||
|
|
||||||
|
|
||||||
class _RpcInfo {
|
class _RpcInfo {
|
||||||
send_timestamp: number;
|
send_timestamp: number;
|
||||||
timeout_timestamp: number;
|
timeout_timestamp: number;
|
||||||
|
@ -74,9 +73,7 @@ export default class ClientConnection {
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
}
|
}
|
||||||
let flag= !!$wujie;
|
if ($wujie) {
|
||||||
|
|
||||||
if(flag){
|
|
||||||
this.ws = new WuJieReconnectingWebSocket();
|
this.ws = new WuJieReconnectingWebSocket();
|
||||||
} else {
|
} else {
|
||||||
this.ws = new ReconnectingWebSocket(url);
|
this.ws = new ReconnectingWebSocket(url);
|
||||||
|
@ -85,7 +82,6 @@ export default class ClientConnection {
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.checkRpcTimeout();
|
this.checkRpcTimeout();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get is_connected() {
|
get is_connected() {
|
||||||
|
@ -715,6 +711,12 @@ export default class ClientConnection {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setConfigure(k: string, v: string) {
|
||||||
|
this.ws?.send(
|
||||||
|
JSON.stringify(new Protocol.SetApplicationConfigRequestEntity(0, k, v))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public setUserName(user_name: string) {
|
public setUserName(user_name: string) {
|
||||||
this.ws?.send(
|
this.ws?.send(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
|
@ -1405,13 +1407,9 @@ export default class ClientConnection {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async EnableBlending(
|
public async EnableBlending(enable: boolean) {
|
||||||
enable: boolean
|
|
||||||
) {
|
|
||||||
return await this.doRpc<Protocol.NoneResponse>(
|
return await this.doRpc<Protocol.NoneResponse>(
|
||||||
new Protocol.EnableBlendingRequestEntity(
|
new Protocol.EnableBlendingRequestEntity(enable)
|
||||||
enable
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
import GlobalData from "src/common/GlobalData";
|
||||||
|
import {
|
||||||
|
LocaleMessage,
|
||||||
|
DateTimeFormat,
|
||||||
|
NumberFormat,
|
||||||
|
} from "@intlify/core-base";
|
||||||
|
import { QVueGlobals } from "quasar";
|
||||||
|
import { Composer, VueMessageType } from "vue-i18n";
|
||||||
|
import { Store } from "vuex";
|
||||||
|
import { IWuJieInterface, StateInterface } from "./../store/index";
|
||||||
|
import EventBus, { EventNamesDefine } from "./EventBus";
|
||||||
|
import Initializer from "./Initializer";
|
||||||
|
import ClientConnection from "./ClientConnection";
|
||||||
|
|
||||||
|
export class WuJieInitializer {
|
||||||
|
public static initialize(
|
||||||
|
$wujie: IWuJieInterface,
|
||||||
|
$store: Store<StateInterface>,
|
||||||
|
$q: QVueGlobals,
|
||||||
|
$t: Composer<
|
||||||
|
{
|
||||||
|
[x: string]: LocaleMessage<VueMessageType>;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[x: string]: DateTimeFormat;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[x: string]: NumberFormat;
|
||||||
|
},
|
||||||
|
string,
|
||||||
|
string,
|
||||||
|
string
|
||||||
|
>
|
||||||
|
) {
|
||||||
|
if ($wujie) {
|
||||||
|
$wujie.bus.$on("initialize_app", (device_sn: string) => {
|
||||||
|
WuJieInitializer.onInitializeApp(device_sn, $wujie, $store, $q, $t);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static onInitializeApp(
|
||||||
|
device_sn: string,
|
||||||
|
$wujie: IWuJieInterface,
|
||||||
|
$store: Store<StateInterface>,
|
||||||
|
$q: QVueGlobals,
|
||||||
|
$t: Composer<
|
||||||
|
{
|
||||||
|
[x: string]: LocaleMessage<VueMessageType>;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[x: string]: DateTimeFormat;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[x: string]: NumberFormat;
|
||||||
|
},
|
||||||
|
string,
|
||||||
|
string,
|
||||||
|
string
|
||||||
|
>
|
||||||
|
) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const global_data = GlobalData.getInstance();
|
||||||
|
const client = global_data.getCurrentClient();
|
||||||
|
if (!client) {
|
||||||
|
const client_name = "WuJie@" + device_sn;
|
||||||
|
console.log(client_name);
|
||||||
|
global_data.addClient(client_name, new ClientConnection("", "", ""));
|
||||||
|
global_data.setCurrentClientName(client_name);
|
||||||
|
}
|
||||||
|
if (client) {
|
||||||
|
client._is_login = true;
|
||||||
|
}
|
||||||
|
new Initializer({
|
||||||
|
$t,
|
||||||
|
$store,
|
||||||
|
$q,
|
||||||
|
})
|
||||||
|
.initialize()
|
||||||
|
.then(() => {
|
||||||
|
$store.commit("setInitialized");
|
||||||
|
});
|
||||||
|
EventBus.getInstance().emit(EventNamesDefine.WebSocketConnected, this);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,6 +38,14 @@ export default route<StateInterface>(function (/* { store, ssrContext } */) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.beforeEach((to, from, next) => {
|
Router.beforeEach((to, from, next) => {
|
||||||
|
if ((<any>window).$wujie) {
|
||||||
|
if (to.path.endsWith("login")) {
|
||||||
|
next("/");
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
to.meta &&
|
to.meta &&
|
||||||
(to.meta.permission_level != null ||
|
(to.meta.permission_level != null ||
|
||||||
|
|
|
@ -39,19 +39,19 @@ export class CustomDefines {
|
||||||
function_mirroring_output = false;
|
function_mirroring_output = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWuJieEventBis {
|
export interface IWuJieEventBus {
|
||||||
$on(event: string, fn: Function): IWuJieEventBis;
|
$on(event: string, fn: Function): IWuJieEventBus;
|
||||||
/** 任何$emit都会导致监听函数触发,第一个参数为事件名,后续的参数为$emit的参数 */
|
/** 任何$emit都会导致监听函数触发,第一个参数为事件名,后续的参数为$emit的参数 */
|
||||||
$onAll(fn: (event: string, ...args: Array<any>) => any): IWuJieEventBis;
|
$onAll(fn: (event: string, ...args: Array<any>) => any): IWuJieEventBus;
|
||||||
$once(event: string, fn: Function): void;
|
$once(event: string, fn: Function): void;
|
||||||
$off(event: string, fn: Function): IWuJieEventBis;
|
$off(event: string, fn: Function): IWuJieEventBus;
|
||||||
$offAll(fn: Function): IWuJieEventBis;
|
$offAll(fn: Function): IWuJieEventBus;
|
||||||
$emit(event: string, ...args: Array<any>): IWuJieEventBis;
|
$emit(event: string, ...args: Array<any>): IWuJieEventBus;
|
||||||
$clear(): IWuJieEventBis;
|
$clear(): IWuJieEventBus;
|
||||||
}
|
}
|
||||||
export interface IWuJieInterface {
|
export interface IWuJieInterface {
|
||||||
props: any;
|
props: any;
|
||||||
bus: IWuJieEventBis;
|
bus: IWuJieEventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StateInterface {
|
export interface StateInterface {
|
||||||
|
|
Loading…
Reference in New Issue