146 lines
3.9 KiB
Vue
146 lines
3.9 KiB
Vue
<template>
|
|
<main class="app">
|
|
<h1>Setup View</h1>
|
|
|
|
<h2>Setup</h2>
|
|
<div class="status-container">
|
|
<div class="status-frame setup-frame">
|
|
<div class="slider-item">
|
|
<div class="slider-header">
|
|
<span class="slider-label">Volume</span>
|
|
<span class="slider-value">{{ volume }}</span>
|
|
</div>
|
|
<input class="slider-input" type="range" min="0" max="100" step="1" v-model.number="volume"
|
|
@input="handleVolume" />
|
|
</div>
|
|
<div class="slider-item">
|
|
<div class="slider-header">
|
|
<span class="slider-label">Promo Delay</span>
|
|
<span class="slider-value">{{ promoDelay }}</span>
|
|
</div>
|
|
<input class="slider-input" type="range" min="30" max="300" step="1" v-model.number="promoDelay"
|
|
@input="handlePromoDelay" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h2>Sound</h2>
|
|
<div class="status-frame">
|
|
<div class="status-item" :class="{ active: soundStatus === 1 }">
|
|
<span class="status-label">Sound Active:</span>
|
|
<span class="status-value">{{ soundStatus }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="status-frame">
|
|
<div class="control-buttons">
|
|
<button @click="handleMute" class="btn-primary">Mute</button>
|
|
<button @click="handleUnMute" class="btn-secondary">Un-Mute</button>
|
|
</div>
|
|
</div>
|
|
|
|
<h2>Sword Status</h2>
|
|
<div class="status-container">
|
|
<div class="status-frame">
|
|
<div class="status-item" :class="{ active: endSensStatus === 1 }">
|
|
<span class="status-label">Sword Present:</span>
|
|
<span class="status-value">{{ endSensStatus }}</span>
|
|
</div>
|
|
<div class="status-item" :class="{ active: lockStatus === 1 }">
|
|
<span class="status-label">Lock Active:</span>
|
|
<span class="status-value">{{ lockStatus }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { enterMaintananceMode, exitMaintananceMode, publishCmd } from '../services/mqtt'
|
|
import { useRoute } from 'vue-router'
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
import type mqtt from 'mqtt'
|
|
|
|
const route = useRoute()
|
|
|
|
const version = ref<string>()
|
|
const endSensStatus = ref<number>(0)
|
|
const startSensStatus = ref<number>(0)
|
|
const pullSensStatus = ref<number>(0)
|
|
const lockStatus = ref<number>(0)
|
|
const soundStatus = ref<number>(0)
|
|
const volume = ref<number>(50)
|
|
const promoDelay = ref<number>(180)
|
|
|
|
let mqttClient: mqtt.MqttClient | null = null
|
|
|
|
function cleanup(): void {
|
|
if (mqttClient) {
|
|
exitMaintananceMode(mqttClient)
|
|
}
|
|
}
|
|
|
|
function handleMute(): void {
|
|
if (mqttClient) {
|
|
publishCmd(mqttClient, "mute")
|
|
}
|
|
}
|
|
|
|
function handleUnMute(): void {
|
|
if (mqttClient) {
|
|
publishCmd(mqttClient, "unmute")
|
|
}
|
|
}
|
|
|
|
function handleVolume(): void {
|
|
if (mqttClient) {
|
|
publishCmd(mqttClient, `volume:${volume.value}`)
|
|
}
|
|
}
|
|
|
|
function handlePromoDelay(): void {
|
|
if (mqttClient) {
|
|
publishCmd(mqttClient, `promoDelay:${promoDelay.value}`)
|
|
}
|
|
}
|
|
|
|
function handlePlayX(sound: number): void {
|
|
if (mqttClient) {
|
|
if (sound === 1) {
|
|
publishCmd(mqttClient, "playSound:Promo")
|
|
} else if (sound === 2) {
|
|
publishCmd(mqttClient, "playSound:Deny")
|
|
} else if (sound === 3) {
|
|
publishCmd(mqttClient, "playSound:Chosen")
|
|
}
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
mqttClient = enterMaintananceMode(
|
|
(sound, endSens, startSens, pullSens, lock, vol, delay) => {
|
|
endSensStatus.value = endSens
|
|
startSensStatus.value = startSens
|
|
pullSensStatus.value = pullSens
|
|
lockStatus.value = lock
|
|
soundStatus.value = sound
|
|
volume.value = vol
|
|
promoDelay.value = delay
|
|
},
|
|
(ver) => { })
|
|
window.addEventListener('beforeunload', cleanup)
|
|
if (mqttClient) {
|
|
publishCmd(mqttClient, `promoDelay:${promoDelay.value}`)
|
|
}
|
|
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener('beforeunload', cleanup)
|
|
cleanup()
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|