添加无界模式初始化代码

This commit is contained in:
fangxiang 2023-01-18 17:32:02 +08:00
parent e5b8380fe3
commit 2b60548fa9
5 changed files with 117 additions and 23 deletions

View File

@ -10,10 +10,11 @@ import { SessionStorage, Cookies, useQuasar, setCssVar } from "quasar";
import { defineComponent } from "vue";
import { useI18n } from "vue-i18n";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { useStore } from "src/store";
import { IWuJieInterface, useStore } from "src/store";
import GlobalData from "./common/GlobalData";
import { EProductNames } from "./entities/ProductNames";
import { api } from "./boot/axios";
import { WuJieInitializer } from "./common/WuJieInitializer";
export default defineComponent({
name: "App",
@ -24,8 +25,9 @@ export default defineComponent({
const $q = useQuasar();
if ((window as any).$wujie) {
const $wujie = (window as any).$wujie;
const $wujie = (window as any).$wujie as IWuJieInterface;
$store.commit("setWuJie", $wujie);
WuJieInitializer.initialize($wujie, $store, $q, $t);
}
document.title = $t.t("title");

View File

@ -18,7 +18,6 @@ import ClientConnectionCustom from "./ClientConnectionCustom";
import MagicWallConfig from "src/entities/MagicWallConfig";
import WuJieReconnectingWebSocket from "./WuJieReconnectingWebSocket";
class _RpcInfo {
send_timestamp: number;
timeout_timestamp: number;
@ -47,7 +46,7 @@ class _RpcInfo {
}
export default class ClientConnection {
ws: ReconnectingWebSocket | null|WuJieReconnectingWebSocket = null;
ws: ReconnectingWebSocket | null | WuJieReconnectingWebSocket = null;
url = "";
user_name = "";
password = "";
@ -74,18 +73,15 @@ export default class ClientConnection {
if (this.ws) {
this.ws.close();
}
let flag= !!$wujie;
if(flag){
if ($wujie) {
this.ws = new WuJieReconnectingWebSocket();
}else{
} else {
this.ws = new ReconnectingWebSocket(url);
}
this.initializeWs();
setInterval(() => {
this.checkRpcTimeout();
}, 1000);
}
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) {
this.ws?.send(
JSON.stringify(
@ -1405,13 +1407,9 @@ export default class ClientConnection {
);
}
public async EnableBlending(
enable: boolean
) {
public async EnableBlending(enable: boolean) {
return await this.doRpc<Protocol.NoneResponse>(
new Protocol.EnableBlendingRequestEntity(
enable
)
new Protocol.EnableBlendingRequestEntity(enable)
);
}

View File

@ -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);
}
}

View File

@ -38,6 +38,14 @@ export default route<StateInterface>(function (/* { store, ssrContext } */) {
});
Router.beforeEach((to, from, next) => {
if ((<any>window).$wujie) {
if (to.path.endsWith("login")) {
next("/");
} else {
next();
}
return;
}
if (
to.meta &&
(to.meta.permission_level != null ||

View File

@ -39,19 +39,19 @@ export class CustomDefines {
function_mirroring_output = false;
}
export interface IWuJieEventBis {
$on(event: string, fn: Function): IWuJieEventBis;
export interface IWuJieEventBus {
$on(event: string, fn: Function): IWuJieEventBus;
/** 任何$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;
$off(event: string, fn: Function): IWuJieEventBis;
$offAll(fn: Function): IWuJieEventBis;
$emit(event: string, ...args: Array<any>): IWuJieEventBis;
$clear(): IWuJieEventBis;
$off(event: string, fn: Function): IWuJieEventBus;
$offAll(fn: Function): IWuJieEventBus;
$emit(event: string, ...args: Array<any>): IWuJieEventBus;
$clear(): IWuJieEventBus;
}
export interface IWuJieInterface {
props: any;
bus: IWuJieEventBis;
bus: IWuJieEventBus;
}
export interface StateInterface {