media_player_client/src/App.vue

208 lines
5.9 KiB
Vue
Raw Normal View History

2021-08-05 14:23:45 +08:00
<template>
2021-08-06 10:54:03 +08:00
<div class="fit">
<q-ajax-bar position="top" color="accent" size="5px" skip-hijack />
2022-04-15 15:39:45 +08:00
<q-menu context-menu />
2021-08-06 10:54:03 +08:00
<router-view />
</div>
2021-08-05 14:23:45 +08:00
</template>
<script lang="ts">
import { SessionStorage, Cookies, useQuasar, setCssVar } from "quasar";
2021-08-05 17:26:27 +08:00
import { defineComponent } from "vue";
import { useI18n } from "vue-i18n";
2021-08-06 10:54:03 +08:00
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { useStore } from "src/store";
import GlobalData from "./common/GlobalData";
import { EProductNames } from "./entities/ProductNames";
import { api } from "./boot/axios";
2021-08-05 14:23:45 +08:00
export default defineComponent({
2021-08-05 17:26:27 +08:00
name: "App",
2021-08-05 14:23:45 +08:00
setup() {
const $t = useI18n();
const $store = useStore();
const $q = useQuasar();
2022-04-15 16:53:00 +08:00
2021-08-05 17:26:27 +08:00
document.title = $t.t("title");
if (!navigator.cookieEnabled) {
$q.dialog({
title: $t.t("error"),
html: true,
message: `
<p>${$t.t(
"The client depends on the Cookie function. If cookies are not enabled in the current browser, the client cannot be used!"
)}</p>
<p> ${$t.t("Please refresh this page after cookies are enabled")} </p>
`,
persistent: true,
ok: false,
cancel: false,
});
}
// 设置产品
if (
!(
(<any>window).media_control_client_product ==
EProductNames.LED_PLAYER ||
(<any>window).media_control_client_product ==
EProductNames.SPECIAL_VIDEO
)
) {
console.error("can't get product, use default led_player");
(<any>window).media_control_client_product = EProductNames.LED_PLAYER;
}
console.log((<any>window).media_control_client_product);
$store.commit("setProductName", (<any>window).media_control_client_product);
// 设置标题
if (
(<any>window).media_control_client_product == EProductNames.LED_PLAYER
) {
document.title = $t.t("LedPlayer") + "WebApp";
} else if (
(<any>window).media_control_client_product == EProductNames.SPECIAL_VIDEO
) {
document.title = $t.t("SpecialVideo") + "WebApp";
}
// 设置 AXIOS 默认请求头
{
api.defaults.headers.common["X-Product-Name"] = (<any>(
window
)).media_control_client_product;
}
2022-06-14 17:58:27 +08:00
// 导入对应的quasar 语言包
try {
{
import("quasar/lang/" + $t.locale.value).then((lang) => {
$q.lang.set(lang.default);
});
}
} catch (e) {
console.log(e);
}
try {
const user_search = (<any>window).user_search || {};
if (typeof user_search == "object") {
$store.commit(
"setAvancedDebug",
typeof user_search["debug"] != "undefined"
);
$store.commit(
"setFactoryMode",
typeof user_search["factory"] != "undefined"
);
2022-06-15 11:15:32 +08:00
}
} catch (e) {
console.log(e);
2022-06-15 11:15:32 +08:00
}
2021-08-05 17:26:27 +08:00
window.onresize = (evt: any) =>
2021-08-06 10:54:03 +08:00
EventBus.getInstance().emit(EventNamesDefine.WindowResize, evt);
2021-08-09 15:05:14 +08:00
window.onmousedown = (evt: MouseEvent) => {
2022-01-25 11:34:07 +08:00
EventBus.getInstance().emit(EventNamesDefine.WindowMouseDown, evt);
};
window.onmousemove = (evt: any) => {
2022-01-25 11:34:07 +08:00
EventBus.getInstance().emit(EventNamesDefine.WindowMouseMove, evt);
};
window.onmouseup = (evt: any) => {
2022-01-25 11:34:07 +08:00
EventBus.getInstance().emit(EventNamesDefine.WindowMouseUp, evt);
};
window.onmouseout = (evt: any) => {
2022-01-25 11:34:07 +08:00
EventBus.getInstance().emit(EventNamesDefine.WindowMouseOut, evt);
};
2022-01-25 11:34:07 +08:00
window.document.body.onclick = (evt: any) => {
2022-04-15 15:39:45 +08:00
if ((<any>window).touchPriority) {
return;
}
EventBus.getInstance().emit(EventNamesDefine.DocumentBodyClick, evt);
};
2022-04-15 15:39:45 +08:00
if ("ontouchstart" in document.documentElement === true) {
window.document.body.ontouchstart = (evt: any) => {
if ((<any>window).touchPriority) {
EventBus.getInstance().emit(EventNamesDefine.DocumentBodyClick, evt);
}
};
}
2021-08-09 15:05:14 +08:00
document.body.classList.add("overflow-hidden");
2022-03-17 19:14:51 +08:00
(window as any).controlLogout = () => {
Cookies.remove("auto_login");
GlobalData.getInstance().getCurrentClient()?.destory();
GlobalData.getInstance().clearClients();
2022-03-17 19:14:51 +08:00
SessionStorage.clear();
try {
$q.fullscreen.exit();
} catch {}
2022-03-17 19:14:51 +08:00
window.location.reload();
};
(window as any).setPcTheme = () => {
setCssVar("primary", "#4aa1ce");
setCssVar("secondary", "#26a69a");
setCssVar("accent", "#9c27b0");
setCssVar("dark", "#1d1d1d");
setCssVar("positive", "#21ba45");
setCssVar("negative", "#c10015");
setCssVar("info", "#31ccec");
setCssVar("warning", "#f2c037");
setCssVar("dark-page", "#121212");
};
(window as any).setPadTheme = () => {
setCssVar("primary", "#0b3536");
setCssVar("secondary", "#ffffff");
setCssVar("accent", "#2fa39b");
setCssVar("dark", "#000000");
setCssVar("positive", "#21ba45");
setCssVar("negative", "#c10015");
setCssVar("info", "#31ccec");
setCssVar("warning", "#f2c037");
setCssVar("dark-page", "#121212");
};
const landspace = () => {
let landspace = false;
landspace = window.innerWidth > innerHeight;
if ($q.platform.is.ipad) {
landspace = window.screen.width > window.screen.height;
if (Math.abs(window.orientation) == 90) {
landspace = !landspace;
}
2022-07-04 14:20:00 +08:00
{
const user_search = (<any>window).user_search || {};
if (typeof user_search == "object") {
landspace = typeof user_search["___debug_ipad___"] != "undefined";
}
}
}
if (window.innerHeight < 600) {
// TODO fix android
}
return landspace;
};
(<any>window).landspace = landspace;
window.onorientationchange = () => {
$store.commit("updateLandspace", landspace());
};
$store.commit("updateLandspace", landspace());
2021-08-05 14:23:45 +08:00
return {};
},
});
</script>