2024-04-13 09:53:41 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { onActivated, ref } from "vue";
|
|
|
|
import { NDialog } from "naive-ui";
|
|
|
|
import { useGlobalStore } from "../store/global";
|
2024-04-14 17:15:39 +08:00
|
|
|
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
2024-04-16 17:07:25 +08:00
|
|
|
import { initShortcuts, listenToKeyEvent, unlistenToKeyEvent } from "../hotkey";
|
2024-04-13 09:53:41 +08:00
|
|
|
|
|
|
|
const maskRef = ref<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
const store = useGlobalStore();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
let isShortcutInited = false;
|
|
|
|
|
2024-04-14 17:15:39 +08:00
|
|
|
onBeforeRouteLeave(() => {
|
|
|
|
if (isShortcutInited) {
|
|
|
|
if (maskRef.value) {
|
|
|
|
unlistenToKeyEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-04-13 09:53:41 +08:00
|
|
|
onActivated(async () => {
|
|
|
|
if (isShortcutInited) {
|
2024-04-14 17:15:39 +08:00
|
|
|
if (maskRef.value) {
|
|
|
|
listenToKeyEvent();
|
|
|
|
}
|
2024-04-13 09:53:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (store.controledDevice) {
|
|
|
|
if (maskRef.value) {
|
2024-04-16 17:07:25 +08:00
|
|
|
initShortcuts([store.screenSizeW, store.screenSizeH], maskRef.value);
|
2024-04-14 17:15:39 +08:00
|
|
|
listenToKeyEvent();
|
2024-04-13 09:53:41 +08:00
|
|
|
isShortcutInited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function toStartServer() {
|
|
|
|
router.replace({ name: "device" });
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO 按键设置
|
|
|
|
// TODO 渲染按钮
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div v-show="!store.controledDevice" class="notice">
|
|
|
|
<div class="content">
|
|
|
|
<NDialog
|
|
|
|
:closable="false"
|
|
|
|
title="未找到受控设备"
|
|
|
|
content="请启动服务端并控制任意设备"
|
|
|
|
positive-text="去启动"
|
|
|
|
type="warning"
|
|
|
|
@positive-click="toStartServer"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-show="store.controledDevice"
|
2024-04-14 17:15:39 +08:00
|
|
|
@contextmenu.prevent
|
2024-04-13 09:53:41 +08:00
|
|
|
class="mask"
|
|
|
|
ref="maskRef"
|
|
|
|
></div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.mask {
|
|
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
|
|
overflow: hidden;
|
2024-04-14 17:15:39 +08:00
|
|
|
cursor: pointer;
|
2024-04-13 09:53:41 +08:00
|
|
|
}
|
|
|
|
.notice {
|
|
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
.content {
|
|
|
|
width: 80%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|